@woosh/meep-engine 3.78.2 → 3.78.4

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 (278) hide show
  1. package/CHANGELOG.md +46 -13
  2. package/editor/view/node-graph/NodeGraphView.d.ts +1 -1
  3. package/editor/view/node-graph/NodeGraphView.js +1 -1
  4. package/package.json +1 -1
  5. package/src/core/math/physics/brdf/fresnel_Schlick_optimized.d.ts +2 -1
  6. package/src/core/math/physics/brdf/fresnel_Schlick_optimized.d.ts.map +1 -1
  7. package/src/core/math/physics/brdf/fresnel_Schlick_optimized.js +2 -1
  8. package/src/core/math/snap_to_integer.d.ts +13 -0
  9. package/src/core/math/snap_to_integer.d.ts.map +1 -0
  10. package/src/core/math/snap_to_integer.js +20 -0
  11. package/src/core/model/node-graph/NodeGraph.d.ts +0 -1
  12. package/src/core/model/node-graph/NodeGraph.d.ts.map +1 -1
  13. package/src/core/model/node-graph/NodeGraph.js +0 -1
  14. package/src/engine/asset/loaders/GroomAssetLoader.d.ts.map +1 -1
  15. package/src/engine/asset/loaders/GroomAssetLoader.js +2 -1
  16. package/src/engine/graphics/hair/Groom.d.ts +30 -0
  17. package/src/engine/graphics/hair/Groom.d.ts.map +1 -1
  18. package/src/engine/graphics/hair/Groom.js +35 -0
  19. package/src/engine/graphics/hair/GroomSerializationAdapter.d.ts +18 -2
  20. package/src/engine/graphics/hair/GroomSerializationAdapter.d.ts.map +1 -1
  21. package/src/engine/graphics/hair/GroomSerializationAdapter.js +36 -6
  22. package/src/engine/graphics/hair/GroomSerializationUpgrader_1_2.d.ts +8 -0
  23. package/src/engine/graphics/hair/GroomSerializationUpgrader_1_2.d.ts.map +1 -0
  24. package/src/engine/graphics/hair/GroomSerializationUpgrader_1_2.js +44 -0
  25. package/src/engine/graphics/hair/groom_bake_shelter.d.ts +33 -0
  26. package/src/engine/graphics/hair/groom_bake_shelter.d.ts.map +1 -0
  27. package/src/engine/graphics/hair/groom_bake_shelter.js +288 -0
  28. package/src/engine/graphics/hair/groom_bind_to_mesh.d.ts +1 -1
  29. package/src/engine/graphics/hair/groom_bind_to_mesh.js +1 -1
  30. package/src/engine/graphics/hair/groom_build_group.d.ts +10 -2
  31. package/src/engine/graphics/hair/groom_build_group.d.ts.map +1 -1
  32. package/src/engine/graphics/hair/groom_build_group.js +8 -2
  33. package/src/engine/graphics/hair/groom_build_guides.d.ts +1 -1
  34. package/src/engine/graphics/hair/groom_build_guides.js +1 -1
  35. package/src/engine/graphics/impostors/voxel/README.md +11 -11
  36. package/src/engine/physics/cloth/collider/ClothColliderKind.js +1 -1
  37. package/src/engine/physics/cloth/ecs/cloth_geodesic.d.ts +1 -1
  38. package/src/engine/physics/cloth/ecs/cloth_geodesic.js +1 -1
  39. package/src/engine/physics/cloth/solver/constraint/cloth_backstop_row.d.ts +2 -3
  40. package/src/engine/physics/cloth/solver/constraint/cloth_backstop_row.d.ts.map +1 -1
  41. package/src/engine/physics/cloth/solver/constraint/cloth_backstop_row.js +2 -3
  42. package/src/generation/filtering/numeric/sampling/AbstractCellFilterSampleGridLayer.d.ts +0 -2
  43. package/src/generation/filtering/numeric/sampling/AbstractCellFilterSampleGridLayer.d.ts.map +1 -1
  44. package/src/generation/filtering/numeric/sampling/AbstractCellFilterSampleGridLayer.js +0 -5
  45. package/src/generation/filtering/numeric/sampling/CellFilterSampleLayerCubic.d.ts.map +1 -1
  46. package/src/generation/filtering/numeric/sampling/CellFilterSampleLayerCubic.js +5 -3
  47. package/src/generation/filtering/numeric/sampling/CellFilterSampleLayerLinear.d.ts.map +1 -1
  48. package/src/generation/filtering/numeric/sampling/CellFilterSampleLayerLinear.js +5 -3
  49. package/src/generation/grid/coords/grid_to_texel.d.ts +7 -1
  50. package/src/generation/grid/coords/grid_to_texel.d.ts.map +1 -1
  51. package/src/generation/grid/coords/grid_to_texel.js +11 -1
  52. package/src/generation/grid/coords/grid_to_texel_span.d.ts +15 -0
  53. package/src/generation/grid/coords/grid_to_texel_span.d.ts.map +1 -0
  54. package/src/generation/grid/coords/grid_to_texel_span.js +38 -0
  55. package/src/generation/grid/coords/texel_to_grid.d.ts +2 -1
  56. package/src/generation/grid/coords/texel_to_grid.d.ts.map +1 -1
  57. package/src/generation/grid/coords/texel_to_grid.js +6 -1
  58. package/src/generation/grid/generation/discrete/GridTaskWaveFunctionCollapse.d.ts +32 -1
  59. package/src/generation/grid/generation/discrete/GridTaskWaveFunctionCollapse.d.ts.map +1 -1
  60. package/src/generation/grid/generation/discrete/GridTaskWaveFunctionCollapse.js +114 -9
  61. package/src/generation/grid/generation/discrete/layer/GridTaskBuildSourceDistanceMap.d.ts +8 -0
  62. package/src/generation/grid/generation/discrete/layer/GridTaskBuildSourceDistanceMap.d.ts.map +1 -1
  63. package/src/generation/grid/generation/discrete/layer/GridTaskBuildSourceDistanceMap.js +91 -29
  64. package/src/generation/grid/layers/GridDataLayer.d.ts +21 -2
  65. package/src/generation/grid/layers/GridDataLayer.d.ts.map +1 -1
  66. package/src/generation/grid/layers/GridDataLayer.js +43 -4
  67. package/src/generation/placement/action/GridCellActionPlaceTags.d.ts +7 -1
  68. package/src/generation/placement/action/GridCellActionPlaceTags.d.ts.map +1 -1
  69. package/src/generation/placement/action/GridCellActionPlaceTags.js +42 -16
  70. package/src/generation/placement/action/GridCellActionWriteFilterToLayer.d.ts +5 -0
  71. package/src/generation/placement/action/GridCellActionWriteFilterToLayer.d.ts.map +1 -1
  72. package/src/generation/placement/action/GridCellActionWriteFilterToLayer.js +32 -9
  73. package/src/generation/rules/CellMatcherLayerBitMaskTest.d.ts.map +1 -1
  74. package/src/generation/rules/CellMatcherLayerBitMaskTest.js +6 -2
  75. package/src/generation/wfc/GridWFCCompiledTileSet.d.ts +4 -2
  76. package/src/generation/wfc/GridWFCCompiledTileSet.d.ts.map +1 -1
  77. package/src/generation/wfc/GridWFCCompiledTileSet.js +2 -2
  78. package/src/generation/wfc/GridWFCTileSet.d.ts +16 -7
  79. package/src/generation/wfc/GridWFCTileSet.d.ts.map +1 -1
  80. package/src/generation/wfc/GridWFCTileSet.js +32 -8
  81. package/src/shade/playground/contact_shadows/shader_contact_lab_composite.js +2 -2
  82. package/src/shade/playground/particle_editor/README.md +2 -2
  83. package/src/shade/playground/probe_clipmap/index.html +1 -1
  84. package/src/shade/playground/screen_probes/README.md +5 -5
  85. package/src/shade/playground/screen_probes/main.js +1 -1
  86. package/src/shade/playground/tonemap_sdr/README.md +3 -2
  87. package/src/shade/playground/vgeo_scene/README.md +1 -3
  88. package/src/shade/playground/vgeo_scene/main.js +3 -3
  89. package/src/shade/renderer/Renderer.d.ts +3 -3
  90. package/src/shade/renderer/Renderer.js +4 -4
  91. package/src/shade/renderer/ShadeIndirectLightingMode.js +1 -1
  92. package/src/shade/renderer/camera/PerspectiveCamera.js +1 -1
  93. package/src/shade/renderer/deferred/tonemap/ColorGrade.d.ts +11 -13
  94. package/src/shade/renderer/deferred/tonemap/ColorGrade.d.ts.map +1 -1
  95. package/src/shade/renderer/deferred/tonemap/ColorGrade.js +11 -13
  96. package/src/shade/renderer/deferred/tonemap/TONE_MAP_OPERATOR_ACES.d.ts.map +1 -1
  97. package/src/shade/renderer/deferred/tonemap/TONE_MAP_OPERATOR_ACES.js +6 -7
  98. package/src/shade/renderer/deferred/tonemap/ToneMapper.d.ts +1 -1
  99. package/src/shade/renderer/deferred/tonemap/ToneMapper.js +1 -1
  100. package/src/shade/renderer/deferred/tonemap/m3_white_balance_rec709.d.ts +6 -8
  101. package/src/shade/renderer/deferred/tonemap/m3_white_balance_rec709.d.ts.map +1 -1
  102. package/src/shade/renderer/deferred/tonemap/m3_white_balance_rec709.js +7 -10
  103. package/src/shade/renderer/geometry/sdf/MESH_SDF.d.ts +1 -1
  104. package/src/shade/renderer/geometry/sdf/MESH_SDF.js +1 -1
  105. package/src/shade/renderer/geometry/sdf/bake/shader_mesh_sdf_classify.d.ts +1 -1
  106. package/src/shade/renderer/geometry/sdf/bake/shader_mesh_sdf_classify.js +1 -1
  107. package/src/shade/renderer/geometry/sdf/bake/shader_mesh_sdf_evaluate.d.ts +1 -1
  108. package/src/shade/renderer/geometry/sdf/bake/shader_mesh_sdf_evaluate.js +1 -1
  109. package/src/shade/renderer/geometry/sdf/chunk_blas_query_band_sdf.d.ts +1 -2
  110. package/src/shade/renderer/geometry/sdf/chunk_blas_query_band_sdf.d.ts.map +1 -1
  111. package/src/shade/renderer/geometry/sdf/chunk_blas_query_band_sdf.js +1 -2
  112. package/src/shade/renderer/geometry/sdf/chunk_scene_point_query_volume_sign.d.ts.map +1 -1
  113. package/src/shade/renderer/geometry/sdf/chunk_scene_point_query_volume_sign.js +2 -1
  114. package/src/shade/renderer/geometry/sdf/surface/MESH_SURFACE_BAKE.d.ts +1 -1
  115. package/src/shade/renderer/geometry/sdf/surface/MESH_SURFACE_BAKE.js +1 -1
  116. package/src/shade/renderer/geometry/virtual/build/level/vgeo_build_cluster_graph.js +1 -1
  117. package/src/shade/renderer/geometry/virtual/format/page/VGEO_DEFAULT_PAGE_SIZE.d.ts +2 -2
  118. package/src/shade/renderer/geometry/virtual/format/page/VGEO_DEFAULT_PAGE_SIZE.js +2 -2
  119. package/src/shade/renderer/geometry/virtual/runtime/cut/chunk_vgeo_cut_access.d.ts +2 -2
  120. package/src/shade/renderer/geometry/virtual/runtime/cut/chunk_vgeo_cut_access.js +4 -4
  121. package/src/shade/renderer/geometry/virtual/runtime/cut/chunk_vgeo_cut_instance.d.ts +1 -1
  122. package/src/shade/renderer/geometry/virtual/runtime/cut/chunk_vgeo_cut_instance.js +1 -1
  123. package/src/shade/renderer/geometry/virtual/runtime/cut/shader_vgeo_cut_collect.js +1 -1
  124. package/src/shade/renderer/geometry/virtual/runtime/layout/VGEO_INSTANCE_OFFSET.d.ts +3 -3
  125. package/src/shade/renderer/geometry/virtual/runtime/layout/VGEO_INSTANCE_OFFSET.js +3 -3
  126. package/src/shade/renderer/global_illumination/brick4/README.md +2 -1
  127. package/src/shade/renderer/global_illumination/probe_clipmap/ProbeClipmapSettings.d.ts +4 -6
  128. package/src/shade/renderer/global_illumination/probe_clipmap/ProbeClipmapSettings.d.ts.map +1 -1
  129. package/src/shade/renderer/global_illumination/probe_clipmap/ProbeClipmapSettings.js +4 -6
  130. package/src/shade/renderer/global_illumination/probe_clipmap/brick/BRICK_MOVERS.d.ts +1 -1
  131. package/src/shade/renderer/global_illumination/probe_clipmap/brick/BRICK_MOVERS.js +1 -1
  132. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.d.ts +1 -1
  133. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.js +2 -2
  134. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/chunk_mesh_brick_texel.d.ts +1 -1
  135. package/src/shade/renderer/global_illumination/probe_clipmap/brick/mesh/chunk_mesh_brick_texel.js +1 -1
  136. package/src/shade/renderer/global_illumination/screen_probe/GPUScreenProbeGI.d.ts +1 -1
  137. package/src/shade/renderer/global_illumination/screen_probe/GPUScreenProbeGI.js +1 -1
  138. package/src/shade/renderer/global_illumination/screen_probe/SCREEN_PROBE.d.ts +28 -35
  139. package/src/shade/renderer/global_illumination/screen_probe/SCREEN_PROBE.d.ts.map +1 -1
  140. package/src/shade/renderer/global_illumination/screen_probe/SCREEN_PROBE.js +28 -35
  141. package/src/shade/renderer/global_illumination/screen_probe/ScreenProbeSettings.d.ts +21 -24
  142. package/src/shade/renderer/global_illumination/screen_probe/ScreenProbeSettings.d.ts.map +1 -1
  143. package/src/shade/renderer/global_illumination/screen_probe/ScreenProbeSettings.js +21 -24
  144. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe.d.ts +8 -8
  145. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe.js +8 -8
  146. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_brdf_density.d.ts +4 -4
  147. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_brdf_density.js +4 -4
  148. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_interpolate.d.ts +3 -5
  149. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_interpolate.d.ts.map +1 -1
  150. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_interpolate.js +3 -5
  151. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_lighting_history.d.ts +4 -4
  152. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_lighting_history.js +4 -4
  153. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_rough_specular.d.ts +2 -3
  154. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_rough_specular.d.ts.map +1 -1
  155. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_rough_specular.js +2 -3
  156. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_screen_march.d.ts +4 -4
  157. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_screen_march.js +4 -4
  158. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_surface.d.ts +2 -4
  159. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_surface.d.ts.map +1 -1
  160. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_surface.js +2 -4
  161. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_brick.d.ts +2 -4
  162. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_brick.d.ts.map +1 -1
  163. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_brick.js +2 -4
  164. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_gather.d.ts +13 -17
  165. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_gather.d.ts.map +1 -1
  166. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_gather.js +13 -17
  167. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_importance.d.ts +11 -14
  168. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_importance.d.ts.map +1 -1
  169. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_importance.js +11 -14
  170. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_pick.d.ts +2 -2
  171. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_pick.js +2 -2
  172. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_place.d.ts +9 -9
  173. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_place.js +9 -9
  174. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_resolve.d.ts +15 -18
  175. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_resolve.d.ts.map +1 -1
  176. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_resolve.js +16 -19
  177. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_trace_screen.d.ts +10 -11
  178. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_trace_screen.d.ts.map +1 -1
  179. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_trace_screen.js +11 -12
  180. package/src/shade/renderer/hair/GPUHairSystem.d.ts.map +1 -1
  181. package/src/shade/renderer/hair/GPUHairSystem.js +27 -2
  182. package/src/shade/renderer/hair/HAIR_DATABASE_SPEC.d.ts.map +1 -1
  183. package/src/shade/renderer/hair/HAIR_DATABASE_SPEC.js +4 -0
  184. package/src/shade/renderer/hair/HAIR_SIMULATION.d.ts +27 -6
  185. package/src/shade/renderer/hair/HAIR_SIMULATION.d.ts.map +1 -1
  186. package/src/shade/renderer/hair/HAIR_SIMULATION.js +33 -6
  187. package/src/shade/renderer/hair/chunk_hair_bsdf.d.ts +9 -8
  188. package/src/shade/renderer/hair/chunk_hair_bsdf.d.ts.map +1 -1
  189. package/src/shade/renderer/hair/chunk_hair_bsdf.js +10 -9
  190. package/src/shade/renderer/hair/chunk_hair_dual_scattering.d.ts +5 -6
  191. package/src/shade/renderer/hair/chunk_hair_dual_scattering.d.ts.map +1 -1
  192. package/src/shade/renderer/hair/chunk_hair_dual_scattering.js +5 -6
  193. package/src/shade/renderer/hair/chunk_hair_guide.d.ts +9 -2
  194. package/src/shade/renderer/hair/chunk_hair_guide.d.ts.map +1 -1
  195. package/src/shade/renderer/hair/chunk_hair_guide.js +30 -2
  196. package/src/shade/renderer/hair/hair_lighting.d.ts +3 -3
  197. package/src/shade/renderer/hair/hair_lighting.d.ts.map +1 -1
  198. package/src/shade/renderer/hair/hair_lighting.js +4 -5
  199. package/src/shade/renderer/hair/hair_scattering_lut.d.ts +5 -5
  200. package/src/shade/renderer/hair/hair_scattering_lut.js +5 -5
  201. package/src/shade/renderer/hair/shader_hair_roots.d.ts +2 -2
  202. package/src/shade/renderer/hair/shader_hair_roots.js +2 -2
  203. package/src/shade/renderer/hair/shader_hair_simulate.d.ts +5 -2
  204. package/src/shade/renderer/hair/shader_hair_simulate.d.ts.map +1 -1
  205. package/src/shade/renderer/hair/shader_hair_simulate.js +23 -5
  206. package/src/shade/renderer/light/environment/DEFINES.d.ts +1 -1
  207. package/src/shade/renderer/light/environment/DEFINES.js +1 -1
  208. package/src/shade/renderer/light/environment/shader_convolve_reflection_map_from_blurred.js +2 -2
  209. package/src/shade/renderer/material/dispatch/MaterialDispatch.d.ts +1 -2
  210. package/src/shade/renderer/material/dispatch/MaterialDispatch.d.ts.map +1 -1
  211. package/src/shade/renderer/material/dispatch/MaterialDispatch.js +1 -2
  212. package/src/shade/renderer/material/standard/fragment_gbuffer.d.ts.map +1 -1
  213. package/src/shade/renderer/material/standard/fragment_gbuffer.js +2 -1
  214. package/src/shade/renderer/material/util/dielectric_specular_color.d.ts +1 -1
  215. package/src/shade/renderer/material/util/dielectric_specular_color.js +1 -1
  216. package/src/shade/renderer/postprocess/dof/gather/DOF2_CONFIG.d.ts +1 -1
  217. package/src/shade/renderer/postprocess/dof/gather/DOF2_CONFIG.js +1 -1
  218. package/src/shade/renderer/postprocess/dof/gather/DOF2_PRESETS.js +1 -1
  219. package/src/shade/renderer/postprocess/dof/gather/DOF2_SETTINGS_STRUCT.d.ts +1 -1
  220. package/src/shade/renderer/postprocess/dof/gather/DOF2_SETTINGS_STRUCT.js +1 -1
  221. package/src/shade/renderer/postprocess/dof/gather/DOF2_TEXTURE_FORMAT.d.ts +1 -1
  222. package/src/shade/renderer/postprocess/dof/gather/DOF2_TEXTURE_FORMAT.js +1 -1
  223. package/src/shade/renderer/postprocess/dof/gather/DepthOfFieldU.d.ts +3 -4
  224. package/src/shade/renderer/postprocess/dof/gather/DepthOfFieldU.d.ts.map +1 -1
  225. package/src/shade/renderer/postprocess/dof/gather/DepthOfFieldU.js +3 -4
  226. package/src/shade/renderer/postprocess/dof/gather/graph_postprocess_dof2.d.ts +1 -1
  227. package/src/shade/renderer/postprocess/dof/gather/graph_postprocess_dof2.js +1 -1
  228. package/src/shade/renderer/postprocess/eye/GPUCameraExposureManager.d.ts +1 -1
  229. package/src/shade/renderer/postprocess/eye/GPUCameraExposureManager.js +1 -1
  230. package/src/shade/renderer/postprocess/gtao/ao_reproject_shader.d.ts.map +1 -1
  231. package/src/shade/renderer/postprocess/gtao/ao_reproject_shader.js +2 -3
  232. package/src/shade/renderer/postprocess/motion_blur/MOTION_BLUR_CONFIG.d.ts +1 -2
  233. package/src/shade/renderer/postprocess/motion_blur/MOTION_BLUR_CONFIG.d.ts.map +1 -1
  234. package/src/shade/renderer/postprocess/motion_blur/MOTION_BLUR_CONFIG.js +1 -2
  235. package/src/shade/renderer/postprocess/taa/chunk_fsr2_compute_depth_clip.d.ts +2 -3
  236. package/src/shade/renderer/postprocess/taa/chunk_fsr2_compute_depth_clip.d.ts.map +1 -1
  237. package/src/shade/renderer/postprocess/taa/chunk_fsr2_compute_depth_clip.js +2 -3
  238. package/src/shade/renderer/postprocess/taa/filter_blackman_harris.d.ts +1 -1
  239. package/src/shade/renderer/postprocess/taa/filter_blackman_harris.js +1 -1
  240. package/src/shade/renderer/rasterize/native/depth/shadow_cascade_rasterization_pass_descriptor.d.ts +1 -1
  241. package/src/shade/renderer/rasterize/native/depth/shadow_cascade_rasterization_pass_descriptor.js +1 -1
  242. package/src/shade/renderer/rasterize/native/depth/shadow_rasterization_alpha_tested_pass_descriptor.js +1 -1
  243. package/src/shade/renderer/restir/di/ReSTIRDI.d.ts +3 -3
  244. package/src/shade/renderer/restir/di/ReSTIRDI.js +3 -3
  245. package/src/shade/renderer/restir/di/chunk_restir_trace_visibility.d.ts +1 -1
  246. package/src/shade/renderer/restir/di/chunk_restir_trace_visibility.js +1 -1
  247. package/src/shade/renderer/shader/chunk/brdf/chunk_MIN_DIELECTRICS_F0.d.ts +1 -1
  248. package/src/shade/renderer/shader/chunk/brdf/chunk_MIN_DIELECTRICS_F0.js +1 -1
  249. package/src/shade/renderer/shader/chunk/brdf/chunk_shadowed_F90.d.ts +1 -2
  250. package/src/shade/renderer/shader/chunk/brdf/chunk_shadowed_F90.d.ts.map +1 -1
  251. package/src/shade/renderer/shader/chunk/brdf/chunk_shadowed_F90.js +1 -2
  252. package/src/shade/renderer/shader/chunk/color/conversion/chunk_CRM_REC709_AP1.d.ts +4 -5
  253. package/src/shade/renderer/shader/chunk/color/conversion/chunk_CRM_REC709_AP1.d.ts.map +1 -1
  254. package/src/shade/renderer/shader/chunk/color/conversion/chunk_CRM_REC709_AP1.js +4 -5
  255. package/src/shade/renderer/shader/chunk/color/grade/chunk_color_grade.js +2 -2
  256. package/src/shade/renderer/shader/chunk/color/tonemap/aces/chunk_aces_ue_matrices.d.ts +2 -2
  257. package/src/shade/renderer/shader/chunk/color/tonemap/aces/chunk_aces_ue_matrices.js +2 -2
  258. package/src/shade/renderer/shader/chunk/color/tonemap/aces/chunk_tonemap_ue_filmic.d.ts +14 -17
  259. package/src/shade/renderer/shader/chunk/color/tonemap/aces/chunk_tonemap_ue_filmic.d.ts.map +1 -1
  260. package/src/shade/renderer/shader/chunk/color/tonemap/aces/chunk_tonemap_ue_filmic.js +18 -21
  261. package/src/shade/renderer/shader/chunk/filter/chunk_filter_blackman_harris.d.ts +1 -1
  262. package/src/shade/renderer/shader/chunk/filter/chunk_filter_blackman_harris.js +1 -1
  263. package/src/shade/renderer/shader/chunk/filter/chunk_filter_blackman_harris229.d.ts +1 -1
  264. package/src/shade/renderer/shader/chunk/filter/chunk_filter_blackman_harris229.js +1 -1
  265. package/src/shade/renderer/shader/chunk/filter/chunk_multiscale_mean.d.ts +3 -4
  266. package/src/shade/renderer/shader/chunk/filter/chunk_multiscale_mean.d.ts.map +1 -1
  267. package/src/shade/renderer/shader/chunk/filter/chunk_multiscale_mean.js +3 -4
  268. package/src/shade/renderer/shader/chunk/material/chunk_re_direct_multiscatter.d.ts +1 -1
  269. package/src/shade/renderer/shader/chunk/material/chunk_re_direct_multiscatter.js +1 -1
  270. package/src/shade/renderer/shadow/map/GPUSceneShadowmapContext.js +3 -3
  271. package/src/shade/renderer/shadow/map/shader/chunk_sample_shadowmap_cascade.d.ts +6 -8
  272. package/src/shade/renderer/shadow/map/shader/chunk_sample_shadowmap_cascade.d.ts.map +1 -1
  273. package/src/shade/renderer/shadow/map/shader/chunk_sample_shadowmap_cascade.js +8 -10
  274. package/src/shade/renderer/shadow/map/shader/chunk_shadow_caster_depth_bias.d.ts +5 -7
  275. package/src/shade/renderer/shadow/map/shader/chunk_shadow_caster_depth_bias.d.ts.map +1 -1
  276. package/src/shade/renderer/shadow/map/shader/chunk_shadow_caster_depth_bias.js +5 -7
  277. package/src/shade/renderer/texture/virtual/README.md +257 -257
  278. package/src/shade/renderer/volumetrics/shader_volumetrics_build_lighting.js +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"chunk_shadow_caster_depth_bias.d.ts","sourceRoot":"","sources":["../../../../../../../src/shade/renderer/shadow/map/shader/chunk_shadow_caster_depth_bias.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,6CAFU,SAAS,CAmBhB;0BAzCuB,uCAAuC"}
