@woosh/meep-engine 3.12.0 → 3.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (301) hide show
  1. package/package.json +1 -1
  2. package/src/core/geom/3d/shape/ConvexHullShape3D.d.ts.map +1 -1
  3. package/src/core/geom/3d/shape/ConvexHullShape3D.js +41 -25
  4. package/src/core/geom/3d/shape/PosedShape3D.d.ts.map +1 -1
  5. package/src/core/geom/3d/shape/PosedShape3D.js +7 -2
  6. package/src/engine/graphics3/decal/GPUDecalRenderer.js +3 -3
  7. package/src/engine/graphics3/decal/shader_decal_composite.d.ts.map +1 -1
  8. package/src/engine/graphics3/decal/shader_decal_composite.js +4 -2
  9. package/src/engine/graphics3/highlight/GPUHighlightRenderer.d.ts.map +1 -1
  10. package/src/engine/graphics3/highlight/GPUHighlightRenderer.js +2 -3
  11. package/src/engine/graphics3/highlight/shader_highlight_outline.js +150 -150
  12. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  13. package/src/shade/RENDERER_CONTRACT.md +2 -1
  14. package/src/shade/descriptor/pipeline/compute/ComputePipelineDescriptor.d.ts +18 -0
  15. package/src/shade/descriptor/pipeline/compute/ComputePipelineDescriptor.d.ts.map +1 -1
  16. package/src/shade/descriptor/pipeline/compute/ComputePipelineDescriptor.js +73 -0
  17. package/src/shade/device/PASS_ENCODER_PROPOSAL_2026_08_31.md +755 -0
  18. package/src/shade/device/ShadeGPUCommandContext.d.ts +10 -16
  19. package/src/shade/device/ShadeGPUCommandContext.d.ts.map +1 -1
  20. package/src/shade/device/ShadeGPUCommandContext.js +801 -994
  21. package/src/shade/device/pass/ShadeGPUComputePassEncoder.d.ts +107 -0
  22. package/src/shade/device/pass/ShadeGPUComputePassEncoder.d.ts.map +1 -0
  23. package/src/shade/device/pass/ShadeGPUComputePassEncoder.js +222 -0
  24. package/src/shade/device/pass/ShadeGPURenderPassEncoder.d.ts +168 -0
  25. package/src/shade/device/pass/ShadeGPURenderPassEncoder.d.ts.map +1 -0
  26. package/src/shade/device/pass/ShadeGPURenderPassEncoder.js +317 -0
  27. package/src/shade/device/timing/GPUTimerArray.d.ts +4 -9
  28. package/src/shade/device/timing/GPUTimerArray.d.ts.map +1 -1
  29. package/src/shade/device/timing/GPUTimerArray.js +261 -289
  30. package/src/shade/device/timing/GPU_PROFILER_PROPOSAL_2026_08_28.md +20 -2
  31. package/src/shade/device/timing/ShadeGPUContextProfiler.d.ts +59 -0
  32. package/src/shade/device/timing/ShadeGPUContextProfiler.d.ts.map +1 -0
  33. package/src/shade/device/timing/ShadeGPUContextProfiler.js +182 -0
  34. package/src/shade/device/timing/profile/GPUProfileSession.d.ts +4 -4
  35. package/src/shade/device/timing/profile/GPUProfileSession.js +4 -4
  36. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_leaf_triangles.d.ts.map +1 -1
  37. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_leaf_triangles.js +3 -1
  38. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_points.d.ts.map +1 -1
  39. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_points.js +3 -1
  40. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_visibility.d.ts.map +1 -1
  41. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_visibility.js +3 -1
  42. package/src/shade/playground/skinned_blas_refit/verify_leaf_triangles.js +2 -2
  43. package/src/shade/playground/skinned_blas_refit/verify_traversal_reachability.js +2 -2
  44. package/src/shade/renderer/Renderer.d.ts +0 -6
  45. package/src/shade/renderer/Renderer.d.ts.map +1 -1
  46. package/src/shade/renderer/Renderer.js +0 -29
  47. package/src/shade/renderer/animation/GPUAnimationManager.d.ts.map +1 -1
  48. package/src/shade/renderer/animation/GPUAnimationManager.js +1 -3
  49. package/src/shade/renderer/animation/shader_animation_tick.d.ts.map +1 -1
  50. package/src/shade/renderer/animation/shader_animation_tick.js +128 -125
  51. package/src/shade/renderer/animation/skinning/GPUMeshSkinningContext.d.ts.map +1 -1
  52. package/src/shade/renderer/animation/skinning/GPUMeshSkinningContext.js +8 -18
  53. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_geometry_sphere_derive.d.ts.map +1 -1
  54. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_geometry_sphere_derive.js +100 -98
  55. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_meshlet_bounds_reduce.d.ts.map +1 -1
  56. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_meshlet_bounds_reduce.js +215 -212
  57. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_meshlet_bounds_scatter.d.ts +1 -1
  58. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_meshlet_bounds_scatter.d.ts.map +1 -1
  59. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_meshlet_bounds_scatter.js +135 -120
  60. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_skinned_mesh_bounds_refresh.d.ts.map +1 -1
  61. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_skinned_mesh_bounds_refresh.js +77 -75
  62. package/src/shade/renderer/animation/skinning/shader_meshlet_apply_skinning.d.ts.map +1 -1
  63. package/src/shade/renderer/animation/skinning/shader_meshlet_apply_skinning.js +375 -371
  64. package/src/shade/renderer/atmosphere/shader_transmittance_lut.js +3 -3
  65. package/src/shade/renderer/buffer/graph_inspect_gpu_buffer.js +1 -1
  66. package/src/shade/renderer/buffer/table/GPUDatabase.d.ts.map +1 -1
  67. package/src/shade/renderer/buffer/table/GPUDatabase.js +14 -19
  68. package/src/shade/renderer/buffer/table/gpu_table_element_upload_shader.d.ts.map +1 -1
  69. package/src/shade/renderer/buffer/table/gpu_table_element_upload_shader.js +7 -2
  70. package/src/shade/renderer/buffer/table/single/GPUSingleTypeTable.d.ts.map +1 -1
  71. package/src/shade/renderer/buffer/table/single/GPUSingleTypeTable.js +325 -319
  72. package/src/shade/renderer/buffer/util/shader_buffer_copy_storage_to_storage.d.ts.map +1 -1
  73. package/src/shade/renderer/buffer/util/shader_buffer_copy_storage_to_storage.js +3 -1
  74. package/src/shade/renderer/deferred/shader_tonemap_HDR.d.ts.map +1 -1
  75. package/src/shade/renderer/deferred/shader_tonemap_HDR.js +4 -1
  76. package/src/shade/renderer/dynamic/GPUDynamicMeshResidency.d.ts +2 -2
  77. package/src/shade/renderer/dynamic/GPUDynamicMeshResidency.d.ts.map +1 -1
  78. package/src/shade/renderer/dynamic/GPUDynamicMeshResidency.js +167 -167
  79. package/src/shade/renderer/fow/GPUFogOfWarRenderer.js +3 -3
  80. package/src/shade/renderer/fow/shader_fog_of_war.d.ts.map +1 -1
  81. package/src/shade/renderer/fow/shader_fog_of_war.js +3 -1
  82. package/src/shade/renderer/geometry/bvh/record_blas_refit.js +102 -102
  83. package/src/shade/renderer/geometry/bvh/shader_blas_refit_leaf_bounds.d.ts.map +1 -1
  84. package/src/shade/renderer/geometry/bvh/shader_blas_refit_leaf_bounds.js +125 -121
  85. package/src/shade/renderer/geometry/meshlet/GPUMeshletManager.d.ts.map +1 -1
  86. package/src/shade/renderer/geometry/meshlet/GPUMeshletManager.js +766 -774
  87. package/src/shade/renderer/geometry/meshlet/shader_meshlet_metadata_address_patch.d.ts.map +1 -1
  88. package/src/shade/renderer/geometry/meshlet/shader_meshlet_metadata_address_patch.js +72 -69
  89. package/src/shade/renderer/geometry/sdf/GPUGeometrySDFManager.d.ts.map +1 -1
  90. package/src/shade/renderer/geometry/sdf/GPUGeometrySDFManager.js +5 -10
  91. package/src/shade/renderer/geometry/sdf/shader_build_sdf.js +129 -129
  92. package/src/shade/renderer/geometry/sdf/shader_sdf_visualize.d.ts.map +1 -1
  93. package/src/shade/renderer/geometry/sdf/shader_sdf_visualize.js +5 -3
  94. package/src/shade/renderer/global_illumination/brick4/gpu/bake/shader_brick4_bake_probes.d.ts.map +1 -1
  95. package/src/shade/renderer/global_illumination/brick4/gpu/bake/shader_brick4_bake_probes.js +4 -1
  96. package/src/shade/renderer/global_illumination/brick4/gpu/bake/shader_brick4_bake_resolve_probes.d.ts.map +1 -1
  97. package/src/shade/renderer/global_illumination/brick4/gpu/bake/shader_brick4_bake_resolve_probes.js +3 -1
  98. package/src/shade/renderer/global_illumination/clipmap/shader_update_clipmap_cascade.d.ts.map +1 -1
  99. package/src/shade/renderer/global_illumination/clipmap/shader_update_clipmap_cascade.js +114 -112
  100. package/src/shade/renderer/global_illumination/probe/octahedral/convolve/graph_lpv_store_sh.d.ts.map +1 -1
  101. package/src/shade/renderer/global_illumination/probe/octahedral/convolve/graph_lpv_store_sh.js +4 -1
  102. package/src/shade/renderer/global_illumination/probe/octahedral/convolve/graph_lvp_atlas_to_sh.d.ts.map +1 -1
  103. package/src/shade/renderer/global_illumination/probe/octahedral/convolve/graph_lvp_atlas_to_sh.js +187 -184
  104. package/src/shade/renderer/global_illumination/probe/octahedral/convolve/graph_reduce_atlas_to_sh.d.ts.map +1 -1
  105. package/src/shade/renderer/global_illumination/probe/octahedral/convolve/graph_reduce_atlas_to_sh.js +4 -1
  106. package/src/shade/renderer/global_illumination/sharc/SpatialHashRadianceCache.d.ts.map +1 -1
  107. package/src/shade/renderer/global_illumination/sharc/SpatialHashRadianceCache.js +6 -8
  108. package/src/shade/renderer/global_illumination/sharc/shader/shader_sharc_evict.d.ts.map +1 -1
  109. package/src/shade/renderer/global_illumination/sharc/shader/shader_sharc_evict.js +3 -1
  110. package/src/shade/renderer/global_illumination/sharc/shader/shader_sharc_update.d.ts.map +1 -1
  111. package/src/shade/renderer/global_illumination/sharc/shader/shader_sharc_update.js +3 -1
  112. package/src/shade/renderer/gpu_primitive/bvh/GPU_BVH_BUILD_PLAN.md +3 -3
  113. package/src/shade/renderer/gpu_primitive/bvh/PHASE1_HANDOVER.md +3 -3
  114. package/src/shade/renderer/gpu_primitive/bvh/graph_bvh_build_lbvh.js +217 -217
  115. package/src/shade/renderer/gpu_primitive/bvh/shader_bvh_emit_hierarchy.d.ts.map +1 -1
  116. package/src/shade/renderer/gpu_primitive/bvh/shader_bvh_emit_hierarchy.js +145 -142
  117. package/src/shade/renderer/gpu_primitive/bvh/shader_bvh_morton.d.ts.map +1 -1
  118. package/src/shade/renderer/gpu_primitive/bvh/shader_bvh_morton.js +87 -82
  119. package/src/shade/renderer/gpu_primitive/bvh/shader_bvh_refit.d.ts.map +1 -1
  120. package/src/shade/renderer/gpu_primitive/bvh/shader_bvh_refit.js +143 -140
  121. package/src/shade/renderer/gpu_primitive/bvh/verify_gpu_bvh_build.d.ts +2 -2
  122. package/src/shade/renderer/gpu_primitive/bvh/verify_gpu_bvh_build.d.ts.map +1 -1
  123. package/src/shade/renderer/gpu_primitive/bvh/verify_gpu_bvh_build.js +43 -8
  124. package/src/shade/renderer/gpu_primitive/sort/graph_radix_sort.d.ts.map +1 -1
  125. package/src/shade/renderer/gpu_primitive/sort/graph_radix_sort.js +4 -5
  126. package/src/shade/renderer/gpu_primitive/sort/shader_radix_sort_histogram.d.ts.map +1 -1
  127. package/src/shade/renderer/gpu_primitive/sort/shader_radix_sort_histogram.js +88 -84
  128. package/src/shade/renderer/gpu_primitive/sort/shader_radix_sort_scatter.d.ts.map +1 -1
  129. package/src/shade/renderer/gpu_primitive/sort/shader_radix_sort_scatter.js +194 -191
  130. package/src/shade/renderer/hiz/HierarchicalZBuffer.d.ts.map +1 -1
  131. package/src/shade/renderer/hiz/HierarchicalZBuffer.js +33 -69
  132. package/src/shade/renderer/hiz/shader_hzb_reduce_any.d.ts.map +1 -1
  133. package/src/shade/renderer/hiz/shader_hzb_reduce_any.js +6 -1
  134. package/src/shade/renderer/hiz/shader_hzb_reduce_mip0_clip.d.ts.map +1 -1
  135. package/src/shade/renderer/hiz/shader_hzb_reduce_mip0_clip.js +23 -7
  136. package/src/shade/renderer/light/environment/execute_filter_environment_map.d.ts.map +1 -1
  137. package/src/shade/renderer/light/environment/execute_filter_environment_map.js +1 -2
  138. package/src/shade/renderer/light/environment/shader_convolve_reflection_map.d.ts.map +1 -1
  139. package/src/shade/renderer/light/environment/shader_convolve_reflection_map.js +6 -1
  140. package/src/shade/renderer/lightmap/bake/raster/graph_draw_lightmap_viz_buffer.d.ts.map +1 -1
  141. package/src/shade/renderer/lightmap/bake/raster/graph_draw_lightmap_viz_buffer.js +234 -219
  142. package/src/shade/renderer/lightmap/bake/raster/shader_lightmap_to_viz_buffer.js +2 -2
  143. package/src/shade/renderer/lightmap/bake/shader_lightmap_denoise_sh.js +191 -191
  144. package/src/shade/renderer/lightmap/bake/tile/shader_lightmap_accummulate_tile.d.ts.map +1 -1
  145. package/src/shade/renderer/lightmap/bake/tile/shader_lightmap_accummulate_tile.js +85 -82
  146. package/src/shade/renderer/particles/graph_particles.d.ts.map +1 -1
  147. package/src/shade/renderer/particles/graph_particles.js +5 -3
  148. package/src/shade/renderer/particles/prototypeParticleSystem.js +3 -4
  149. package/src/shade/renderer/particles/shaders/shader_particle_emit.d.ts.map +1 -1
  150. package/src/shade/renderer/particles/shaders/shader_particle_emit.js +132 -117
  151. package/src/shade/renderer/particles/shaders/shader_particle_finalize.d.ts.map +1 -1
  152. package/src/shade/renderer/particles/shaders/shader_particle_finalize.js +79 -77
  153. package/src/shade/renderer/particles/shaders/shader_particle_simulate.d.ts.map +1 -1
  154. package/src/shade/renderer/particles/shaders/shader_particle_simulate.js +111 -99
  155. package/src/shade/renderer/particles/sort/shader_particle_sort.d.ts.map +1 -1
  156. package/src/shade/renderer/particles/sort/shader_particle_sort.js +187 -158
  157. package/src/shade/renderer/path_tracer/accumulating/AccumulatingPathTracer.d.ts.map +1 -1
  158. package/src/shade/renderer/path_tracer/accumulating/AccumulatingPathTracer.js +7 -10
  159. package/src/shade/renderer/path_tracer/accumulating/shader_accumulating_path_tracer.d.ts.map +1 -1
  160. package/src/shade/renderer/path_tracer/accumulating/shader_accumulating_path_tracer.js +4 -1
  161. package/src/shade/renderer/postprocess/bloom/shader_bloom_mix.d.ts.map +1 -1
  162. package/src/shade/renderer/postprocess/bloom/shader_bloom_mix.js +3 -1
  163. package/src/shade/renderer/postprocess/cas/shader_ffx_rcas.d.ts.map +1 -1
  164. package/src/shade/renderer/postprocess/cas/shader_ffx_rcas.js +4 -2
  165. package/src/shade/renderer/postprocess/denoise/fragment_shader_denoise_ao.js +147 -147
  166. package/src/shade/renderer/postprocess/denoise/graph_atorus_denoise_luma.d.ts.map +1 -1
  167. package/src/shade/renderer/postprocess/denoise/graph_atorus_denoise_luma.js +121 -119
  168. package/src/shade/renderer/postprocess/dof/gather/graph_postprocess_dof2.d.ts.map +1 -1
  169. package/src/shade/renderer/postprocess/dof/gather/graph_postprocess_dof2.js +1 -2
  170. package/src/shade/renderer/postprocess/dof/gather/shader_dof2_gather_far.d.ts.map +1 -1
  171. package/src/shade/renderer/postprocess/dof/gather/shader_dof2_gather_far.js +4 -1
  172. package/src/shade/renderer/postprocess/dof/gather/shader_dof2_gather_near.d.ts.map +1 -1
  173. package/src/shade/renderer/postprocess/dof/gather/shader_dof2_gather_near.js +4 -1
  174. package/src/shade/renderer/postprocess/dof/gather/shader_dof2_recombine.d.ts.map +1 -1
  175. package/src/shade/renderer/postprocess/dof/gather/shader_dof2_recombine.js +4 -1
  176. package/src/shade/renderer/postprocess/dof/gather/shader_dof2_setup.d.ts.map +1 -1
  177. package/src/shade/renderer/postprocess/dof/gather/shader_dof2_setup.js +4 -1
  178. package/src/shade/renderer/postprocess/dof/raymarch/graph_postprocess_dof.d.ts.map +1 -1
  179. package/src/shade/renderer/postprocess/dof/raymarch/graph_postprocess_dof.js +2 -4
  180. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_composite.d.ts.map +1 -1
  181. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_composite.js +4 -1
  182. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_prefilter.d.ts.map +1 -1
  183. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_prefilter.js +4 -1
  184. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_raymarch.d.ts.map +1 -1
  185. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_raymarch.js +4 -1
  186. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_raymarch_compute.d.ts.map +1 -1
  187. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_raymarch_compute.js +269 -266
  188. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_slice_compute.d.ts.map +1 -1
  189. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_slice_compute.js +273 -270
  190. package/src/shade/renderer/postprocess/dof/shader_dof_autofocus.d.ts.map +1 -1
  191. package/src/shade/renderer/postprocess/dof/shader_dof_autofocus.js +4 -1
  192. package/src/shade/renderer/postprocess/eye/GPUCameraExposureManager.d.ts.map +1 -1
  193. package/src/shade/renderer/postprocess/eye/GPUCameraExposureManager.js +8 -11
  194. package/src/shade/renderer/postprocess/eye/shader_autoexposure_adapt.d.ts.map +1 -1
  195. package/src/shade/renderer/postprocess/eye/shader_autoexposure_adapt.js +5 -1
  196. package/src/shade/renderer/postprocess/gtao/fragment_shader_gtao.d.ts.map +1 -1
  197. package/src/shade/renderer/postprocess/gtao/fragment_shader_gtao.js +11 -8
  198. package/src/shade/renderer/postprocess/gtao/fragment_shader_gtao_with_irradiance.d.ts.map +1 -1
  199. package/src/shade/renderer/postprocess/gtao/fragment_shader_gtao_with_irradiance.js +7 -8
  200. package/src/shade/renderer/postprocess/motion_blur/shader_motion_blur_reconstruct.d.ts.map +1 -1
  201. package/src/shade/renderer/postprocess/motion_blur/shader_motion_blur_reconstruct.js +3 -1
  202. package/src/shade/renderer/postprocess/nss/NSS.d.ts +1 -1
  203. package/src/shade/renderer/postprocess/nss/shader_nss_concat.d.ts.map +1 -1
  204. package/src/shade/renderer/postprocess/nss/shader_nss_concat.js +70 -68
  205. package/src/shade/renderer/postprocess/ssr/depth_max_shader.d.ts.map +1 -1
  206. package/src/shade/renderer/postprocess/ssr/depth_max_shader.js +70 -68
  207. package/src/shade/renderer/postprocess/ssr/resolve/ssr_resolve_shader_IBL.d.ts.map +1 -1
  208. package/src/shade/renderer/postprocess/ssr/resolve/ssr_resolve_shader_IBL.js +3 -1
  209. package/src/shade/renderer/postprocess/ssr/resolve/ssr_resolve_shader_LPV.d.ts.map +1 -1
  210. package/src/shade/renderer/postprocess/ssr/resolve/ssr_resolve_shader_LPV.js +4 -1
  211. package/src/shade/renderer/postprocess/ssr/shader_downsample_encoded_normal.d.ts.map +1 -1
  212. package/src/shade/renderer/postprocess/ssr/shader_downsample_encoded_normal.js +103 -101
  213. package/src/shade/renderer/postprocess/ssr/ssr_spatial_denoise_shader.d.ts.map +1 -1
  214. package/src/shade/renderer/postprocess/ssr/ssr_spatial_denoise_shader.js +4 -2
  215. package/src/shade/renderer/postprocess/ssr/ssr_trace_shader.d.ts.map +1 -1
  216. package/src/shade/renderer/postprocess/ssr/ssr_trace_shader.js +3 -1
  217. package/src/shade/renderer/postprocess/taa/shader_taa.d.ts.map +1 -1
  218. package/src/shade/renderer/postprocess/taa/shader_taa.js +4 -1
  219. package/src/shade/renderer/postprocess/upscale-dither/fragment_shader_upscale_dither.js +5 -5
  220. package/src/shade/renderer/rasterize/bucket/prepare_meshlet_draw_commands_by_material.d.ts.map +1 -1
  221. package/src/shade/renderer/rasterize/bucket/prepare_meshlet_draw_commands_by_material.js +339 -341
  222. package/src/shade/renderer/rasterize/cull/hzb/shader_hzb_mesh_filter_2way.d.ts.map +1 -1
  223. package/src/shade/renderer/rasterize/cull/hzb/shader_hzb_mesh_filter_2way.js +114 -109
  224. package/src/shade/renderer/rasterize/cull/hzb/shader_hzb_meshlet_filter_1way_full.d.ts.map +1 -1
  225. package/src/shade/renderer/rasterize/cull/hzb/shader_hzb_meshlet_filter_1way_full.js +118 -115
  226. package/src/shade/renderer/rasterize/expand/bucket/meshlet/shader_meshlets_extract_bucket.d.ts.map +1 -1
  227. package/src/shade/renderer/rasterize/expand/bucket/meshlet/shader_meshlets_extract_bucket.js +69 -65
  228. package/src/shade/renderer/rasterize/native/oit/graph_rasterize_meshes_transparent_oit.js +722 -722
  229. package/src/shade/renderer/rasterize/standard/graph_rasterize_partial_opaque.d.ts.map +1 -1
  230. package/src/shade/renderer/rasterize/standard/graph_rasterize_partial_opaque.js +1 -9
  231. package/src/shade/renderer/rasterize/standard/graph_rasterize_remaining_opaque.d.ts.map +1 -1
  232. package/src/shade/renderer/rasterize/standard/graph_rasterize_remaining_opaque.js +1 -6
  233. package/src/shade/renderer/restir/di/graph_restir_di.d.ts.map +1 -1
  234. package/src/shade/renderer/restir/di/graph_restir_di.js +2 -3
  235. package/src/shade/renderer/restir/di/graph_restir_di_denoise.d.ts.map +1 -1
  236. package/src/shade/renderer/restir/di/graph_restir_di_denoise.js +1 -2
  237. package/src/shade/renderer/restir/di/shader_restir_di_denoise.d.ts.map +1 -1
  238. package/src/shade/renderer/restir/di/shader_restir_di_denoise.js +139 -136
  239. package/src/shade/renderer/restir/di/shader_restir_di_resample.d.ts.map +1 -1
  240. package/src/shade/renderer/restir/di/shader_restir_di_resample.js +131 -129
  241. package/src/shade/renderer/restir/di/shader_restir_di_resolve.d.ts.map +1 -1
  242. package/src/shade/renderer/restir/di/shader_restir_di_resolve.js +101 -99
  243. package/src/shade/renderer/scene/GPUInstancesAccelerationStructure.d.ts.map +1 -1
  244. package/src/shade/renderer/scene/GPUInstancesAccelerationStructure.js +379 -383
  245. package/src/shade/renderer/scene/Mesh.d.ts.map +1 -1
  246. package/src/shade/renderer/scene/Mesh.js +4 -6
  247. package/src/shade/renderer/scene/shader_bvh_extract_instance_leaves.d.ts.map +1 -1
  248. package/src/shade/renderer/scene/shader_bvh_extract_instance_leaves.js +147 -144
  249. package/src/shade/renderer/shader/ComputeShader.d.ts +2 -2
  250. package/src/shade/renderer/shader/ComputeShader.d.ts.map +1 -1
  251. package/src/shade/renderer/shader/ComputeShader.js +14 -17
  252. package/src/shade/renderer/shader/pass/RenderPassDescriptor.d.ts +2 -2
  253. package/src/shade/renderer/shader/pass/RenderPassDescriptor.d.ts.map +1 -1
  254. package/src/shade/renderer/shader/pass/RenderPassDescriptor.js +189 -189
  255. package/src/shade/renderer/shader/resource/ShaderResourceSetDescriptor.d.ts.map +1 -1
  256. package/src/shade/renderer/shader/resource/ShaderResourceSetDescriptor.js +3 -1
  257. package/src/shade/renderer/shadow/map/GPUSceneShadowmapContext.d.ts +16 -7
  258. package/src/shade/renderer/shadow/map/GPUSceneShadowmapContext.d.ts.map +1 -1
  259. package/src/shade/renderer/shadow/map/GPUSceneShadowmapContext.js +1342 -1326
  260. package/src/shade/renderer/shadow/map/Shadowmap.d.ts +13 -0
  261. package/src/shade/renderer/shadow/map/Shadowmap.d.ts.map +1 -1
  262. package/src/shade/renderer/shadow/map/Shadowmap.js +14 -0
  263. package/src/shade/renderer/shadow/map/ShadowmapDrawSelector.d.ts +79 -0
  264. package/src/shade/renderer/shadow/map/ShadowmapDrawSelector.d.ts.map +1 -0
  265. package/src/shade/renderer/shadow/map/ShadowmapDrawSelector.js +196 -0
  266. package/src/shade/renderer/shadow/map/ShadowmapRegistry.d.ts +91 -0
  267. package/src/shade/renderer/shadow/map/ShadowmapRegistry.d.ts.map +1 -0
  268. package/src/shade/renderer/shadow/map/ShadowmapRegistry.js +156 -0
  269. package/src/shade/renderer/shadow/map/shader/shader_shadowmap_remap_cube_to_octahedral.d.ts.map +1 -1
  270. package/src/shade/renderer/shadow/map/shader/shader_shadowmap_remap_cube_to_octahedral.js +5 -1
  271. package/src/shade/renderer/shadow/ray/shader_shadow_upscale.d.ts.map +1 -1
  272. package/src/shade/renderer/shadow/ray/shader_shadow_upscale.js +3 -1
  273. package/src/shade/renderer/shadow/ray/staged/gen/graph_gen_rays.js +73 -73
  274. package/src/shade/renderer/shadow/ray/staged/gen/shader_generate_rays.d.ts.map +1 -1
  275. package/src/shade/renderer/shadow/ray/staged/gen/shader_generate_rays.js +151 -148
  276. package/src/shade/renderer/shadow/ray/staged/trace/graph_trace_rays.d.ts.map +1 -1
  277. package/src/shade/renderer/shadow/ray/staged/trace/graph_trace_rays.js +4 -2
  278. package/src/shade/renderer/shadow/ray/staged/trace/shader_trace_rays.d.ts.map +1 -1
  279. package/src/shade/renderer/shadow/ray/staged/trace/shader_trace_rays.js +18 -4
  280. package/src/shade/renderer/shadow/sdf/cascade/CascadedSceneSDF.d.ts.map +1 -1
  281. package/src/shade/renderer/shadow/sdf/cascade/CascadedSceneSDF.js +7 -8
  282. package/src/shade/renderer/shadow/sdf/cascade/shader_build_scene_sdf_f32.d.ts.map +1 -1
  283. package/src/shade/renderer/shadow/sdf/cascade/shader_build_scene_sdf_f32.js +6 -2
  284. package/src/shade/renderer/shadow/sdf/cascade/shader_scene_sdf_debug_viz.d.ts.map +1 -1
  285. package/src/shade/renderer/shadow/sdf/cascade/shader_scene_sdf_debug_viz.js +129 -127
  286. package/src/shade/renderer/shadow/sdf/graph_draw_sdf_shadows.d.ts.map +1 -1
  287. package/src/shade/renderer/shadow/sdf/graph_draw_sdf_shadows.js +5 -3
  288. package/src/shade/renderer/texture/virtual/VirtualTextureManager.d.ts.map +1 -1
  289. package/src/shade/renderer/texture/virtual/VirtualTextureManager.js +2 -5
  290. package/src/shade/renderer/texture/virtual/build_shader_vt_feedback.d.ts.map +1 -1
  291. package/src/shade/renderer/texture/virtual/build_shader_vt_feedback.js +233 -231
  292. package/src/shade/renderer/volumetrics/graph_build_volumetrics.d.ts.map +1 -1
  293. package/src/shade/renderer/volumetrics/graph_build_volumetrics.js +2 -4
  294. package/src/shade/wgsl/validate_wgsl_source.d.ts.map +1 -1
  295. package/src/shade/wgsl/validate_wgsl_source.js +8 -3
  296. package/src/shade/device/timing/profile/make_profiling_pass_encoder.d.ts +0 -21
  297. package/src/shade/device/timing/profile/make_profiling_pass_encoder.d.ts.map +0 -1
  298. package/src/shade/device/timing/profile/make_profiling_pass_encoder.js +0 -114
  299. package/src/shade/device/timing/profile/parse_workgroup_size.d.ts +0 -20
  300. package/src/shade/device/timing/profile/parse_workgroup_size.d.ts.map +0 -1
  301. package/src/shade/device/timing/profile/parse_workgroup_size.js +0 -43
