@zephyr3d/scene 0.9.27 → 0.10.0
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.
- package/README.md +60 -27
- package/dist/animation/animation_bank.js +634 -0
- package/dist/animation/animation_bank.js.map +1 -0
- package/dist/animation/animation_bank_gpu.js +256 -0
- package/dist/animation/animation_bank_gpu.js.map +1 -0
- package/dist/animation/animationset.js +54 -0
- package/dist/animation/animationset.js.map +1 -1
- package/dist/animation/cloth/gpu_cloth_component.js +406 -0
- package/dist/animation/cloth/gpu_cloth_component.js.map +1 -0
- package/dist/animation/cloth/gpu_cloth_system.js +332 -202
- package/dist/animation/cloth/gpu_cloth_system.js.map +1 -1
- package/dist/animation/gpu_animation_driver.js +289 -0
- package/dist/animation/gpu_animation_driver.js.map +1 -0
- package/dist/animation/joint_dynamics/collision.js +112 -1
- package/dist/animation/joint_dynamics/collision.js.map +1 -1
- package/dist/animation/joint_dynamics/controller.js +6 -0
- package/dist/animation/joint_dynamics/controller.js.map +1 -1
- package/dist/animation/joint_dynamics/joint_dynamics_system.js +11 -0
- package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
- package/dist/animation/joint_dynamics/solver.js +50 -12
- package/dist/animation/joint_dynamics/solver.js.map +1 -1
- package/dist/animation/joint_dynamics/types.js.map +1 -1
- package/dist/animation/skeleton.js +279 -55
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/animation/skin_palette_atlas.js +252 -0
- package/dist/animation/skin_palette_atlas.js.map +1 -0
- package/dist/animation/spring/multi_chain_spring_system.js +298 -38
- package/dist/animation/spring/multi_chain_spring_system.js.map +1 -1
- package/dist/animation/spring/spring_chain.js +2 -0
- package/dist/animation/spring/spring_chain.js.map +1 -1
- package/dist/animation/spring/spring_collider.js +159 -21
- package/dist/animation/spring/spring_collider.js.map +1 -1
- package/dist/animation/spring/spring_particle.js +1 -0
- package/dist/animation/spring/spring_particle.js.map +1 -1
- package/dist/animation/spring/spring_solver.js +173 -0
- package/dist/animation/spring/spring_solver.js.map +1 -0
- package/dist/animation/spring/spring_system.js +249 -24
- package/dist/animation/spring/spring_system.js.map +1 -1
- package/dist/animation/spring_modifier.js +32 -1
- package/dist/animation/spring_modifier.js.map +1 -1
- package/dist/app/app.js +26 -0
- package/dist/app/app.js.map +1 -1
- package/dist/app/engine.js +86 -15
- package/dist/app/engine.js.map +1 -1
- package/dist/app/gamepad.js +191 -0
- package/dist/app/gamepad.js.map +1 -0
- package/dist/app/inputactions.js +271 -0
- package/dist/app/inputactions.js.map +1 -0
- package/dist/app/inputmgr.js +331 -22
- package/dist/app/inputmgr.js.map +1 -1
- package/dist/app/loading.js +138 -0
- package/dist/app/loading.js.map +1 -0
- package/dist/app/pipelinecache.js +209 -0
- package/dist/app/pipelinecache.js.map +1 -0
- package/dist/app/runtimescript.js +25 -0
- package/dist/app/runtimescript.js.map +1 -1
- package/dist/app/scriptingsystem.js +54 -0
- package/dist/app/scriptingsystem.js.map +1 -1
- package/dist/app/scriptregistry.js +7 -2
- package/dist/app/scriptregistry.js.map +1 -1
- package/dist/asset/asset_manifest.js +59 -0
- package/dist/asset/asset_manifest.js.map +1 -0
- package/dist/asset/asset_preload.js +258 -0
- package/dist/asset/asset_preload.js.map +1 -0
- package/dist/asset/assetmanager.js +117 -65
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/loaders/ktx2/basis/LICENSE +201 -0
- package/dist/asset/loaders/ktx2/basis/basis_transcoder.js +2 -0
- package/dist/asset/loaders/ktx2/basis/basis_transcoder.wasm +0 -0
- package/dist/asset/loaders/ktx2/basis_location.js +17 -0
- package/dist/asset/loaders/ktx2/basis_location.js.map +1 -0
- package/dist/asset/loaders/ktx2/ktx2_loader.js +88 -0
- package/dist/asset/loaders/ktx2/ktx2_loader.js.map +1 -0
- package/dist/asset/loaders/ktx2/ktx2_targets.js +118 -0
- package/dist/asset/loaders/ktx2/ktx2_targets.js.map +1 -0
- package/dist/asset/loaders/ktx2/transcoder_pool.js +259 -0
- package/dist/asset/loaders/ktx2/transcoder_pool.js.map +1 -0
- package/dist/asset/mesh_lod_builder.js +104 -0
- package/dist/asset/mesh_lod_builder.js.map +1 -0
- package/dist/asset/mesh_settings.js +111 -0
- package/dist/asset/mesh_settings.js.map +1 -0
- package/dist/asset/meshopt_decoder.js +18 -0
- package/dist/asset/meshopt_decoder.js.map +1 -0
- package/dist/asset/meshopt_simplifier.js +26 -0
- package/dist/asset/meshopt_simplifier.js.map +1 -0
- package/dist/asset/model.js +171 -1
- package/dist/asset/model.js.map +1 -1
- package/dist/asset/texture_settings.js +231 -0
- package/dist/asset/texture_settings.js.map +1 -0
- package/dist/asset/zmsh_binary.js +131 -0
- package/dist/asset/zmsh_binary.js.map +1 -0
- package/dist/asset/zsdf_binary.js +111 -0
- package/dist/asset/zsdf_binary.js.map +1 -0
- package/dist/blitter/bilateralblur.js +1 -2
- package/dist/blitter/bilateralblur.js.map +1 -1
- package/dist/blitter/gaussianblur.js +1 -6
- package/dist/blitter/gaussianblur.js.map +1 -1
- package/dist/camera/base.js +31 -10
- package/dist/camera/base.js.map +1 -1
- package/dist/camera/camera.js +104 -178
- package/dist/camera/camera.js.map +1 -1
- package/dist/camera/follow.js +342 -0
- package/dist/camera/follow.js.map +1 -0
- package/dist/camera/fps.js +9 -7
- package/dist/camera/fps.js.map +1 -1
- package/dist/camera/orbit.js +46 -19
- package/dist/camera/orbit.js.map +1 -1
- package/dist/index.d.ts +25436 -15990
- package/dist/index.js +65 -11
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +3 -0
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/eye.js +1 -1
- package/dist/material/eye.js.map +1 -1
- package/dist/material/hair.js +2 -3
- package/dist/material/hair.js.map +1 -1
- package/dist/material/lambert.js +4 -1
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/material.js +66 -4
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +118 -45
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
- package/dist/material/mixins/lightmodel/lambert.js +1 -1
- package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +34 -61
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +16 -2
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +2 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
- package/dist/material/mixins/lit.js +191 -83
- package/dist/material/mixins/lit.js.map +1 -1
- package/dist/material/mixins/pbr/common.js +31 -206
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/mtoon.js +1 -1
- package/dist/material/mtoon.js.map +1 -1
- package/dist/material/pbrmr.js +3 -0
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/pbrsg.js +3 -0
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/sdf_debug.js +78 -0
- package/dist/material/sdf_debug.js.map +1 -0
- package/dist/material/shader/helper.js +333 -191
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/shader/terrain_blend.js +204 -43
- package/dist/material/shader/terrain_blend.js.map +1 -1
- package/dist/material/skin.js +331 -297
- package/dist/material/skin.js.map +1 -1
- package/dist/material/skinprofile.js +1058 -0
- package/dist/material/skinprofile.js.map +1 -0
- package/dist/material/sss.js +353 -0
- package/dist/material/sss.js.map +1 -0
- package/dist/material/sss_kernel.js +265 -0
- package/dist/material/sss_kernel.js.map +1 -0
- package/dist/material/sssprofile.js +879 -0
- package/dist/material/sssprofile.js.map +1 -0
- package/dist/material/subsurfaceprofile.js +4 -8
- package/dist/material/subsurfaceprofile.js.map +1 -1
- package/dist/material/terrain-cm.js +464 -188
- package/dist/material/terrain-cm.js.map +1 -1
- package/dist/material/unlit.js +3 -0
- package/dist/material/unlit.js.map +1 -1
- package/dist/material/water.js +1261 -1438
- package/dist/material/water.js.map +1 -1
- package/dist/node_modules/meshoptimizer/LICENSE +21 -0
- package/dist/node_modules/meshoptimizer/meshopt_decoder.js +197 -0
- package/dist/node_modules/meshoptimizer/meshopt_decoder.js.map +1 -0
- package/dist/node_modules/meshoptimizer/meshopt_simplifier.js +677 -0
- package/dist/node_modules/meshoptimizer/meshopt_simplifier.js.map +1 -0
- package/dist/physics/character.js +226 -0
- package/dist/physics/character.js.map +1 -0
- package/dist/physics/collider.js +209 -0
- package/dist/physics/collider.js.map +1 -0
- package/dist/physics/events.js +79 -0
- package/dist/physics/events.js.map +1 -0
- package/dist/physics/joint.js +272 -0
- package/dist/physics/joint.js.map +1 -0
- package/dist/physics/node_physics.js +234 -0
- package/dist/physics/node_physics.js.map +1 -0
- package/dist/physics/part.js +91 -0
- package/dist/physics/part.js.map +1 -0
- package/dist/physics/rigid_body.js +379 -0
- package/dist/physics/rigid_body.js.map +1 -0
- package/dist/physics/vehicle.js +335 -0
- package/dist/physics/vehicle.js.map +1 -0
- package/dist/physics/world.js +25 -0
- package/dist/physics/world.js.map +1 -0
- package/dist/posteffect/bloom.js +49 -14
- package/dist/posteffect/bloom.js.map +1 -1
- package/dist/posteffect/motionblur.js +106 -106
- package/dist/posteffect/motionblur.js.map +1 -1
- package/dist/posteffect/postsss.js +572 -0
- package/dist/posteffect/postsss.js.map +1 -0
- package/dist/posteffect/sao.js +2 -6
- package/dist/posteffect/sao.js.map +1 -1
- package/dist/posteffect/skinsss.js +605 -355
- package/dist/posteffect/skinsss.js.map +1 -1
- package/dist/posteffect/ssgi.js +91 -162
- package/dist/posteffect/ssgi.js.map +1 -1
- package/dist/posteffect/ssr.js +3 -11
- package/dist/posteffect/ssr.js.map +1 -1
- package/dist/posteffect/sss.js +4 -13
- package/dist/posteffect/sss.js.map +1 -1
- package/dist/posteffect/taa.js +1 -0
- package/dist/posteffect/taa.js.map +1 -1
- package/dist/render/abuffer_oit.js +3 -2
- package/dist/render/abuffer_oit.js.map +1 -1
- package/dist/render/clipmap.js +179 -64
- package/dist/render/clipmap.js.map +1 -1
- package/dist/render/cluster_light.js +958 -224
- package/dist/render/cluster_light.js.map +1 -1
- package/dist/render/cull_visitor.js +25 -5
- package/dist/render/cull_visitor.js.map +1 -1
- package/dist/render/debug_views.js +37 -0
- package/dist/render/debug_views.js.map +1 -0
- package/dist/render/depthpass.js +5 -1
- package/dist/render/depthpass.js.map +1 -1
- package/dist/render/drawable_mixin.js +53 -6
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/dualdepthpeeling_oit.js +5 -5
- package/dist/render/dualdepthpeeling_oit.js.map +1 -1
- package/dist/render/envlight.js +196 -113
- package/dist/render/envlight.js.map +1 -1
- package/dist/render/fbm_wavegenerator.js +5 -10
- package/dist/render/fbm_wavegenerator.js.map +1 -1
- package/dist/render/fft_wavegenerator.js +247 -157
- package/dist/render/fft_wavegenerator.js.map +1 -1
- package/dist/render/gerstner_wavegenerator.js +16 -38
- package/dist/render/gerstner_wavegenerator.js.map +1 -1
- package/dist/render/gi/probe_volume.js +1334 -0
- package/dist/render/gi/probe_volume.js.map +1 -0
- package/dist/render/gi/scene_gi.js +282 -0
- package/dist/render/gi/scene_gi.js.map +1 -0
- package/dist/render/gi/voxel_atlas.js +198 -0
- package/dist/render/gi/voxel_atlas.js.map +1 -0
- package/dist/render/gi/voxel_lighting.js +652 -0
- package/dist/render/gi/voxel_lighting.js.map +1 -0
- package/dist/render/gi/voxel_scene.js +642 -0
- package/dist/render/gi/voxel_scene.js.map +1 -0
- package/dist/render/gi/voxelize_pass.js +223 -0
- package/dist/render/gi/voxelize_pass.js.map +1 -0
- package/dist/render/globalbindgroup_allocator.js +3 -2
- package/dist/render/globalbindgroup_allocator.js.map +1 -1
- package/dist/render/gpu_picking.js +9 -36
- package/dist/render/gpu_picking.js.map +1 -1
- package/dist/render/instance_culling.js +499 -0
- package/dist/render/instance_culling.js.map +1 -0
- package/dist/render/lightpass.js +19 -8
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/lod.js +46 -0
- package/dist/render/lod.js.map +1 -0
- package/dist/render/primitive.js +301 -9
- package/dist/render/primitive.js.map +1 -1
- package/dist/render/primitive_readback.js +209 -0
- package/dist/render/primitive_readback.js.map +1 -0
- package/dist/render/render_queue.js +162 -11
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +10 -7
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/rendergraph/blackboard.js +14 -1
- package/dist/render/rendergraph/blackboard.js.map +1 -1
- package/dist/render/rendergraph/executor.js +136 -0
- package/dist/render/rendergraph/executor.js.map +1 -1
- package/dist/render/rendergraph/forward_plus_builder.js +272 -55
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/render/rendergraph/frame_graph_context.js +41 -0
- package/dist/render/rendergraph/frame_graph_context.js.map +1 -0
- package/dist/render/rendergraph/scene_render_context.js +31 -2
- package/dist/render/rendergraph/scene_render_context.js.map +1 -1
- package/dist/render/rendergraph/types.js.map +1 -1
- package/dist/render/renderpass.js +28 -5
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/sdf/box_allocator.js +98 -0
- package/dist/render/sdf/box_allocator.js.map +1 -0
- package/dist/render/sdf/global_sdf.js +865 -0
- package/dist/render/sdf/global_sdf.js.map +1 -0
- package/dist/render/sdf/scene_sdf.js +562 -0
- package/dist/render/sdf/scene_sdf.js.map +1 -0
- package/dist/render/sdf/sdf_atlas.js +227 -0
- package/dist/render/sdf/sdf_atlas.js.map +1 -0
- package/dist/render/sdf/sdf_programs.js +42 -0
- package/dist/render/sdf/sdf_programs.js.map +1 -0
- package/dist/render/sdf/sdf_view.js +199 -0
- package/dist/render/sdf/sdf_view.js.map +1 -0
- package/dist/render/sdf/waterline.js +610 -0
- package/dist/render/sdf/waterline.js.map +1 -0
- package/dist/render/shadow_mask_pass.js +142 -25
- package/dist/render/shadow_mask_pass.js.map +1 -1
- package/dist/render/shore_wave_generator.js +1193 -0
- package/dist/render/shore_wave_generator.js.map +1 -0
- package/dist/render/sky.js +516 -86
- package/dist/render/sky.js.map +1 -1
- package/dist/render/transmission_thickness_pass.js +477 -0
- package/dist/render/transmission_thickness_pass.js.map +1 -0
- package/dist/render/underwater.js +58 -158
- package/dist/render/underwater.js.map +1 -1
- package/dist/render/virtualtexture/virtual_texture.js +1214 -0
- package/dist/render/virtualtexture/virtual_texture.js.map +1 -0
- package/dist/render/volumetric_cloud/cloud_common.js +472 -0
- package/dist/render/volumetric_cloud/cloud_common.js.map +1 -0
- package/dist/render/volumetric_cloud/cloud_noise.js +189 -0
- package/dist/render/volumetric_cloud/cloud_noise.js.map +1 -0
- package/dist/render/volumetric_cloud/debug_view.js +131 -0
- package/dist/render/volumetric_cloud/debug_view.js.map +1 -0
- package/dist/render/volumetric_cloud/resources.js +380 -0
- package/dist/render/volumetric_cloud/resources.js.map +1 -0
- package/dist/render/volumetric_cloud/sky_cache.js +380 -0
- package/dist/render/volumetric_cloud/sky_cache.js.map +1 -0
- package/dist/render/volumetric_cloud/volumetric_cloud.js +318 -0
- package/dist/render/volumetric_cloud/volumetric_cloud.js.map +1 -0
- package/dist/render/water_caustics.js +134 -319
- package/dist/render/water_caustics.js.map +1 -1
- package/dist/render/water_foam.js +627 -0
- package/dist/render/water_foam.js.map +1 -0
- package/dist/render/water_interaction.js +1795 -0
- package/dist/render/water_interaction.js.map +1 -0
- package/dist/render/weightedblended_oit.js +3 -3
- package/dist/render/weightedblended_oit.js.map +1 -1
- package/dist/scene/basesprite.js +9 -4
- package/dist/scene/basesprite.js.map +1 -1
- package/dist/scene/batchgroup.js +108 -12
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +28 -7
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/foliage.js +1020 -0
- package/dist/scene/foliage.js.map +1 -0
- package/dist/scene/foliage_buckets.js +147 -0
- package/dist/scene/foliage_buckets.js.map +1 -0
- package/dist/scene/foliage_mask.js +358 -0
- package/dist/scene/foliage_mask.js.map +1 -0
- package/dist/scene/hair.js +15 -4
- package/dist/scene/hair.js.map +1 -1
- package/dist/scene/light.js +179 -13
- package/dist/scene/light.js.map +1 -1
- package/dist/scene/mesh.js +327 -45
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/meshdrawable.js +6 -0
- package/dist/scene/meshdrawable.js.map +1 -1
- package/dist/scene/msdftext.js +9 -3
- package/dist/scene/msdftext.js.map +1 -1
- package/dist/scene/msdftextsprite.js +9 -3
- package/dist/scene/msdftextsprite.js.map +1 -1
- package/dist/scene/particlesys.js +8 -2
- package/dist/scene/particlesys.js.map +1 -1
- package/dist/scene/physics_settings.js +157 -0
- package/dist/scene/physics_settings.js.map +1 -0
- package/dist/scene/scene.js +190 -44
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/scene_node.js +147 -6
- package/dist/scene/scene_node.js.map +1 -1
- package/dist/scene/terrain-cm/bladegrassmaterial.js +735 -0
- package/dist/scene/terrain-cm/bladegrassmaterial.js.map +1 -0
- package/dist/scene/terrain-cm/grass.js +881 -42
- package/dist/scene/terrain-cm/grass.js.map +1 -1
- package/dist/scene/terrain-cm/grass_gpu.js +929 -0
- package/dist/scene/terrain-cm/grass_gpu.js.map +1 -0
- package/dist/scene/terrain-cm/grassmaterial.js +180 -9
- package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
- package/dist/scene/terrain-cm/terrain-cm.js +465 -36
- package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
- package/dist/scene/terrain-cm/terrain_gi_albedo.js +257 -0
- package/dist/scene/terrain-cm/terrain_gi_albedo.js.map +1 -0
- package/dist/scene/terrain-cm/terrain_rvt.js +395 -0
- package/dist/scene/terrain-cm/terrain_rvt.js.map +1 -0
- package/dist/scene/update_queue.js +54 -0
- package/dist/scene/update_queue.js.map +1 -0
- package/dist/scene/water.js +633 -268
- package/dist/scene/water.js.map +1 -1
- package/dist/scene/water_surface_sampler.js +324 -0
- package/dist/scene/water_surface_sampler.js.map +1 -0
- package/dist/scene/wind.js +317 -0
- package/dist/scene/wind.js.map +1 -0
- package/dist/shaders/atmosphere.js +388 -166
- package/dist/shaders/atmosphere.js.map +1 -1
- package/dist/shaders/fog.js +100 -32
- package/dist/shaders/fog.js.map +1 -1
- package/dist/shaders/gi.js +365 -0
- package/dist/shaders/gi.js.map +1 -0
- package/dist/shaders/ltc_rect.js +202 -0
- package/dist/shaders/ltc_rect.js.map +1 -0
- package/dist/shaders/misc.js +1 -10
- package/dist/shaders/misc.js.map +1 -1
- package/dist/shaders/noise.js +5 -1
- package/dist/shaders/noise.js.map +1 -1
- package/dist/shaders/probes.js +309 -0
- package/dist/shaders/probes.js.map +1 -0
- package/dist/shaders/sdf.js +537 -0
- package/dist/shaders/sdf.js.map +1 -0
- package/dist/shaders/shadow.js +104 -70
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shaders/skin_brdf.js +243 -0
- package/dist/shaders/skin_brdf.js.map +1 -0
- package/dist/shaders/ssgi.js +63 -0
- package/dist/shaders/ssgi.js.map +1 -0
- package/dist/shaders/ssgi_reprojection.js +118 -0
- package/dist/shaders/ssgi_reprojection.js.map +1 -0
- package/dist/shaders/ssr.js +6 -159
- package/dist/shaders/ssr.js.map +1 -1
- package/dist/shaders/temporal.js +38 -27
- package/dist/shaders/temporal.js.map +1 -1
- package/dist/shaders/water.js +32 -82
- package/dist/shaders/water.js.map +1 -1
- package/dist/shaders/water_medium.js +7 -21
- package/dist/shaders/water_medium.js.map +1 -1
- package/dist/shadow/dom.js +110 -19
- package/dist/shadow/dom.js.map +1 -1
- package/dist/shadow/esm.js +3 -3
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/pcf_opt.js +15 -48
- package/dist/shadow/pcf_opt.js.map +1 -1
- package/dist/shadow/pcf_pd.js +15 -53
- package/dist/shadow/pcf_pd.js.map +1 -1
- package/dist/shadow/pcss.js +34 -9
- package/dist/shadow/pcss.js.map +1 -1
- package/dist/shadow/shadow_impl.js +3 -8
- package/dist/shadow/shadow_impl.js.map +1 -1
- package/dist/shadow/shadow_region.js +40 -2
- package/dist/shadow/shadow_region.js.map +1 -1
- package/dist/shadow/shadowmapper.js +93 -53
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/ssm.js +18 -72
- package/dist/shadow/ssm.js.map +1 -1
- package/dist/shadow/vsm.js +3 -3
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/shapes/shape.js +44 -1
- package/dist/shapes/shape.js.map +1 -1
- package/dist/utility/buoyancy.js +287 -0
- package/dist/utility/buoyancy.js.map +1 -0
- package/dist/utility/physical.js +10 -1
- package/dist/utility/physical.js.map +1 -1
- package/dist/utility/pmrem.js +17 -43
- package/dist/utility/pmrem.js.map +1 -1
- package/dist/utility/sdf/bake.js +435 -0
- package/dist/utility/sdf/bake.js.map +1 -0
- package/dist/utility/sdf/bvh.js +576 -0
- package/dist/utility/sdf/bvh.js.map +1 -0
- package/dist/utility/serialization/manager.js +34 -6
- package/dist/utility/serialization/manager.js.map +1 -1
- package/dist/utility/serialization/scene/animation.js +46 -5
- package/dist/utility/serialization/scene/animation.js.map +1 -1
- package/dist/utility/serialization/scene/batch.js +11 -4
- package/dist/utility/serialization/scene/batch.js.map +1 -1
- package/dist/utility/serialization/scene/camera.js +87 -254
- package/dist/utility/serialization/scene/camera.js.map +1 -1
- package/dist/utility/serialization/scene/cloth.js +25 -0
- package/dist/utility/serialization/scene/cloth.js.map +1 -0
- package/dist/utility/serialization/scene/common.js +14 -6
- package/dist/utility/serialization/scene/common.js.map +1 -1
- package/dist/utility/serialization/scene/foliage.js +821 -0
- package/dist/utility/serialization/scene/foliage.js.map +1 -0
- package/dist/utility/serialization/scene/hair.js +11 -4
- package/dist/utility/serialization/scene/hair.js.map +1 -1
- package/dist/utility/serialization/scene/light.js +115 -7
- package/dist/utility/serialization/scene/light.js.map +1 -1
- package/dist/utility/serialization/scene/material.js +388 -220
- package/dist/utility/serialization/scene/material.js.map +1 -1
- package/dist/utility/serialization/scene/mesh.js +69 -4
- package/dist/utility/serialization/scene/mesh.js.map +1 -1
- package/dist/utility/serialization/scene/node.js +140 -5
- package/dist/utility/serialization/scene/node.js.map +1 -1
- package/dist/utility/serialization/scene/node_physics.js +1318 -0
- package/dist/utility/serialization/scene/node_physics.js.map +1 -0
- package/dist/utility/serialization/scene/particle.js +11 -4
- package/dist/utility/serialization/scene/particle.js.map +1 -1
- package/dist/utility/serialization/scene/physics.js +120 -0
- package/dist/utility/serialization/scene/physics.js.map +1 -0
- package/dist/utility/serialization/scene/primitive.js +124 -10
- package/dist/utility/serialization/scene/primitive.js.map +1 -1
- package/dist/utility/serialization/scene/scene.js +1687 -51
- package/dist/utility/serialization/scene/scene.js.map +1 -1
- package/dist/utility/serialization/scene/sprite.js +11 -4
- package/dist/utility/serialization/scene/sprite.js.map +1 -1
- package/dist/utility/serialization/scene/terrain.js +163 -33
- package/dist/utility/serialization/scene/terrain.js.map +1 -1
- package/dist/utility/serialization/scene/text.js +11 -4
- package/dist/utility/serialization/scene/text.js.map +1 -1
- package/dist/utility/serialization/scene/water.js +1543 -264
- package/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/utility/serialization/types.js.map +1 -1
- package/dist/utility/shprojector.js +10 -22
- package/dist/utility/shprojector.js.map +1 -1
- package/dist/utility/textures/foam.js +170 -0
- package/dist/utility/textures/foam.js.map +1 -0
- package/dist/utility/textures/ggxlut.js +17 -43
- package/dist/utility/textures/ggxlut.js.map +1 -1
- package/dist/utility/textures/ltcdata.js +4 -4
- package/dist/utility/textures/ltcdata.js.map +1 -1
- package/dist/utility/textures/ltclut.js +16 -6
- package/dist/utility/textures/ltclut.js.map +1 -1
- package/dist/utility/unsupported.js +24 -0
- package/dist/utility/unsupported.js.map +1 -0
- package/dist/values.js +13 -1
- package/dist/values.js.map +1 -1
- package/package.json +25 -12
- package/src/asset/loaders/ktx2/basis/LICENSE +201 -0
- package/src/asset/loaders/ktx2/basis/basis_transcoder.js +2 -0
- package/src/asset/loaders/ktx2/basis/basis_transcoder.wasm +0 -0
- package/src/asset/meshoptimizer/LICENSE +21 -0
- package/dist/animation/joint_dynamics/convex_collider.js +0 -320
- package/dist/animation/joint_dynamics/convex_collider.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"water_caustics.js","sources":["../../src/render/water_caustics.ts"],"sourcesContent":["import type { Nullable } from '@zephyr3d/base';\r\nimport { Matrix4x4, REVERSE_Z, Vector3, Vector4 } from '@zephyr3d/base';\r\nimport type {\r\n AbstractDevice,\r\n BindGroup,\r\n FrameBuffer,\r\n GPUDataBuffer,\r\n GPUProgram,\r\n IndexBuffer,\r\n PBGlobalScope,\r\n PBRenderOptions,\r\n ProgramBuilder,\r\n RenderStateSet,\r\n Texture2D,\r\n Texture2DArray,\r\n TextureFormat,\r\n VertexLayout\r\n} from '@zephyr3d/device';\r\nimport type { DrawContext } from './drawable';\r\nimport type { WaveGenerator } from './wavegenerator';\r\nimport type { Water } from '../scene/water';\r\nimport type { PunctualLight } from '../scene/light';\r\nimport type { Camera } from '../camera/camera';\r\nimport { drawFullscreenQuad } from './fullscreenquad';\r\nimport { fetchSampler } from '../utility/misc';\r\nimport { CAUSTIC_HEIGHT_BIAS, MAX_CAUSTIC_WATERS, ShaderHelper } from '../material/shader/helper';\r\n\r\n/** Index of refraction of water relative to air. */\r\nconst WATER_IOR = 1.333;\r\n/** Air-to-water eta used when refracting the sun ray at the surface. */\r\nconst WATER_ETA = 1 / WATER_IOR;\r\n/**\r\n * Minimum |sin(sun elevation)| for caustics to be generated. The photon sweep\r\n * degenerates below this, and real caustics vanish there too, so the pass\r\n * simply switches off.\r\n */\r\nconst MIN_SUN_ELEVATION = 0.15;\r\n/**\r\n * Fixed-point steps taken to land a photon on the scene rather than on the\r\n * focal plane. Two suffice for a receiver flat over the distance the guess\r\n * moves; the third covers a steep slope. Beyond that the sequence has either\r\n * converged or is oscillating between two surfaces.\r\n */\r\nconst SCENE_DEPTH_ITERATIONS = 3;\r\n/**\r\n * Photons per covered map texel the automatic grid size solves for.\r\n *\r\n * Measured against a converged (16x denser) map: four lands within about 4% of\r\n * it, for a quarter of the photons full convergence would need.\r\n */\r\nconst PHOTONS_PER_TEXEL = 4;\r\n/** Automatic edge fade width, as a fraction of the map half-extent. */\r\nconst AUTO_FADE_FRACTION = 0.2;\r\n/** Floor in meters under the automatic fade width. */\r\nconst AUTO_FADE_MIN_DISTANCE = 3;\r\n/** Bounds on the share of the map half-extent the fade may consume. */\r\nconst MIN_FADE_FRACTION = 0.001;\r\nconst MAX_FADE_FRACTION = 0.9;\r\n/**\r\n * Largest ratio between the fitted slice's two half-extents. The map is square,\r\n * so an anisotropic slice resolves the pattern at different frequencies along\r\n * each axis.\r\n */\r\nconst MAX_SLICE_ASPECT = 2;\r\n/**\r\n * Steps per octave the fitted half-extents are quantised to. Four costs at most\r\n * 19% of linear resolution against a perfect fit, and keeps a level change small\r\n * enough to pass as a slight change in sharpness rather than a pop.\r\n */\r\nconst SLICE_QUANTISE_STEPS = 4;\r\n/** Smallest half-extent in meters a fitted slice may shrink to. */\r\nconst MIN_SLICE_EXTENT = 0.5;\r\n/**\r\n * Divisions of the half-extent the slice centre snaps to under a warp.\r\n *\r\n * A whole-texel shift is exact only on a linear map; under a warp it is a\r\n * different number of texels at each position, so the map has to be resampled\r\n * whenever the centre moves. Snapping coarsely holds the centre still for many\r\n * frames and pays for one resample, which the resolve's neighbourhood clamp\r\n * absorbs.\r\n */\r\nconst WARPED_CENTER_SNAP_DIVISIONS = 8;\r\n/**\r\n * How far past the map border the photon grid is laid out, as a fraction of the\r\n * half-extent, on the sides where the range - not the water - is what bounds it.\r\n *\r\n * Horizontal displacement carries a photon across the border in either\r\n * direction, so a grid cut exactly at the border loses the photons that would\r\n * have arrived from outside while still losing the ones that leave; the border\r\n * ring then holds a density no interior texel does. Launching from a margin\r\n * outside feeds the border from both sides.\r\n *\r\n * Only the launch area grows - `_gridFraction` scales the per-photon weight and\r\n * the solved grid size by it - so density per texel is unchanged and the cost is\r\n * photon count. At the default warp this margin buys about 11% more photons.\r\n */\r\nconst GRID_BORDER_MARGIN = 0.15;\r\n\r\n/**\r\n * Concentrates a map coordinate towards the centre. CPU twin of\r\n * `ShaderHelper.warpCausticNDC`; see it for the reasoning.\r\n *\r\n * @internal\r\n */\r\nfunction warpCausticNDC(ndc: number, strength: number): number {\r\n return (ndc * (1 + strength)) / (1 + strength * Math.abs(ndc));\r\n}\r\n\r\n/**\r\n * Rounds a fitted half-extent up onto a discrete ladder below `range`.\r\n *\r\n * The ladder is geometric and anchored at `range`, so water that fills the range\r\n * lands exactly on a level.\r\n *\r\n * @internal\r\n */\r\nfunction quantiseSliceExtent(half: number, range: number): number {\r\n if (!(half > 0) || half >= range) {\r\n return range;\r\n }\r\n const steps = Math.floor(Math.log2(range / half) * SLICE_QUANTISE_STEPS);\r\n return range / Math.pow(2, steps / SLICE_QUANTISE_STEPS);\r\n}\r\n\r\n/**\r\n * CPU-side parameters describing the caustic map, uploaded to the light pass.\r\n *\r\n * The map is a single orthographic slice of light space, fitted to the water\r\n * within range of the camera. `frameX`/`frameY` are the two axes perpendicular\r\n * to the light direction, carrying the reciprocal of the slice's half-extent\r\n * along each, so a world position projects into the map with two dot products\r\n * and no matrix.\r\n *\r\n * @public\r\n */\r\nexport interface WaterCausticUniforms {\r\n /** (right.xyz, 1 / half-extent along right) */\r\n frameX: Vector4;\r\n /** (up.xyz, 1 / half-extent along up) */\r\n frameY: Vector4;\r\n /** (center.xyz, water surface level) */\r\n center: Vector4;\r\n /** (lightDir.xyz, 1 / max(-lightDir.y, MIN_SUN_ELEVATION)) */\r\n lightDir: Vector4;\r\n /** (intensity, focal depth, defocus rate, edge fade start in map-radius units) */\r\n params: Vector4;\r\n /** (unused.xyz, warp strength). The medium moved to {@link waterMedia}. */\r\n extinction: Vector4;\r\n /** Water bodies contributing to this map, at most {@link MAX_CAUSTIC_WATERS}. */\r\n waterCount: number;\r\n /** Per body, world XZ footprint: (minX, minZ, maxX, maxZ). */\r\n waterRegions: Float32Array<ArrayBuffer>;\r\n /** Per body, (sigma_t.xyz, surface height). */\r\n waterMedia: Float32Array<ArrayBuffer>;\r\n}\r\n\r\n/** Shadow cascade reused as a light-space depth map of the scene. @internal */\r\ntype SceneDepthBinding = {\r\n texture: Texture2DArray;\r\n layer: number;\r\n size: number;\r\n matrix: Matrix4x4;\r\n matrixInv: Matrix4x4;\r\n};\r\n\r\n/**\r\n * Vertices per side of the grid the height map rasterises the surface with.\r\n *\r\n * Laid out in warped map space over the body's footprint, so each cell covers a\r\n * few map texels at most and the linear height across a cell is well inside what\r\n * a wave of any visible wavelength needs.\r\n */\r\nconst HEIGHT_GRID_SIZE = 256;\r\n\r\n/** @internal */\r\ntype SplatProgramInfo = {\r\n program: GPUProgram;\r\n /** One per water slot; see _getSplatBindGroup. */\r\n bindGroups: BindGroup[];\r\n};\r\n\r\n/**\r\n * Shader for the photon splat pass.\r\n *\r\n * Everything happens in the vertex stage: one vertex is one photon, and the\r\n * position it emits is where that photon lands. The fragment stage only deposits\r\n * the weight, which additive blending accumulates.\r\n *\r\n * Returned as a descriptor rather than a built program so it can be compiled\r\n * against a bare {@link ProgramBuilder} in tests, without a device.\r\n *\r\n * @param waveGenerator - Supplies the surface displacement and normal.\r\n * @internal\r\n */\r\nexport function createCausticSplatShader(waveGenerator: WaveGenerator, sceneDepth: boolean): PBRenderOptions {\r\n const setupUniforms = (scope: PBGlobalScope) => {\r\n const pb = scope.$builder;\r\n scope.causticFrameX = pb.vec4().uniform(0);\r\n scope.causticFrameY = pb.vec4().uniform(0);\r\n scope.causticCenter = pb.vec4().uniform(0);\r\n scope.causticLightDir = pb.vec4().uniform(0);\r\n scope.causticRegion = pb.vec4().uniform(0);\r\n /** Map-NDC rectangle the photon grid is laid out over: (minX, minY, maxX, maxY). */\r\n scope.causticGridBounds = pb.vec4().uniform(0);\r\n scope.causticSplatParams = pb.vec4().uniform(0);\r\n /** (grid size, 1 / grid size, 0, 0) */\r\n scope.causticPhotonParams = pb.vec4().uniform(0);\r\n if (sceneDepth) {\r\n // The sun's own shadow cascade, reused as a light-space depth map of the\r\n // scene: already orthographic, along the light, covering what the light\r\n // reaches, and costing no extra geometry pass.\r\n scope.causticSceneMatrix = pb.mat4().uniform(0);\r\n scope.causticSceneMatrixInv = pb.mat4().uniform(0);\r\n /** (cascade layer, 0, 0, 0) */\r\n scope.causticSceneParams = pb.vec4().uniform(0);\r\n // Sampled for its stored depth, not compared against a reference, so this\r\n // takes an ordinary sampler rather than the comparison one the lighting\r\n // pass binds to the same texture.\r\n scope.causticSceneDepth = pb.tex2DArrayShadow().uniform(0);\r\n }\r\n // FBM and Gerstner animate from camera.elapsedTime, which this pass has to\r\n // supply itself - it is not one of the engine's camera passes.\r\n ShaderHelper.declareStandaloneCameraTime(scope, 0);\r\n waveGenerator.setupUniforms(scope, 0);\r\n };\r\n return {\r\n vertex(this: PBGlobalScope, pb: ProgramBuilder) {\r\n // Photon ordinal, one vertex per photon. The grid coordinate is derived\r\n // from it here rather than stored, so the buffer outlives any one grid\r\n // size - see _updatePhotonLayout.\r\n this.$inputs.photonIndex = pb.float().attrib('position');\r\n this.$outputs.photonWeight = pb.float();\r\n setupUniforms(this);\r\n pb.main(function () {\r\n // Per-axis: the slice is fitted to the water, so its two half-extents\r\n // are independent and the map is only square in texels.\r\n this.$l.invRadius = pb.vec2(this.causticFrameX.w, this.causticFrameY.w);\r\n this.$l.radius = pb.div(pb.vec2(1), this.invRadius);\r\n this.$l.focalDepth = this.causticSplatParams.y;\r\n this.$l.eta = this.causticSplatParams.z;\r\n this.$l.L = this.causticLightDir.xyz;\r\n this.$l.waterLevel = this.causticCenter.w;\r\n // Grid position on the orthographic slice through the map centre.\r\n //\r\n // The grid spans only the part of the slice the water can actually cast\r\n // through, not the whole map: spread over the whole map, a pool covering\r\n // a tenth of it would leave most of the lit area with no photon at all,\r\n // and a caustic value of zero puts the sun out.\r\n //\r\n // Laid out in warped map space and unwarped to reach the plane, so the\r\n // grid is uniform in texels rather than in meters. That is what keeps\r\n // photon (i,j) on texel (i,j) for calm water under any warp strength,\r\n // and with it the map's normalisation to 1.0.\r\n //\r\n // Ordinal to grid coordinate: row is the quotient, column the remainder.\r\n this.$l.gridSize = this.causticPhotonParams.x;\r\n this.$l.invGrid = this.causticPhotonParams.y;\r\n this.$l.photonRow = pb.floor(pb.mul(this.$inputs.photonIndex, this.invGrid));\r\n this.$l.photonCol = pb.sub(this.$inputs.photonIndex, pb.mul(this.photonRow, this.gridSize));\r\n this.$l.photonUV = pb.mul(\r\n pb.add(pb.vec2(this.photonCol, this.photonRow), pb.vec2(0.5)),\r\n this.invGrid\r\n );\r\n this.$l.warpedNDC = pb.mix(this.causticGridBounds.xy, this.causticGridBounds.zw, this.photonUV);\r\n this.$l.ndc = ShaderHelper.unwarpCausticNDC(this, this.warpedNDC, this.causticSplatParams.x);\r\n this.$l.planePos = pb.add(\r\n this.causticCenter.xyz,\r\n pb.mul(this.causticFrameX.xyz, pb.mul(this.ndc.x, this.radius.x)),\r\n pb.mul(this.causticFrameY.xyz, pb.mul(this.ndc.y, this.radius.y))\r\n );\r\n // Sweep along the light direction onto the undisturbed water plane.\r\n this.$l.sweep = pb.div(pb.sub(this.waterLevel, this.planePos.y), this.L.y);\r\n this.$l.surfaceXZ = pb.add(this.planePos, pb.mul(this.L, this.sweep));\r\n this.$l.outside = pb.or(\r\n pb.any(pb.lessThan(this.surfaceXZ.xz, this.causticRegion.xy)),\r\n pb.any(pb.greaterThan(this.surfaceXZ.xz, this.causticRegion.zw))\r\n );\r\n // Displaced surface point and the detail normal that bends the ray. Both\r\n // wave generators sample with an explicit LOD, which is what makes this\r\n // legal in a vertex shader.\r\n //\r\n // The photon is launched from the rest point and lands wherever the\r\n // surface carried it, so the refraction is right. What it is not is\r\n // uniform in world xz - the horizontal displacement bunches the launch\r\n // points by the surface Jacobian, over-weighting compressed crests by\r\n // 1/J. Inverting the displacement per photon would fix that, but the\r\n // inversion only converges where the surface does not fold, and a choppy\r\n // FFT folds exactly at the crests it would matter for.\r\n this.$l.surfacePos = pb.vec3();\r\n this.$l.coarseNormal = pb.vec3();\r\n waveGenerator.calcVertexPositionAndNormal(this, this.surfaceXZ, this.surfacePos, this.coarseNormal);\r\n this.$l.normal = waveGenerator.calcFragmentNormal(this, this.surfaceXZ.xz, this.coarseNormal);\r\n // Refract, then subtract the deflection a flat surface would have\r\n // produced. Calm water then leaves the ray parallel to L, which lands\r\n // photon (i,j) back on texel (i,j) and normalises the map to 1.\r\n this.$l.refracted = pb.refract(this.L, this.normal, this.eta);\r\n this.$l.refractedFlat = pb.refract(this.L, pb.vec3(0, 1, 0), this.eta);\r\n this.$l.dir = pb.normalize(pb.add(pb.sub(this.refracted, this.refractedFlat), this.L));\r\n // Intersect the horizontal focal plane below the surface. The ray always\r\n // travels downwards here, but clamp anyway so a grazing ray cannot\r\n // produce an enormous or negative step.\r\n this.$l.invDirY = pb.min(this.dir.y, -1e-4);\r\n this.$l.targetY = pb.sub(this.waterLevel, this.focalDepth);\r\n this.$l.hitT = pb.div(pb.sub(this.targetY, this.surfacePos.y), this.invDirY);\r\n this.$l.hitPos = pb.add(this.surfacePos, pb.mul(this.dir, pb.max(this.hitT, 0)));\r\n if (sceneDepth) {\r\n // Land the photon on the scene rather than on a plane through it.\r\n //\r\n // Fixed-point iteration, not a ray march: read the height of the scene\r\n // under the current guess, re-intersect the ray with a horizontal\r\n // plane at that height, repeat. Each step is one texture fetch and the\r\n // sequence converges in two or three for any receiver that is smooth\r\n // over the distance the guess moves. A march would need an order of\r\n // magnitude more fetches, which the photon count cannot afford - at\r\n // the default density a full-coverage 1024 map launches four million.\r\n //\r\n // Where the assumption fails - a silhouette, an overhang - the\r\n // iteration lands on one of the two surfaces rather than diverging,\r\n // because every step is still a valid intersection of the ray with\r\n // some horizontal plane.\r\n this.$l.probe = this.hitPos;\r\n this.$l.layer = pb.int(this.causticSceneParams.x);\r\n for (let i = 0; i < SCENE_DEPTH_ITERATIONS; i++) {\r\n this.$l[`clip${i}`] = pb.mul(this.causticSceneMatrix, pb.vec4(this.probe, 1));\r\n this.$l[`ndc${i}`] = pb.div(this[`clip${i}`].xyz, this[`clip${i}`].w);\r\n this.$l[`uv${i}`] = pb.add(pb.mul(this[`ndc${i}`].xy, 0.5), pb.vec2(0.5));\r\n // Outside the cascade there is nothing to intersect against; keep\r\n // whatever the previous step produced, which for the first step is\r\n // the focal plane hit the flat path would have used.\r\n this.$l[`inside${i}`] = pb.and(\r\n pb.all(pb.greaterThanEqual(this[`uv${i}`], pb.vec2(0))),\r\n pb.all(pb.lessThanEqual(this[`uv${i}`], pb.vec2(1)))\r\n );\r\n // texelFetch rather than a filtered sample: the value is a depth,\r\n // and averaging two depths across a silhouette names a surface that\r\n // is not there. WebGPU only - GLSL ES 3.0 forbids texelFetch on a\r\n // shadow-sampler texture, which is what gates this whole path.\r\n this.$l[`depth${i}`] = pb.textureArrayLoad(\r\n this.causticSceneDepth,\r\n pb.ivec2(pb.mul(this[`uv${i}`], this.causticSceneParams.y)),\r\n this.layer,\r\n pb.int(0)\r\n );\r\n // Back to a world position. The cascade is orthographic, so the\r\n // stored depth and the sample's uv are enough to place the point.\r\n this.$l[`sceneNDC${i}`] = pb.vec3(\r\n this[`ndc${i}`].xy,\r\n REVERSE_Z ? this[`depth${i}`] : pb.sub(pb.mul(this[`depth${i}`], 2), 1)\r\n );\r\n this.$l[`sceneClip${i}`] = pb.mul(this.causticSceneMatrixInv, pb.vec4(this[`sceneNDC${i}`], 1));\r\n this.$l[`scenePos${i}`] = pb.div(this[`sceneClip${i}`].xyz, this[`sceneClip${i}`].w);\r\n // Re-intersect at the height just read. Only accept it while it is\r\n // below the *displaced* surface at this photon's entry: a scene\r\n // point above that is not something the photon passed through. The\r\n // rest level is the wrong bar - it would drop every photon landing\r\n // on a receiver that pokes above the rest plane under a passing\r\n // crest, cutting the caustics off along a flat line.\r\n this.$l[`t${i}`] = pb.div(pb.sub(this[`scenePos${i}`].y, this.surfacePos.y), this.invDirY);\r\n this.$l[`next${i}`] = pb.add(this.surfacePos, pb.mul(this.dir, pb.max(this[`t${i}`], 0)));\r\n // mix rather than select: the builder has no vec3 select.\r\n this.probe = pb.mix(\r\n this.probe,\r\n this[`next${i}`],\r\n pb.float(pb.and(this[`inside${i}`], pb.lessThan(this[`scenePos${i}`].y, this.surfacePos.y)))\r\n );\r\n }\r\n this.hitPos = this.probe;\r\n }\r\n // Project the hit back into the map. frameX/frameY are perpendicular to\r\n // L and to each other, so this is just two dot products.\r\n this.$l.rel = pb.sub(this.hitPos, this.causticCenter.xyz);\r\n this.$l.hitNDC = pb.mul(\r\n pb.vec2(pb.dot(this.rel, this.causticFrameX.xyz), pb.dot(this.rel, this.causticFrameY.xyz)),\r\n this.invRadius\r\n );\r\n // Into warped space, where the map's texels live.\r\n this.$l.hitWarped = ShaderHelper.warpCausticNDC(this, this.hitNDC, this.causticSplatParams.x);\r\n this.$outputs.photonWeight = this.causticSplatParams.w;\r\n // No per-backend y flip. A fragment written at clip y lands on the same\r\n // texture row on both backends, so the map the receiver samples with\r\n // `ndc * 0.5 + 0.5` is the one this writes at clip `ndc`.\r\n this.$builtins.position = pb.vec4(this.hitWarped, 0, 1);\r\n if (pb.getDevice().type !== 'webgpu') {\r\n // GLSL leaves gl_PointSize undefined unless it is written, and an\r\n // undefined size rasterises nothing at all. WebGPU points are always\r\n // one pixel.\r\n this.$builtins.pointSize = 1;\r\n }\r\n this.$if(this.outside, function () {\r\n // Park the photon outside the clip volume so it is discarded. Keep\r\n // w at 1: a zero w would divide to NaN instead of clipping.\r\n this.$builtins.position = pb.vec4(-2, -2, 0, 1);\r\n });\r\n });\r\n },\r\n fragment(this: PBGlobalScope, pb: ProgramBuilder) {\r\n this.$outputs.outColor = pb.vec4();\r\n pb.main(function () {\r\n this.$outputs.outColor = pb.vec4(this.$inputs.photonWeight, 0, 0, 1);\r\n });\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Shader for the displaced surface height map.\r\n *\r\n * Rasterises the water surface itself into the light-space slice, one body per\r\n * draw. A grid is laid out over the body's footprint in warped map space; each\r\n * vertex sweeps its grid point along the light onto the rest plane, lets the\r\n * wave generator carry it to where that bit of surface is, and projects the\r\n * displaced point back into the map as its clip position. The fragment writes\r\n * its height above the rest plane, offset by `CAUSTIC_HEIGHT_BIAS`, into this\r\n * body's channel - selected with a colour write mask, so where the surface\r\n * overlaps itself in the light's view the last triangle wins rather than the two\r\n * heights adding. The target is cleared first, and a texel the surface never\r\n * reaches stays at zero, which the receiver reads as \"no water on this ray\".\r\n *\r\n * Rasterising is what makes the horizontal displacement a non-issue: sampling\r\n * the generator at the map position would return the surface that *started*\r\n * there, and inverting that displacement only converges where the surface does\r\n * not fold. It also makes the footprint edge right - a receiver whose sun ray\r\n * crosses the rest plane outside the footprint finds an empty texel and stays\r\n * dry, where a flat stored height would put it under water that does not exist.\r\n *\r\n * The receiver looks this up with the very uv it uses for the caustic pattern:\r\n * its fragment and the ray's crossing of the rest plane lie on one light ray,\r\n * and the map's projection is invariant along the light.\r\n *\r\n * Everything runs in the vertex stage; the generators sample with an explicit\r\n * LOD, which is what makes that legal.\r\n *\r\n * @param waveGenerator - Supplies the surface displacement of this body.\r\n * @internal\r\n */\r\nexport function createCausticHeightShader(waveGenerator: WaveGenerator): PBRenderOptions {\r\n return {\r\n vertex(this: PBGlobalScope, pb: ProgramBuilder) {\r\n // Vertex ordinal; the grid coordinate is derived from it.\r\n this.$inputs.vertexIndex = pb.float().attrib('position');\r\n this.$outputs.height = pb.float();\r\n this.$outputs.inside = pb.float();\r\n this.causticFrameX = pb.vec4().uniform(0);\r\n this.causticFrameY = pb.vec4().uniform(0);\r\n /** (slice centre.xyz, this body's rest level) */\r\n this.causticCenter = pb.vec4().uniform(0);\r\n this.causticLightDir = pb.vec4().uniform(0);\r\n this.causticRegion = pb.vec4().uniform(0);\r\n /** Map-NDC rectangle the grid is laid out over: (minX, minY, maxX, maxY). */\r\n this.causticGridBounds = pb.vec4().uniform(0);\r\n /** (warp strength, grid size, 1 / (grid size + 1), 1 / grid size) */\r\n this.causticHeightParams = pb.vec4().uniform(0);\r\n ShaderHelper.declareStandaloneCameraTime(this, 0);\r\n waveGenerator.setupUniforms(this, 0);\r\n pb.main(function () {\r\n this.$l.invRadius = pb.vec2(this.causticFrameX.w, this.causticFrameY.w);\r\n this.$l.radius = pb.div(pb.vec2(1), this.invRadius);\r\n this.$l.L = this.causticLightDir.xyz;\r\n this.$l.waterLevel = this.causticCenter.w;\r\n // Ordinal to grid coordinate, (gridSize + 1) vertices per side. Half a\r\n // vertex up before the floor: the reciprocal is inexact, and an ordinal\r\n // that is an exact multiple of the row length must not round down into\r\n // the previous row.\r\n this.$l.row = pb.floor(pb.mul(pb.add(this.$inputs.vertexIndex, 0.5), this.causticHeightParams.z));\r\n this.$l.col = pb.sub(\r\n this.$inputs.vertexIndex,\r\n pb.mul(this.row, pb.add(this.causticHeightParams.y, 1))\r\n );\r\n this.$l.gridUV = pb.mul(pb.vec2(this.col, this.row), this.causticHeightParams.w);\r\n // Grid point to the slice, through the warp the map's texels live under.\r\n this.$l.warpedNDC = pb.mix(this.causticGridBounds.xy, this.causticGridBounds.zw, this.gridUV);\r\n this.$l.ndc = ShaderHelper.unwarpCausticNDC(this, this.warpedNDC, this.causticHeightParams.x);\r\n this.$l.planePos = pb.add(\r\n this.causticCenter.xyz,\r\n pb.mul(this.causticFrameX.xyz, pb.mul(this.ndc.x, this.radius.x)),\r\n pb.mul(this.causticFrameY.xyz, pb.mul(this.ndc.y, this.radius.y))\r\n );\r\n // Along the light onto the rest plane: the rest point of this vertex.\r\n this.$l.sweep = pb.div(pb.sub(this.waterLevel, this.planePos.y), this.L.y);\r\n this.$l.surfaceXZ = pb.add(this.planePos, pb.mul(this.L, this.sweep));\r\n // Outside the footprint there is no surface. Resolved per vertex and\r\n // interpolated, which fades the edge over one grid cell.\r\n this.$outputs.inside = pb.float(\r\n pb.and(\r\n pb.all(pb.greaterThanEqual(this.surfaceXZ.xz, this.causticRegion.xy)),\r\n pb.all(pb.lessThanEqual(this.surfaceXZ.xz, this.causticRegion.zw))\r\n )\r\n );\r\n // Where the surface carried this rest point, and how high it is there.\r\n this.$l.surfacePos = pb.vec3();\r\n this.$l.surfaceNormal = pb.vec3();\r\n waveGenerator.calcVertexPositionAndNormal(this, this.surfaceXZ, this.surfacePos, this.surfaceNormal);\r\n this.$outputs.height = pb.sub(this.surfacePos.y, this.waterLevel);\r\n // The displaced point back into the map, exactly as the splat projects a\r\n // photon hit: two dot products, then the warp.\r\n this.$l.rel = pb.sub(this.surfacePos, this.causticCenter.xyz);\r\n this.$l.hitNDC = pb.mul(\r\n pb.vec2(pb.dot(this.rel, this.causticFrameX.xyz), pb.dot(this.rel, this.causticFrameY.xyz)),\r\n this.invRadius\r\n );\r\n this.$l.hitWarped = ShaderHelper.warpCausticNDC(this, this.hitNDC, this.causticHeightParams.x);\r\n // The receiver reads the map at `v = 0.5 + 0.5 * ndc.y`. On WebGL a\r\n // fragment at clip y lands on that row; on WebGPU clip +1 is the first\r\n // row, so the surface is drawn upside down to land where the receiver\r\n // looks. The splat needs no such flip because its map reaches the\r\n // receiver through the blur and resolve quads, each of which flips it\r\n // once more on WebGPU; this map goes straight.\r\n this.$builtins.position =\r\n pb.getDevice().type === 'webgpu'\r\n ? pb.vec4(this.hitWarped.x, pb.neg(this.hitWarped.y), 0, 1)\r\n : pb.vec4(this.hitWarped, 0, 1);\r\n });\r\n },\r\n fragment(this: PBGlobalScope, pb: ProgramBuilder) {\r\n this.$outputs.outColor = pb.vec4();\r\n pb.main(function () {\r\n // Outside the footprint nothing is written at all, so the texel keeps\r\n // reading as \"no surface\" rather than as a surface at height zero.\r\n this.$if(pb.lessThan(this.$inputs.inside, 0.5), function () {\r\n pb.discard();\r\n });\r\n // Every channel; the colour mask keeps all but this body's.\r\n this.$outputs.outColor = pb.vec4(pb.add(this.$inputs.height, CAUSTIC_HEIGHT_BIAS));\r\n });\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Shader for the caustic map blur.\r\n *\r\n * Four bilinear taps at the texel corners average a 2x2 neighbourhood. The\r\n * weights sum to one, so the \"calm water reads 1.0\" normalisation established by\r\n * the accumulation pass survives any number of iterations.\r\n *\r\n * @internal\r\n */\r\nexport function createCausticBlurShader(): PBRenderOptions {\r\n return {\r\n vertex(this: PBGlobalScope, pb: ProgramBuilder) {\r\n this.$inputs.pos = pb.vec2().attrib('position');\r\n this.$outputs.uv = pb.vec2();\r\n pb.main(function () {\r\n this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);\r\n this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos, 0.5), pb.vec2(0.5));\r\n });\r\n },\r\n fragment(this: PBGlobalScope, pb: ProgramBuilder) {\r\n this.causticSrc = pb.tex2D().uniform(0);\r\n this.causticTexelSize = pb.vec4().uniform(0);\r\n this.$outputs.outColor = pb.vec4();\r\n pb.main(function () {\r\n this.$l.o = pb.mul(this.causticTexelSize.xy, 0.5);\r\n this.$l.sum = pb.add(\r\n pb.textureSampleLevel(this.causticSrc, pb.add(this.$inputs.uv, pb.vec2(this.o.x, this.o.y)), 0),\r\n pb.textureSampleLevel(\r\n this.causticSrc,\r\n pb.add(this.$inputs.uv, pb.vec2(pb.neg(this.o.x), this.o.y)),\r\n 0\r\n ),\r\n pb.textureSampleLevel(\r\n this.causticSrc,\r\n pb.add(this.$inputs.uv, pb.vec2(this.o.x, pb.neg(this.o.y))),\r\n 0\r\n ),\r\n pb.textureSampleLevel(\r\n this.causticSrc,\r\n pb.add(this.$inputs.uv, pb.vec2(pb.neg(this.o.x), pb.neg(this.o.y))),\r\n 0\r\n )\r\n );\r\n this.$outputs.outColor = pb.vec4(pb.mul(this.sum.x, 0.25), 0, 0, 1);\r\n });\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Shader for the temporal resolve.\r\n *\r\n * Reprojection is exact and matrix-free. Both frames parameterise the map as an\r\n * orthographic slice perpendicular to the light, so a texel maps to a world\r\n * point with two scaled axes, and that point maps into the previous frame with\r\n * two dot products. Photons travel along the light and the slice is normal to\r\n * it, so the plane the point is taken on does not matter.\r\n *\r\n * Map NDC relates to texture coordinate by the receiver's `ndc * 0.5 + 0.5`\r\n * (see `ShaderHelper.calculateWaterCaustic`), which is what makes this\r\n * independent of the clip-space y flip the splat has to apply.\r\n *\r\n * @internal\r\n */\r\nexport function createCausticResolveShader(): PBRenderOptions {\r\n return {\r\n vertex(this: PBGlobalScope, pb: ProgramBuilder) {\r\n this.$inputs.pos = pb.vec2().attrib('position');\r\n this.$outputs.uv = pb.vec2();\r\n pb.main(function () {\r\n this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);\r\n this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos, 0.5), pb.vec2(0.5));\r\n });\r\n },\r\n fragment(this: PBGlobalScope, pb: ProgramBuilder) {\r\n this.causticCurrent = pb.tex2D().uniform(0);\r\n this.causticHistory = pb.tex2D().uniform(0);\r\n this.causticFrameX = pb.vec4().uniform(0);\r\n this.causticFrameY = pb.vec4().uniform(0);\r\n this.causticCenter = pb.vec4().uniform(0);\r\n this.causticPrevFrameX = pb.vec4().uniform(0);\r\n this.causticPrevFrameY = pb.vec4().uniform(0);\r\n this.causticPrevCenter = pb.vec4().uniform(0);\r\n /** (blend weight, texel size, warp, previous frame's warp) */\r\n this.causticResolveParams = pb.vec4().uniform(0);\r\n this.$outputs.outColor = pb.vec4();\r\n pb.main(function () {\r\n this.$l.texel = this.causticResolveParams.y;\r\n this.$l.current = pb.textureSampleLevel(this.causticCurrent, this.$inputs.uv, 0).x;\r\n // Range the current frame supports around this texel. The reprojected\r\n // value is clamped into it, which is what lets a long blend coexist with\r\n // an animated pattern: where the waves have moved on, the neighbourhood\r\n // no longer covers the old value.\r\n this.$l.mn = this.current;\r\n this.$l.mx = this.current;\r\n for (let dy = -1; dy <= 1; dy++) {\r\n for (let dx = -1; dx <= 1; dx++) {\r\n if (dx === 0 && dy === 0) {\r\n continue;\r\n }\r\n this.$l.s = pb.textureSampleLevel(\r\n this.causticCurrent,\r\n pb.add(this.$inputs.uv, pb.mul(pb.vec2(dx, dy), this.texel)),\r\n 0\r\n ).x;\r\n this.mn = pb.min(this.mn, this.s);\r\n this.mx = pb.max(this.mx, this.s);\r\n }\r\n }\r\n // This texel's world point on the slice, then where the previous frame\r\n // put that same point. Texels are laid out in warped space, so this\r\n // leaves it to reach the world and re-enters it to land on the history:\r\n // the two frames may differ in slice and in warp strength alike.\r\n this.$l.warpedNDC = pb.sub(pb.mul(this.$inputs.uv, 2), pb.vec2(1));\r\n this.$l.ndc = ShaderHelper.unwarpCausticNDC(this, this.warpedNDC, this.causticResolveParams.z);\r\n this.$l.radius = pb.div(pb.vec2(1), pb.vec2(this.causticFrameX.w, this.causticFrameY.w));\r\n this.$l.world = pb.add(\r\n this.causticCenter.xyz,\r\n pb.mul(this.causticFrameX.xyz, pb.mul(this.ndc.x, this.radius.x)),\r\n pb.mul(this.causticFrameY.xyz, pb.mul(this.ndc.y, this.radius.y))\r\n );\r\n this.$l.rel = pb.sub(this.world, this.causticPrevCenter.xyz);\r\n this.$l.prevNDC = pb.mul(\r\n pb.vec2(pb.dot(this.rel, this.causticPrevFrameX.xyz), pb.dot(this.rel, this.causticPrevFrameY.xyz)),\r\n pb.vec2(this.causticPrevFrameX.w, this.causticPrevFrameY.w)\r\n );\r\n this.$l.prevWarped = ShaderHelper.warpCausticNDC(this, this.prevNDC, this.causticResolveParams.w);\r\n this.$l.prevUV = pb.add(pb.mul(this.prevWarped, 0.5), pb.vec2(0.5));\r\n // Ground the camera has just scrolled into has no history at all.\r\n this.$l.inside = pb.and(\r\n pb.all(pb.greaterThanEqual(this.prevUV, pb.vec2(0))),\r\n pb.all(pb.lessThanEqual(this.prevUV, pb.vec2(1)))\r\n );\r\n this.$l.history = pb.textureSampleLevel(this.causticHistory, this.prevUV, 0).x;\r\n this.$l.blend = pb.mul(this.causticResolveParams.x, pb.float(this.inside));\r\n this.$outputs.outColor = pb.vec4(\r\n pb.mix(this.current, pb.clamp(this.history, this.mn, this.mx), this.blend),\r\n 0,\r\n 0,\r\n 1\r\n );\r\n });\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Renders the water caustic map.\r\n *\r\n * One photon is emitted per texel of a uniform grid laid out on the same\r\n * orthographic light-space slice the map covers. Each photon is refracted at the\r\n * water surface, intersected with the scene (or a horizontal focal plane) below\r\n * it, and splatted additively at the hit position. Because the grid and the map\r\n * share a parameterisation, and the mean deflection of a flat surface is removed\r\n * from the refracted direction, calm water maps photon `(i,j)` onto texel\r\n * `(i,j)` and the map converges to a uniform 1.0 - which the receiver treats as\r\n * \"no caustics\".\r\n *\r\n * @internal\r\n */\r\nexport class WaterCausticsRenderer {\r\n /** Splat programs keyed by the wave generator's shader hash. */\r\n private readonly _splatPrograms: Map<string, SplatProgramInfo>;\r\n /** Height-map programs keyed by the wave generator's shader hash. */\r\n private readonly _heightPrograms: Map<string, SplatProgramInfo>;\r\n /** One per water slot, differing only in which channel they let through. */\r\n private readonly _heightStates: Nullable<RenderStateSet>[];\r\n private readonly _heightParams: Vector4;\r\n /** The surface grid the height map is rasterised with; built once. */\r\n private _heightLayout: Nullable<VertexLayout>;\r\n private _heightVertexBuffer: Nullable<GPUDataBuffer>;\r\n private _heightIndexBuffer: Nullable<IndexBuffer>;\r\n private _heightIndexCount: number;\r\n private _blurProgram: Nullable<GPUProgram>;\r\n private _blurBindGroup: Nullable<BindGroup>;\r\n private _resolveProgram: Nullable<GPUProgram>;\r\n private _resolveBindGroup: Nullable<BindGroup>;\r\n private _resolveStates: Nullable<RenderStateSet>;\r\n /**\r\n * Slice parameters the last map committed as history was built with, per\r\n * camera.\r\n *\r\n * Per camera because the history textures are, and this has to describe the\r\n * exact map the resolve is about to reproject; one shared entry would make a\r\n * second viewport reproject through the first one's slice.\r\n */\r\n private readonly _prevSlices: WeakMap<\r\n Camera,\r\n { frameX: Vector4; frameY: Vector4; center: Vector4; warp: number }\r\n >;\r\n private readonly _resolveParams: Vector4;\r\n private _photonLayout: Nullable<VertexLayout>;\r\n /** Photons the buffer can serve; it grows and is never rebuilt smaller. */\r\n private _photonCapacity: number;\r\n private _photonBuffer: Nullable<GPUDataBuffer>;\r\n private readonly _photonParams: Vector4;\r\n private _photonCount: number;\r\n private _splatStates: Nullable<RenderStateSet>;\r\n private _blurStates: Nullable<RenderStateSet>;\r\n private readonly _uniforms: WaterCausticUniforms;\r\n private readonly _tmpRight: Vector3;\r\n private readonly _tmpUp: Vector3;\r\n private readonly _tmpDir: Vector3;\r\n private readonly _tmpCenter: Vector3;\r\n private readonly _splatParams: Vector4;\r\n private readonly _blurTexelSize: Vector4;\r\n /** Map-NDC rectangle the photon grid covers, and the map fraction it is. */\r\n private readonly _gridBounds: Vector4;\r\n private _gridFraction: number;\r\n /** Furthest the fitted slice reaches from the camera, for cascade selection. */\r\n private _sliceReach: number;\r\n /** Slice frame and extents, kept for the per-body grid fit. */\r\n private _sliceRight: Vector3;\r\n private _sliceUp: Vector3;\r\n private _sliceCenterR: number;\r\n private _sliceCenterU: number;\r\n private _sliceHalfR: number;\r\n private _sliceHalfU: number;\r\n private readonly _splatCenter: Vector4;\r\n private readonly _sceneMatrixT: Matrix4x4;\r\n private readonly _sceneMatrix: Matrix4x4;\r\n private readonly _sceneMatrixInv: Matrix4x4;\r\n private readonly _sceneDepthParams: Vector4;\r\n /** Warp strength the current slice was built with; 0 when the map is linear. */\r\n private _warp: number;\r\n constructor() {\r\n this._splatPrograms = new Map();\r\n this._heightPrograms = new Map();\r\n this._heightStates = [];\r\n this._heightParams = new Vector4();\r\n this._heightLayout = null;\r\n this._heightVertexBuffer = null;\r\n this._heightIndexBuffer = null;\r\n this._heightIndexCount = 0;\r\n this._blurProgram = null;\r\n this._blurBindGroup = null;\r\n this._resolveProgram = null;\r\n this._resolveBindGroup = null;\r\n this._resolveStates = null;\r\n this._prevSlices = new WeakMap();\r\n this._resolveParams = new Vector4();\r\n this._photonLayout = null;\r\n this._photonCapacity = 0;\r\n this._photonBuffer = null;\r\n this._photonParams = new Vector4();\r\n this._photonCount = 0;\r\n this._splatStates = null;\r\n this._blurStates = null;\r\n this._uniforms = {\r\n frameX: new Vector4(),\r\n frameY: new Vector4(),\r\n center: new Vector4(),\r\n lightDir: new Vector4(),\r\n params: new Vector4(),\r\n extinction: new Vector4(),\r\n waterCount: 0,\r\n waterRegions: new Float32Array(MAX_CAUSTIC_WATERS * 4),\r\n waterMedia: new Float32Array(MAX_CAUSTIC_WATERS * 4)\r\n };\r\n this._tmpRight = new Vector3();\r\n this._tmpUp = new Vector3();\r\n this._tmpDir = new Vector3();\r\n this._tmpCenter = new Vector3();\r\n this._splatParams = new Vector4();\r\n this._blurTexelSize = new Vector4();\r\n this._gridBounds = new Vector4(-1, -1, 1, 1);\r\n this._gridFraction = 1;\r\n this._sliceReach = 1;\r\n this._sliceRight = new Vector3();\r\n this._sliceUp = new Vector3();\r\n this._sliceCenterR = 0;\r\n this._sliceCenterU = 0;\r\n this._sliceHalfR = 1;\r\n this._sliceHalfU = 1;\r\n this._splatCenter = new Vector4();\r\n this._sceneMatrixT = new Matrix4x4();\r\n this._sceneMatrix = new Matrix4x4();\r\n this._sceneMatrixInv = new Matrix4x4();\r\n this._sceneDepthParams = new Vector4();\r\n this._warp = 0;\r\n }\r\n /** Parameters of the map produced by the last successful {@link render}. */\r\n get uniforms(): WaterCausticUniforms {\r\n return this._uniforms;\r\n }\r\n /**\r\n * Storage format for the caustic map. Single channel when the device can both\r\n * render to and filter it, which the additive accumulation and the bilinear\r\n * sampling need.\r\n */\r\n static getMapFormat(device: AbstractDevice): TextureFormat {\r\n const info = device.getDeviceCaps().textureCaps.getTextureFormatInfo('r16f');\r\n return info.renderable && info.filterable ? 'r16f' : 'rgba16f';\r\n }\r\n /**\r\n * Storage format for the displaced surface height map. One channel per water\r\n * slot, so always four wide; half floats carry a wave height to well under a\r\n * millimetre at any plausible level.\r\n */\r\n static getHeightMapFormat(): TextureFormat {\r\n return 'rgba16f';\r\n }\r\n /**\r\n * Whether caustics can be produced for this water surface and light.\r\n *\r\n * @param water - Water surface the photons are refracted through.\r\n * @param light - Directional light the photons come from.\r\n * @returns True when {@link render} would produce a usable map.\r\n */\r\n static canRender(water: Water, light: PunctualLight): boolean {\r\n const material = water.material;\r\n if (!material?.causticsEnabled || !material.waveGenerator || !light.isDirectionLight()) {\r\n return false;\r\n }\r\n // Sun too close to the horizon: the swept photon grid degenerates.\r\n return -light.directionAndCutoff.y >= MIN_SUN_ELEVATION;\r\n }\r\n /**\r\n * Builds the caustic map for one water surface.\r\n *\r\n * @param ctx - Draw context; supplies the device and the camera the map is centred on.\r\n * @param water - Water surface to refract through.\r\n * @param light - Directional light acting as the photon source.\r\n * @param map - Accumulation target; also the result when nothing resolves after it.\r\n * @param scratch - Ping-pong target for the blur, and the temporal resolve's\r\n * output. Same size and format as `map`.\r\n * @param heights - Target for the displaced surface height map, in\r\n * {@link getHeightMapFormat} and the same size as `map`. Filled by this call\r\n * and read by the light pass alongside the map.\r\n * @param history - Previous frame's resolved map, or null when there is none\r\n * to reproject. Ignored unless the material asks for temporal accumulation.\r\n * @param createFramebuffer - Wraps a target texture into a framebuffer.\r\n * @returns The texture holding the finished map, which is `map` or `scratch`\r\n * depending on whether the temporal resolve ran.\r\n */\r\n render(\r\n ctx: DrawContext,\r\n waters: readonly Water[],\r\n light: PunctualLight,\r\n map: Texture2D,\r\n scratch: Texture2D,\r\n heights: Texture2D,\r\n history: Nullable<Texture2D>,\r\n createFramebuffer: (texture: Texture2D) => FrameBuffer\r\n ): Texture2D {\r\n const device = ctx.device;\r\n this._updateUniforms(ctx, waters, light, map.width);\r\n const sceneDepth = this._anySceneDepth(waters) ? this._resolveSceneDepth(ctx, light) : null;\r\n\r\n // The height map first: it depends on the slice alone, and the receiver\r\n // needs it whatever the splat produces.\r\n device.pushDeviceStates();\r\n device.setFramebuffer(createFramebuffer(heights));\r\n device.setViewport(null);\r\n device.setScissor(null);\r\n device.clearFrameBuffer(Vector4.zero(), null, null);\r\n this._ensureHeightGrid(device);\r\n for (let i = 0; i < waters.length; i++) {\r\n this._renderHeightsOne(device, ctx, waters[i], i);\r\n }\r\n device.popDeviceStates();\r\n\r\n device.pushDeviceStates();\r\n device.setFramebuffer(createFramebuffer(map));\r\n // The viewport and scissor survive a framebuffer change, and this pass runs\r\n // straight after the shadow maps, whose targets are a different size.\r\n device.setViewport(null);\r\n device.setScissor(null);\r\n device.clearFrameBuffer(Vector4.zero(), null, null);\r\n device.setRenderStates(this._getSplatStates(device));\r\n\r\n // One draw per water body, accumulating into the one map. They share the\r\n // slice, so a receiver still resolves the pattern with a single lookup; the\r\n // footprint, surface height and wave generator are per-draw state.\r\n for (let i = 0; i < waters.length; i++) {\r\n this._splatOne(device, ctx, waters[i], i, map, sceneDepth);\r\n }\r\n device.popDeviceStates();\r\n return this._postProcess(device, waters[0].material, map, scratch, history, ctx, createFramebuffer);\r\n }\r\n /**\r\n * Writes one body's displaced surface height into its channel of the height\r\n * map. Per body for the same reason the splat is: each has its own wave\r\n * generator, rest level and footprint.\r\n * @internal\r\n */\r\n private _renderHeightsOne(device: AbstractDevice, ctx: DrawContext, water: Water, index: number): void {\r\n const material = water.material;\r\n const waveGenerator = material.waveGenerator!;\r\n // The grid covers this body's footprint, like the photon grid does; a body\r\n // the map does not reach has nothing to draw.\r\n this._updateGridBounds(water);\r\n if (!(this._gridFraction > 0)) {\r\n return;\r\n }\r\n const info = this._getHeightProgram(device, waveGenerator);\r\n // A bind group per slot; see _getSplatBindGroup.\r\n const bindGroup = this._getSplatBindGroup(device, info, index);\r\n bindGroup.setValue('causticFrameX', this._uniforms.frameX);\r\n bindGroup.setValue('causticFrameY', this._uniforms.frameY);\r\n this._splatCenter.setXYZW(\r\n this._uniforms.center.x,\r\n this._uniforms.center.y,\r\n this._uniforms.center.z,\r\n water.worldMatrix.m13\r\n );\r\n bindGroup.setValue('causticCenter', this._splatCenter);\r\n bindGroup.setValue('causticLightDir', this._uniforms.lightDir);\r\n bindGroup.setValue('causticRegion', material.region);\r\n bindGroup.setValue('causticGridBounds', this._gridBounds);\r\n this._heightParams.setXYZW(\r\n this._warp,\r\n HEIGHT_GRID_SIZE,\r\n 1 / (HEIGHT_GRID_SIZE + 1),\r\n 1 / HEIGHT_GRID_SIZE\r\n );\r\n bindGroup.setValue('causticHeightParams', this._heightParams);\r\n ShaderHelper.setStandaloneCameraTime(bindGroup, ctx);\r\n waveGenerator.applyWaterBindGroup(bindGroup);\r\n // Channel i for slot i, which is how the receiver picks it back out.\r\n device.setRenderStates(this._getHeightStates(device, index));\r\n device.setProgram(info.program);\r\n device.setBindGroup(0, bindGroup);\r\n device.setVertexLayout(this._heightLayout!);\r\n device.draw('triangle-list', 0, this._heightIndexCount);\r\n }\r\n /**\r\n * Builds the surface grid once: vertex ordinals, and the index list that\r\n * stitches a (HEIGHT_GRID_SIZE + 1)^2 lattice of them into triangles.\r\n * @internal\r\n */\r\n private _ensureHeightGrid(device: AbstractDevice): void {\r\n if (this._heightLayout) {\r\n return;\r\n }\r\n const side = HEIGHT_GRID_SIZE + 1;\r\n const ordinals = new Float32Array(side * side);\r\n for (let i = 0; i < ordinals.length; i++) {\r\n ordinals[i] = i;\r\n }\r\n const indices = new Uint32Array(HEIGHT_GRID_SIZE * HEIGHT_GRID_SIZE * 6);\r\n let n = 0;\r\n for (let row = 0; row < HEIGHT_GRID_SIZE; row++) {\r\n for (let col = 0; col < HEIGHT_GRID_SIZE; col++) {\r\n const a = row * side + col;\r\n const b = a + 1;\r\n const c = a + side;\r\n const d = c + 1;\r\n indices[n++] = a;\r\n indices[n++] = b;\r\n indices[n++] = d;\r\n indices[n++] = a;\r\n indices[n++] = d;\r\n indices[n++] = c;\r\n }\r\n }\r\n const vertexBuffer = device.createVertexBuffer('position_f32', ordinals)!;\r\n const indexBuffer = device.createIndexBuffer(indices);\r\n this._heightVertexBuffer = vertexBuffer;\r\n this._heightIndexBuffer = indexBuffer;\r\n this._heightLayout = device.createVertexLayout({\r\n vertexBuffers: [{ buffer: vertexBuffer }],\r\n indexBuffer\r\n });\r\n this._heightIndexCount = indices.length;\r\n }\r\n /** @internal */\r\n private _splatOne(\r\n device: AbstractDevice,\r\n ctx: DrawContext,\r\n water: Water,\r\n index: number,\r\n map: Texture2D,\r\n sceneDepth: Nullable<SceneDepthBinding>\r\n ): void {\r\n const material = water.material;\r\n const waveGenerator = material.waveGenerator!;\r\n // Photons are laid out over this body's own footprint, so the grid bounds\r\n // and the fraction of the map they cover are per body, not per map.\r\n this._updateGridBounds(water);\r\n if (!(this._gridFraction > 0)) {\r\n return;\r\n }\r\n const photonGrid = this._resolvePhotonGrid(material.causticsPhotonResolution, map.width);\r\n this._updatePhotonLayout(device, photonGrid);\r\n // Scene-depth intersection is per material, but the program is per draw, so\r\n // a body that has it off simply compiles the flat variant.\r\n const useSceneDepth = !!sceneDepth && material.causticsSceneDepth;\r\n const splat = this._getSplatProgram(device, waveGenerator, useSceneDepth);\r\n // A bind group per slot; see _getSplatBindGroup.\r\n const bindGroup = this._getSplatBindGroup(device, splat, index);\r\n if (useSceneDepth) {\r\n bindGroup.setValue('causticSceneMatrix', sceneDepth!.matrix);\r\n bindGroup.setValue('causticSceneMatrixInv', sceneDepth!.matrixInv);\r\n this._sceneDepthParams.setXYZW(sceneDepth!.layer, sceneDepth!.size, 0, 0);\r\n bindGroup.setValue('causticSceneParams', this._sceneDepthParams);\r\n // Point sampling: the stored value is a depth, and averaging two depths\r\n // across a silhouette names a surface that is not there.\r\n bindGroup.setTexture('causticSceneDepth', sceneDepth!.texture, fetchSampler('clamp_nearest_nomip'));\r\n }\r\n bindGroup.setValue('causticFrameX', this._uniforms.frameX);\r\n bindGroup.setValue('causticFrameY', this._uniforms.frameY);\r\n // The slice centre is shared, but the water level in w is this body's.\r\n this._splatCenter.setXYZW(\r\n this._uniforms.center.x,\r\n this._uniforms.center.y,\r\n this._uniforms.center.z,\r\n water.worldMatrix.m13\r\n );\r\n bindGroup.setValue('causticCenter', this._splatCenter);\r\n bindGroup.setValue('causticLightDir', this._uniforms.lightDir);\r\n bindGroup.setValue('causticRegion', material.region);\r\n bindGroup.setValue('causticGridBounds', this._gridBounds);\r\n // A photon grid denser than the map deposits more than one photon per texel;\r\n // scale the deposit so a flat surface still integrates to exactly 1. The\r\n // grid fraction is part of that: concentrating the same photons onto a\r\n // smaller part of the map raises the density there by exactly its inverse.\r\n const photonWeight = (this._gridFraction * map.width * map.height) / (photonGrid * photonGrid);\r\n this._splatParams.setXYZW(this._warp, material.causticsDepth, WATER_ETA, photonWeight);\r\n bindGroup.setValue('causticSplatParams', this._splatParams);\r\n this._photonParams.setXYZW(photonGrid, 1 / photonGrid, 0, 0);\r\n bindGroup.setValue('causticPhotonParams', this._photonParams);\r\n ShaderHelper.setStandaloneCameraTime(bindGroup, ctx);\r\n waveGenerator.applyWaterBindGroup(bindGroup);\r\n device.setProgram(splat.program);\r\n device.setBindGroup(0, bindGroup);\r\n device.setVertexLayout(this._photonLayout);\r\n device.draw('point-list', 0, this._photonCount);\r\n }\r\n /**\r\n * Blur and temporal resolve, which run once over the finished map rather than\r\n * per water body.\r\n *\r\n * The settings come from one body's material because the map is one texture.\r\n * The largest body supplies them, which is the one the viewer is most likely\r\n * under.\r\n * @internal\r\n */\r\n private _postProcess(\r\n device: AbstractDevice,\r\n material: Water['material'],\r\n map: Texture2D,\r\n scratch: Texture2D,\r\n history: Nullable<Texture2D>,\r\n ctx: DrawContext,\r\n createFramebuffer: (texture: Texture2D) => FrameBuffer\r\n ): Texture2D {\r\n // Ping-pong between the two targets. The count is rounded up to an even\r\n // number by the material so the last pass always lands back in `map`.\r\n const blurPasses = Math.max(0, Math.min(material.causticsBlurPasses, 4));\r\n for (let i = 0; i < blurPasses; i++) {\r\n const src = i % 2 === 0 ? map : scratch;\r\n const dst = i % 2 === 0 ? scratch : map;\r\n this._blur(device, src, createFramebuffer(dst));\r\n }\r\n\r\n // The blur always lands back in `map`, so `scratch` is free to take the\r\n // resolve. Doing it the other way round would make the resolve read and\r\n // write one texture.\r\n const strength = material.causticsTemporalStrength;\r\n if (strength <= 0) {\r\n // Nothing is committed as history this frame, so the recorded slice has to\r\n // keep describing whichever map the history slot still holds.\r\n return map;\r\n }\r\n const camera = ctx.camera;\r\n const previous = this._prevSlices.get(camera);\r\n // No history on the first frame, after a resize, or after the pass was off\r\n // for a while. The current map stands on its own and becomes the history.\r\n const resolved = history && previous ? scratch : map;\r\n if (resolved === scratch) {\r\n this._resolve(device, map, history!, previous!, strength, createFramebuffer(scratch));\r\n }\r\n this._rememberSlice(camera);\r\n return resolved;\r\n }\r\n /**\r\n * Shadow cascade to read the scene depth from, or null when this backend or\r\n * this light cannot supply one.\r\n * @internal\r\n */\r\n private _resolveSceneDepth(\r\n ctx: DrawContext,\r\n light: PunctualLight\r\n ): Nullable<{\r\n texture: Texture2DArray;\r\n layer: number;\r\n size: number;\r\n matrix: Matrix4x4;\r\n matrixInv: Matrix4x4;\r\n }> {\r\n // WebGPU only. Reading a raw depth out of the shadow map needs a texel\r\n // fetch, and GLSL ES 3.0 does not allow one on a shadow-sampler texture.\r\n // WebGL2 keeps the focal plane.\r\n if (ctx.device.type !== 'webgpu') {\r\n return null;\r\n }\r\n const params = ctx.shadowMapInfo?.get(light);\r\n const shadowMap = params?.shadowMap;\r\n // Only the cascaded native-depth path. A packed RGBA map stores an encoded\r\n // distance rather than a sampled depth, and a non-array map has no cascade\r\n // to select; both fall back to the plane.\r\n if (!params || !shadowMap?.isTexture2DArray() || !shadowMap.isDepth()) {\r\n return null;\r\n }\r\n // The cascade that covers the slice most tightly: the smallest one whose\r\n // split distance clears the slice's reach. Falling off the end means the\r\n // slice outruns the shadow map and the last cascade is all there is.\r\n const count = Math.max(1, Math.min(params.numShadowCascades, 4));\r\n const reach = Math.max(1, this._sliceReach);\r\n let layer = count - 1;\r\n for (let i = 0; i < count; i++) {\r\n if (params.cascadeDistances[i] >= reach) {\r\n layer = i;\r\n break;\r\n }\r\n }\r\n // shadowMatrices holds each cascade's view-projection transposed, four vec4\r\n // rows per cascade, which is the layout the lighting pass dots against.\r\n this._sceneMatrixT.set(params.shadowMatrices.subarray(layer * 16, layer * 16 + 16));\r\n Matrix4x4.transpose(this._sceneMatrixT, this._sceneMatrix);\r\n Matrix4x4.invert(this._sceneMatrix, this._sceneMatrixInv);\r\n return {\r\n texture: shadowMap as Texture2DArray,\r\n layer,\r\n size: shadowMap.width,\r\n matrix: this._sceneMatrix,\r\n matrixInv: this._sceneMatrixInv\r\n };\r\n }\r\n /**\r\n * Photon grid edge length for this frame.\r\n *\r\n * Auto solves the grid for a fixed density in photons per covered map texel:\r\n * the grid covers `gridFraction` of the map, so the target is reached at\r\n * `grid = size * sqrt(target * gridFraction)`. Fixing the grid instead leaves\r\n * the density swinging with the water's footprint.\r\n *\r\n * @param requested - Material setting; 0 asks for the automatic size.\r\n * @param mapSize - Edge length of the caustic map.\r\n * @internal\r\n */\r\n private _resolvePhotonGrid(requested: number, mapSize: number): number {\r\n if (requested > 0) {\r\n return Math.max(8, Math.min(requested, 4096));\r\n }\r\n const grid = Math.round(mapSize * Math.sqrt(PHOTONS_PER_TEXEL * this._gridFraction));\r\n return Math.max(8, Math.min(grid, 4096));\r\n }\r\n /**\r\n * Records the slice the map just produced was built with, for the next frame's\r\n * reprojection.\r\n * @internal\r\n */\r\n private _rememberSlice(camera: Camera): void {\r\n let slice = this._prevSlices.get(camera);\r\n if (!slice) {\r\n slice = { frameX: new Vector4(), frameY: new Vector4(), center: new Vector4(), warp: 0 };\r\n this._prevSlices.set(camera, slice);\r\n }\r\n slice.frameX.set(this._uniforms.frameX);\r\n slice.frameY.set(this._uniforms.frameY);\r\n slice.center.set(this._uniforms.center);\r\n slice.warp = this._warp;\r\n }\r\n /** @internal */\r\n private _resolve(\r\n device: AbstractDevice,\r\n current: Texture2D,\r\n history: Texture2D,\r\n previous: { frameX: Vector4; frameY: Vector4; center: Vector4; warp: number },\r\n strength: number,\r\n dst: FrameBuffer\r\n ): void {\r\n const program = this._getResolveProgram(device);\r\n const bindGroup = this._resolveBindGroup!;\r\n device.pushDeviceStates();\r\n device.setFramebuffer(dst);\r\n device.setViewport(null);\r\n device.setScissor(null);\r\n device.setProgram(program);\r\n bindGroup.setTexture('causticCurrent', current, fetchSampler('clamp_linear_nomip'));\r\n bindGroup.setTexture('causticHistory', history, fetchSampler('clamp_linear_nomip'));\r\n bindGroup.setValue('causticFrameX', this._uniforms.frameX);\r\n bindGroup.setValue('causticFrameY', this._uniforms.frameY);\r\n bindGroup.setValue('causticCenter', this._uniforms.center);\r\n bindGroup.setValue('causticPrevFrameX', previous.frameX);\r\n bindGroup.setValue('causticPrevFrameY', previous.frameY);\r\n bindGroup.setValue('causticPrevCenter', previous.center);\r\n this._resolveParams.setXYZW(strength, 1 / current.width, this._warp, previous.warp);\r\n bindGroup.setValue('causticResolveParams', this._resolveParams);\r\n device.setBindGroup(0, bindGroup);\r\n drawFullscreenQuad(this._getResolveStates(device));\r\n device.popDeviceStates();\r\n }\r\n /** @internal */\r\n private _getResolveProgram(device: AbstractDevice): GPUProgram {\r\n if (!this._resolveProgram) {\r\n this._resolveProgram = device.buildRenderProgram(createCausticResolveShader())!;\r\n this._resolveProgram.name = '@Water_CausticResolve';\r\n this._resolveBindGroup = device.createBindGroup(this._resolveProgram.bindGroupLayouts[0])!;\r\n }\r\n return this._resolveProgram;\r\n }\r\n /** @internal */\r\n private _getResolveStates(device: AbstractDevice): RenderStateSet {\r\n if (!this._resolveStates) {\r\n this._resolveStates = device.createRenderStateSet();\r\n this._resolveStates.useRasterizerState().setCullMode('none');\r\n this._resolveStates.useDepthState().enableTest(false).enableWrite(false);\r\n }\r\n return this._resolveStates;\r\n }\r\n /** Releases the GPU objects owned by this renderer. */\r\n dispose(): void {\r\n for (const info of this._splatPrograms.values()) {\r\n for (const bindGroup of info.bindGroups) {\r\n bindGroup?.dispose();\r\n }\r\n info.program.dispose();\r\n }\r\n this._splatPrograms.clear();\r\n for (const info of this._heightPrograms.values()) {\r\n for (const bindGroup of info.bindGroups) {\r\n bindGroup?.dispose();\r\n }\r\n info.program.dispose();\r\n }\r\n this._heightPrograms.clear();\r\n this._heightStates.length = 0;\r\n // The layout does not own its buffers; see _updatePhotonLayout.\r\n this._heightLayout?.dispose();\r\n this._heightLayout = null;\r\n this._heightVertexBuffer?.dispose();\r\n this._heightVertexBuffer = null;\r\n this._heightIndexBuffer?.dispose();\r\n this._heightIndexBuffer = null;\r\n this._heightIndexCount = 0;\r\n this._blurBindGroup?.dispose();\r\n this._blurBindGroup = null;\r\n this._resolveProgram?.dispose();\r\n this._resolveProgram = null;\r\n this._resolveBindGroup?.dispose();\r\n this._resolveBindGroup = null;\r\n this._resolveStates = null;\r\n this._blurProgram?.dispose();\r\n this._blurProgram = null;\r\n this._photonLayout?.dispose();\r\n this._photonLayout = null;\r\n // Disposing the layout releases its vertex array object, not the buffer it\r\n // was built over.\r\n this._photonBuffer?.dispose();\r\n this._photonBuffer = null;\r\n this._photonCapacity = 0;\r\n this._photonCount = 0;\r\n this._splatStates = null;\r\n this._blurStates = null;\r\n }\r\n /** @internal */\r\n private _blur(device: AbstractDevice, src: Texture2D, dst: FrameBuffer): void {\r\n const program = this._getBlurProgram(device);\r\n device.pushDeviceStates();\r\n device.setFramebuffer(dst);\r\n device.setProgram(program);\r\n this._blurBindGroup!.setTexture('causticSrc', src, fetchSampler('clamp_linear_nomip'));\r\n this._blurTexelSize.setXYZW(1 / src.width, 1 / src.height, 0, 0);\r\n this._blurBindGroup!.setValue('causticTexelSize', this._blurTexelSize);\r\n device.setBindGroup(0, this._blurBindGroup!);\r\n drawFullscreenQuad(this._getBlurStates(device));\r\n device.popDeviceStates();\r\n }\r\n /**\r\n * Recomputes the orthographic light-space slice the map covers.\r\n * @internal\r\n */\r\n private _updateUniforms(\r\n ctx: DrawContext,\r\n waters: readonly Water[],\r\n light: PunctualLight,\r\n mapSize: number\r\n ): void {\r\n // Slice-wide settings come from the first body, which the caller has sorted\r\n // largest first. They describe the map, not the water, so one body has to\r\n // win: a range or a warp per body would ask one texture for two resolutions.\r\n const material = waters[0].material;\r\n const dir = this._tmpDir;\r\n dir.set(light.directionAndCutoff.xyz());\r\n dir.inplaceNormalize();\r\n // Two axes perpendicular to the light direction. Any pair will do; picking a\r\n // world axis that is not parallel to the light keeps the cross products stable.\r\n const seed = Math.abs(dir.y) > 0.99 ? Vector3.axisPZ() : Vector3.axisPY();\r\n Vector3.cross(seed, dir, this._tmpRight);\r\n this._tmpRight.inplaceNormalize();\r\n Vector3.cross(dir, this._tmpRight, this._tmpUp);\r\n this._tmpUp.inplaceNormalize();\r\n const right = this._tmpRight;\r\n const up = this._tmpUp;\r\n const waterLevel = waters[0].worldMatrix.m13;\r\n const range = Math.max(1, material.causticsRange);\r\n const camera = ctx.camera.getWorldPosition();\r\n const center = this._tmpCenter.setXYZ(camera.x, waterLevel, camera.z);\r\n const cameraRight = Vector3.dot(center, right);\r\n const cameraUp = Vector3.dot(center, up);\r\n // The component along the light direction is arbitrary: both the projection\r\n // into the map and the photon sweep are invariant along it.\r\n const alongDir = Vector3.dot(center, dir);\r\n\r\n // Water region in light space. A world-axis-aligned rectangle projects to a\r\n // parallelogram here, so its bounds come from the four corners; the map is a\r\n // box in these coordinates, which is why the fit is against the AABB.\r\n //\r\n // Over every body at once, so the slice covers all of them. Bodies far\r\n // apart make the union mostly empty, but `causticsRange` already bounds how\r\n // much of that reaches the map.\r\n let regionMinR = Infinity;\r\n let regionMaxR = -Infinity;\r\n let regionMinU = Infinity;\r\n let regionMaxU = -Infinity;\r\n for (const body of waters) {\r\n const region = body.material.region;\r\n // Each body's own height, since the projection is taken on its surface.\r\n const level = body.worldMatrix.m13;\r\n for (const [x, z] of [\r\n [region.x, region.y],\r\n [region.z, region.y],\r\n [region.x, region.w],\r\n [region.z, region.w]\r\n ]) {\r\n const r = x * right.x + level * right.y + z * right.z;\r\n const v = x * up.x + level * up.y + z * up.z;\r\n regionMinR = Math.min(regionMinR, r);\r\n regionMaxR = Math.max(regionMaxR, r);\r\n regionMinU = Math.min(regionMinU, v);\r\n regionMaxU = Math.max(regionMaxU, v);\r\n }\r\n }\r\n // Fit the slice to what the water can actually cast into, instead of always\r\n // spending the map on a camera-centred square of `range`, which leaves most\r\n // of it permanently zero for a pool far smaller than the range.\r\n // `causticsRange` becomes a cap on how far from the camera the map reaches\r\n // rather than its literal half-extent.\r\n let loR = Math.max(regionMinR, cameraRight - range);\r\n let hiR = Math.min(regionMaxR, cameraRight + range);\r\n let loU = Math.max(regionMinU, cameraUp - range);\r\n let hiU = Math.min(regionMaxU, cameraUp + range);\r\n if (hiR <= loR || hiU <= loU) {\r\n // The water casts nowhere within range. Nothing will be drawn, but the\r\n // slice still has to be finite: the receiver projects through it whatever\r\n // the map holds, and the grid bounds below have to come out empty rather\r\n // than inverted.\r\n loR = cameraRight - range;\r\n hiR = cameraRight + range;\r\n loU = cameraUp - range;\r\n hiU = cameraUp + range;\r\n }\r\n let halfR = Math.max(MIN_SLICE_EXTENT, (hiR - loR) * 0.5);\r\n let halfU = Math.max(MIN_SLICE_EXTENT, (hiU - loU) * 0.5);\r\n // The map is square, so an anisotropic slice gives its two axes different\r\n // world texel sizes, which reads as directional smearing. Capping the ratio\r\n // keeps most of the fit while bounding that, and bounds the same asymmetry\r\n // in the edge fade, whose band is a share of each axis.\r\n halfR = Math.max(halfR, halfU / MAX_SLICE_ASPECT);\r\n halfU = Math.max(halfU, halfR / MAX_SLICE_ASPECT);\r\n // Quantise so the extent holds still while the camera moves: texel snapping\r\n // below only stops the map crawling if the texel size itself is stable, and\r\n // a continuously shrinking slice resamples the temporal history every frame.\r\n // The two common cases - a pool wholly inside the range, a sea wholly\r\n // covering it - sit on a fixed level and never change at all.\r\n halfR = Math.min(range, quantiseSliceExtent(halfR, range));\r\n halfU = Math.min(range, quantiseSliceExtent(halfU, range));\r\n // Warping only pays where the range, not the water, is what bounds the map.\r\n // A slice already fitted to a pool has every texel on water the camera can\r\n // see, and concentrating them further would just blur its far side.\r\n const rangeLimited =\r\n regionMinR < cameraRight - range ||\r\n regionMaxR > cameraRight + range ||\r\n regionMinU < cameraUp - range ||\r\n regionMaxU > cameraUp + range;\r\n const warp = rangeLimited ? material.causticsWarp : 0;\r\n // Snap the centre so the map does not crawl as the camera moves. Whole\r\n // texels when the map is linear, which is exact; a coarse ladder under a\r\n // warp, where no shift is exact and the goal is instead to shift rarely.\r\n const snapR = warp > 0 ? halfR / WARPED_CENTER_SNAP_DIVISIONS : (2 * halfR) / mapSize;\r\n const snapU = warp > 0 ? halfU / WARPED_CENTER_SNAP_DIVISIONS : (2 * halfU) / mapSize;\r\n const centerR = Math.round(((loR + hiR) * 0.5) / snapR) * snapR;\r\n const centerU = Math.round(((loU + hiU) * 0.5) / snapU) * snapU;\r\n center.setXYZ(\r\n right.x * centerR + up.x * centerU + dir.x * alongDir,\r\n right.y * centerR + up.y * centerU + dir.y * alongDir,\r\n right.z * centerR + up.z * centerU + dir.z * alongDir\r\n );\r\n const u = this._uniforms;\r\n u.frameX.setXYZW(right.x, right.y, right.z, 1 / halfR);\r\n u.frameY.setXYZW(up.x, up.y, up.z, 1 / halfU);\r\n u.center.setXYZW(center.x, center.y, center.z, waterLevel);\r\n u.lightDir.setXYZW(dir.x, dir.y, dir.z, 1 / Math.max(-dir.y, MIN_SUN_ELEVATION));\r\n // Edge fade, expressed to the receiver as the distance from the map centre\r\n // the fade begins at, in units of the map half-extent. Resolving it here\r\n // keeps the shader free of the extents and lets the auto width put a floor\r\n // in meters under a band the map fraction alone would collapse.\r\n //\r\n // Only a border the range put there needs fading. Where the fit stopped at\r\n // the water instead, the border already coincides with the region the\r\n // receiver gates on, so a band there is at best a no-op and at worst eats\r\n // caustics from the last few meters of a pool the map now fits exactly.\r\n const minHalf = Math.min(halfR, halfU);\r\n const fadeDistance = !rangeLimited\r\n ? 0\r\n : material.causticsFadeDistance > 0\r\n ? material.causticsFadeDistance\r\n : Math.max(AUTO_FADE_MIN_DISTANCE, AUTO_FADE_FRACTION * minHalf);\r\n const fadeFraction = Math.max(MIN_FADE_FRACTION, Math.min(MAX_FADE_FRACTION, fadeDistance / minHalf));\r\n u.params.setXYZW(\r\n material.causticsIntensity,\r\n material.causticsDepth,\r\n material.causticsDefocus,\r\n 1 - fadeFraction\r\n );\r\n u.extinction.setXYZW(0, 0, 0, warp);\r\n this._warp = warp;\r\n // Retained for the per-body grid fit, which runs per draw rather than here.\r\n this._sliceRight = right;\r\n this._sliceUp = up;\r\n this._sliceCenterR = centerR;\r\n this._sliceCenterU = centerU;\r\n this._sliceHalfR = halfR;\r\n this._sliceHalfU = halfU;\r\n // How far the slice reaches from the camera, which is what decides how\r\n // coarse a shadow cascade has to be to contain it.\r\n this._sliceReach = Math.hypot(halfR, halfU);\r\n\r\n // The per-body table the receiver searches. Footprint and surface height\r\n // decide which body is above a given point; the medium is what attenuates\r\n // the light once one is.\r\n u.waterCount = Math.min(waters.length, MAX_CAUSTIC_WATERS);\r\n for (let i = 0; i < u.waterCount; i++) {\r\n const body = waters[i];\r\n const region = body.material.region;\r\n u.waterRegions[i * 4 + 0] = region.x;\r\n u.waterRegions[i * 4 + 1] = region.y;\r\n u.waterRegions[i * 4 + 2] = region.z;\r\n u.waterRegions[i * 4 + 3] = region.w;\r\n const ext = body.material.extinction;\r\n u.waterMedia[i * 4 + 0] = ext.x;\r\n u.waterMedia[i * 4 + 1] = ext.y;\r\n u.waterMedia[i * 4 + 2] = ext.z;\r\n u.waterMedia[i * 4 + 3] = body.worldMatrix.m13;\r\n }\r\n }\r\n /**\r\n * Map-NDC bounds of one body's footprint, so its photon grid covers just that.\r\n *\r\n * Projecting into the slice is invariant along the light and the slice is\r\n * normal to it, so a point on the water plane and the photon it launches share\r\n * a map position: the body's light-space bounds carry over directly. Clamped\r\n * to the map, because photons outside it are rasterised away and the fraction\r\n * has to describe what is left. Warped, because the grid is laid out in the\r\n * space the map's texels live in - the warp is monotone and separable, so\r\n * warping the interval's ends gives the warped interval exactly.\r\n * @internal\r\n */\r\n private _updateGridBounds(water: Water): void {\r\n const region = water.material.region;\r\n const level = water.worldMatrix.m13;\r\n const right = this._sliceRight;\r\n const up = this._sliceUp;\r\n let minR = Infinity;\r\n let maxR = -Infinity;\r\n let minU = Infinity;\r\n let maxU = -Infinity;\r\n for (const [x, z] of [\r\n [region.x, region.y],\r\n [region.z, region.y],\r\n [region.x, region.w],\r\n [region.z, region.w]\r\n ]) {\r\n const r = x * right.x + level * right.y + z * right.z;\r\n const v = x * up.x + level * up.y + z * up.z;\r\n minR = Math.min(minR, r);\r\n maxR = Math.max(maxR, r);\r\n minU = Math.min(minU, v);\r\n maxU = Math.max(maxU, v);\r\n }\r\n const warp = this._warp;\r\n // Clamped to the map plus a margin, but never past the water itself. Where\r\n // the footprint ends inside the map the bound stays on the water, because a\r\n // photon launched off the water is killed by the region test and would only\r\n // dilute the weight the fraction below hands out. Where the water carries on\r\n // past the border, the margin lets the displaced surface throw photons back\r\n // in across it - see GRID_BORDER_MARGIN.\r\n const m = 1 + GRID_BORDER_MARGIN;\r\n const lo = (v: number) => Math.max(-m, Math.min(m, v));\r\n const minX = warpCausticNDC(lo((minR - this._sliceCenterR) / this._sliceHalfR), warp);\r\n const maxX = warpCausticNDC(lo((maxR - this._sliceCenterR) / this._sliceHalfR), warp);\r\n const minY = warpCausticNDC(lo((minU - this._sliceCenterU) / this._sliceHalfU), warp);\r\n const maxY = warpCausticNDC(lo((maxU - this._sliceCenterU) / this._sliceHalfU), warp);\r\n this._gridBounds.setXYZW(minX, minY, maxX, maxY);\r\n // Share of the map the grid covers, which is what keeps calm water at 1.0:\r\n // the same photon count spread over a smaller area has to deposit\r\n // proportionally less each.\r\n this._gridFraction = Math.max(0, ((maxX - minX) * (maxY - minY)) / 4);\r\n }\r\n /** @internal */\r\n private _updatePhotonLayout(device: AbstractDevice, gridSize: number): void {\r\n this._photonCount = gridSize * gridSize;\r\n if (this._photonCapacity >= this._photonCount) {\r\n return;\r\n }\r\n // Grow only, and never rebuild for a size change.\r\n //\r\n // The buffer holds each photon's ordinal, and the shader divides that\r\n // by the grid size to place it.\r\n const capacity = Math.max(this._photonCount, this._photonCapacity * 2);\r\n const indices = new Float32Array(capacity);\r\n for (let i = 0; i < capacity; i++) {\r\n indices[i] = i;\r\n }\r\n // WebGL2 refuses to draw without a bound vertex layout, so the ordinal is\r\n // materialised as an attribute rather than read from the vertex index.\r\n const buffer = device.createVertexBuffer('position_f32', indices)!;\r\n this._photonLayout?.dispose();\r\n this._photonBuffer?.dispose();\r\n this._photonBuffer = buffer;\r\n this._photonLayout = device.createVertexLayout({ vertexBuffers: [{ buffer }] });\r\n this._photonCapacity = capacity;\r\n }\r\n /** @internal */\r\n private _getSplatStates(device: AbstractDevice): RenderStateSet {\r\n if (!this._splatStates) {\r\n this._splatStates = device.createRenderStateSet();\r\n this._splatStates.useRasterizerState().setCullMode('none');\r\n this._splatStates.useDepthState().enableTest(false).enableWrite(false);\r\n // Photon accumulation: every splat adds to whatever is already there.\r\n this._splatStates\r\n .useBlendingState()\r\n .enable(true)\r\n .setBlendFunc('one', 'one')\r\n .setBlendEquation('add', 'add');\r\n }\r\n return this._splatStates;\r\n }\r\n /** @internal */\r\n private _getHeightStates(device: AbstractDevice, slot: number): RenderStateSet {\r\n let states = this._heightStates[slot];\r\n if (!states) {\r\n states = device.createRenderStateSet();\r\n states.useRasterizerState().setCullMode('none');\r\n states.useDepthState().enableTest(false).enableWrite(false);\r\n // Plain overwrite into this slot's channel only. Blending would add the\r\n // heights wherever the surface overlaps itself in the light's view.\r\n states.useColorState().setColorMask(slot === 0, slot === 1, slot === 2, slot === 3);\r\n this._heightStates[slot] = states;\r\n }\r\n return states;\r\n }\r\n /** @internal */\r\n private _getHeightProgram(device: AbstractDevice, waveGenerator: WaveGenerator): SplatProgramInfo {\r\n const key = waveGenerator.getHash();\r\n let info = this._heightPrograms.get(key);\r\n if (info) {\r\n return info;\r\n }\r\n const program = device.buildRenderProgram(createCausticHeightShader(waveGenerator))!;\r\n program.name = '@Water_CausticHeight';\r\n info = { program, bindGroups: [] };\r\n this._heightPrograms.set(key, info);\r\n return info;\r\n }\r\n /** @internal */\r\n private _getBlurStates(device: AbstractDevice): RenderStateSet {\r\n if (!this._blurStates) {\r\n this._blurStates = device.createRenderStateSet();\r\n this._blurStates.useRasterizerState().setCullMode('none');\r\n this._blurStates.useDepthState().enableTest(false).enableWrite(false);\r\n }\r\n return this._blurStates;\r\n }\r\n /** @internal */\r\n private _getSplatProgram(\r\n device: AbstractDevice,\r\n waveGenerator: WaveGenerator,\r\n sceneDepth: boolean\r\n ): SplatProgramInfo {\r\n const key = `${waveGenerator.getHash()}:${sceneDepth ? 1 : 0}`;\r\n let info = this._splatPrograms.get(key);\r\n if (info) {\r\n return info;\r\n }\r\n const program = device.buildRenderProgram(createCausticSplatShader(waveGenerator, sceneDepth))!;\r\n program.name = `@Water_CausticSplat${sceneDepth ? '_SceneDepth' : ''}`;\r\n info = { program, bindGroups: [] };\r\n this._splatPrograms.set(key, info);\r\n return info;\r\n }\r\n /**\r\n * The bind group for one water slot of a splat program.\r\n * @internal\r\n */\r\n private _getSplatBindGroup(device: AbstractDevice, info: SplatProgramInfo, slot: number): BindGroup {\r\n let bindGroup = info.bindGroups[slot];\r\n if (!bindGroup) {\r\n bindGroup = device.createBindGroup(info.program.bindGroupLayouts[0])!;\r\n info.bindGroups[slot] = bindGroup;\r\n }\r\n return bindGroup;\r\n }\r\n /**\r\n * Whether any body asks for the scene-depth intersection, which decides\r\n * whether the shadow cascade needs resolving at all.\r\n * @internal\r\n */\r\n private _anySceneDepth(waters: readonly Water[]): boolean {\r\n return waters.some((w) => w.material.causticsSceneDepth);\r\n }\r\n /** @internal */\r\n private _getBlurProgram(device: AbstractDevice): GPUProgram {\r\n if (!this._blurProgram) {\r\n this._blurProgram = device.buildRenderProgram(createCausticBlurShader())!;\r\n this._blurProgram.name = '@Water_CausticBlur';\r\n this._blurBindGroup = device.createBindGroup(this._blurProgram.bindGroupLayouts[0])!;\r\n }\r\n return this._blurProgram;\r\n }\r\n}\r\n"],"names":["WATER_IOR","WATER_ETA","MIN_SUN_ELEVATION","SCENE_DEPTH_ITERATIONS","PHOTONS_PER_TEXEL","AUTO_FADE_FRACTION","AUTO_FADE_MIN_DISTANCE","MIN_FADE_FRACTION","MAX_FADE_FRACTION","MAX_SLICE_ASPECT","SLICE_QUANTISE_STEPS","MIN_SLICE_EXTENT","WARPED_CENTER_SNAP_DIVISIONS","GRID_BORDER_MARGIN","warpCausticNDC","ndc","strength","Math","abs","quantiseSliceExtent","half","range","steps","floor","log2","pow","HEIGHT_GRID_SIZE","createCausticSplatShader","waveGenerator","sceneDepth","setupUniforms","scope","pb","$builder","causticFrameX","vec4","uniform","causticFrameY","causticCenter","causticLightDir","causticRegion","causticGridBounds","causticSplatParams","causticPhotonParams","causticSceneMatrix","mat4","causticSceneMatrixInv","causticSceneParams","causticSceneDepth","tex2DArrayShadow","ShaderHelper","declareStandaloneCameraTime","vertex","$inputs","photonIndex","float","attrib","$outputs","photonWeight","main","$l","invRadius","vec2","w","radius","div","focalDepth","y","eta","z","L","xyz","waterLevel","gridSize","x","invGrid","photonRow","mul","photonCol","sub","photonUV","add","warpedNDC","mix","xy","zw","unwarpCausticNDC","planePos","sweep","surfaceXZ","outside","or","any","lessThan","xz","greaterThan","surfacePos","vec3","coarseNormal","calcVertexPositionAndNormal","normal","calcFragmentNormal","refracted","refract","refractedFlat","dir","normalize","invDirY","min","targetY","hitT","hitPos","max","probe","layer","int","i","and","all","greaterThanEqual","lessThanEqual","textureArrayLoad","ivec2","REVERSE_Z","rel","hitNDC","dot","hitWarped","$builtins","position","getDevice","type","pointSize","$if","fragment","outColor","createCausticHeightShader","vertexIndex","height","inside","causticHeightParams","row","col","gridUV","surfaceNormal","neg","discard","CAUSTIC_HEIGHT_BIAS","createCausticBlurShader","pos","uv","causticSrc","tex2D","causticTexelSize","o","sum","textureSampleLevel","createCausticResolveShader","causticCurrent","causticHistory","causticPrevFrameX","causticPrevFrameY","causticPrevCenter","causticResolveParams","texel","current","mn","mx","dy","dx","s","world","prevNDC","prevWarped","prevUV","history","blend","clamp","WaterCausticsRenderer","_heightParams","_heightVertexBuffer","_heightIndexBuffer","_heightIndexCount","_blurProgram","_blurBindGroup","_resolveProgram","_resolveBindGroup","_resolveStates","_resolveParams","_photonLayout","_photonBuffer","_photonParams","_photonCount","_splatStates","_blurStates","_uniforms","_tmpRight","_tmpUp","_tmpDir","_tmpCenter","_splatParams","_blurTexelSize","_gridFraction","_sliceUp","_sliceCenterR","_sliceCenterU","_sliceHalfR","_sliceHalfU","_splatCenter","_sceneMatrixT","_sceneMatrix","_sceneMatrixInv","_sceneDepthParams","_splatPrograms","Map","_heightPrograms","_heightStates","Vector4","_heightLayout","_prevSlices","WeakMap","_photonCapacity","frameX","frameY","center","lightDir","params","extinction","waterCount","waterRegions","Float32Array","MAX_CAUSTIC_WATERS","waterMedia","Vector3","_gridBounds","_sliceReach","_sliceRight","Matrix4x4","_warp","uniforms","getMapFormat","device","info","getDeviceCaps","textureCaps","getTextureFormatInfo","renderable","filterable","getHeightMapFormat","canRender","water","light","material","causticsEnabled","isDirectionLight","directionAndCutoff","render","ctx","waters","map","scratch","heights","createFramebuffer","_updateUniforms","width","_anySceneDepth","_resolveSceneDepth","pushDeviceStates","setFramebuffer","setViewport","setScissor","clearFrameBuffer","zero","_ensureHeightGrid","length","_renderHeightsOne","popDeviceStates","setRenderStates","_getSplatStates","_splatOne","_postProcess","index","_updateGridBounds","_getHeightProgram","bindGroup","_getSplatBindGroup","setValue","setXYZW","worldMatrix","m13","region","setStandaloneCameraTime","applyWaterBindGroup","_getHeightStates","setProgram","program","setBindGroup","setVertexLayout","draw","side","ordinals","indices","Uint32Array","n","a","b","c","d","vertexBuffer","createVertexBuffer","indexBuffer","createIndexBuffer","createVertexLayout","vertexBuffers","buffer","photonGrid","_resolvePhotonGrid","causticsPhotonResolution","_updatePhotonLayout","useSceneDepth","causticsSceneDepth","splat","_getSplatProgram","matrix","matrixInv","size","setTexture","texture","fetchSampler","causticsDepth","blurPasses","causticsBlurPasses","src","dst","_blur","causticsTemporalStrength","camera","previous","get","resolved","_resolve","_rememberSlice","shadowMapInfo","shadowMap","isTexture2DArray","isDepth","count","numShadowCascades","reach","cascadeDistances","set","shadowMatrices","subarray","transpose","invert","requested","mapSize","grid","round","sqrt","slice","warp","_getResolveProgram","drawFullscreenQuad","_getResolveStates","buildRenderProgram","name","createBindGroup","bindGroupLayouts","createRenderStateSet","useRasterizerState","setCullMode","useDepthState","enableTest","enableWrite","dispose","values","bindGroups","clear","_getBlurProgram","_getBlurStates","inplaceNormalize","seed","axisPZ","axisPY","cross","right","up","causticsRange","getWorldPosition","setXYZ","cameraRight","cameraUp","alongDir","regionMinR","Infinity","regionMaxR","regionMinU","regionMaxU","body","level","r","v","loR","hiR","loU","hiU","halfR","halfU","rangeLimited","causticsWarp","snapR","snapU","centerR","centerU","u","minHalf","fadeDistance","causticsFadeDistance","fadeFraction","causticsIntensity","causticsDefocus","hypot","ext","minR","maxR","minU","maxU","m","lo","minX","maxX","minY","maxY","capacity","useBlendingState","enable","setBlendFunc","setBlendEquation","slot","states","useColorState","setColorMask","key","getHash","some"],"mappings":";;;;;AA2BA,qDACA,MAAMA,SAAY,GAAA,KAAA;AAClB,yEACA,MAAMC,SAAAA,GAAY,CAAID,GAAAA,SAAAA;AACtB;;;;AAIC,IACD,MAAME,iBAAoB,GAAA,IAAA;AAC1B;;;;;AAKC,IACD,MAAMC,sBAAyB,GAAA,CAAA;AAC/B;;;;;AAKC,IACD,MAAMC,iBAAoB,GAAA,CAAA;AAC1B,wEACA,MAAMC,kBAAqB,GAAA,GAAA;AAC3B,uDACA,MAAMC,sBAAyB,GAAA,CAAA;AAC/B,wEACA,MAAMC,iBAAoB,GAAA,KAAA;AAC1B,MAAMC,iBAAoB,GAAA,GAAA;AAC1B;;;;AAIC,IACD,MAAMC,gBAAmB,GAAA,CAAA;AACzB;;;;AA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,IAAI,CAACpK,cAAc,CAACyI,GAAG,CAAC6F,GAAKzM,EAAAA,IAAAA,CAAAA;QAC7B,OAAOA,IAAAA;AACT;AACA;;;AAGC,MACD,kBAA2BD,CAAAA,MAAsB,EAAEC,IAAsB,EAAEqM,IAAY,EAAa;AAClG,QAAA,IAAI3J,SAAY1C,GAAAA,IAAAA,CAAKuI,UAAU,CAAC8D,IAAK,CAAA;AACrC,QAAA,IAAI,CAAC3J,SAAW,EAAA;YACdA,SAAY3C,GAAAA,MAAAA,CAAO8H,eAAe,CAAC7H,IAAAA,CAAKqD,OAAO,CAACyE,gBAAgB,CAAC,CAAE,CAAA,CAAA;YACnE9H,IAAKuI,CAAAA,UAAU,CAAC8D,IAAAA,CAAK,GAAG3J,SAAAA;AAC1B;QACA,OAAOA,SAAAA;AACT;AACA;;;;MAKQnB,cAAeP,CAAAA,MAAwB,EAAW;QACxD,OAAOA,MAAAA,CAAO2L,IAAI,CAAC,CAAC9X,IAAMA,CAAE6L,CAAAA,QAAQ,CAACoE,kBAAkB,CAAA;AACzD;AACA,qBACQ2D,eAAgB1I,CAAAA,MAAsB,EAAc;AAC1D,QAAA,IAAI,CAAC,IAAI,CAAC1D,YAAY,EAAE;AACtB,YAAA,IAAI,CAACA,YAAY,GAAG0D,MAAAA,CAAO4H,kBAAkB,CAACzN,uBAAAA,EAAAA,CAAAA;AAC9C,YAAA,IAAI,CAACmC,YAAY,CAACuL,IAAI,GAAG,oBAAA;AACzB,YAAA,IAAI,CAACtL,cAAc,GAAGyD,MAAAA,CAAO8H,eAAe,CAAC,IAAI,CAACxL,YAAY,CAACyL,gBAAgB,CAAC,CAAE,CAAA,CAAA;AACpF;QACA,OAAO,IAAI,CAACzL,YAAY;AAC1B;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"water_caustics.js","sources":["../../src/render/water_caustics.ts"],"sourcesContent":["import type { Nullable } from '@zephyr3d/base';\r\nimport { Matrix4x4, REVERSE_Z, Vector3, Vector4 } from '@zephyr3d/base';\r\nimport type {\r\n AbstractDevice,\r\n BindGroup,\r\n FrameBuffer,\r\n GPUDataBuffer,\r\n GPUProgram,\r\n PBGlobalScope,\r\n PBRenderOptions,\r\n ProgramBuilder,\r\n RenderStateSet,\r\n Texture2D,\r\n Texture2DArray,\r\n TextureFormat,\r\n VertexLayout\r\n} from '@zephyr3d/device';\r\nimport type { DrawContext } from './drawable';\r\nimport type { WaveGenerator } from './wavegenerator';\r\nimport type { Water } from '../scene/water';\r\nimport type { PunctualLight } from '../scene/light';\r\nimport type { Camera } from '../camera/camera';\r\nimport { drawFullscreenQuad } from './fullscreenquad';\r\nimport { fetchSampler } from '../utility/misc';\r\nimport { CAUSTIC_HEIGHT_BIAS, MAX_CAUSTIC_WATERS, ShaderHelper } from '../material/shader/helper';\r\nimport { warnUnsupported } from '../utility/unsupported';\r\n\r\n/** Index of refraction of water relative to air. */\r\nconst WATER_IOR = 1.333;\r\n/** Air-to-water eta used when refracting the sun ray at the surface. */\r\nconst WATER_ETA = 1 / WATER_IOR;\r\n/**\r\n * Minimum |sin(sun elevation)| for caustics to be generated; below it the\r\n * photon sweep degenerates and the pass switches off.\r\n */\r\nconst MIN_SUN_ELEVATION = 0.15;\r\n/**\r\n * Fixed-point steps taken to land a photon on the scene rather than on the\r\n * focal plane. Two suffice for a flat receiver; the third covers a steep slope.\r\n */\r\nconst SCENE_DEPTH_ITERATIONS = 3;\r\n/**\r\n * Photons per covered map texel the automatic grid size solves for. Four lands\r\n * within about 4% of a converged (16x denser) map.\r\n */\r\nconst PHOTONS_PER_TEXEL = 4;\r\n/** Automatic edge fade width, as a fraction of the map half-extent. */\r\nconst AUTO_FADE_FRACTION = 0.2;\r\n/** Floor in meters under the automatic fade width. */\r\nconst AUTO_FADE_MIN_DISTANCE = 3;\r\n/** Bounds on the share of the map half-extent the fade may consume. */\r\nconst MIN_FADE_FRACTION = 0.001;\r\nconst MAX_FADE_FRACTION = 0.9;\r\n/**\r\n * Largest ratio between the fitted slice's two half-extents. The map is square,\r\n * so an anisotropic slice resolves the pattern at different frequencies along\r\n * each axis.\r\n */\r\nconst MAX_SLICE_ASPECT = 2;\r\n/**\r\n * Steps per octave the fitted half-extents are quantised to. Four costs at most\r\n * 19% of linear resolution and keeps a level change from reading as a pop.\r\n */\r\nconst SLICE_QUANTISE_STEPS = 4;\r\n/** Smallest half-extent in meters a fitted slice may shrink to. */\r\nconst MIN_SLICE_EXTENT = 0.5;\r\n/**\r\n * Divisions of the half-extent the slice centre snaps to under a warp. A warped\r\n * map must be resampled whenever the centre moves, so it snaps coarsely.\r\n */\r\nconst WARPED_CENTER_SNAP_DIVISIONS = 8;\r\n/**\r\n * How far past the map border the photon grid is laid out, as a fraction of the\r\n * half-extent, on the sides where the range - not the water - is what bounds it.\r\n *\r\n * Horizontal displacement carries photons across the border both ways, so\r\n * launching from a margin outside keeps the border density consistent.\r\n * `_gridFraction` accounts for the larger launch area, so density per texel is\r\n * unchanged.\r\n */\r\nconst GRID_BORDER_MARGIN = 0.15;\r\n\r\n/**\r\n * Concentrates a map coordinate towards the centre. CPU twin of\r\n * `ShaderHelper.warpCausticNDC`.\r\n *\r\n * @internal\r\n */\r\nfunction warpCausticNDC(ndc: number, strength: number): number {\r\n return (ndc * (1 + strength)) / (1 + strength * Math.abs(ndc));\r\n}\r\n\r\n/**\r\n * Rounds a fitted half-extent up onto a discrete ladder below `range`.\r\n *\r\n * The ladder is geometric and anchored at `range`, so water that fills the range\r\n * lands exactly on a level.\r\n *\r\n * @internal\r\n */\r\nfunction quantiseSliceExtent(half: number, range: number): number {\r\n if (!(half > 0) || half >= range) {\r\n return range;\r\n }\r\n const steps = Math.floor(Math.log2(range / half) * SLICE_QUANTISE_STEPS);\r\n return range / Math.pow(2, steps / SLICE_QUANTISE_STEPS);\r\n}\r\n\r\n/**\r\n * CPU-side parameters describing the caustic map, uploaded to the light pass.\r\n *\r\n * The map is a single orthographic slice of light space, fitted to the water\r\n * within range of the camera. `frameX`/`frameY` are the two axes perpendicular\r\n * to the light direction, carrying the reciprocal of the slice's half-extent\r\n * along each, so a world position projects into the map with two dot products\r\n * and no matrix.\r\n *\r\n * @public\r\n */\r\nexport interface WaterCausticUniforms {\r\n /** (right.xyz, 1 / half-extent along right) */\r\n frameX: Vector4;\r\n /** (up.xyz, 1 / half-extent along up) */\r\n frameY: Vector4;\r\n /** (center.xyz, water surface level) */\r\n center: Vector4;\r\n /** (lightDir.xyz, 1 / max(-lightDir.y, MIN_SUN_ELEVATION)) */\r\n lightDir: Vector4;\r\n /** (intensity, focal depth, defocus rate, edge fade start in map-radius units) */\r\n params: Vector4;\r\n /** (minimum water depth, unused.yz, warp strength). The medium is in {@link waterMedia}. */\r\n extinction: Vector4;\r\n /** Water bodies contributing to this map, at most {@link MAX_CAUSTIC_WATERS}. */\r\n waterCount: number;\r\n /** Per body, world XZ footprint: (minX, minZ, maxX, maxZ). */\r\n waterRegions: Float32Array<ArrayBuffer>;\r\n /** Per body, (sigma_t.xyz, surface height). */\r\n waterMedia: Float32Array<ArrayBuffer>;\r\n}\r\n\r\n/** Shadow cascade reused as a light-space depth map of the scene. @internal */\r\ntype SceneDepthBinding = {\r\n texture: Texture2DArray;\r\n layer: number;\r\n size: number;\r\n matrix: Matrix4x4;\r\n matrixInv: Matrix4x4;\r\n};\r\n\r\n/**\r\n * Vertices per side of the grid the height map rasterises the surface with, laid\r\n * out in warped map space over the body's footprint.\r\n */\r\nconst HEIGHT_GRID_SIZE = 256;\r\n\r\n/** @internal */\r\ntype SplatProgramInfo = {\r\n program: GPUProgram;\r\n /** One per water slot; see _getSplatBindGroup. */\r\n bindGroups: BindGroup[];\r\n};\r\n\r\n/**\r\n * Shader for the photon splat pass.\r\n *\r\n * One vertex is one photon, emitted where it lands; the fragment stage deposits\r\n * the weight, which additive blending accumulates.\r\n *\r\n * Returned as a descriptor so it can be compiled against a bare\r\n * {@link ProgramBuilder} in tests, without a device.\r\n *\r\n * @param waveGenerator - Supplies the surface displacement and normal.\r\n * @internal\r\n */\r\nexport function createCausticSplatShader(waveGenerator: WaveGenerator, sceneDepth: boolean): PBRenderOptions {\r\n const setupUniforms = (scope: PBGlobalScope) => {\r\n const pb = scope.$builder;\r\n scope.causticFrameX = pb.vec4().uniform(0);\r\n scope.causticFrameY = pb.vec4().uniform(0);\r\n scope.causticCenter = pb.vec4().uniform(0);\r\n scope.causticLightDir = pb.vec4().uniform(0);\r\n scope.causticRegion = pb.vec4().uniform(0);\r\n /** Map-NDC rectangle the photon grid is laid out over: (minX, minY, maxX, maxY). */\r\n scope.causticGridBounds = pb.vec4().uniform(0);\r\n scope.causticSplatParams = pb.vec4().uniform(0);\r\n /** (grid size, 1 / grid size, 0, 0) */\r\n scope.causticPhotonParams = pb.vec4().uniform(0);\r\n if (sceneDepth) {\r\n // The sun's shadow cascade, reused as an orthographic light-space depth map.\r\n scope.causticSceneMatrix = pb.mat4().uniform(0);\r\n scope.causticSceneMatrixInv = pb.mat4().uniform(0);\r\n /** (cascade layer, 0, 0, 0) */\r\n scope.causticSceneParams = pb.vec4().uniform(0);\r\n // Read for its stored depth, not compared.\r\n scope.causticSceneDepth = pb.tex2DArrayShadow().uniform(0);\r\n }\r\n // Wave generators animate from camera.elapsedTime, which this standalone\r\n // pass supplies itself.\r\n ShaderHelper.declareStandaloneCameraTime(scope, 0);\r\n waveGenerator.setupUniforms(scope, 0);\r\n };\r\n return {\r\n vertex(this: PBGlobalScope, pb: ProgramBuilder) {\r\n // Photon ordinal; the grid coordinate is derived from it, so the buffer\r\n // serves any grid size.\r\n this.$inputs.photonIndex = pb.float().attrib('position');\r\n this.$outputs.photonWeight = pb.float();\r\n setupUniforms(this);\r\n pb.main(function () {\r\n // Per-axis: the slice's two half-extents are independent.\r\n this.$l.invRadius = pb.vec2(this.causticFrameX.w, this.causticFrameY.w);\r\n this.$l.radius = pb.div(pb.vec2(1), this.invRadius);\r\n this.$l.focalDepth = this.causticSplatParams.y;\r\n this.$l.eta = this.causticSplatParams.z;\r\n this.$l.L = this.causticLightDir.xyz;\r\n this.$l.waterLevel = this.causticCenter.w;\r\n // Grid position on the orthographic slice through the map centre. The\r\n // grid spans only the part of the slice the water casts through, and is\r\n // uniform in warped map space so calm water keeps photon (i,j) on texel\r\n // (i,j) and the map normalised to 1.0.\r\n //\r\n // Ordinal to grid coordinate: row is the quotient, column the remainder.\r\n this.$l.gridSize = this.causticPhotonParams.x;\r\n this.$l.invGrid = this.causticPhotonParams.y;\r\n this.$l.photonRow = pb.floor(pb.mul(this.$inputs.photonIndex, this.invGrid));\r\n this.$l.photonCol = pb.sub(this.$inputs.photonIndex, pb.mul(this.photonRow, this.gridSize));\r\n this.$l.photonUV = pb.mul(\r\n pb.add(pb.vec2(this.photonCol, this.photonRow), pb.vec2(0.5)),\r\n this.invGrid\r\n );\r\n this.$l.warpedNDC = pb.mix(this.causticGridBounds.xy, this.causticGridBounds.zw, this.photonUV);\r\n this.$l.ndc = ShaderHelper.unwarpCausticNDC(this, this.warpedNDC, this.causticSplatParams.x);\r\n this.$l.planePos = pb.add(\r\n this.causticCenter.xyz,\r\n pb.mul(this.causticFrameX.xyz, pb.mul(this.ndc.x, this.radius.x)),\r\n pb.mul(this.causticFrameY.xyz, pb.mul(this.ndc.y, this.radius.y))\r\n );\r\n // Sweep along the light direction onto the undisturbed water plane.\r\n this.$l.sweep = pb.div(pb.sub(this.waterLevel, this.planePos.y), this.L.y);\r\n this.$l.surfaceXZ = pb.add(this.planePos, pb.mul(this.L, this.sweep));\r\n this.$l.outside = pb.or(\r\n pb.any(pb.lessThan(this.surfaceXZ.xz, this.causticRegion.xy)),\r\n pb.any(pb.greaterThan(this.surfaceXZ.xz, this.causticRegion.zw))\r\n );\r\n // Displaced surface point and the detail normal that bends the ray. The\r\n // wave generators sample with an explicit LOD, legal in a vertex shader.\r\n //\r\n // Launching from the rest point over-weights compressed crests by 1/J;\r\n // inverting the displacement does not converge where the surface folds.\r\n this.$l.surfacePos = pb.vec3();\r\n this.$l.coarseNormal = pb.vec3();\r\n waveGenerator.calcVertexPositionAndNormal(this, this.surfaceXZ, this.surfacePos, this.coarseNormal);\r\n this.$l.normal = waveGenerator.calcFragmentNormal(this, this.surfaceXZ.xz, this.coarseNormal);\r\n // Refract, then subtract the deflection a flat surface would have\r\n // produced. Calm water then leaves the ray parallel to L, which lands\r\n // photon (i,j) back on texel (i,j) and normalises the map to 1.\r\n this.$l.refracted = pb.refract(this.L, this.normal, this.eta);\r\n this.$l.refractedFlat = pb.refract(this.L, pb.vec3(0, 1, 0), this.eta);\r\n this.$l.dir = pb.normalize(pb.add(pb.sub(this.refracted, this.refractedFlat), this.L));\r\n // Intersect the horizontal focal plane below the surface; clamped so a\r\n // grazing ray cannot produce an enormous or negative step.\r\n this.$l.invDirY = pb.min(this.dir.y, -1e-4);\r\n this.$l.targetY = pb.sub(this.waterLevel, this.focalDepth);\r\n this.$l.hitT = pb.div(pb.sub(this.targetY, this.surfacePos.y), this.invDirY);\r\n this.$l.hitPos = pb.add(this.surfacePos, pb.mul(this.dir, pb.max(this.hitT, 0)));\r\n if (sceneDepth) {\r\n // Land the photon on the scene by fixed-point iteration: read the scene\r\n // height under the current guess, re-intersect the ray with a\r\n // horizontal plane at that height, repeat. One fetch per step; at a\r\n // silhouette it lands on one of the two surfaces rather than diverging.\r\n this.$l.probe = this.hitPos;\r\n this.$l.layer = pb.int(this.causticSceneParams.x);\r\n for (let i = 0; i < SCENE_DEPTH_ITERATIONS; i++) {\r\n this.$l[`clip${i}`] = pb.mul(this.causticSceneMatrix, pb.vec4(this.probe, 1));\r\n this.$l[`ndc${i}`] = pb.div(this[`clip${i}`].xyz, this[`clip${i}`].w);\r\n this.$l[`uv${i}`] = pb.add(pb.mul(this[`ndc${i}`].xy, 0.5), pb.vec2(0.5));\r\n // Outside the cascade, keep the previous step's result.\r\n this.$l[`inside${i}`] = pb.and(\r\n pb.all(pb.greaterThanEqual(this[`uv${i}`], pb.vec2(0))),\r\n pb.all(pb.lessThanEqual(this[`uv${i}`], pb.vec2(1)))\r\n );\r\n // texelFetch, since filtered depths across a silhouette are wrong.\r\n // WebGPU only - GLSL ES 3.0 forbids texelFetch on a shadow-sampler\r\n // texture, which gates this whole path.\r\n this.$l[`depth${i}`] = pb.textureArrayLoad(\r\n this.causticSceneDepth,\r\n pb.ivec2(pb.mul(this[`uv${i}`], this.causticSceneParams.y)),\r\n this.layer,\r\n pb.int(0)\r\n );\r\n // Back to a world position through the orthographic cascade.\r\n this.$l[`sceneNDC${i}`] = pb.vec3(\r\n this[`ndc${i}`].xy,\r\n REVERSE_Z ? this[`depth${i}`] : pb.sub(pb.mul(this[`depth${i}`], 2), 1)\r\n );\r\n this.$l[`sceneClip${i}`] = pb.mul(this.causticSceneMatrixInv, pb.vec4(this[`sceneNDC${i}`], 1));\r\n this.$l[`scenePos${i}`] = pb.div(this[`sceneClip${i}`].xyz, this[`sceneClip${i}`].w);\r\n // Re-intersect at the height just read, accepted only below the\r\n // *displaced* surface at this photon's entry (not the rest level).\r\n this.$l[`t${i}`] = pb.div(pb.sub(this[`scenePos${i}`].y, this.surfacePos.y), this.invDirY);\r\n this.$l[`next${i}`] = pb.add(this.surfacePos, pb.mul(this.dir, pb.max(this[`t${i}`], 0)));\r\n // mix rather than select: the builder has no vec3 select.\r\n this.probe = pb.mix(\r\n this.probe,\r\n this[`next${i}`],\r\n pb.float(pb.and(this[`inside${i}`], pb.lessThan(this[`scenePos${i}`].y, this.surfacePos.y)))\r\n );\r\n }\r\n this.hitPos = this.probe;\r\n }\r\n // Project the hit back into the map. frameX/frameY are perpendicular to\r\n // L and to each other, so this is just two dot products.\r\n this.$l.rel = pb.sub(this.hitPos, this.causticCenter.xyz);\r\n this.$l.hitNDC = pb.mul(\r\n pb.vec2(pb.dot(this.rel, this.causticFrameX.xyz), pb.dot(this.rel, this.causticFrameY.xyz)),\r\n this.invRadius\r\n );\r\n // Into warped space, where the map's texels live.\r\n this.$l.hitWarped = ShaderHelper.warpCausticNDC(this, this.hitNDC, this.causticSplatParams.x);\r\n this.$outputs.photonWeight = this.causticSplatParams.w;\r\n // No per-backend y flip here; the blur and resolve quads account for it.\r\n this.$builtins.position = pb.vec4(this.hitWarped, 0, 1);\r\n if (pb.getDevice().type !== 'webgpu') {\r\n // GLSL rasterises nothing unless gl_PointSize is written; WebGPU points\r\n // are always one pixel.\r\n this.$builtins.pointSize = 1;\r\n }\r\n this.$if(this.outside, function () {\r\n // Park the photon outside the clip volume; w stays 1 to avoid NaN.\r\n this.$builtins.position = pb.vec4(-2, -2, 0, 1);\r\n });\r\n });\r\n },\r\n fragment(this: PBGlobalScope, pb: ProgramBuilder) {\r\n this.$outputs.outColor = pb.vec4();\r\n pb.main(function () {\r\n this.$outputs.outColor = pb.vec4(this.$inputs.photonWeight, 0, 0, 1);\r\n });\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Shader for the displaced surface height map.\r\n *\r\n * Rasterises the water surface into the light-space slice, one body per draw. A\r\n * grid over the body's footprint in warped map space is swept along the light\r\n * onto the rest plane, displaced by the wave generator, and projected back into\r\n * the map. The fragment writes its height above the rest plane, offset by\r\n * `CAUSTIC_HEIGHT_BIAS`, into this body's channel via a colour write mask (last\r\n * triangle wins). A texel the surface never reaches stays zero, which the\r\n * receiver reads as \"no water on this ray\".\r\n *\r\n * Rasterising handles horizontal displacement without inverting it, and keeps\r\n * the footprint edge exact. The receiver looks this up with the same uv as the\r\n * caustic pattern, since the projection is invariant along the light.\r\n *\r\n * @param waveGenerator - Supplies the surface displacement of this body.\r\n * @internal\r\n */\r\nexport function createCausticHeightShader(waveGenerator: WaveGenerator): PBRenderOptions {\r\n return {\r\n vertex(this: PBGlobalScope, pb: ProgramBuilder) {\r\n // Vertex ordinal; the grid coordinate is derived from it.\r\n this.$inputs.vertexIndex = pb.float().attrib('position');\r\n this.$outputs.height = pb.float();\r\n this.$outputs.inside = pb.float();\r\n this.causticFrameX = pb.vec4().uniform(0);\r\n this.causticFrameY = pb.vec4().uniform(0);\r\n /** (slice centre.xyz, this body's rest level) */\r\n this.causticCenter = pb.vec4().uniform(0);\r\n this.causticLightDir = pb.vec4().uniform(0);\r\n this.causticRegion = pb.vec4().uniform(0);\r\n /** Map-NDC rectangle the grid is laid out over: (minX, minY, maxX, maxY). */\r\n this.causticGridBounds = pb.vec4().uniform(0);\r\n /** (warp strength, grid size, 1 / (grid size + 1), 1 / grid size) */\r\n this.causticHeightParams = pb.vec4().uniform(0);\r\n ShaderHelper.declareStandaloneCameraTime(this, 0);\r\n waveGenerator.setupUniforms(this, 0);\r\n pb.main(function () {\r\n this.$l.invRadius = pb.vec2(this.causticFrameX.w, this.causticFrameY.w);\r\n this.$l.radius = pb.div(pb.vec2(1), this.invRadius);\r\n this.$l.L = this.causticLightDir.xyz;\r\n this.$l.waterLevel = this.causticCenter.w;\r\n // Ordinal to grid coordinate, (gridSize + 1) vertices per side. The +0.5\r\n // keeps the inexact reciprocal from rounding into the previous row.\r\n this.$l.row = pb.floor(pb.mul(pb.add(this.$inputs.vertexIndex, 0.5), this.causticHeightParams.z));\r\n this.$l.col = pb.sub(\r\n this.$inputs.vertexIndex,\r\n pb.mul(this.row, pb.add(this.causticHeightParams.y, 1))\r\n );\r\n this.$l.gridUV = pb.mul(pb.vec2(this.col, this.row), this.causticHeightParams.w);\r\n // Grid point to the slice, through the warp the map's texels live under.\r\n this.$l.warpedNDC = pb.mix(this.causticGridBounds.xy, this.causticGridBounds.zw, this.gridUV);\r\n this.$l.ndc = ShaderHelper.unwarpCausticNDC(this, this.warpedNDC, this.causticHeightParams.x);\r\n this.$l.planePos = pb.add(\r\n this.causticCenter.xyz,\r\n pb.mul(this.causticFrameX.xyz, pb.mul(this.ndc.x, this.radius.x)),\r\n pb.mul(this.causticFrameY.xyz, pb.mul(this.ndc.y, this.radius.y))\r\n );\r\n // Along the light onto the rest plane: the rest point of this vertex.\r\n this.$l.sweep = pb.div(pb.sub(this.waterLevel, this.planePos.y), this.L.y);\r\n this.$l.surfaceXZ = pb.add(this.planePos, pb.mul(this.L, this.sweep));\r\n // Footprint test, interpolated so the edge fades over one grid cell.\r\n this.$outputs.inside = pb.float(\r\n pb.and(\r\n pb.all(pb.greaterThanEqual(this.surfaceXZ.xz, this.causticRegion.xy)),\r\n pb.all(pb.lessThanEqual(this.surfaceXZ.xz, this.causticRegion.zw))\r\n )\r\n );\r\n // Where the surface carried this rest point, and how high it is there.\r\n this.$l.surfacePos = pb.vec3();\r\n this.$l.surfaceNormal = pb.vec3();\r\n waveGenerator.calcVertexPositionAndNormal(this, this.surfaceXZ, this.surfacePos, this.surfaceNormal);\r\n this.$outputs.height = pb.sub(this.surfacePos.y, this.waterLevel);\r\n // The displaced point back into the map, as the splat projects a hit.\r\n this.$l.rel = pb.sub(this.surfacePos, this.causticCenter.xyz);\r\n this.$l.hitNDC = pb.mul(\r\n pb.vec2(pb.dot(this.rel, this.causticFrameX.xyz), pb.dot(this.rel, this.causticFrameY.xyz)),\r\n this.invRadius\r\n );\r\n this.$l.hitWarped = ShaderHelper.warpCausticNDC(this, this.hitNDC, this.causticHeightParams.x);\r\n // The receiver reads the map at `v = 0.5 + 0.5 * ndc.y`. On WebGPU clip\r\n // +1 is the first row, so the surface is drawn flipped. The splat needs\r\n // no flip because its map passes through the blur and resolve quads.\r\n this.$builtins.position =\r\n pb.getDevice().type === 'webgpu'\r\n ? pb.vec4(this.hitWarped.x, pb.neg(this.hitWarped.y), 0, 1)\r\n : pb.vec4(this.hitWarped, 0, 1);\r\n });\r\n },\r\n fragment(this: PBGlobalScope, pb: ProgramBuilder) {\r\n this.$outputs.outColor = pb.vec4();\r\n pb.main(function () {\r\n // Outside the footprint nothing is written, so the texel reads \"no surface\".\r\n this.$if(pb.lessThan(this.$inputs.inside, 0.5), function () {\r\n pb.discard();\r\n });\r\n // Every channel; the colour mask keeps all but this body's.\r\n this.$outputs.outColor = pb.vec4(pb.add(this.$inputs.height, CAUSTIC_HEIGHT_BIAS));\r\n });\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Shader for the caustic map blur.\r\n *\r\n * Four bilinear taps at the texel corners average a 2x2 neighbourhood; weights\r\n * sum to one, preserving the \"calm water reads 1.0\" normalisation.\r\n *\r\n * @internal\r\n */\r\nexport function createCausticBlurShader(): PBRenderOptions {\r\n return {\r\n vertex(this: PBGlobalScope, pb: ProgramBuilder) {\r\n this.$inputs.pos = pb.vec2().attrib('position');\r\n this.$outputs.uv = pb.vec2();\r\n pb.main(function () {\r\n this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);\r\n this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos, 0.5), pb.vec2(0.5));\r\n });\r\n },\r\n fragment(this: PBGlobalScope, pb: ProgramBuilder) {\r\n this.causticSrc = pb.tex2D().uniform(0);\r\n this.causticTexelSize = pb.vec4().uniform(0);\r\n this.$outputs.outColor = pb.vec4();\r\n pb.main(function () {\r\n this.$l.o = pb.mul(this.causticTexelSize.xy, 0.5);\r\n this.$l.sum = pb.add(\r\n pb.textureSampleLevel(this.causticSrc, pb.add(this.$inputs.uv, pb.vec2(this.o.x, this.o.y)), 0),\r\n pb.textureSampleLevel(\r\n this.causticSrc,\r\n pb.add(this.$inputs.uv, pb.vec2(pb.neg(this.o.x), this.o.y)),\r\n 0\r\n ),\r\n pb.textureSampleLevel(\r\n this.causticSrc,\r\n pb.add(this.$inputs.uv, pb.vec2(this.o.x, pb.neg(this.o.y))),\r\n 0\r\n ),\r\n pb.textureSampleLevel(\r\n this.causticSrc,\r\n pb.add(this.$inputs.uv, pb.vec2(pb.neg(this.o.x), pb.neg(this.o.y))),\r\n 0\r\n )\r\n );\r\n this.$outputs.outColor = pb.vec4(pb.mul(this.sum.x, 0.25), 0, 0, 1);\r\n });\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Shader for the temporal resolve.\r\n *\r\n * Reprojection is exact and matrix-free: both frames are orthographic slices\r\n * perpendicular to the light, so a texel maps to the world with two scaled axes\r\n * and into the previous frame with two dot products.\r\n *\r\n * Map NDC relates to texture coordinate by the receiver's `ndc * 0.5 + 0.5`\r\n * (see `ShaderHelper.calculateWaterCaustic`).\r\n *\r\n * @internal\r\n */\r\nexport function createCausticResolveShader(): PBRenderOptions {\r\n return {\r\n vertex(this: PBGlobalScope, pb: ProgramBuilder) {\r\n this.$inputs.pos = pb.vec2().attrib('position');\r\n this.$outputs.uv = pb.vec2();\r\n pb.main(function () {\r\n this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);\r\n this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos, 0.5), pb.vec2(0.5));\r\n });\r\n },\r\n fragment(this: PBGlobalScope, pb: ProgramBuilder) {\r\n this.causticCurrent = pb.tex2D().uniform(0);\r\n this.causticHistory = pb.tex2D().uniform(0);\r\n this.causticFrameX = pb.vec4().uniform(0);\r\n this.causticFrameY = pb.vec4().uniform(0);\r\n this.causticCenter = pb.vec4().uniform(0);\r\n this.causticPrevFrameX = pb.vec4().uniform(0);\r\n this.causticPrevFrameY = pb.vec4().uniform(0);\r\n this.causticPrevCenter = pb.vec4().uniform(0);\r\n /** (blend weight, texel size, warp, previous frame's warp) */\r\n this.causticResolveParams = pb.vec4().uniform(0);\r\n this.$outputs.outColor = pb.vec4();\r\n pb.main(function () {\r\n this.$l.texel = this.causticResolveParams.y;\r\n this.$l.current = pb.textureSampleLevel(this.causticCurrent, this.$inputs.uv, 0).x;\r\n // Neighbourhood range of the current frame; history is clamped into it\r\n // so a long blend can follow an animated pattern.\r\n this.$l.mn = this.current;\r\n this.$l.mx = this.current;\r\n for (let dy = -1; dy <= 1; dy++) {\r\n for (let dx = -1; dx <= 1; dx++) {\r\n if (dx === 0 && dy === 0) {\r\n continue;\r\n }\r\n this.$l.s = pb.textureSampleLevel(\r\n this.causticCurrent,\r\n pb.add(this.$inputs.uv, pb.mul(pb.vec2(dx, dy), this.texel)),\r\n 0\r\n ).x;\r\n this.mn = pb.min(this.mn, this.s);\r\n this.mx = pb.max(this.mx, this.s);\r\n }\r\n }\r\n // This texel's world point, then its place in the previous frame; the\r\n // frames may differ in slice and warp strength.\r\n this.$l.warpedNDC = pb.sub(pb.mul(this.$inputs.uv, 2), pb.vec2(1));\r\n this.$l.ndc = ShaderHelper.unwarpCausticNDC(this, this.warpedNDC, this.causticResolveParams.z);\r\n this.$l.radius = pb.div(pb.vec2(1), pb.vec2(this.causticFrameX.w, this.causticFrameY.w));\r\n this.$l.world = pb.add(\r\n this.causticCenter.xyz,\r\n pb.mul(this.causticFrameX.xyz, pb.mul(this.ndc.x, this.radius.x)),\r\n pb.mul(this.causticFrameY.xyz, pb.mul(this.ndc.y, this.radius.y))\r\n );\r\n this.$l.rel = pb.sub(this.world, this.causticPrevCenter.xyz);\r\n this.$l.prevNDC = pb.mul(\r\n pb.vec2(pb.dot(this.rel, this.causticPrevFrameX.xyz), pb.dot(this.rel, this.causticPrevFrameY.xyz)),\r\n pb.vec2(this.causticPrevFrameX.w, this.causticPrevFrameY.w)\r\n );\r\n this.$l.prevWarped = ShaderHelper.warpCausticNDC(this, this.prevNDC, this.causticResolveParams.w);\r\n this.$l.prevUV = pb.add(pb.mul(this.prevWarped, 0.5), pb.vec2(0.5));\r\n // Ground the camera has just scrolled into has no history at all.\r\n this.$l.inside = pb.and(\r\n pb.all(pb.greaterThanEqual(this.prevUV, pb.vec2(0))),\r\n pb.all(pb.lessThanEqual(this.prevUV, pb.vec2(1)))\r\n );\r\n this.$l.history = pb.textureSampleLevel(this.causticHistory, this.prevUV, 0).x;\r\n this.$l.blend = pb.mul(this.causticResolveParams.x, pb.float(this.inside));\r\n this.$outputs.outColor = pb.vec4(\r\n pb.mix(this.current, pb.clamp(this.history, this.mn, this.mx), this.blend),\r\n 0,\r\n 0,\r\n 1\r\n );\r\n });\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Renders the water caustic map.\r\n *\r\n * One photon is emitted per texel of a uniform grid laid out on the same\r\n * orthographic light-space slice the map covers. Each photon is refracted at the\r\n * water surface, intersected with the scene (or a horizontal focal plane) below\r\n * it, and splatted additively at the hit position. With the flat-surface\r\n * deflection removed, calm water maps photon `(i,j)` onto texel `(i,j)` and the\r\n * map converges to a uniform 1.0 - which the receiver treats as \"no caustics\".\r\n *\r\n * @internal\r\n */\r\nexport class WaterCausticsRenderer {\r\n /** Splat programs keyed by the wave generator's shader hash. */\r\n private readonly _splatPrograms: Map<string, SplatProgramInfo>;\r\n /** Height-map programs keyed by the wave generator's shader hash. */\r\n private readonly _heightPrograms: Map<string, SplatProgramInfo>;\r\n /** One per water slot, differing only in which channel they let through. */\r\n private readonly _heightStates: Nullable<RenderStateSet>[];\r\n private readonly _heightParams: Vector4;\r\n /** The surface grid the height map is rasterised with; built once. */\r\n private _heightLayout: Nullable<VertexLayout>;\r\n private _heightIndexCount: number;\r\n private _blurProgram: Nullable<GPUProgram>;\r\n private _blurBindGroup: Nullable<BindGroup>;\r\n private _resolveProgram: Nullable<GPUProgram>;\r\n private _resolveBindGroup: Nullable<BindGroup>;\r\n private _resolveStates: Nullable<RenderStateSet>;\r\n /** Slice parameters of the last map committed as history, per camera. */\r\n private readonly _prevSlices: WeakMap<\r\n Camera,\r\n { frameX: Vector4; frameY: Vector4; center: Vector4; warp: number }\r\n >;\r\n private readonly _resolveParams: Vector4;\r\n private _photonLayout: Nullable<VertexLayout>;\r\n /** Photons the buffer can serve; it grows and is never rebuilt smaller. */\r\n private _photonCapacity: number;\r\n private _photonBuffer: Nullable<GPUDataBuffer>;\r\n private readonly _photonParams: Vector4;\r\n private _photonCount: number;\r\n private _splatStates: Nullable<RenderStateSet>;\r\n private _blurStates: Nullable<RenderStateSet>;\r\n private readonly _uniforms: WaterCausticUniforms;\r\n private readonly _tmpRight: Vector3;\r\n private readonly _tmpUp: Vector3;\r\n private readonly _tmpDir: Vector3;\r\n private readonly _tmpCenter: Vector3;\r\n private readonly _splatParams: Vector4;\r\n private readonly _blurTexelSize: Vector4;\r\n /** Map-NDC rectangle the photon grid covers, and the map fraction it is. */\r\n private readonly _gridBounds: Vector4;\r\n private _gridFraction: number;\r\n /** Furthest the fitted slice reaches from the camera, for cascade selection. */\r\n private _sliceReach: number;\r\n /** Slice frame and extents, kept for the per-body grid fit. */\r\n private _sliceRight: Vector3;\r\n private _sliceUp: Vector3;\r\n private _sliceCenterR: number;\r\n private _sliceCenterU: number;\r\n private _sliceHalfR: number;\r\n private _sliceHalfU: number;\r\n private readonly _splatCenter: Vector4;\r\n private readonly _sceneMatrixT: Matrix4x4;\r\n private readonly _sceneMatrix: Matrix4x4;\r\n private readonly _sceneMatrixInv: Matrix4x4;\r\n private readonly _sceneDepthParams: Vector4;\r\n /** Warp strength the current slice was built with; 0 when the map is linear. */\r\n private _warp: number;\r\n constructor() {\r\n this._splatPrograms = new Map();\r\n this._heightPrograms = new Map();\r\n this._heightStates = [];\r\n this._heightParams = new Vector4();\r\n this._heightLayout = null;\r\n this._heightIndexCount = 0;\r\n this._blurProgram = null;\r\n this._blurBindGroup = null;\r\n this._resolveProgram = null;\r\n this._resolveBindGroup = null;\r\n this._resolveStates = null;\r\n this._prevSlices = new WeakMap();\r\n this._resolveParams = new Vector4();\r\n this._photonLayout = null;\r\n this._photonCapacity = 0;\r\n this._photonBuffer = null;\r\n this._photonParams = new Vector4();\r\n this._photonCount = 0;\r\n this._splatStates = null;\r\n this._blurStates = null;\r\n this._uniforms = {\r\n frameX: new Vector4(),\r\n frameY: new Vector4(),\r\n center: new Vector4(),\r\n lightDir: new Vector4(),\r\n params: new Vector4(),\r\n extinction: new Vector4(),\r\n waterCount: 0,\r\n waterRegions: new Float32Array(MAX_CAUSTIC_WATERS * 4),\r\n waterMedia: new Float32Array(MAX_CAUSTIC_WATERS * 4)\r\n };\r\n this._tmpRight = new Vector3();\r\n this._tmpUp = new Vector3();\r\n this._tmpDir = new Vector3();\r\n this._tmpCenter = new Vector3();\r\n this._splatParams = new Vector4();\r\n this._blurTexelSize = new Vector4();\r\n this._gridBounds = new Vector4(-1, -1, 1, 1);\r\n this._gridFraction = 1;\r\n this._sliceReach = 1;\r\n this._sliceRight = new Vector3();\r\n this._sliceUp = new Vector3();\r\n this._sliceCenterR = 0;\r\n this._sliceCenterU = 0;\r\n this._sliceHalfR = 1;\r\n this._sliceHalfU = 1;\r\n this._splatCenter = new Vector4();\r\n this._sceneMatrixT = new Matrix4x4();\r\n this._sceneMatrix = new Matrix4x4();\r\n this._sceneMatrixInv = new Matrix4x4();\r\n this._sceneDepthParams = new Vector4();\r\n this._warp = 0;\r\n }\r\n /** Parameters of the map produced by the last successful {@link render}. */\r\n get uniforms(): WaterCausticUniforms {\r\n return this._uniforms;\r\n }\r\n /**\r\n * Storage format for the caustic map. Single channel when the device can both\r\n * render to and filter it, which the additive accumulation and the bilinear\r\n * sampling need.\r\n */\r\n static getMapFormat(device: AbstractDevice): TextureFormat {\r\n const info = device.getDeviceCaps().textureCaps.getTextureFormatInfo('r16f');\r\n return info.renderable && info.filterable ? 'r16f' : 'rgba16f';\r\n }\r\n /**\r\n * Storage format for the displaced surface height map: one channel per water\r\n * slot.\r\n */\r\n static getHeightMapFormat(): TextureFormat {\r\n return 'rgba16f';\r\n }\r\n /**\r\n * Whether caustics can be produced for this water surface and light.\r\n *\r\n * @param water - Water surface the photons are refracted through.\r\n * @param light - Directional light the photons come from.\r\n * @returns True when {@link render} would produce a usable map.\r\n */\r\n static canRender(water: Water, light: PunctualLight): boolean {\r\n const material = water.material;\r\n if (!material?.causticsEnabled || !material.waveGenerator || !light.isDirectionLight()) {\r\n return false;\r\n }\r\n // Sun too close to the horizon: the swept photon grid degenerates.\r\n return -light.directionAndCutoff.y >= MIN_SUN_ELEVATION;\r\n }\r\n /**\r\n * Builds the caustic map for one water surface.\r\n *\r\n * @param ctx - Draw context; supplies the device and the camera the map is centred on.\r\n * @param water - Water surface to refract through.\r\n * @param light - Directional light acting as the photon source.\r\n * @param map - Accumulation target; also the result when nothing resolves after it.\r\n * @param scratch - Ping-pong target for the blur, and the temporal resolve's\r\n * output. Same size and format as `map`.\r\n * @param heights - Target for the displaced surface height map, in\r\n * {@link getHeightMapFormat} and the same size as `map`. Filled by this call\r\n * and read by the light pass alongside the map.\r\n * @param history - Previous frame's resolved map, or null when there is none\r\n * to reproject. Ignored unless the material asks for temporal accumulation.\r\n * @param createFramebuffer - Wraps a target texture into a framebuffer.\r\n * @returns The texture holding the finished map, which is `map` or `scratch`\r\n * depending on whether the temporal resolve ran.\r\n */\r\n render(\r\n ctx: DrawContext,\r\n waters: readonly Water[],\r\n light: PunctualLight,\r\n map: Texture2D,\r\n scratch: Texture2D,\r\n heights: Texture2D,\r\n history: Nullable<Texture2D>,\r\n createFramebuffer: (texture: Texture2D) => FrameBuffer\r\n ): Texture2D {\r\n const device = ctx.device;\r\n this._updateUniforms(ctx, waters, light, map.width);\r\n const sceneDepth = this._anySceneDepth(waters) ? this._resolveSceneDepth(ctx, light) : null;\r\n\r\n // The height map first; it depends on the slice alone.\r\n device.pushDeviceStates();\r\n device.setFramebuffer(createFramebuffer(heights));\r\n device.setViewport(null);\r\n device.setScissor(null);\r\n device.clearFrameBuffer(Vector4.zero(), null, null);\r\n this._ensureHeightGrid(device);\r\n for (let i = 0; i < waters.length; i++) {\r\n this._renderHeightsOne(device, ctx, waters[i], i);\r\n }\r\n device.popDeviceStates();\r\n\r\n device.pushDeviceStates();\r\n device.setFramebuffer(createFramebuffer(map));\r\n // Viewport and scissor survive a framebuffer change; reset them.\r\n device.setViewport(null);\r\n device.setScissor(null);\r\n device.clearFrameBuffer(Vector4.zero(), null, null);\r\n device.setRenderStates(this._getSplatStates(device));\r\n\r\n // One draw per water body, accumulating into the one shared-slice map.\r\n for (let i = 0; i < waters.length; i++) {\r\n this._splatOne(device, ctx, waters[i], i, map, sceneDepth);\r\n }\r\n device.popDeviceStates();\r\n return this._postProcess(device, waters[0].material, map, scratch, history, ctx, createFramebuffer);\r\n }\r\n /**\r\n * Writes one body's displaced surface height into its channel of the height\r\n * map.\r\n * @internal\r\n */\r\n private _renderHeightsOne(device: AbstractDevice, ctx: DrawContext, water: Water, index: number): void {\r\n const material = water.material;\r\n const waveGenerator = material.waveGenerator!;\r\n // The grid covers this body's footprint.\r\n this._updateGridBounds(water);\r\n if (!(this._gridFraction > 0)) {\r\n return;\r\n }\r\n const info = this._getHeightProgram(device, waveGenerator);\r\n // A bind group per slot; see _getSplatBindGroup.\r\n const bindGroup = this._getSplatBindGroup(device, info, index);\r\n bindGroup.setValue('causticFrameX', this._uniforms.frameX);\r\n bindGroup.setValue('causticFrameY', this._uniforms.frameY);\r\n this._splatCenter.setXYZW(\r\n this._uniforms.center.x,\r\n this._uniforms.center.y,\r\n this._uniforms.center.z,\r\n water.worldMatrix.m13\r\n );\r\n bindGroup.setValue('causticCenter', this._splatCenter);\r\n bindGroup.setValue('causticLightDir', this._uniforms.lightDir);\r\n bindGroup.setValue('causticRegion', material.region);\r\n bindGroup.setValue('causticGridBounds', this._gridBounds);\r\n this._heightParams.setXYZW(\r\n this._warp,\r\n HEIGHT_GRID_SIZE,\r\n 1 / (HEIGHT_GRID_SIZE + 1),\r\n 1 / HEIGHT_GRID_SIZE\r\n );\r\n bindGroup.setValue('causticHeightParams', this._heightParams);\r\n ShaderHelper.setStandaloneCameraTime(bindGroup, ctx);\r\n waveGenerator.applyWaterBindGroup(bindGroup);\r\n // Channel i for slot i, which is how the receiver picks it back out.\r\n device.setRenderStates(this._getHeightStates(device, index));\r\n device.setProgram(info.program);\r\n device.setBindGroup(0, bindGroup);\r\n device.setVertexLayout(this._heightLayout!);\r\n device.draw('triangle-list', 0, this._heightIndexCount);\r\n }\r\n /**\r\n * Builds the surface grid once: vertex ordinals, and the index list that\r\n * stitches a (HEIGHT_GRID_SIZE + 1)^2 lattice of them into triangles.\r\n * @internal\r\n */\r\n private _ensureHeightGrid(device: AbstractDevice): void {\r\n if (this._heightLayout) {\r\n return;\r\n }\r\n const side = HEIGHT_GRID_SIZE + 1;\r\n const ordinals = new Float32Array(side * side);\r\n for (let i = 0; i < ordinals.length; i++) {\r\n ordinals[i] = i;\r\n }\r\n const indices = new Uint32Array(HEIGHT_GRID_SIZE * HEIGHT_GRID_SIZE * 6);\r\n let n = 0;\r\n for (let row = 0; row < HEIGHT_GRID_SIZE; row++) {\r\n for (let col = 0; col < HEIGHT_GRID_SIZE; col++) {\r\n const a = row * side + col;\r\n const b = a + 1;\r\n const c = a + side;\r\n const d = c + 1;\r\n indices[n++] = a;\r\n indices[n++] = b;\r\n indices[n++] = d;\r\n indices[n++] = a;\r\n indices[n++] = d;\r\n indices[n++] = c;\r\n }\r\n }\r\n const vertexBuffer = device.createVertexBuffer('position_f32', ordinals)!;\r\n const indexBuffer = device.createIndexBuffer(indices);\r\n this._heightLayout = device.createVertexLayout({\r\n vertexBuffers: [{ buffer: vertexBuffer }],\r\n indexBuffer\r\n });\r\n this._heightIndexCount = indices.length;\r\n }\r\n /** @internal */\r\n private _splatOne(\r\n device: AbstractDevice,\r\n ctx: DrawContext,\r\n water: Water,\r\n index: number,\r\n map: Texture2D,\r\n sceneDepth: Nullable<SceneDepthBinding>\r\n ): void {\r\n const material = water.material;\r\n const waveGenerator = material.waveGenerator!;\r\n // Photons are laid out over this body's own footprint.\r\n this._updateGridBounds(water);\r\n if (!(this._gridFraction > 0)) {\r\n return;\r\n }\r\n const photonGrid = this._resolvePhotonGrid(material.causticsPhotonResolution, map.width);\r\n this._updatePhotonLayout(device, photonGrid);\r\n const useSceneDepth = !!sceneDepth && material.causticsSceneDepth;\r\n const splat = this._getSplatProgram(device, waveGenerator, useSceneDepth);\r\n // A bind group per slot; see _getSplatBindGroup.\r\n const bindGroup = this._getSplatBindGroup(device, splat, index);\r\n if (useSceneDepth) {\r\n bindGroup.setValue('causticSceneMatrix', sceneDepth!.matrix);\r\n bindGroup.setValue('causticSceneMatrixInv', sceneDepth!.matrixInv);\r\n this._sceneDepthParams.setXYZW(sceneDepth!.layer, sceneDepth!.size, 0, 0);\r\n bindGroup.setValue('causticSceneParams', this._sceneDepthParams);\r\n bindGroup.setTexture('causticSceneDepth', sceneDepth!.texture, fetchSampler('clamp_nearest_nomip'));\r\n }\r\n bindGroup.setValue('causticFrameX', this._uniforms.frameX);\r\n bindGroup.setValue('causticFrameY', this._uniforms.frameY);\r\n // The slice centre is shared, but the water level in w is this body's.\r\n this._splatCenter.setXYZW(\r\n this._uniforms.center.x,\r\n this._uniforms.center.y,\r\n this._uniforms.center.z,\r\n water.worldMatrix.m13\r\n );\r\n bindGroup.setValue('causticCenter', this._splatCenter);\r\n bindGroup.setValue('causticLightDir', this._uniforms.lightDir);\r\n bindGroup.setValue('causticRegion', material.region);\r\n bindGroup.setValue('causticGridBounds', this._gridBounds);\r\n // Scale the deposit by covered texels per photon so a flat surface\r\n // integrates to exactly 1.\r\n const photonWeight = (this._gridFraction * map.width * map.height) / (photonGrid * photonGrid);\r\n this._splatParams.setXYZW(this._warp, material.causticsDepth, WATER_ETA, photonWeight);\r\n bindGroup.setValue('causticSplatParams', this._splatParams);\r\n this._photonParams.setXYZW(photonGrid, 1 / photonGrid, 0, 0);\r\n bindGroup.setValue('causticPhotonParams', this._photonParams);\r\n ShaderHelper.setStandaloneCameraTime(bindGroup, ctx);\r\n waveGenerator.applyWaterBindGroup(bindGroup);\r\n device.setProgram(splat.program);\r\n device.setBindGroup(0, bindGroup);\r\n device.setVertexLayout(this._photonLayout);\r\n device.draw('point-list', 0, this._photonCount);\r\n }\r\n /**\r\n * Blur and temporal resolve, run once over the finished map. Settings come\r\n * from the largest body's material.\r\n * @internal\r\n */\r\n private _postProcess(\r\n device: AbstractDevice,\r\n material: Water['material'],\r\n map: Texture2D,\r\n scratch: Texture2D,\r\n history: Nullable<Texture2D>,\r\n ctx: DrawContext,\r\n createFramebuffer: (texture: Texture2D) => FrameBuffer\r\n ): Texture2D {\r\n // Ping-pong between the two targets. The count is rounded up to an even\r\n // number by the material so the last pass always lands back in `map`.\r\n const blurPasses = Math.max(0, Math.min(material.causticsBlurPasses, 4));\r\n for (let i = 0; i < blurPasses; i++) {\r\n const src = i % 2 === 0 ? map : scratch;\r\n const dst = i % 2 === 0 ? scratch : map;\r\n this._blur(device, src, createFramebuffer(dst));\r\n }\r\n\r\n // The blur lands back in `map`, so `scratch` takes the resolve.\r\n const strength = material.causticsTemporalStrength;\r\n if (strength <= 0) {\r\n // No history committed; keep the recorded slice matching the history slot.\r\n return map;\r\n }\r\n const camera = ctx.camera;\r\n const previous = this._prevSlices.get(camera);\r\n // Without history the current map stands on its own and becomes the history.\r\n const resolved = history && previous ? scratch : map;\r\n if (resolved === scratch) {\r\n this._resolve(device, map, history!, previous!, strength, createFramebuffer(scratch));\r\n }\r\n this._rememberSlice(camera);\r\n return resolved;\r\n }\r\n /**\r\n * Shadow cascade to read the scene depth from, or null when this backend or\r\n * this light cannot supply one.\r\n * @internal\r\n */\r\n private _resolveSceneDepth(ctx: DrawContext, light: PunctualLight): Nullable<SceneDepthBinding> {\r\n // WebGPU only: GLSL ES 3.0 forbids texelFetch on a shadow-sampler texture.\r\n if (ctx.device.type !== 'webgpu') {\r\n warnUnsupported(\r\n 'Water caustics on scene depth (WaterMaterial.causticsSceneDepth)',\r\n 'WebGPU',\r\n 'caustics are projected onto the flat plane at causticsDepth'\r\n );\r\n return null;\r\n }\r\n const params = ctx.shadowMapInfo?.get(light);\r\n const shadowMap = params?.shadowMap;\r\n // Only cascaded native-depth maps; others fall back to the plane.\r\n if (!params || !shadowMap?.isTexture2DArray() || !shadowMap.isDepth()) {\r\n return null;\r\n }\r\n // The smallest cascade whose split distance clears the slice's reach, else\r\n // the last.\r\n const count = Math.max(1, Math.min(params.numShadowCascades, 4));\r\n const reach = Math.max(1, this._sliceReach);\r\n let layer = count - 1;\r\n for (let i = 0; i < count; i++) {\r\n if (params.cascadeDistances[i] >= reach) {\r\n layer = i;\r\n break;\r\n }\r\n }\r\n // shadowMatrices holds each cascade's view-projection transposed.\r\n this._sceneMatrixT.set(params.shadowMatrices.subarray(layer * 16, layer * 16 + 16));\r\n Matrix4x4.transpose(this._sceneMatrixT, this._sceneMatrix);\r\n Matrix4x4.invert(this._sceneMatrix, this._sceneMatrixInv);\r\n return {\r\n texture: shadowMap as Texture2DArray,\r\n layer,\r\n size: shadowMap.width,\r\n matrix: this._sceneMatrix,\r\n matrixInv: this._sceneMatrixInv\r\n };\r\n }\r\n /**\r\n * Photon grid edge length for this frame.\r\n *\r\n * Auto solves the grid for a fixed density in photons per covered map texel:\r\n * the grid covers `gridFraction` of the map, so the target is reached at\r\n * `grid = size * sqrt(target * gridFraction)`.\r\n *\r\n * @param requested - Material setting; 0 asks for the automatic size.\r\n * @param mapSize - Edge length of the caustic map.\r\n * @internal\r\n */\r\n private _resolvePhotonGrid(requested: number, mapSize: number): number {\r\n if (requested > 0) {\r\n return Math.max(8, Math.min(requested, 4096));\r\n }\r\n const grid = Math.round(mapSize * Math.sqrt(PHOTONS_PER_TEXEL * this._gridFraction));\r\n return Math.max(8, Math.min(grid, 4096));\r\n }\r\n /**\r\n * Records the slice the map just produced was built with, for the next frame's\r\n * reprojection.\r\n * @internal\r\n */\r\n private _rememberSlice(camera: Camera): void {\r\n let slice = this._prevSlices.get(camera);\r\n if (!slice) {\r\n slice = { frameX: new Vector4(), frameY: new Vector4(), center: new Vector4(), warp: 0 };\r\n this._prevSlices.set(camera, slice);\r\n }\r\n slice.frameX.set(this._uniforms.frameX);\r\n slice.frameY.set(this._uniforms.frameY);\r\n slice.center.set(this._uniforms.center);\r\n slice.warp = this._warp;\r\n }\r\n /** @internal */\r\n private _resolve(\r\n device: AbstractDevice,\r\n current: Texture2D,\r\n history: Texture2D,\r\n previous: { frameX: Vector4; frameY: Vector4; center: Vector4; warp: number },\r\n strength: number,\r\n dst: FrameBuffer\r\n ): void {\r\n const program = this._getResolveProgram(device);\r\n const bindGroup = this._resolveBindGroup!;\r\n device.pushDeviceStates();\r\n device.setFramebuffer(dst);\r\n device.setViewport(null);\r\n device.setScissor(null);\r\n device.setProgram(program);\r\n bindGroup.setTexture('causticCurrent', current, fetchSampler('clamp_linear_nomip'));\r\n bindGroup.setTexture('causticHistory', history, fetchSampler('clamp_linear_nomip'));\r\n bindGroup.setValue('causticFrameX', this._uniforms.frameX);\r\n bindGroup.setValue('causticFrameY', this._uniforms.frameY);\r\n bindGroup.setValue('causticCenter', this._uniforms.center);\r\n bindGroup.setValue('causticPrevFrameX', previous.frameX);\r\n bindGroup.setValue('causticPrevFrameY', previous.frameY);\r\n bindGroup.setValue('causticPrevCenter', previous.center);\r\n this._resolveParams.setXYZW(strength, 1 / current.width, this._warp, previous.warp);\r\n bindGroup.setValue('causticResolveParams', this._resolveParams);\r\n device.setBindGroup(0, bindGroup);\r\n drawFullscreenQuad(this._getResolveStates(device));\r\n device.popDeviceStates();\r\n }\r\n /** @internal */\r\n private _getResolveProgram(device: AbstractDevice): GPUProgram {\r\n if (!this._resolveProgram) {\r\n this._resolveProgram = device.buildRenderProgram(createCausticResolveShader())!;\r\n this._resolveProgram.name = '@Water_CausticResolve';\r\n this._resolveBindGroup = device.createBindGroup(this._resolveProgram.bindGroupLayouts[0])!;\r\n }\r\n return this._resolveProgram;\r\n }\r\n /** @internal */\r\n private _getResolveStates(device: AbstractDevice): RenderStateSet {\r\n if (!this._resolveStates) {\r\n this._resolveStates = device.createRenderStateSet();\r\n this._resolveStates.useRasterizerState().setCullMode('none');\r\n this._resolveStates.useDepthState().enableTest(false).enableWrite(false);\r\n }\r\n return this._resolveStates;\r\n }\r\n /** Releases the GPU objects owned by this renderer. */\r\n dispose(): void {\r\n for (const info of this._splatPrograms.values()) {\r\n for (const bindGroup of info.bindGroups) {\r\n bindGroup?.dispose();\r\n }\r\n info.program.dispose();\r\n }\r\n this._splatPrograms.clear();\r\n for (const info of this._heightPrograms.values()) {\r\n for (const bindGroup of info.bindGroups) {\r\n bindGroup?.dispose();\r\n }\r\n info.program.dispose();\r\n }\r\n this._heightPrograms.clear();\r\n this._heightStates.length = 0;\r\n // The layout does not own its buffers.\r\n this._heightLayout?.dispose();\r\n this._heightLayout = null;\r\n this._heightIndexCount = 0;\r\n this._blurBindGroup?.dispose();\r\n this._blurBindGroup = null;\r\n this._resolveProgram?.dispose();\r\n this._resolveProgram = null;\r\n this._resolveBindGroup?.dispose();\r\n this._resolveBindGroup = null;\r\n this._resolveStates = null;\r\n this._blurProgram?.dispose();\r\n this._blurProgram = null;\r\n this._photonLayout?.dispose();\r\n this._photonLayout = null;\r\n this._photonBuffer?.dispose();\r\n this._photonBuffer = null;\r\n this._photonCapacity = 0;\r\n this._photonCount = 0;\r\n this._splatStates = null;\r\n this._blurStates = null;\r\n }\r\n /** @internal */\r\n private _blur(device: AbstractDevice, src: Texture2D, dst: FrameBuffer): void {\r\n const program = this._getBlurProgram(device);\r\n device.pushDeviceStates();\r\n device.setFramebuffer(dst);\r\n device.setProgram(program);\r\n this._blurBindGroup!.setTexture('causticSrc', src, fetchSampler('clamp_linear_nomip'));\r\n this._blurTexelSize.setXYZW(1 / src.width, 1 / src.height, 0, 0);\r\n this._blurBindGroup!.setValue('causticTexelSize', this._blurTexelSize);\r\n device.setBindGroup(0, this._blurBindGroup!);\r\n drawFullscreenQuad(this._getBlurStates(device));\r\n device.popDeviceStates();\r\n }\r\n /**\r\n * Recomputes the orthographic light-space slice the map covers.\r\n * @internal\r\n */\r\n private _updateUniforms(\r\n ctx: DrawContext,\r\n waters: readonly Water[],\r\n light: PunctualLight,\r\n mapSize: number\r\n ): void {\r\n // Slice-wide settings come from the first (largest) body.\r\n const material = waters[0].material;\r\n const dir = this._tmpDir;\r\n dir.set(light.directionAndCutoff.xyz());\r\n dir.inplaceNormalize();\r\n // Two axes perpendicular to the light, seeded by a non-parallel world axis.\r\n const seed = Math.abs(dir.y) > 0.99 ? Vector3.axisPZ() : Vector3.axisPY();\r\n Vector3.cross(seed, dir, this._tmpRight);\r\n this._tmpRight.inplaceNormalize();\r\n Vector3.cross(dir, this._tmpRight, this._tmpUp);\r\n this._tmpUp.inplaceNormalize();\r\n const right = this._tmpRight;\r\n const up = this._tmpUp;\r\n const waterLevel = waters[0].worldMatrix.m13;\r\n const range = Math.max(1, material.causticsRange);\r\n const camera = ctx.camera.getWorldPosition();\r\n const center = this._tmpCenter.setXYZ(camera.x, waterLevel, camera.z);\r\n const cameraRight = Vector3.dot(center, right);\r\n const cameraUp = Vector3.dot(center, up);\r\n // The component along the light direction is arbitrary: both the projection\r\n // into the map and the photon sweep are invariant along it.\r\n const alongDir = Vector3.dot(center, dir);\r\n\r\n // Light-space AABB of all bodies' regions, from their four corners.\r\n let regionMinR = Infinity;\r\n let regionMaxR = -Infinity;\r\n let regionMinU = Infinity;\r\n let regionMaxU = -Infinity;\r\n for (const body of waters) {\r\n const region = body.material.region;\r\n // Each body's own height, since the projection is taken on its surface.\r\n const level = body.worldMatrix.m13;\r\n for (const [x, z] of [\r\n [region.x, region.y],\r\n [region.z, region.y],\r\n [region.x, region.w],\r\n [region.z, region.w]\r\n ]) {\r\n const r = x * right.x + level * right.y + z * right.z;\r\n const v = x * up.x + level * up.y + z * up.z;\r\n regionMinR = Math.min(regionMinR, r);\r\n regionMaxR = Math.max(regionMaxR, r);\r\n regionMinU = Math.min(regionMinU, v);\r\n regionMaxU = Math.max(regionMaxU, v);\r\n }\r\n }\r\n // Fit the slice to the water; `causticsRange` caps how far from the camera\r\n // the map reaches.\r\n let loR = Math.max(regionMinR, cameraRight - range);\r\n let hiR = Math.min(regionMaxR, cameraRight + range);\r\n let loU = Math.max(regionMinU, cameraUp - range);\r\n let hiU = Math.min(regionMaxU, cameraUp + range);\r\n if (hiR <= loR || hiU <= loU) {\r\n // No water within range; keep the slice finite so the grid bounds come\r\n // out empty rather than inverted.\r\n loR = cameraRight - range;\r\n hiR = cameraRight + range;\r\n loU = cameraUp - range;\r\n hiU = cameraUp + range;\r\n }\r\n let halfR = Math.max(MIN_SLICE_EXTENT, (hiR - loR) * 0.5);\r\n let halfU = Math.max(MIN_SLICE_EXTENT, (hiU - loU) * 0.5);\r\n // Cap the aspect ratio to bound directional smearing on the square map.\r\n halfR = Math.max(halfR, halfU / MAX_SLICE_ASPECT);\r\n halfU = Math.max(halfU, halfR / MAX_SLICE_ASPECT);\r\n // Quantise so the texel size holds still while the camera moves, which the\r\n // centre snapping and the temporal history rely on.\r\n halfR = Math.min(range, quantiseSliceExtent(halfR, range));\r\n halfU = Math.min(range, quantiseSliceExtent(halfU, range));\r\n // Warp only when the range, not the water, bounds the map.\r\n const rangeLimited =\r\n regionMinR < cameraRight - range ||\r\n regionMaxR > cameraRight + range ||\r\n regionMinU < cameraUp - range ||\r\n regionMaxU > cameraUp + range;\r\n const warp = rangeLimited ? material.causticsWarp : 0;\r\n // Snap the centre so the map does not crawl: whole texels when linear, a\r\n // coarse ladder under a warp.\r\n const snapR = warp > 0 ? halfR / WARPED_CENTER_SNAP_DIVISIONS : (2 * halfR) / mapSize;\r\n const snapU = warp > 0 ? halfU / WARPED_CENTER_SNAP_DIVISIONS : (2 * halfU) / mapSize;\r\n const centerR = Math.round(((loR + hiR) * 0.5) / snapR) * snapR;\r\n const centerU = Math.round(((loU + hiU) * 0.5) / snapU) * snapU;\r\n center.setXYZ(\r\n right.x * centerR + up.x * centerU + dir.x * alongDir,\r\n right.y * centerR + up.y * centerU + dir.y * alongDir,\r\n right.z * centerR + up.z * centerU + dir.z * alongDir\r\n );\r\n const u = this._uniforms;\r\n u.frameX.setXYZW(right.x, right.y, right.z, 1 / halfR);\r\n u.frameY.setXYZW(up.x, up.y, up.z, 1 / halfU);\r\n u.center.setXYZW(center.x, center.y, center.z, waterLevel);\r\n u.lightDir.setXYZW(dir.x, dir.y, dir.z, 1 / Math.max(-dir.y, MIN_SUN_ELEVATION));\r\n // Edge fade start, in units of the map half-extent. Only a border set by the\r\n // range is faded; a border fitted to the water coincides with the region.\r\n const minHalf = Math.min(halfR, halfU);\r\n const fadeDistance = !rangeLimited\r\n ? 0\r\n : material.causticsFadeDistance > 0\r\n ? material.causticsFadeDistance\r\n : Math.max(AUTO_FADE_MIN_DISTANCE, AUTO_FADE_FRACTION * minHalf);\r\n const fadeFraction = Math.max(MIN_FADE_FRACTION, Math.min(MAX_FADE_FRACTION, fadeDistance / minHalf));\r\n u.params.setXYZW(\r\n material.causticsIntensity,\r\n material.causticsDepth,\r\n material.causticsDefocus,\r\n 1 - fadeFraction\r\n );\r\n u.extinction.setXYZW(material.causticsMinDepth, 0, 0, warp);\r\n this._warp = warp;\r\n // Retained for the per-body grid fit.\r\n this._sliceRight = right;\r\n this._sliceUp = up;\r\n this._sliceCenterR = centerR;\r\n this._sliceCenterU = centerU;\r\n this._sliceHalfR = halfR;\r\n this._sliceHalfU = halfU;\r\n // Slice reach from the camera, for shadow cascade selection.\r\n this._sliceReach = Math.hypot(halfR, halfU);\r\n\r\n // Per-body table the receiver searches: footprint, medium and surface height.\r\n u.waterCount = Math.min(waters.length, MAX_CAUSTIC_WATERS);\r\n for (let i = 0; i < u.waterCount; i++) {\r\n const body = waters[i];\r\n const region = body.material.region;\r\n u.waterRegions[i * 4 + 0] = region.x;\r\n u.waterRegions[i * 4 + 1] = region.y;\r\n u.waterRegions[i * 4 + 2] = region.z;\r\n u.waterRegions[i * 4 + 3] = region.w;\r\n const ext = body.material.extinction;\r\n u.waterMedia[i * 4 + 0] = ext.x;\r\n u.waterMedia[i * 4 + 1] = ext.y;\r\n u.waterMedia[i * 4 + 2] = ext.z;\r\n u.waterMedia[i * 4 + 3] = body.worldMatrix.m13;\r\n }\r\n }\r\n /**\r\n * Map-NDC bounds of one body's footprint, so its photon grid covers just that.\r\n *\r\n * The body's light-space bounds carry over directly since the projection is\r\n * invariant along the light. Clamped to the map, then warped; the warp is\r\n * monotone and separable, so warping the interval's ends is exact.\r\n * @internal\r\n */\r\n private _updateGridBounds(water: Water): void {\r\n const region = water.material.region;\r\n const level = water.worldMatrix.m13;\r\n const right = this._sliceRight;\r\n const up = this._sliceUp;\r\n let minR = Infinity;\r\n let maxR = -Infinity;\r\n let minU = Infinity;\r\n let maxU = -Infinity;\r\n for (const [x, z] of [\r\n [region.x, region.y],\r\n [region.z, region.y],\r\n [region.x, region.w],\r\n [region.z, region.w]\r\n ]) {\r\n const r = x * right.x + level * right.y + z * right.z;\r\n const v = x * up.x + level * up.y + z * up.z;\r\n minR = Math.min(minR, r);\r\n maxR = Math.max(maxR, r);\r\n minU = Math.min(minU, v);\r\n maxU = Math.max(maxU, v);\r\n }\r\n const warp = this._warp;\r\n // Clamped to the map plus a margin (see GRID_BORDER_MARGIN), but never past\r\n // the water itself.\r\n const m = 1 + GRID_BORDER_MARGIN;\r\n const lo = (v: number) => Math.max(-m, Math.min(m, v));\r\n const minX = warpCausticNDC(lo((minR - this._sliceCenterR) / this._sliceHalfR), warp);\r\n const maxX = warpCausticNDC(lo((maxR - this._sliceCenterR) / this._sliceHalfR), warp);\r\n const minY = warpCausticNDC(lo((minU - this._sliceCenterU) / this._sliceHalfU), warp);\r\n const maxY = warpCausticNDC(lo((maxU - this._sliceCenterU) / this._sliceHalfU), warp);\r\n this._gridBounds.setXYZW(minX, minY, maxX, maxY);\r\n // Share of the map the grid covers; scales the photon weight to keep calm\r\n // water at 1.0.\r\n this._gridFraction = Math.max(0, ((maxX - minX) * (maxY - minY)) / 4);\r\n }\r\n /** @internal */\r\n private _updatePhotonLayout(device: AbstractDevice, gridSize: number): void {\r\n this._photonCount = gridSize * gridSize;\r\n if (this._photonCapacity >= this._photonCount) {\r\n return;\r\n }\r\n // Grow only. The buffer holds each photon's ordinal.\r\n const capacity = Math.max(this._photonCount, this._photonCapacity * 2);\r\n const indices = new Float32Array(capacity);\r\n for (let i = 0; i < capacity; i++) {\r\n indices[i] = i;\r\n }\r\n // WebGL2 refuses to draw without a bound vertex layout, so the ordinal is\r\n // materialised as an attribute rather than read from the vertex index.\r\n const buffer = device.createVertexBuffer('position_f32', indices)!;\r\n this._photonLayout?.dispose();\r\n this._photonBuffer?.dispose();\r\n this._photonBuffer = buffer;\r\n this._photonLayout = device.createVertexLayout({ vertexBuffers: [{ buffer }] });\r\n this._photonCapacity = capacity;\r\n }\r\n /** @internal */\r\n private _getSplatStates(device: AbstractDevice): RenderStateSet {\r\n if (!this._splatStates) {\r\n this._splatStates = device.createRenderStateSet();\r\n this._splatStates.useRasterizerState().setCullMode('none');\r\n this._splatStates.useDepthState().enableTest(false).enableWrite(false);\r\n // Photon accumulation: every splat adds to whatever is already there.\r\n this._splatStates\r\n .useBlendingState()\r\n .enable(true)\r\n .setBlendFunc('one', 'one')\r\n .setBlendEquation('add', 'add');\r\n }\r\n return this._splatStates;\r\n }\r\n /** @internal */\r\n private _getHeightStates(device: AbstractDevice, slot: number): RenderStateSet {\r\n let states = this._heightStates[slot];\r\n if (!states) {\r\n states = device.createRenderStateSet();\r\n states.useRasterizerState().setCullMode('none');\r\n states.useDepthState().enableTest(false).enableWrite(false);\r\n // Plain overwrite into this slot's channel only.\r\n states.useColorState().setColorMask(slot === 0, slot === 1, slot === 2, slot === 3);\r\n this._heightStates[slot] = states;\r\n }\r\n return states;\r\n }\r\n /** @internal */\r\n private _getHeightProgram(device: AbstractDevice, waveGenerator: WaveGenerator): SplatProgramInfo {\r\n const key = waveGenerator.getHash();\r\n let info = this._heightPrograms.get(key);\r\n if (info) {\r\n return info;\r\n }\r\n const program = device.buildRenderProgram(createCausticHeightShader(waveGenerator))!;\r\n program.name = '@Water_CausticHeight';\r\n info = { program, bindGroups: [] };\r\n this._heightPrograms.set(key, info);\r\n return info;\r\n }\r\n /** @internal */\r\n private _getBlurStates(device: AbstractDevice): RenderStateSet {\r\n if (!this._blurStates) {\r\n this._blurStates = device.createRenderStateSet();\r\n this._blurStates.useRasterizerState().setCullMode('none');\r\n this._blurStates.useDepthState().enableTest(false).enableWrite(false);\r\n }\r\n return this._blurStates;\r\n }\r\n /** @internal */\r\n private _getSplatProgram(\r\n device: AbstractDevice,\r\n waveGenerator: WaveGenerator,\r\n sceneDepth: boolean\r\n ): SplatProgramInfo {\r\n const key = `${waveGenerator.getHash()}:${sceneDepth ? 1 : 0}`;\r\n let info = this._splatPrograms.get(key);\r\n if (info) {\r\n return info;\r\n }\r\n const program = device.buildRenderProgram(createCausticSplatShader(waveGenerator, sceneDepth))!;\r\n program.name = `@Water_CausticSplat${sceneDepth ? '_SceneDepth' : ''}`;\r\n info = { program, bindGroups: [] };\r\n this._splatPrograms.set(key, info);\r\n return info;\r\n }\r\n /**\r\n * The bind group for one water slot of a splat program.\r\n * @internal\r\n */\r\n private _getSplatBindGroup(device: AbstractDevice, info: SplatProgramInfo, slot: number): BindGroup {\r\n let bindGroup = info.bindGroups[slot];\r\n if (!bindGroup) {\r\n bindGroup = device.createBindGroup(info.program.bindGroupLayouts[0])!;\r\n info.bindGroups[slot] = bindGroup;\r\n }\r\n return bindGroup;\r\n }\r\n /**\r\n * Whether any body asks for the scene-depth intersection, which decides\r\n * whether the shadow cascade needs resolving at all.\r\n * @internal\r\n */\r\n private _anySceneDepth(waters: readonly Water[]): boolean {\r\n return waters.some((w) => w.material.causticsSceneDepth);\r\n }\r\n /** @internal */\r\n private _getBlurProgram(device: AbstractDevice): GPUProgram {\r\n if (!this._blurProgram) {\r\n this._blurProgram = device.buildRenderProgram(createCausticBlurShader())!;\r\n this._blurProgram.name = '@Water_CausticBlur';\r\n this._blurBindGroup = device.createBindGroup(this._blurProgram.bindGroupLayouts[0])!;\r\n }\r\n return this._blurProgram;\r\n }\r\n}\r\n"],"names":["WATER_IOR","WATER_ETA","MIN_SUN_ELEVATION","SCENE_DEPTH_ITERATIONS","PHOTONS_PER_TEXEL","AUTO_FADE_FRACTION","AUTO_FADE_MIN_DISTANCE","MIN_FADE_FRACTION","MAX_FADE_FRACTION","MAX_SLICE_ASPECT","SLICE_QUANTISE_STEPS","MIN_SLICE_EXTENT","WARPED_CENTER_SNAP_DIVISIONS","GRID_BORDER_MARGIN","warpCausticNDC","ndc","strength","Math","abs","quantiseSliceExtent","half","range","steps","floor","log2","pow","HEIGHT_GRID_SIZE","createCausticSplatShader","waveGenerator","sceneDepth","setupUniforms","scope","pb","$builder","causticFrameX","vec4","uniform","causticFrameY","causticCenter","causticLightDir","causticRegion","causticGridBounds","causticSplatParams","causticPhotonParams","causticSceneMatrix","mat4","causticSceneMatrixInv","causticSceneParams","causticSceneDepth","tex2DArrayShadow","ShaderHelper","declareStandaloneCameraTime","vertex","$inputs","photonIndex","float","attrib","$outputs","photonWeight","main","$l","invRadius","vec2","w","radius","div","focalDepth","y","eta","z","L","xyz","waterLevel","gridSize","x","invGrid","photonRow","mul","photonCol","sub","photonUV","add","warpedNDC","mix","xy","zw","unwarpCausticNDC","planePos","sweep","surfaceXZ","outside","or","any","lessThan","xz","greaterThan","surfacePos","vec3","coarseNormal","calcVertexPositionAndNormal","normal","calcFragmentNormal","refracted","refract","refractedFlat","dir","normalize","invDirY","min","targetY","hitT","hitPos","max","probe","layer","int","i","and","all","greaterThanEqual","lessThanEqual","textureArrayLoad","ivec2","REVERSE_Z","rel","hitNDC","dot","hitWarped","$builtins","position","getDevice","type","pointSize","$if","fragment","outColor","createCausticHeightShader","vertexIndex","height","inside","causticHeightParams","row","col","gridUV","surfaceNormal","neg","discard","CAUSTIC_HEIGHT_BIAS","createCausticBlurShader","pos","uv","causticSrc","tex2D","causticTexelSize","o","sum","textureSampleLevel","createCausticResolveShader","causticCurrent","causticHistory","causticPrevFrameX","causticPrevFrameY","causticPrevCenter","causticResolveParams","texel","current","mn","mx","dy","dx","s","world","prevNDC","prevWarped","prevUV","history","blend","clamp","WaterCausticsRenderer","_heightParams","_heightIndexCount","_blurProgram","_blurBindGroup","_resolveProgram","_resolveBindGroup","_resolveStates","_resolveParams","_photonLayout","_photonBuffer","_photonParams","_photonCount","_splatStates","_blurStates","_uniforms","_tmpRight","_tmpUp","_tmpDir","_tmpCenter","_splatParams","_blurTexelSize","_gridFraction","_sliceUp","_sliceCenterR","_sliceCenterU","_sliceHalfR","_sliceHalfU","_splatCenter","_sceneMatrixT","_sceneMatrix","_sceneMatrixInv","_sceneDepthParams","_splatPrograms","Map","_heightPrograms","_heightStates","Vector4","_heightLayout","_prevSlices","WeakMap","_photonCapacity","frameX","frameY","center","lightDir","params","extinction","waterCount","waterRegions","Float32Array","MAX_CAUSTIC_WATERS","waterMedia","Vector3","_gridBounds","_sliceReach","_sliceRight","Matrix4x4","_warp","uniforms","getMapFormat","device","info","getDeviceCaps","textureCaps","getTextureFormatInfo","renderable","filterable","getHeightMapFormat","canRender","water","light","material","causticsEnabled","isDirectionLight","directionAndCutoff","render","ctx","waters","map","scratch","heights","createFramebuffer","_updateUniforms","width","_anySceneDepth","_resolveSceneDepth","pushDeviceStates","setFramebuffer","setViewport","setScissor","clearFrameBuffer","zero","_ensureHeightGrid","length","_renderHeightsOne","popDeviceStates","setRenderStates","_getSplatStates","_splatOne","_postProcess","index","_updateGridBounds","_getHeightProgram","bindGroup","_getSplatBindGroup","setValue","setXYZW","worldMatrix","m13","region","setStandaloneCameraTime","applyWaterBindGroup","_getHeightStates","setProgram","program","setBindGroup","setVertexLayout","draw","side","ordinals","indices","Uint32Array","n","a","b","c","d","vertexBuffer","createVertexBuffer","indexBuffer","createIndexBuffer","createVertexLayout","vertexBuffers","buffer","photonGrid","_resolvePhotonGrid","causticsPhotonResolution","_updatePhotonLayout","useSceneDepth","causticsSceneDepth","splat","_getSplatProgram","matrix","matrixInv","size","setTexture","texture","fetchSampler","causticsDepth","blurPasses","causticsBlurPasses","src","dst","_blur","causticsTemporalStrength","camera","previous","get","resolved","_resolve","_rememberSlice","warnUnsupported","shadowMapInfo","shadowMap","isTexture2DArray","isDepth","count","numShadowCascades","reach","cascadeDistances","set","shadowMatrices","subarray","transpose","invert","requested","mapSize","grid","round","sqrt","slice","warp","_getResolveProgram","drawFullscreenQuad","_getResolveStates","buildRenderProgram","name","createBindGroup","bindGroupLayouts","createRenderStateSet","useRasterizerState","setCullMode","useDepthState","enableTest","enableWrite","dispose","values","bindGroups","clear","_getBlurProgram","_getBlurStates","inplaceNormalize","seed","axisPZ","axisPY","cross","right","up","causticsRange","getWorldPosition","setXYZ","cameraRight","cameraUp","alongDir","regionMinR","Infinity","regionMaxR","regionMinU","regionMaxU","body","level","r","v","loR","hiR","loU","hiU","halfR","halfU","rangeLimited","causticsWarp","snapR","snapU","centerR","centerU","u","minHalf","fadeDistance","causticsFadeDistance","fadeFraction","causticsIntensity","causticsDefocus","causticsMinDepth","hypot","ext","minR","maxR","minU","maxU","m","lo","minX","maxX","minY","maxY","capacity","useBlendingState","enable","setBlendFunc","setBlendEquation","slot","states","useColorState","setColorMask","key","getHash","some"],"mappings":";;;;;;AA2BA,qDACA,MAAMA,SAAY,GAAA,KAAA;AAClB,yEACA,MAAMC,SAAAA,GAAY,CAAID,GAAAA,SAAAA;AACtB;;;AAGC,IACD,MAAME,iBAAoB,GAAA,IAAA;AAC1B;;;AAGC,IACD,MAAMC,sBAAyB,GAAA,CAAA;AAC/B;;;AAGC,IACD,MAAMC,iBAAoB,GAAA,CAAA;AAC1B,wEACA,MAAMC,kBAAqB,GAAA,GAAA;AAC3B,uDACA,MAAMC,sBAAyB,GAAA,CAAA;AAC/B,wEACA,MAAMC,iBAAoB,GAAA,KAAA;AAC1B,MAAMC,iBAAoB,GAAA,GAAA;AAC1B;;;;AAIC,IACD,MAAMC,gBAAmB,GAAA,CAAA;AACzB;;;AAGC,IACD,MAAMC,oBAAuB,GAAA,CAAA;AAC7B,oEACA,MAAMC,gBAAmB,GAAA,GAAA;AACzB;;;AAGC,IACD,MAAMC,4BAA+B,GAAA,CAAA;AACrC;;;;;;;;AAQC,IACD,MAAMC,kBAAqB,GAAA,IAAA;AAE3B;;;;;AAKC,IACD,SAASC,cAAAA,CAAeC,GAAW,EAAEC,QAAgB,EAAA;AACnD,IAAA,OAAO,GAACD,IAAO,CAAA,GAAIC,QAAO,CAAA,IAAO,CAAA,GAAIA,QAAWC,GAAAA,IAAAA,CAAKC,GAAG,CAACH,GAAG,CAAA,CAAA;AAC9D;AAEA;;;;;;;AAOC,IACD,SAASI,mBAAAA,CAAoBC,IAAY,EAAEC,KAAa,EAAA;AACtD,IAAA,IAAI,EAAED,IAAAA,GAAO,CAAA,CAAA,IAAMA,QAAQC,KAAO,EAAA;QAChC,OAAOA,KAAAA;AACT;IACA,MAAMC,KAAAA,GAAQL,KAAKM,K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