1
+ {"version":3,"file":"chunk_shadow_caster_depth_bias.d.ts","sourceRoot":"","sources":["../../../../../../../src/shade/renderer/shadow/map/shader/chunk_shadow_caster_depth_bias.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,6CAFU,SAAS,CAmBhB;0BAvCuB,uCAAuC"}
@@ -1,19 +1,17 @@
1
1
  import { CodeChunk } from "../../../shader/compiler/CodeChunk.js";
2
2
 
3
3
  /**
4
- * How far a cascade's caster vertex is pushed away from the light, in world units: Unreal's cascaded
5
- * shadow map caster bias (UE 5.4 `ShadowDepthVertexShader.usf`, `FProjectedShadowInfo::UpdateShaderDepthBias`)
6
- * at its defaults, in texels of the cascade.
4
+ * How far a cascade's caster vertex is pushed away from the light, in world units: the caster bias of
5
+ * the cascaded shadow map scheme, set in texels of the cascade.
7
6
  *
8
7
  * ```wgsl
9
8
  * fn shadow_caster_depth_bias(normal_ws: vec3f, light_direction_ws: vec3f, texel_world_size: f32) -> f32
10
9
  * ```
11
10
  *
12
11
  * `2.5 texels × (1 + 1.5 × min(tan θ, 1))`, θ the angle between the vertex normal and the light, either
13
- * facing. The constant is `r.Shadow.CSMDepthBias` (10) times the light's `ShadowBias` (0.5) times the
14
- * cascade's `WorldSpaceTexelScale`, half a texel, at `ShadowCascadeBiasDistribution` 1. The slope term is
15
- * that times `r.Shadow.CSMSlopeScaleDepthBias` (3) times the light's `ShadowSlopeBias` (0.5), with the
16
- * slope clamped at `r.Shadow.ShadowMaxSlopeScaleDepthBias` (1, 45°).
12
+ * facing. The constant push is 2.5 texels, whatever the slope. The slope term adds 1.5 times the
13
+ * constant per unit of `tan θ`, with the slope clamped at 1 (45°), so no caster is pushed further than a
14
+ * 45° one.
17
15
  *
18
16
  * It is the caster half of one scheme: the rasterizer adds no bias of its own, and the receiver
19
17
  * ({@link chunk_sample_shadowmap_cascade}) takes no offset and compares softly instead.
@@ -1,257 +1,257 @@
1
- # Virtual Textures
2
-
3
- Opt-in software virtual texturing for the deferred (visibility-buffer)
4
- renderer: materials sample from streamed pages of arbitrarily large
5
- textures, with GPU memory bounded by what is visible instead of what is
6
- loaded. Built for **hundreds of simultaneous virtual textures** sharing one
7
- page table, one physical cache and one feedback pass.
8
-
9
- This README is the design document: adopting the system, configuration and
10
- how it works. It used to defer the extended treatment — literature survey,
11
- decision log, scale math, future work — to a `VIRTUAL_TEXTURES.md` in the
12
- repo root, but that file belonged to the repository Shade was vendored from
13
- and never came across. The decision log is under "How it works" below; the
14
- scale numbers are in the configuration table.
15
-
16
- ---
17
-
18
- ## Exercising it
19
-
20
- There is no demo page. `prototype_virtual_texture.js` used to be one, but it
21
- booted from a harness in a repo that is no longer around and imported
22
- `lil-gui`/`stats.js`, neither of which is installed here; it was deleted along
23
- with the rest of the unreachable playground entries. For the record, the scene
24
- it stood up was four objects chosen to exercise every path:
25
-
26
- | Object | Stack | Source | Demonstrated |
27
- |---|---|---|---|
28
- | Ground plane (100 m) | 8192² | `VTSourceProcedural`, instant | mip selection & residency, visually |
29
- | Back wall | 4096² | `VTSourceProcedural`, 250 ms latency | streaming: pinned root first, refinement blending in |
30
- | Box | 2048² | `VTSourceImage` (runtime-tiled canvas) | zero-pipeline adoption of ordinary images |
31
- | Plain orange box | — | regular material | mixed standard/VT pipelines in one material pass |
32
-
33
- The procedural tiles used the classic VT debug pattern: **color = mip level,
34
- label = `mip:x,y` page address**, white page frames.
35
-
36
- What exercises the system now is its spec coverage, each `.spec.js` sitting
37
- beside the module it tests: `VTPageTable`, `VTPhysicalCache`,
38
- `PageTableQuadAllocator`, `VirtualTextureManager`, `VT_CONSTANTS`,
39
- `vt_pipeline_compat` and `vt_shaders`.
40
-
41
- ---
42
-
43
- ## Using it
44
-
45
- ### Opt a material in
46
-
47
- ```js
48
- import { VirtualTextureStack } from "./texture/virtual/VirtualTextureStack.js";
49
- import { VTSourceTiled } from "./texture/virtual/source/VTSourceTiled.js";
50
-
51
- material.vt_stack = VirtualTextureStack.from({
52
- label: 'rock',
53
- size: 8192, // texels; square, power of two
54
- source: new VTSourceTiled({
55
- layers: [ // URL template per cache layer
56
- 'tiles/rock/albedo/{mip}/{x}_{y}.webp',
57
- 'tiles/rock/normal/{mip}/{x}_{y}.webp',
58
- 'tiles/rock/orm/{mip}/{x}_{y}.webp',
59
- ],
60
- }),
61
- wrap: true, // repeat (false = clamp), applied in-shader
62
- uv_set: 0, // 0 or 1
63
- average_color: [0.4, 0.35, 0.3, 1], // linear premultiplied; shown before the root arrives
64
- });
65
- ```
66
-
67
- That is the entire opt-in. Registration happens automatically when the
68
- material is first built; a stack may be shared by any number of materials.
69
- Everything else in the engine renders exactly as before, and the system
70
- allocates nothing until the first stack registers.
71
-
72
- A **stack** is the unit of virtualization: a set of texture layers
73
- (albedo / normal / ORM in the standard cache group) sharing one UV set and
74
- one resolution. The whole set streams, resides and is addressed as one —
75
- one feedback value, one page-table entry, one residency decision, and in the
76
- material shader one page-table fetch feeds all three layer samples. This is
77
- the "do the work once for matching UV sets" design, per UE's VT stacks /
78
- Granite's stacked textures.
79
-
80
- ### Tile sources
81
-
82
- A source implements:
83
-
84
- ```js
85
- prepare(geometry)? // called on registration: {page_size, border,
86
- // slot_size, layer_count, size, mip_count}
87
- load_page(mip, x, y, signal) // → Promise<payload[]>, one per layer;
88
- // payloads are slot_size² (border baked in);
89
- // reject with AbortError on signal abort
90
- layer_mask // bitmask of layers provided (bit0 = albedo…)
91
- destroy()? // called on last unregistration
92
- ```
93
-
94
- Included:
95
-
96
- - **`VTSourceTiled`** — pre-tiled page files over HTTP, decoded with
97
- `createImageBitmap` (WebP/AVIF/PNG/JPEG — browser-native, no WASM).
98
- `legacy_meep_mips: true` consumes the original meep VT converter's output
99
- (`${mip}-${x}-${y}.png`, coarsest-is-zero naming) unchanged. Serve
100
- normal/ORM tiles lossless or 4:4:4 — chroma subsampling mangles them.
101
- - **`VTSourceImage`** — runtime tiler: hand it ordinary decoded images and it
102
- builds a canvas mip pyramid once and blits padded tiles on demand. The
103
- adoption path — wins GPU memory and bandwidth, not host memory.
104
- - **`VTSourceProcedural`** — instant labeled debug tiles, optional artificial
105
- latency. Also the reference source implementation.
106
-
107
- Missing layers (e.g. albedo-only stacks) fall back per layer in the shader:
108
- albedo → the stack's `average_color`, normal → flat +Z, ORM → neutral.
109
-
110
- ### Constraints (v1)
111
-
112
- - **Opaque materials only** (asserted). The alpha-tested visibility pass and
113
- OIT sample the *regular* albedo texture, where VT residency isn't
114
- guaranteed.
115
- - `size` is square, power-of-two, a multiple of `page_size`, ≤ 512 pages per
116
- axis (64k texels at the default page size).
117
- - Emissive stays a regular texture; a `uv_set: 1` stack re-interpolates uv1
118
- for all of that material's samples, emissive included.
119
- - Feedback covers the primary view. Path tracer / lightmap baker see
120
- fallback colors (no VT sampling there yet).
121
- - Filtering is bilinear + per-pixel nearest mip (id Tech's shipped baseline);
122
- anisotropy and trilinear are documented follow-ups — the 4-texel borders
123
- already budget for aniso ~4×.
124
-
125
- ### Configuration
126
-
127
- `graphics.virtual_textures.configure({...})` **before the first stack
128
- registers** (geometry freezes at first use):
129
-
130
- | Key | Default | Meaning |
131
- |---|---|---|
132
- | `page_size` | 128 | payload texels per page side |
133
- | `border` | 4 | border texels per side, baked into tiles (slot = 136²) |
134
- | `atlas_size` | 4096 | physical cache side → 30×30 = 900 pages, ~64 MB/layer |
135
- | `table_size` | 1024 | shared page table side (texels = pages), mip-mapped r32uint |
136
- | `layers` | albedo/normal/orm | cache group: name, format, premultiply |
137
- | `feedback_stride` | 4 | sample 1 px per stride² block, jittered (runtime-adjustable) |
138
- | `max_uploads_per_frame` | 8 | page-upload budget |
139
- | `max_concurrent_loads` | 32 | in-flight source loads |
140
- | `request_cap_fraction` | ⅓ | pending requests ≤ cap × cache capacity |
141
- | `eviction_protect_window` | 4 | frames a touched page is unevictable (covers readback latency) |
142
- | `queue_stale_window` | 30 | untouched queued requests dropped after N frames |
143
- | `pressure_high/low_watermark` | 0.9 / 0.75 | residency bias hysteresis |
144
-
145
- Runtime switch: `renderer.feature_virtual_textures` (default true) stops
146
- feedback and streaming; already-resident pages keep rendering.
147
-
148
- ---
149
-
150
- ## How it works
151
-
152
- ```
153
- viz buffer (mesh+triangle ids)
154
- │
155
- ▼
156
- vt_feedback (compute, 1 px per stride², jittered) [GPU]
157
- pixel → mesh → material → stack; UV + analytic gradients
158
- (same chunks as the material pass); mip select; insert
159
- packed key into a hash set of unique requests
160
- │ ~64 KB raw hash buffer
161
- ▼
162
- async readback (pooled staging, mapAsync, ≤3 in flight) [GPU→CPU, 1–2 frames]
163
- │
164
- ▼
165
- VirtualTextureManager.process_feedback [CPU]
166
- resident → LRU touch (incl. the ancestor actually serving
167
- a missing cell); miss → request + missing-ancestor chain
168
- │
169
- update() per frame: apply arrivals (budgeted uploads),
170
- evict (LRU + protection window + finest-first ties),
171
- flush page-table dirty rects + stack info rows,
172
- issue loads coarse-first with backoff on failures
173
- │
174
- ▼
175
- VTPageTable (shared r32uint, mips) VTPhysicalCache (atlas per layer,
176
- quadtree regions per stack; lockstep slots, page+border)
177
- every texel = nearest RESIDENT │
178
- ancestor-or-self entry │
179
- └───────────────┬───────────────────────────┘
180
- ▼
181
- material pass (VT variant): ONE textureLoad into the
182
- table → physical UV → N bilinear layer fetches
183
- ```
184
-
185
- Design points worth knowing before modifying:
186
-
187
- - **Shared page table.** Every stack owns a buddy-allocated square region of
188
- one mip-mapped `r32uint` texture. Buddy alignment makes `origin >> mip`
189
- exact at every mip the region supports, so hundreds of stacks need no
190
- per-mip metadata and never collide. Entries are **pre-filled with the
191
- nearest resident ancestor** (maintained incrementally on load/evict by
192
- `VTPageTable`'s match-and-prune DFS), which is what keeps sampling a
193
- single fetch with automatic coarse fallback — no shader mip-walk.
194
- - **Feedback ↔ sampler parity.** Both compile the same
195
- `build_chunk_vt_lookup` chunk and the same derivative-bias constants; if
196
- the mip formulas ever diverge, the system requests pages it doesn't sample.
197
- Change the chunk, never one side.
198
- - **Key formats** (single source: `VT_CONSTANTS.js`, WGSL mirrors tested for
199
- parity): request key `stack:10 | mip:4 | x:9 | y:9`, stored `key+1` so a
200
- zero-cleared buffer reads empty; page-table entry
201
- `phys_x:8 | phys_y:8 | mip:5 | valid:1`. **Stack ids 0 and 1023 are
202
- reserved** — 1023 is the "no stack" sentinel, and 0 is never assigned so
203
- zero-initialized / not-yet-flushed GPU rows decode to a harmless
204
- "unknown stack" instead of junk requests.
205
- - **Residency policy.** LRU with a protection window covering readback
206
- latency; each stack's root page is pinned at registration (a fallback is
207
- always resident once it arrives — held and retried, never dropped, even
208
- under lock saturation); eviction ties shed the finest mip first; requests
209
- are capped per cycle and canceled when stale; failed loads back off
210
- exponentially in a negative cache; cache pressure raises a feedback mip
211
- bias so oversubscription degrades to blur instead of thrash.
212
- - **Frame protocol.** `update()` runs in `Renderer.#begin_frame`
213
- (queue-ordered before the frame's submits). Stacks registered mid-frame
214
- (materials build during scene update) are published by an idempotent
215
- `flush_gpu_state()` re-run from `graph_feedback`, so first frames render
216
- correctly.
217
- - **Struct packing hazard.** `WebGPUStruct.pack()` reorders fields — never
218
- construct packed structs positionally in WGSL (tests included); use
219
- member-wise assignment. Inline chunk structs (`VTPhysical`,
220
- `VTPageTableEntry`) are unpacked and safe.
221
-
222
- ## Files
223
-
224
- | File | Role |
225
- |---|---|
226
- | `VirtualTextureManager.js` | orchestrator: registry, residency, streaming, FrameGraph wiring |
227
- | `VirtualTextureStack.js` | scene-side stack description (`material.vt_stack`) |
228
- | `VTPageTable.js` | shared table texture + CPU mirror + ancestor-closure propagation |
229
- | `PageTableQuadAllocator.js` | buddy allocator (the `origin >> mip` guarantee) |
230
- | `VTPhysicalCache.js` | per-layer atlases, lockstep slots, LRU metadata, uploads |
231
- | `VT_CONSTANTS.js` | bit layouts, sentinels, JS pack/unpack |
232
- | `VT_STACK_INFO_STRUCT.js` | per-stack GPU record |
233
- | `build_chunk_vt_lookup.js` | shared WGSL: wrap, mip select, table load, physical UV |
234
- | `chunk_vt_request_key.js` | WGSL request-key packing |
235
- | `build_shader_vt_feedback.js` | the feedback compute shader |
236
- | `source/VTSource{Procedural,Image,Tiled}.js` | tile providers |
237
- | `../../material/standard/fragment_gbuffer_vt.js` | VT material shader variant |
238
-
239
- ## Tests
240
-
241
- ```
242
- npx vitest run src/shade/renderer/texture/virtual
243
- ```
244
-
245
- ~60 tests: allocator properties; page-table nearest-ancestor invariant
246
- against a brute-force reference model (randomized, including physical-slot
247
- recycling); cache LRU/pinning/tie-breaks; manager end-to-end with a mocked
248
- GPU (register → pin → feedback → stream → evict → unregister) plus the
249
- policy set (request cap, stale aging, coarse-first order, serving-ancestor
250
- protection, failure backoff, locked-root retry, teardown flush, stale-key
251
- rejection); WGSL validity for both shaders (tree-sitter); WGSL↔JS packing
252
- and physical-UV parity through the in-repo emulator, under default and
253
- non-default geometry; and standard↔VT pipeline bind-group-layout equality.
254
-
255
- Known untestable-here: the GPU hash-set insert loop (the emulator has no
256
- atomics) and the canvas-based sources (no OffscreenCanvas under Node) — both
257
- are covered by the demo instead.
1
+ # Virtual Textures
2
+
3
+ Opt-in software virtual texturing for the deferred (visibility-buffer)
4
+ renderer: materials sample from streamed pages of arbitrarily large
5
+ textures, with GPU memory bounded by what is visible instead of what is
6
+ loaded. Built for **hundreds of simultaneous virtual textures** sharing one
7
+ page table, one physical cache and one feedback pass.
8
+
9
+ This README is the design document: adopting the system, configuration and
10
+ how it works. It used to defer the extended treatment — literature survey,
11
+ decision log, scale math, future work — to a `VIRTUAL_TEXTURES.md` in the
12
+ repo root, but that file belonged to the repository Shade was vendored from
13
+ and never came across. The decision log is under "How it works" below; the
14
+ scale numbers are in the configuration table.
15
+
16
+ ---
17
+
18
+ ## Exercising it
19
+
20
+ There is no demo page. `prototype_virtual_texture.js` used to be one, but it
21
+ booted from a harness in a repo that is no longer around and imported
22
+ `lil-gui`/`stats.js`, neither of which is installed here; it was deleted along
23
+ with the rest of the unreachable playground entries. For the record, the scene
24
+ it stood up was four objects chosen to exercise every path:
25
+
26
+ | Object | Stack | Source | Demonstrated |
27
+ |---|---|---|---|
28
+ | Ground plane (100 m) | 8192² | `VTSourceProcedural`, instant | mip selection & residency, visually |
29
+ | Back wall | 4096² | `VTSourceProcedural`, 250 ms latency | streaming: pinned root first, refinement blending in |
30
+ | Box | 2048² | `VTSourceImage` (runtime-tiled canvas) | zero-pipeline adoption of ordinary images |
31
+ | Plain orange box | — | regular material | mixed standard/VT pipelines in one material pass |
32
+
33
+ The procedural tiles used the classic VT debug pattern: **color = mip level,
34
+ label = `mip:x,y` page address**, white page frames.
35
+
36
+ What exercises the system now is its spec coverage, each `.spec.js` sitting
37
+ beside the module it tests: `VTPageTable`, `VTPhysicalCache`,
38
+ `PageTableQuadAllocator`, `VirtualTextureManager`, `VT_CONSTANTS`,
39
+ `vt_pipeline_compat` and `vt_shaders`.
40
+
41
+ ---
42
+
43
+ ## Using it
44
+
45
+ ### Opt a material in
46
+
47
+ ```js
48
+ import { VirtualTextureStack } from "./texture/virtual/VirtualTextureStack.js";
49
+ import { VTSourceTiled } from "./texture/virtual/source/VTSourceTiled.js";
50
+
51
+ material.vt_stack = VirtualTextureStack.from({
52
+ label: 'rock',
53
+ size: 8192, // texels; square, power of two
54
+ source: new VTSourceTiled({
55
+ layers: [ // URL template per cache layer
56
+ 'tiles/rock/albedo/{mip}/{x}_{y}.webp',
57
+ 'tiles/rock/normal/{mip}/{x}_{y}.webp',
58
+ 'tiles/rock/orm/{mip}/{x}_{y}.webp',
59
+ ],
60
+ }),
61
+ wrap: true, // repeat (false = clamp), applied in-shader
62
+ uv_set: 0, // 0 or 1
63
+ average_color: [0.4, 0.35, 0.3, 1], // linear premultiplied; shown before the root arrives
64
+ });
65
+ ```
66
+
67
+ That is the entire opt-in. Registration happens automatically when the
68
+ material is first built; a stack may be shared by any number of materials.
69
+ Everything else in the engine renders exactly as before, and the system
70
+ allocates nothing until the first stack registers.
71
+
72
+ A **stack** is the unit of virtualization: a set of texture layers
73
+ (albedo / normal / ORM in the standard cache group) sharing one UV set and
74
+ one resolution. The whole set streams, resides and is addressed as one —
75
+ one feedback value, one page-table entry, one residency decision, and in the
76
+ material shader one page-table fetch feeds all three layer samples. This is
77
+ the "do the work once for matching UV sets" design, as in Granite's stacked
78
+ textures.
79
+
80
+ ### Tile sources
81
+
82
+ A source implements:
83
+
84
+ ```js
85
+ prepare(geometry)? // called on registration: {page_size, border,
86
+ // slot_size, layer_count, size, mip_count}
87
+ load_page(mip, x, y, signal) // → Promise<payload[]>, one per layer;
88
+ // payloads are slot_size² (border baked in);
89
+ // reject with AbortError on signal abort
90
+ layer_mask // bitmask of layers provided (bit0 = albedo…)
91
+ destroy()? // called on last unregistration
92
+ ```
93
+
94
+ Included:
95
+
96
+ - **`VTSourceTiled`** — pre-tiled page files over HTTP, decoded with
97
+ `createImageBitmap` (WebP/AVIF/PNG/JPEG — browser-native, no WASM).
98
+ `legacy_meep_mips: true` consumes the original meep VT converter's output
99
+ (`${mip}-${x}-${y}.png`, coarsest-is-zero naming) unchanged. Serve
100
+ normal/ORM tiles lossless or 4:4:4 — chroma subsampling mangles them.
101
+ - **`VTSourceImage`** — runtime tiler: hand it ordinary decoded images and it
102
+ builds a canvas mip pyramid once and blits padded tiles on demand. The
103
+ adoption path — wins GPU memory and bandwidth, not host memory.
104
+ - **`VTSourceProcedural`** — instant labeled debug tiles, optional artificial
105
+ latency. Also the reference source implementation.
106
+
107
+ Missing layers (e.g. albedo-only stacks) fall back per layer in the shader:
108
+ albedo → the stack's `average_color`, normal → flat +Z, ORM → neutral.
109
+
110
+ ### Constraints (v1)
111
+
112
+ - **Opaque materials only** (asserted). The alpha-tested visibility pass and
113
+ OIT sample the *regular* albedo texture, where VT residency isn't
114
+ guaranteed.
115
+ - `size` is square, power-of-two, a multiple of `page_size`, ≤ 512 pages per
116
+ axis (64k texels at the default page size).
117
+ - Emissive stays a regular texture; a `uv_set: 1` stack re-interpolates uv1
118
+ for all of that material's samples, emissive included.
119
+ - Feedback covers the primary view. Path tracer / lightmap baker see
120
+ fallback colors (no VT sampling there yet).
121
+ - Filtering is bilinear + per-pixel nearest mip (id Tech's shipped baseline);
122
+ anisotropy and trilinear are documented follow-ups — the 4-texel borders
123
+ already budget for aniso ~4×.
124
+
125
+ ### Configuration
126
+
127
+ `graphics.virtual_textures.configure({...})` **before the first stack
128
+ registers** (geometry freezes at first use):
129
+
130
+ | Key | Default | Meaning |
131
+ |---|---|---|
132
+ | `page_size` | 128 | payload texels per page side |
133
+ | `border` | 4 | border texels per side, baked into tiles (slot = 136²) |
134
+ | `atlas_size` | 4096 | physical cache side → 30×30 = 900 pages, ~64 MB/layer |
135
+ | `table_size` | 1024 | shared page table side (texels = pages), mip-mapped r32uint |
136
+ | `layers` | albedo/normal/orm | cache group: name, format, premultiply |
137
+ | `feedback_stride` | 4 | sample 1 px per stride² block, jittered (runtime-adjustable) |
138
+ | `max_uploads_per_frame` | 8 | page-upload budget |
139
+ | `max_concurrent_loads` | 32 | in-flight source loads |
140
+ | `request_cap_fraction` | ⅓ | pending requests ≤ cap × cache capacity |
141
+ | `eviction_protect_window` | 4 | frames a touched page is unevictable (covers readback latency) |
142
+ | `queue_stale_window` | 30 | untouched queued requests dropped after N frames |
143
+ | `pressure_high/low_watermark` | 0.9 / 0.75 | residency bias hysteresis |
144
+
145
+ Runtime switch: `renderer.feature_virtual_textures` (default true) stops
146
+ feedback and streaming; already-resident pages keep rendering.
147
+
148
+ ---
149
+
150
+ ## How it works
151
+
152
+ ```
153
+ viz buffer (mesh+triangle ids)
154
+ │
155
+ ▼
156
+ vt_feedback (compute, 1 px per stride², jittered) [GPU]
157
+ pixel → mesh → material → stack; UV + analytic gradients
158
+ (same chunks as the material pass); mip select; insert
159
+ packed key into a hash set of unique requests
160
+ │ ~64 KB raw hash buffer
161
+ ▼
162
+ async readback (pooled staging, mapAsync, ≤3 in flight) [GPU→CPU, 1–2 frames]
163
+ │
164
+ ▼
165
+ VirtualTextureManager.process_feedback [CPU]
166
+ resident → LRU touch (incl. the ancestor actually serving
167
+ a missing cell); miss → request + missing-ancestor chain
168
+ │
169
+ update() per frame: apply arrivals (budgeted uploads),
170
+ evict (LRU + protection window + finest-first ties),
171
+ flush page-table dirty rects + stack info rows,
172
+ issue loads coarse-first with backoff on failures
173
+ │
174
+ ▼
175
+ VTPageTable (shared r32uint, mips) VTPhysicalCache (atlas per layer,
176
+ quadtree regions per stack; lockstep slots, page+border)
177
+ every texel = nearest RESIDENT │
178
+ ancestor-or-self entry │
179
+ └───────────────┬───────────────────────────┘
180
+ ▼
181
+ material pass (VT variant): ONE textureLoad into the
182
+ table → physical UV → N bilinear layer fetches
183
+ ```
184
+
185
+ Design points worth knowing before modifying:
186
+
187
+ - **Shared page table.** Every stack owns a buddy-allocated square region of
188
+ one mip-mapped `r32uint` texture. Buddy alignment makes `origin >> mip`
189
+ exact at every mip the region supports, so hundreds of stacks need no
190
+ per-mip metadata and never collide. Entries are **pre-filled with the
191
+ nearest resident ancestor** (maintained incrementally on load/evict by
192
+ `VTPageTable`'s match-and-prune DFS), which is what keeps sampling a
193
+ single fetch with automatic coarse fallback — no shader mip-walk.
194
+ - **Feedback ↔ sampler parity.** Both compile the same
195
+ `build_chunk_vt_lookup` chunk and the same derivative-bias constants; if
196
+ the mip formulas ever diverge, the system requests pages it doesn't sample.
197
+ Change the chunk, never one side.
198
+ - **Key formats** (single source: `VT_CONSTANTS.js`, WGSL mirrors tested for
199
+ parity): request key `stack:10 | mip:4 | x:9 | y:9`, stored `key+1` so a
200
+ zero-cleared buffer reads empty; page-table entry
201
+ `phys_x:8 | phys_y:8 | mip:5 | valid:1`. **Stack ids 0 and 1023 are
202
+ reserved** — 1023 is the "no stack" sentinel, and 0 is never assigned so
203
+ zero-initialized / not-yet-flushed GPU rows decode to a harmless
204
+ "unknown stack" instead of junk requests.
205
+ - **Residency policy.** LRU with a protection window covering readback
206
+ latency; each stack's root page is pinned at registration (a fallback is
207
+ always resident once it arrives — held and retried, never dropped, even
208
+ under lock saturation); eviction ties shed the finest mip first; requests
209
+ are capped per cycle and canceled when stale; failed loads back off
210
+ exponentially in a negative cache; cache pressure raises a feedback mip
211
+ bias so oversubscription degrades to blur instead of thrash.
212
+ - **Frame protocol.** `update()` runs in `Renderer.#begin_frame`
213
+ (queue-ordered before the frame's submits). Stacks registered mid-frame
214
+ (materials build during scene update) are published by an idempotent
215
+ `flush_gpu_state()` re-run from `graph_feedback`, so first frames render
216
+ correctly.
217
+ - **Struct packing hazard.** `WebGPUStruct.pack()` reorders fields — never
218
+ construct packed structs positionally in WGSL (tests included); use
219
+ member-wise assignment. Inline chunk structs (`VTPhysical`,
220
+ `VTPageTableEntry`) are unpacked and safe.
221
+
222
+ ## Files
223
+
224
+ | File | Role |
225
+ |---|---|
226
+ | `VirtualTextureManager.js` | orchestrator: registry, residency, streaming, FrameGraph wiring |
227
+ | `VirtualTextureStack.js` | scene-side stack description (`material.vt_stack`) |
228
+ | `VTPageTable.js` | shared table texture + CPU mirror + ancestor-closure propagation |
229
+ | `PageTableQuadAllocator.js` | buddy allocator (the `origin >> mip` guarantee) |
230
+ | `VTPhysicalCache.js` | per-layer atlases, lockstep slots, LRU metadata, uploads |
231
+ | `VT_CONSTANTS.js` | bit layouts, sentinels, JS pack/unpack |
232
+ | `VT_STACK_INFO_STRUCT.js` | per-stack GPU record |
233
+ | `build_chunk_vt_lookup.js` | shared WGSL: wrap, mip select, table load, physical UV |
234
+ | `chunk_vt_request_key.js` | WGSL request-key packing |
235
+ | `build_shader_vt_feedback.js` | the feedback compute shader |
236
+ | `source/VTSource{Procedural,Image,Tiled}.js` | tile providers |
237
+ | `../../material/standard/fragment_gbuffer_vt.js` | VT material shader variant |
238
+
239
+ ## Tests
240
+
241
+ ```
242
+ npx vitest run src/shade/renderer/texture/virtual
243
+ ```
244
+
245
+ ~60 tests: allocator properties; page-table nearest-ancestor invariant
246
+ against a brute-force reference model (randomized, including physical-slot
247
+ recycling); cache LRU/pinning/tie-breaks; manager end-to-end with a mocked
248
+ GPU (register → pin → feedback → stream → evict → unregister) plus the
249
+ policy set (request cap, stale aging, coarse-first order, serving-ancestor
250
+ protection, failure backoff, locked-root retry, teardown flush, stale-key
251
+ rejection); WGSL validity for both shaders (tree-sitter); WGSL↔JS packing
252
+ and physical-UV parity through the in-repo emulator, under default and
253
+ non-default geometry; and standard↔VT pipeline bind-group-layout equality.
254
+
255
+ Known untestable-here: the GPU hash-set insert loop (the emulator has no
256
+ atomics) and the canvas-based sources (no OffscreenCanvas under Node) — both
257
+ are covered by the demo instead.
@@ -379,8 +379,8 @@ fn main(
379
379
  // the medium shadowed itself and geometry did not shadow it at all, so a torch behind a
380
380
  // wall lit the fog through the wall and a light through a window cast no shaft. The
381
381
  // directional loop above has always multiplied its shadow map in; this is the same
382
- // operation for the clustered lights, which is what Frostbite and UE both do in the
383
- // froxel pass. One nearest atlas tap rather than the deferred path's filter kernel —
382
+ // operation for the clustered lights, in the froxel pass. One nearest atlas tap rather
383
+ // than the deferred path's filter kernel —
384
384
  // see the chunk for why that is not a compromise here.
385
385
  let shadow_term = volumetrics_point_light_shadow(&light_data, light_index, position_ws);
386
386