@@ -1,266 +1,269 @@
1
- import { chunk_stbn_sample_vec2 } from "../../../shader/chunk/noise/chunk_stbn_sample_vec2.js";
2
- import { chunk_rgb_to_luminance } from "../../../shader/chunk/color/chunk_rgb_to_luminance.js";
3
- import { PI_DECLARATION } from "../../../shader/chunk/math/PI_DECLARATION.js";
4
- import { CodeChunk } from "../../../shader/compiler/CodeChunk.js";
5
- import { ComputeShader } from "../../../shader/ComputeShader.js";
6
- import { ShaderResourceSetDescriptor } from "../../../shader/resource/ShaderResourceSetDescriptor.js";
7
- import { chunk_dof_aperture_shape } from "../chunk_dof_aperture_shape.js";
8
- import { chunk_dof_sample_offset } from "../chunk_dof_sample_offset.js";
9
- import { DOF_FOCUS_CUTOFF, DOF_LDS_APRON, DOF_LDS_WORKGROUP, DOF_MAX_COC_RADIUS, DOF_TILE_SIZE } from "../DOF_CONFIG.js";
10
- import { DOF_SETTINGS_STRUCT } from "./DOF_SETTINGS_STRUCT.js";
11
-
12
- const resources = new ShaderResourceSetDescriptor();
13
- resources.createGroup()
14
- // Full-res (colour.rgb, signed CoC radius) from the prefilter.
15
- .addTexture("tColorCoc", "float")
16
- // Spatio-temporal blue noise (NVIDIA STBN) for the aperture phase.
17
- .addTexture("tSTBN_vec2", "unfilterable-float", "3d")
18
- // Dilated per-tile max |CoC| the fast-path early-out source.
19
- .addTexture("tTile", "float")
20
- .addUniform("dof", DOF_SETTINGS_STRUCT)
21
- // Defocused colour (rgb) + defocus amount (a) — same contract as the
22
- // fragment march's render target, but written via textureStore.
23
- .addStorageTexture("tOut", "rgba16float", "2d", "write-only")
24
- ;
25
-
26
- // ── Workgroup-LDS cache geometry (derived; see DOF_LDS_* in DOF_CONFIG) ──
27
- const WG = DOF_LDS_WORKGROUP; // 8 — workgroup side
28
- const APRON = DOF_LDS_APRON; // 40 — cached skirt, full-res px
29
- const REGION = WG + 2 * APRON; // 88 cached square side (even)
30
- const ROW_U32 = REGION / 2; // 44u32 per cached row (2 f16/u32)
31
- const LDS_U32 = REGION * ROW_U32; // 3872total u32 4 B = 15 488 B)
32
- const WG_THREADS = WG * WG; // 64threads per workgroup
33
-
34
- const body = CodeChunk.from(
35
- //language=WGSL
36
- `
37
- const MAXR: f32 = ${DOF_MAX_COC_RADIUS};
38
- const CUTOFF: f32 = ${DOF_FOCUS_CUTOFF};
39
- const TILE_SIZE: i32 = ${DOF_TILE_SIZE};
40
- const MAX_STEPS: u32 = 64u; // bitmask width (vec2<u32>); >= max STEPS (ultra = 48)
41
-
42
- const WG: i32 = ${WG};
43
- const APRON: i32 = ${APRON};
44
- const REGION: i32 = ${REGION};
45
- const ROW_U32: i32 = ${ROW_U32};
46
- const LDS_U32: u32 = ${LDS_U32}u;
47
- const WG_THREADS: u32 = ${WG_THREADS}u;
48
-
49
- // Workgroup CoC cache: the REGION×REGION (tile + apron) signed-CoC field, two
50
- // f16 packed per u32. The CoC texture is rgba16float, so packing its already-
51
- // f16 .a channel round-trips losslessly — the cached march stays bit-identical
52
- // to the texture march (and to the fragment reference).
53
- var<workgroup> lds_coc: array<u32, LDS_U32>;
54
-
55
- // Clamped CoC fetch used by the cooperative load.
56
- fn dof_load_coc(p: vec2<i32>, dims: vec2<i32>) -> f32 {
57
- return textureLoad(tColorCoc, clamp(p, vec2<i32>(0), dims - vec2<i32>(1)), 0).a;
58
- }
59
-
60
- @compute @workgroup_size(${WG}, ${WG}, 1)
61
- fn main(
62
- @builtin(global_invocation_id) gid: vec3<u32>,
63
- @builtin(local_invocation_index) lid: u32,
64
- @builtin(workgroup_id) wid: vec3<u32>,
65
- ) {
66
- let dims = vec2<i32>(textureDimensions(tColorCoc));
67
-
68
- // Tile fast-path decision, computed from the WORKGROUP id so it is the same
69
- // value for every thread: the workgroup sits wholly inside one tile (the
70
- // tile size is a multiple of the workgroup side), so all 64 pixels share
71
- // it. A workgroup-uniform decision is what lets the cooperative load be
72
- // skipped wholesale for an in-focus tile without leaving holes in the cache.
73
- let tile_origin = vec2<i32>(wid.xy) * WG;
74
- let wg_tile = tile_origin / TILE_SIZE;
75
- let tile_max_coc = textureLoad(tTile, wg_tile, 0).r;
76
- let tile_blurred = tile_max_coc >= CUTOFF;
77
-
78
- // Cooperative load: pack the tile+apron CoC field into shared memory. Each
79
- // u32 slot holds two horizontally-adjacent texels of the REGION grid; every
80
- // slot is written by exactly one thread, so there is no read-modify-write
81
- // race. Skipped entirely for an in-focus tile (the load is the bulk of the
82
- // cost the cache is meant to remove).
83
- let region_origin = tile_origin - vec2<i32>(APRON);
84
- if (tile_blurred) {
85
- for (var s: u32 = lid; s < LDS_U32; s = s + WG_THREADS) {
86
- let si = i32(s);
87
- let ry = si / ROW_U32;
88
- let jx = si % ROW_U32;
89
- let gy = region_origin.y + ry;
90
- let gx = region_origin.x + 2 * jx;
91
- let c0 = dof_load_coc(vec2<i32>(gx, gy), dims);
92
- let c1 = dof_load_coc(vec2<i32>(gx + 1, gy), dims);
93
- lds_coc[s] = pack2x16float(vec2<f32>(c0, c1));
94
- }
95
- }
96
- // Unconditional barrier (uniform control flow): every thread reaches it, so
97
- // the cache is fully published before any thread reads it.
98
- workgroupBarrier();
99
-
100
- let pixel = vec2<i32>(gid.xy);
101
- if (pixel.x >= dims.x || pixel.y >= dims.y) {
102
- return;
103
- }
104
-
105
- let center = textureLoad(tColorCoc, pixel, 0);
106
- let center_rgb = center.rgb;
107
- let center_coc = center.a; // signed full-res radius
108
- let center_is_background = center_coc > CUTOFF;
109
-
110
- // In-focus tile: the march would accumulate nothing but the sharp centre
111
- // (mirrors the fragment reference's tile fast-path). The cache was not
112
- // loaded for this tile, so this must return before any LDS read.
113
- if (!tile_blurred) {
114
- textureStore(tOut, pixel, vec4<f32>(center_rgb, 0.0));
115
- return;
116
- }
117
-
118
- // Pixel-centre float coords — identical to the fragment march's
119
- // @builtin(position).xy, so every per-pixel value matches the reference.
120
- let coord = vec2<f32>(gid.xy) + 0.5;
121
- let dims_f = vec2<f32>(dims);
122
-
123
- // Per-pixel blue-noise aperture phase (STBN), static slice (post-TAA).
124
- let rotation = stbn_sample_vec2(vec3<u32>(vec2<u32>(coord), 0u)).x;
125
- let rot = rotation * 2.0 * PI;
126
- let blades = dof.blade_count;
127
- const aa = 1.0 / MAXR;
128
- let SAMPLES = u32(dof.sample_count);
129
- // Clamp to the bitmask's capacity (see Step 2a): b = MAX_STEPS - k
130
- // underflows for k > 64. Preset step counts top out at 48.
131
- let STEPS = min(u32(dof.step_count), MAX_STEPS);
132
-
133
- var acc = vec3<f32>(0.0);
134
- var wsum = 0.0;
135
- var max_reach = select(0.0, abs(center_coc), abs(center_coc) > CUTOFF);
136
-
137
- for (var i: u32 = 0u; i < SAMPLES; i = i + 1u) {
138
- let o = dof_sample_offset(i, SAMPLES, rot); // unit-disk aperture point
139
- let rho = length(o);
140
- if (rho < 1e-3) {
141
- continue;
142
- }
143
- let dir = o / rho;
144
- let shape = dof_aperture_shape(o, blades, dof.blade_rotation, aa);
145
- if (shape <= 0.0) {
146
- continue;
147
- }
148
-
149
- let step_len = (rho * MAXR) / f32(STEPS);
150
-
151
- // Branchless nearest-hit via a register bitmask + firstLeadingBit
152
- // (Stachowiak; see Step 2a). The CoC for each step is read from the
153
- // workgroup cache when the tap lands inside the apron, and from the
154
- // texture for the rare far tap (|offset| in (APRON, MAXR]).
155
- var mask_lo: u32 = 0u;
156
- var mask_hi: u32 = 0u;
157
-
158
- for (var k: u32 = 1u; k <= STEPS; k = k + 1u) {
159
- let r = f32(k) * step_len; // full-res px from centre
160
- let x = coord + dir * r;
161
- let xt = vec2<i32>(clamp(x, vec2<f32>(0.0), dims_f - 1.0));
162
-
163
- let rc = xt - region_origin; // cache coord
164
- var s_coc: f32;
165
- if (rc.x >= 0 && rc.x < REGION && rc.y >= 0 && rc.y < REGION) {
166
- let pair = unpack2x16float(lds_coc[rc.y * ROW_U32 + (rc.x >> 1)]);
167
- s_coc = select(pair.x, pair.y, (rc.x & 1) != 0);
168
- } else {
169
- s_coc = textureLoad(tColorCoc, xt, 0).a;
170
- }
171
- let reach = abs(s_coc);
172
-
173
- let cover = saturate(rho * reach - r + 1.0);
174
- // Occlusion gate: foreground floods over everything; background
175
- // only blurs a background centre (no bleed across a discontinuity).
176
- let accept = (s_coc < -CUTOFF) || (s_coc > CUTOFF && center_is_background);
177
-
178
- if (cover > 0.5 && accept) {
179
- let b = MAX_STEPS - k; // k=1 -> bit 63 (MSB = nearest)
180
- if (b < 32u) {
181
- mask_lo = mask_lo | (1u << b);
182
- } else {
183
- mask_hi = mask_hi | (1u << (b - 32u));
184
- }
185
- }
186
- }
187
-
188
- // Nearest accepted cover = highest set bit; the high word holds the
189
- // nearer steps (k <= 32) so test it first.
190
- var found = false;
191
- var samp = center_rgb;
192
- var reach_used = 0.0;
193
- var hb: u32 = 0xFFFFFFFFu;
194
- if (mask_hi != 0u) {
195
- hb = 32u + firstLeadingBit(mask_hi);
196
- } else if (mask_lo != 0u) {
197
- hb = firstLeadingBit(mask_lo);
198
- }
199
- if (hb != 0xFFFFFFFFu) {
200
- let k = MAX_STEPS - hb;
201
- let x = coord + dir * (f32(k) * step_len);
202
- let xt = vec2<i32>(clamp(x, vec2<f32>(0.0), dims_f - 1.0));
203
- let s = textureLoad(tColorCoc, xt, 0); // rgb + reach at the hit
204
- samp = s.rgb;
205
- reach_used = abs(s.a);
206
- found = true;
207
- }
208
-
209
- let hl = 1.0 + dof.highlight_boost * rgb_to_luminance(samp);
210
- let w = shape * hl;
211
- acc = acc + samp * w;
212
- wsum = wsum + w;
213
- if (found) {
214
- max_reach = max(max_reach, reach_used);
215
- }
216
- }
217
-
218
- let color = acc / max(wsum, 1e-4);
219
- let defocus = saturate(max_reach - CUTOFF);
220
- textureStore(tOut, pixel, vec4<f32>(color, defocus));
221
- }
222
- `,
223
- [
224
- chunk_dof_sample_offset,
225
- chunk_dof_aperture_shape,
226
- chunk_stbn_sample_vec2,
227
- chunk_rgb_to_luminance,
228
- PI_DECLARATION,
229
- ]
230
- );
231
-
232
- /**
233
- * DoF ray-march — compute form (Form-1 Phase B; see DOF_REFINEMENT_PLAN_02).
234
- * A compute port of the fragment {@link shader_dof_raymarch} writing a storage
235
- * texture. Same chunks, same 24-direction aperture sampling, same
236
- * `(defocused colour, defocus amount)` output contract; `coord = gid + 0.5`
237
- * reproduces the fragment's pixel-centre `@builtin(position)`, so per-pixel
238
- * results match the reference.
239
- *
240
- * Built incrementally so each blind (GPU-only) change is validated in
241
- * isolation against the fragment reference:
242
- * - **Step 1**: bit-identical port — proves the compute/storage-texture
243
- * FrameGraph integration.
244
- * - **Step 2a**: the per-ray serial break-loop becomes a branchless register
245
- * bitmask resolved by `firstLeadingBit`same nearest-hit result, but every
246
- * lane marches uniformly (no data-dependent break), the prerequisite for the
247
- * cache.
248
- * - **Step 2b** (here): each workgroup cooperatively loads its tile + apron
249
- * CoC neighbourhood into `var<workgroup>` shared memory (two f16 packed per
250
- * u32), and the inner march reads the cache instead of the texture. Because
251
- * the CoC source is already `rgba16float`, the pack is lossless and the
252
- * output stays bit-identical to the reference; the in-focus tile fast-path
253
- * skips the load, and far taps beyond the apron fall back to a texture read.
254
- * The win is the SAMPLES×STEPS per-pixel CoC taps collapsing to one
255
- * cooperative load shared across the workgroup.
256
- *
257
- * Selected by `DepthOfField.march_mode === DOF_MARCH_MODE.COMPUTE`; the
258
- * fragment march stays the default and the GPU correctness oracle.
259
- *
260
- * @type {ComputeShader}
261
- */
262
- export const shader_dof_raymarch_compute = ComputeShader.from({
263
- label: "DoF/RayMarchCompute",
264
- resources,
265
- body,
266
- });
1
+ import { chunk_stbn_sample_vec2 } from "../../../shader/chunk/noise/chunk_stbn_sample_vec2.js";
2
+ import { chunk_rgb_to_luminance } from "../../../shader/chunk/color/chunk_rgb_to_luminance.js";
3
+ import { PI_DECLARATION } from "../../../shader/chunk/math/PI_DECLARATION.js";
4
+ import { CodeChunk } from "../../../shader/compiler/CodeChunk.js";
5
+ import { ComputeShader } from "../../../shader/ComputeShader.js";
6
+ import { ShaderResourceSetDescriptor } from "../../../shader/resource/ShaderResourceSetDescriptor.js";
7
+ import { chunk_dof_aperture_shape } from "../chunk_dof_aperture_shape.js";
8
+ import { chunk_dof_sample_offset } from "../chunk_dof_sample_offset.js";
9
+ import { DOF_FOCUS_CUTOFF, DOF_LDS_APRON, DOF_LDS_WORKGROUP, DOF_MAX_COC_RADIUS, DOF_TILE_SIZE } from "../DOF_CONFIG.js";
10
+ import { DOF_SETTINGS_STRUCT } from "./DOF_SETTINGS_STRUCT.js";
11
+
12
+ const resources = new ShaderResourceSetDescriptor();
13
+
14
+ // per-pass, under 64 bytes, read-only: immediate data rather than a uniform buffer. focus_state
15
+ // beside it stays bound — the autofocus pass writes it on the GPU, so there is no CPU value.
16
+ resources.setImmediate("dof", DOF_SETTINGS_STRUCT);
17
+ resources.createGroup()
18
+ // Full-res (colour.rgb, signed CoC radius) from the prefilter.
19
+ .addTexture("tColorCoc", "float")
20
+ // Spatio-temporal blue noise (NVIDIA STBN) for the aperture phase.
21
+ .addTexture("tSTBN_vec2", "unfilterable-float", "3d")
22
+ // Dilated per-tile max |CoC| the fast-path early-out source.
23
+ .addTexture("tTile", "float")
24
+ // Defocused colour (rgb) + defocus amount (a) — same contract as the
25
+ // fragment march's render target, but written via textureStore.
26
+ .addStorageTexture("tOut", "rgba16float", "2d", "write-only")
27
+ ;
28
+
29
+ // ── Workgroup-LDS cache geometry (derived; see DOF_LDS_* in DOF_CONFIG) ──
30
+ const WG = DOF_LDS_WORKGROUP; // 8workgroup side
31
+ const APRON = DOF_LDS_APRON; // 40cached skirt, full-res px
32
+ const REGION = WG + 2 * APRON; // 88cached square side (even)
33
+ const ROW_U32 = REGION / 2; // 44 — u32 per cached row (2 f16/u32)
34
+ const LDS_U32 = REGION * ROW_U32; // 3872 — total u32 (× 4 B = 15 488 B)
35
+ const WG_THREADS = WG * WG; // 64 — threads per workgroup
36
+
37
+ const body = CodeChunk.from(
38
+ //language=WGSL
39
+ `
40
+ const MAXR: f32 = ${DOF_MAX_COC_RADIUS};
41
+ const CUTOFF: f32 = ${DOF_FOCUS_CUTOFF};
42
+ const TILE_SIZE: i32 = ${DOF_TILE_SIZE};
43
+ const MAX_STEPS: u32 = 64u; // bitmask width (vec2<u32>); >= max STEPS (ultra = 48)
44
+
45
+ const WG: i32 = ${WG};
46
+ const APRON: i32 = ${APRON};
47
+ const REGION: i32 = ${REGION};
48
+ const ROW_U32: i32 = ${ROW_U32};
49
+ const LDS_U32: u32 = ${LDS_U32}u;
50
+ const WG_THREADS: u32 = ${WG_THREADS}u;
51
+
52
+ // Workgroup CoC cache: the REGION×REGION (tile + apron) signed-CoC field, two
53
+ // f16 packed per u32. The CoC texture is rgba16float, so packing its already-
54
+ // f16 .a channel round-trips losslessly — the cached march stays bit-identical
55
+ // to the texture march (and to the fragment reference).
56
+ var<workgroup> lds_coc: array<u32, LDS_U32>;
57
+
58
+ // Clamped CoC fetch used by the cooperative load.
59
+ fn dof_load_coc(p: vec2<i32>, dims: vec2<i32>) -> f32 {
60
+ return textureLoad(tColorCoc, clamp(p, vec2<i32>(0), dims - vec2<i32>(1)), 0).a;
61
+ }
62
+
63
+ @compute @workgroup_size(${WG}, ${WG}, 1)
64
+ fn main(
65
+ @builtin(global_invocation_id) gid: vec3<u32>,
66
+ @builtin(local_invocation_index) lid: u32,
67
+ @builtin(workgroup_id) wid: vec3<u32>,
68
+ ) {
69
+ let dims = vec2<i32>(textureDimensions(tColorCoc));
70
+
71
+ // Tile fast-path decision, computed from the WORKGROUP id so it is the same
72
+ // value for every thread: the workgroup sits wholly inside one tile (the
73
+ // tile size is a multiple of the workgroup side), so all 64 pixels share
74
+ // it. A workgroup-uniform decision is what lets the cooperative load be
75
+ // skipped wholesale for an in-focus tile without leaving holes in the cache.
76
+ let tile_origin = vec2<i32>(wid.xy) * WG;
77
+ let wg_tile = tile_origin / TILE_SIZE;
78
+ let tile_max_coc = textureLoad(tTile, wg_tile, 0).r;
79
+ let tile_blurred = tile_max_coc >= CUTOFF;
80
+
81
+ // Cooperative load: pack the tile+apron CoC field into shared memory. Each
82
+ // u32 slot holds two horizontally-adjacent texels of the REGION grid; every
83
+ // slot is written by exactly one thread, so there is no read-modify-write
84
+ // race. Skipped entirely for an in-focus tile (the load is the bulk of the
85
+ // cost the cache is meant to remove).
86
+ let region_origin = tile_origin - vec2<i32>(APRON);
87
+ if (tile_blurred) {
88
+ for (var s: u32 = lid; s < LDS_U32; s = s + WG_THREADS) {
89
+ let si = i32(s);
90
+ let ry = si / ROW_U32;
91
+ let jx = si % ROW_U32;
92
+ let gy = region_origin.y + ry;
93
+ let gx = region_origin.x + 2 * jx;
94
+ let c0 = dof_load_coc(vec2<i32>(gx, gy), dims);
95
+ let c1 = dof_load_coc(vec2<i32>(gx + 1, gy), dims);
96
+ lds_coc[s] = pack2x16float(vec2<f32>(c0, c1));
97
+ }
98
+ }
99
+ // Unconditional barrier (uniform control flow): every thread reaches it, so
100
+ // the cache is fully published before any thread reads it.
101
+ workgroupBarrier();
102
+
103
+ let pixel = vec2<i32>(gid.xy);
104
+ if (pixel.x >= dims.x || pixel.y >= dims.y) {
105
+ return;
106
+ }
107
+
108
+ let center = textureLoad(tColorCoc, pixel, 0);
109
+ let center_rgb = center.rgb;
110
+ let center_coc = center.a; // signed full-res radius
111
+ let center_is_background = center_coc > CUTOFF;
112
+
113
+ // In-focus tile: the march would accumulate nothing but the sharp centre
114
+ // (mirrors the fragment reference's tile fast-path). The cache was not
115
+ // loaded for this tile, so this must return before any LDS read.
116
+ if (!tile_blurred) {
117
+ textureStore(tOut, pixel, vec4<f32>(center_rgb, 0.0));
118
+ return;
119
+ }
120
+
121
+ // Pixel-centre float coords — identical to the fragment march's
122
+ // @builtin(position).xy, so every per-pixel value matches the reference.
123
+ let coord = vec2<f32>(gid.xy) + 0.5;
124
+ let dims_f = vec2<f32>(dims);
125
+
126
+ // Per-pixel blue-noise aperture phase (STBN), static slice (post-TAA).
127
+ let rotation = stbn_sample_vec2(vec3<u32>(vec2<u32>(coord), 0u)).x;
128
+ let rot = rotation * 2.0 * PI;
129
+ let blades = dof.blade_count;
130
+ const aa = 1.0 / MAXR;
131
+ let SAMPLES = u32(dof.sample_count);
132
+ // Clamp to the bitmask's capacity (see Step 2a): b = MAX_STEPS - k
133
+ // underflows for k > 64. Preset step counts top out at 48.
134
+ let STEPS = min(u32(dof.step_count), MAX_STEPS);
135
+
136
+ var acc = vec3<f32>(0.0);
137
+ var wsum = 0.0;
138
+ var max_reach = select(0.0, abs(center_coc), abs(center_coc) > CUTOFF);
139
+
140
+ for (var i: u32 = 0u; i < SAMPLES; i = i + 1u) {
141
+ let o = dof_sample_offset(i, SAMPLES, rot); // unit-disk aperture point
142
+ let rho = length(o);
143
+ if (rho < 1e-3) {
144
+ continue;
145
+ }
146
+ let dir = o / rho;
147
+ let shape = dof_aperture_shape(o, blades, dof.blade_rotation, aa);
148
+ if (shape <= 0.0) {
149
+ continue;
150
+ }
151
+
152
+ let step_len = (rho * MAXR) / f32(STEPS);
153
+
154
+ // Branchless nearest-hit via a register bitmask + firstLeadingBit
155
+ // (Stachowiak; see Step 2a). The CoC for each step is read from the
156
+ // workgroup cache when the tap lands inside the apron, and from the
157
+ // texture for the rare far tap (|offset| in (APRON, MAXR]).
158
+ var mask_lo: u32 = 0u;
159
+ var mask_hi: u32 = 0u;
160
+
161
+ for (var k: u32 = 1u; k <= STEPS; k = k + 1u) {
162
+ let r = f32(k) * step_len; // full-res px from centre
163
+ let x = coord + dir * r;
164
+ let xt = vec2<i32>(clamp(x, vec2<f32>(0.0), dims_f - 1.0));
165
+
166
+ let rc = xt - region_origin; // cache coord
167
+ var s_coc: f32;
168
+ if (rc.x >= 0 && rc.x < REGION && rc.y >= 0 && rc.y < REGION) {
169
+ let pair = unpack2x16float(lds_coc[rc.y * ROW_U32 + (rc.x >> 1)]);
170
+ s_coc = select(pair.x, pair.y, (rc.x & 1) != 0);
171
+ } else {
172
+ s_coc = textureLoad(tColorCoc, xt, 0).a;
173
+ }
174
+ let reach = abs(s_coc);
175
+
176
+ let cover = saturate(rho * reach - r + 1.0);
177
+ // Occlusion gate: foreground floods over everything; background
178
+ // only blurs a background centre (no bleed across a discontinuity).
179
+ let accept = (s_coc < -CUTOFF) || (s_coc > CUTOFF && center_is_background);
180
+
181
+ if (cover > 0.5 && accept) {
182
+ let b = MAX_STEPS - k; // k=1 -> bit 63 (MSB = nearest)
183
+ if (b < 32u) {
184
+ mask_lo = mask_lo | (1u << b);
185
+ } else {
186
+ mask_hi = mask_hi | (1u << (b - 32u));
187
+ }
188
+ }
189
+ }
190
+
191
+ // Nearest accepted cover = highest set bit; the high word holds the
192
+ // nearer steps (k <= 32) so test it first.
193
+ var found = false;
194
+ var samp = center_rgb;
195
+ var reach_used = 0.0;
196
+ var hb: u32 = 0xFFFFFFFFu;
197
+ if (mask_hi != 0u) {
198
+ hb = 32u + firstLeadingBit(mask_hi);
199
+ } else if (mask_lo != 0u) {
200
+ hb = firstLeadingBit(mask_lo);
201
+ }
202
+ if (hb != 0xFFFFFFFFu) {
203
+ let k = MAX_STEPS - hb;
204
+ let x = coord + dir * (f32(k) * step_len);
205
+ let xt = vec2<i32>(clamp(x, vec2<f32>(0.0), dims_f - 1.0));
206
+ let s = textureLoad(tColorCoc, xt, 0); // rgb + reach at the hit
207
+ samp = s.rgb;
208
+ reach_used = abs(s.a);
209
+ found = true;
210
+ }
211
+
212
+ let hl = 1.0 + dof.highlight_boost * rgb_to_luminance(samp);
213
+ let w = shape * hl;
214
+ acc = acc + samp * w;
215
+ wsum = wsum + w;
216
+ if (found) {
217
+ max_reach = max(max_reach, reach_used);
218
+ }
219
+ }
220
+
221
+ let color = acc / max(wsum, 1e-4);
222
+ let defocus = saturate(max_reach - CUTOFF);
223
+ textureStore(tOut, pixel, vec4<f32>(color, defocus));
224
+ }
225
+ `,
226
+ [
227
+ chunk_dof_sample_offset,
228
+ chunk_dof_aperture_shape,
229
+ chunk_stbn_sample_vec2,
230
+ chunk_rgb_to_luminance,
231
+ PI_DECLARATION,
232
+ ]
233
+ );
234
+
235
+ /**
236
+ * DoF ray-march compute form (Form-1 Phase B; see DOF_REFINEMENT_PLAN_02).
237
+ * A compute port of the fragment {@link shader_dof_raymarch} writing a storage
238
+ * texture. Same chunks, same 24-direction aperture sampling, same
239
+ * `(defocused colour, defocus amount)` output contract; `coord = gid + 0.5`
240
+ * reproduces the fragment's pixel-centre `@builtin(position)`, so per-pixel
241
+ * results match the reference.
242
+ *
243
+ * Built incrementally so each blind (GPU-only) change is validated in
244
+ * isolation against the fragment reference:
245
+ * - **Step 1**: bit-identical port proves the compute/storage-texture
246
+ * FrameGraph integration.
247
+ * - **Step 2a**: the per-ray serial break-loop becomes a branchless register
248
+ * bitmask resolved by `firstLeadingBit` same nearest-hit result, but every
249
+ * lane marches uniformly (no data-dependent break), the prerequisite for the
250
+ * cache.
251
+ * - **Step 2b** (here): each workgroup cooperatively loads its tile + apron
252
+ * CoC neighbourhood into `var<workgroup>` shared memory (two f16 packed per
253
+ * u32), and the inner march reads the cache instead of the texture. Because
254
+ * the CoC source is already `rgba16float`, the pack is lossless and the
255
+ * output stays bit-identical to the reference; the in-focus tile fast-path
256
+ * skips the load, and far taps beyond the apron fall back to a texture read.
257
+ * The win is the SAMPLES×STEPS per-pixel CoC taps collapsing to one
258
+ * cooperative load shared across the workgroup.
259
+ *
260
+ * Selected by `DepthOfField.march_mode === DOF_MARCH_MODE.COMPUTE`; the
261
+ * fragment march stays the default and the GPU correctness oracle.
262
+ *
263
+ * @type {ComputeShader}
264
+ */
265
+ export const shader_dof_raymarch_compute = ComputeShader.from({
266
+ label: "DoF/RayMarchCompute",
267
+ resources,
268
+ body,
269
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"shader_dof_slice_compute.d.ts","sourceRoot":"","sources":["../../../../../../../src/shade/renderer/postprocess/dof/raymarch/shader_dof_slice_compute.js"],"names":[],"mappings":"AAoPA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,uCAFU,aAAa,CAMpB;8BAzQ2B,kCAAkC"}
1
+ {"version":3,"file":"shader_dof_slice_compute.d.ts","sourceRoot":"","sources":["../../../../../../../src/shade/renderer/postprocess/dof/raymarch/shader_dof_slice_compute.js"],"names":[],"mappings":"AAuPA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,uCAFU,aAAa,CAMpB;8BA5Q2B,kCAAkC"}