@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
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { distributionGGX, visGGX, fresnelSchlick } from './pbr.js';
|
|
2
|
+
import { SSSProfile, SKIN_TRANSMISSION_NO_DATA_ENCODING } from '../material/sssprofile.js';
|
|
3
|
+
|
|
4
|
+
/** Opacity below which the dual-lobe specular fades back to a single lobe. */ const OPACITY_THRESHOLD_EPS = 0.1;
|
|
5
|
+
/**
|
|
6
|
+
* Multiple-scattering energy terms for a GGX specular lobe.
|
|
7
|
+
*
|
|
8
|
+
* @param scope - Shader scope.
|
|
9
|
+
* @param roughness - Roughness of the lobe being corrected.
|
|
10
|
+
* @param NoV - Clamped dot(normal, viewDir).
|
|
11
|
+
* @param F0 - Fresnel reflectance at normal incidence.
|
|
12
|
+
* @returns `vec2(W, A)`: specular gain and reflected share.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/ function skinSpecularEnergyTerms(scope, roughness, NoV, F0) {
|
|
16
|
+
const pb = scope.$builder;
|
|
17
|
+
const funcName = 'lib_skinSpecularEnergyTerms';
|
|
18
|
+
pb.func(funcName, [
|
|
19
|
+
pb.float('roughness'),
|
|
20
|
+
pb.float('NoV'),
|
|
21
|
+
pb.float('F0')
|
|
22
|
+
], function() {
|
|
23
|
+
this.$l.r = pb.max(this.roughness, 1e-3);
|
|
24
|
+
this.$l.c = pb.max(this.NoV, 1e-3);
|
|
25
|
+
this.$l.E = pb.sub(1, pb.clamp(pb.mul(pb.pow(this.r, pb.div(this.c, this.r)), pb.div(pb.add(pb.mul(this.r, this.c), 0.0266916), pb.add(0.466495, this.c))), 0, 1));
|
|
26
|
+
this.E = pb.max(this.E, 1e-4);
|
|
27
|
+
this.$l.oneMinusC = pb.sub(1, this.c);
|
|
28
|
+
this.$l.pow5 = pb.mul(pb.mul(this.oneMinusC, this.oneMinusC), pb.mul(this.oneMinusC, this.oneMinusC), this.oneMinusC);
|
|
29
|
+
this.$l.Ef = pb.mul(this.pow5, pb.pow(pb.add(pb.mul(2.36651, pb.pow(this.c, pb.mul(4.7703, this.r))), 0.0387332), this.r));
|
|
30
|
+
this.$l.F90 = pb.clamp(pb.mul(50, this.F0), 0, 1);
|
|
31
|
+
this.$l.W = pb.add(1, pb.mul(this.F0, pb.div(pb.sub(1, this.E), this.E)));
|
|
32
|
+
this.$l.A = pb.mul(this.W, pb.add(pb.mul(this.E, this.F0), pb.mul(this.Ef, pb.sub(this.F90, this.F0))));
|
|
33
|
+
this.$return(pb.vec2(this.W, pb.clamp(this.A, 0, 1)));
|
|
34
|
+
});
|
|
35
|
+
return pb.getGlobalScope()[funcName](roughness, NoV, F0);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Burley diffuse BRDF.
|
|
39
|
+
*
|
|
40
|
+
* @param scope - Shader scope.
|
|
41
|
+
* @param NdotV - Clamped dot(normal, viewDir).
|
|
42
|
+
* @param NdotL - Clamped dot(normal, lightDir).
|
|
43
|
+
* @param VdotH - dot(viewDir, halfVector).
|
|
44
|
+
* @param roughness - Material roughness.
|
|
45
|
+
* @returns Scalar diffuse BRDF value; the caller applies albedo and `NoL`.
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/ function skinDiffuseBRDF(scope, NdotV, NdotL, VdotH, roughness) {
|
|
49
|
+
const pb = scope.$builder;
|
|
50
|
+
const funcName = 'lib_skinDiffuseBurley';
|
|
51
|
+
pb.func(funcName, [
|
|
52
|
+
pb.float('NdotV'),
|
|
53
|
+
pb.float('NdotL'),
|
|
54
|
+
pb.float('VdotH'),
|
|
55
|
+
pb.float('roughness')
|
|
56
|
+
], function() {
|
|
57
|
+
this.$l.fd90 = pb.add(0.5, pb.mul(2, this.VdotH, this.VdotH, this.roughness));
|
|
58
|
+
this.$l.fd90m1 = pb.sub(this.fd90, 1);
|
|
59
|
+
this.$l.oneMinusNoV = pb.sub(1, this.NdotV);
|
|
60
|
+
this.$l.pow5V = pb.mul(pb.mul(this.oneMinusNoV, this.oneMinusNoV), pb.mul(this.oneMinusNoV, this.oneMinusNoV), this.oneMinusNoV);
|
|
61
|
+
this.$l.oneMinusNoL = pb.sub(1, this.NdotL);
|
|
62
|
+
this.$l.pow5L = pb.mul(pb.mul(this.oneMinusNoL, this.oneMinusNoL), pb.mul(this.oneMinusNoL, this.oneMinusNoL), this.oneMinusNoL);
|
|
63
|
+
this.$l.fdV = pb.add(1, pb.mul(this.fd90m1, this.pow5V));
|
|
64
|
+
this.$l.fdL = pb.add(1, pb.mul(this.fd90m1, this.pow5L));
|
|
65
|
+
this.$return(pb.mul(1 / Math.PI, this.fdV, this.fdL));
|
|
66
|
+
});
|
|
67
|
+
return pb.getGlobalScope()[funcName](NdotV, NdotL, VdotH, roughness);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Resolves the two specular lobe roughnesses from the profile.
|
|
71
|
+
*
|
|
72
|
+
* @param scope - Shader scope.
|
|
73
|
+
* @param roughness - Material roughness.
|
|
74
|
+
* @param opacity - Subsurface opacity, used to fade the effect out.
|
|
75
|
+
* @param lobe0Scale - Profile roughness multiplier for the narrow lobe.
|
|
76
|
+
* @param lobe1Scale - Profile roughness multiplier for the wide lobe.
|
|
77
|
+
* @returns `vec2(lobe0Roughness, lobe1Roughness)`.
|
|
78
|
+
*
|
|
79
|
+
* @internal
|
|
80
|
+
*/ function skinDualSpecularRoughness(scope, roughness, opacity, lobe0Scale, lobe1Scale) {
|
|
81
|
+
const pb = scope.$builder;
|
|
82
|
+
const funcName = 'lib_skinDualSpecularRoughness';
|
|
83
|
+
pb.func(funcName, [
|
|
84
|
+
pb.float('roughness'),
|
|
85
|
+
pb.float('opacity'),
|
|
86
|
+
pb.float('lobe0Scale'),
|
|
87
|
+
pb.float('lobe1Scale')
|
|
88
|
+
], function() {
|
|
89
|
+
this.$l.fade = pb.clamp(pb.mul(pb.sub(this.opacity, OPACITY_THRESHOLD_EPS), 10), 0, 1);
|
|
90
|
+
this.$l.scale0 = pb.mix(pb.float(1), this.lobe0Scale, this.fade);
|
|
91
|
+
this.$l.scale1 = pb.mix(pb.float(1), this.lobe1Scale, this.fade);
|
|
92
|
+
this.$return(pb.vec2(pb.max(pb.clamp(pb.mul(this.roughness, this.scale0), 0, 1), 0.02), pb.clamp(pb.mul(this.roughness, this.scale1), 0, 1)));
|
|
93
|
+
});
|
|
94
|
+
return pb.getGlobalScope()[funcName](roughness, opacity, lobe0Scale, lobe1Scale);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Dual-lobe GGX specular for skin.
|
|
98
|
+
*
|
|
99
|
+
* @param scope - Shader scope.
|
|
100
|
+
* @param NoH - dot(normal, halfVector).
|
|
101
|
+
* @param NoV - dot(normal, viewDir).
|
|
102
|
+
* @param NoL - dot(normal, lightDir).
|
|
103
|
+
* @param VoH - dot(viewDir, halfVector).
|
|
104
|
+
* @param lobeRoughness - `vec2` of the two lobe roughnesses.
|
|
105
|
+
* @param lobeMix - Blend between the narrow and wide lobe.
|
|
106
|
+
* @param F0 - Specular colour at normal incidence.
|
|
107
|
+
* @returns vec3 specular contribution; the caller applies light colour and `NoL`.
|
|
108
|
+
*
|
|
109
|
+
* @internal
|
|
110
|
+
*/ function skinDualLobeSpecular(scope, NoH, NoV, NoL, VoH, lobeRoughness, lobeMix, F0) {
|
|
111
|
+
const pb = scope.$builder;
|
|
112
|
+
const funcName = 'lib_skinDualLobeSpecular';
|
|
113
|
+
pb.func(funcName, [
|
|
114
|
+
pb.float('NoH'),
|
|
115
|
+
pb.float('NoV'),
|
|
116
|
+
pb.float('NoL'),
|
|
117
|
+
pb.float('VoH'),
|
|
118
|
+
pb.vec2('lobeRoughness'),
|
|
119
|
+
pb.float('lobeMix'),
|
|
120
|
+
pb.float('F0')
|
|
121
|
+
], function() {
|
|
122
|
+
this.$l.a0 = pb.mul(this.lobeRoughness.x, this.lobeRoughness.x);
|
|
123
|
+
this.$l.a1 = pb.mul(this.lobeRoughness.y, this.lobeRoughness.y);
|
|
124
|
+
this.$l.avgRoughness = pb.mix(this.lobeRoughness.x, this.lobeRoughness.y, this.lobeMix);
|
|
125
|
+
this.$l.avgAlpha = pb.mul(this.avgRoughness, this.avgRoughness);
|
|
126
|
+
this.$l.D = pb.mix(distributionGGX(this, this.NoH, this.a0), distributionGGX(this, this.NoH, this.a1), this.lobeMix);
|
|
127
|
+
this.$l.Vis = visGGX(this, this.NoV, this.NoL, this.avgAlpha);
|
|
128
|
+
this.$l.F = fresnelSchlick(this, this.VoH, pb.vec3(this.F0), pb.vec3(1));
|
|
129
|
+
this.$return(pb.mul(this.F, pb.mul(this.D, this.Vis)));
|
|
130
|
+
});
|
|
131
|
+
return pb.getGlobalScope()[funcName](NoH, NoV, NoL, VoH, lobeRoughness, lobeMix, F0);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Fetches one column of a profile row from the packed table.
|
|
135
|
+
*
|
|
136
|
+
* @remarks
|
|
137
|
+
* The table is `rgba32f`, hence `unfilterable-float` on WebGPU: the sampler must
|
|
138
|
+
* be non-filtering, so this is an exact texel fetch and anything wanting
|
|
139
|
+
* interpolation between columns has to lerp two fetches by hand.
|
|
140
|
+
*
|
|
141
|
+
* Emitted inline rather than behind a shader function: on WebGPU a texture
|
|
142
|
+
* parameter needs its sampler passed alongside it, and `textureSampleLevel` on
|
|
143
|
+
* the parameter alone compiles to nothing usable.
|
|
144
|
+
*
|
|
145
|
+
* @param scope - Shader scope.
|
|
146
|
+
* @param tex - The packed profile table, as declared in the caller's scope.
|
|
147
|
+
* @param texelSize - `vec2(1 / columns, 1 / rows)`.
|
|
148
|
+
* @param row - Precomputed `v` coordinate of the profile's row.
|
|
149
|
+
* @param column - Column to read, as a float.
|
|
150
|
+
* @returns The `vec4` stored at that column.
|
|
151
|
+
*
|
|
152
|
+
* @internal
|
|
153
|
+
*/ function readSSSProfileColumn(scope, tex, texelSize, row, column) {
|
|
154
|
+
const pb = scope.$builder;
|
|
155
|
+
return pb.textureSampleLevel(tex, pb.vec2(pb.mul(pb.add(column, 0.5), texelSize.x), row), 0);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Back-lit subsurface transmission.
|
|
159
|
+
*
|
|
160
|
+
* @param scope - Shader scope.
|
|
161
|
+
* @param profileTex - The packed profile table.
|
|
162
|
+
* @param profileTexelSize - `vec2(1 / columns, 1 / rows)` of that table.
|
|
163
|
+
* @param profileId - Normalized profile id.
|
|
164
|
+
* @param thickness - Encoded optical depth from the thickness pass, where 1
|
|
165
|
+
* means "nothing in the way".
|
|
166
|
+
* @param normal - Shading normal.
|
|
167
|
+
* @param viewVec - Unit vector from the surface towards the eye.
|
|
168
|
+
* @param lightDir - Unit vector from the surface towards the light.
|
|
169
|
+
* @returns vec3 transmitted radiance; the caller applies light colour,
|
|
170
|
+
* attenuation and the transmission shadow.
|
|
171
|
+
*
|
|
172
|
+
* @internal
|
|
173
|
+
*/ function skinTransmission(scope, profileTex, profileTexelSize, profileId, thickness, normal, viewVec, lightDir) {
|
|
174
|
+
const pb = scope.$builder;
|
|
175
|
+
const lutOffset = SSSProfile.transmissionLutOffset;
|
|
176
|
+
const lutSize = SSSProfile.transmissionLutSize;
|
|
177
|
+
const lastLutColumn = lutOffset + lutSize - 1;
|
|
178
|
+
// Table reads stay inline (see readSSSProfileColumn); the locals are prefixed
|
|
179
|
+
// so they cannot collide with the caller's. Rows are addressed by the profile
|
|
180
|
+
// id, which arrives normalized because it rides in an 8-bit channel.
|
|
181
|
+
scope.$l.zSkinTrRow = pb.mul(pb.add(pb.mul(pb.clamp(profileId, 0, 1), 255), 0.5), profileTexelSize.y);
|
|
182
|
+
// GetTransmissionProfile. The index is `opticalDepth / MAX * (size - 1)` and
|
|
183
|
+
// the decode is `opticalDepth = (1 - thickness) * MAX`, so the MAX cancels and
|
|
184
|
+
// the encoded thickness maps onto the table directly.
|
|
185
|
+
scope.$l.zSkinTrIndex = pb.mul(pb.clamp(pb.sub(1, thickness), 0, 1), lutSize - 1);
|
|
186
|
+
scope.$l.zSkinTrI0 = pb.floor(scope.zSkinTrIndex);
|
|
187
|
+
scope.$l.zSkinTrC0 = pb.add(scope.zSkinTrI0, lutOffset);
|
|
188
|
+
scope.$l.zSkinTrC1 = pb.min(pb.add(scope.zSkinTrC0, 1), lastLutColumn);
|
|
189
|
+
scope.$l.zSkinTrProfile = pb.mix(readSSSProfileColumn(scope, profileTex, profileTexelSize, scope.zSkinTrRow, scope.zSkinTrC0).rgb, readSSSProfileColumn(scope, profileTex, profileTexelSize, scope.zSkinTrRow, scope.zSkinTrC1).rgb, pb.sub(scope.zSkinTrIndex, scope.zSkinTrI0));
|
|
190
|
+
// (extinctionScale, normalScale, scatteringDistribution, 1 / ior)
|
|
191
|
+
scope.$l.zSkinTrParams = readSSSProfileColumn(scope, profileTex, profileTexelSize, scope.zSkinTrRow, pb.float(SSSProfile.transmissionParamColumn));
|
|
192
|
+
return skinTransmissionPhase(scope, scope.zSkinTrProfile, scope.zSkinTrParams, thickness, normal, viewVec, lightDir);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The part of the transmission BxDF that touches no textures.
|
|
196
|
+
*
|
|
197
|
+
* @remarks
|
|
198
|
+
* Split out so the math can live behind a shader function while the table reads
|
|
199
|
+
* stay inline at the call site, where the sampler is in scope.
|
|
200
|
+
*
|
|
201
|
+
* @param scope - Shader scope.
|
|
202
|
+
* @param profile - The interpolated transmission profile, `rgb`.
|
|
203
|
+
* @param params - `(extinctionScale, normalScale, scatteringDistribution, 1 / ior)`.
|
|
204
|
+
* @param thickness - The raw encoding, still needed to spot the "no data" sentinel.
|
|
205
|
+
* @param normal - Shading normal.
|
|
206
|
+
* @param viewVec - Unit vector from the surface towards the eye.
|
|
207
|
+
* @param lightDir - Unit vector from the surface towards the light.
|
|
208
|
+
* @returns vec3 transmitted radiance.
|
|
209
|
+
*
|
|
210
|
+
* @internal
|
|
211
|
+
*/ function skinTransmissionPhase(scope, profile, params, thickness, normal, viewVec, lightDir) {
|
|
212
|
+
const pb = scope.$builder;
|
|
213
|
+
const funcName = 'lib_skinTransmissionPhase';
|
|
214
|
+
pb.func(funcName, [
|
|
215
|
+
pb.vec3('profile'),
|
|
216
|
+
pb.vec4('params'),
|
|
217
|
+
pb.float('thickness'),
|
|
218
|
+
pb.vec3('normal'),
|
|
219
|
+
pb.vec3('viewVec'),
|
|
220
|
+
pb.vec3('lightDir')
|
|
221
|
+
], function() {
|
|
222
|
+
// "No data" must be rejected rather than decoded: it decodes to zero
|
|
223
|
+
// optical depth, the *most* transmissive entry, so letting it through lights
|
|
224
|
+
// the subject from behind with a light that was never behind it. The
|
|
225
|
+
// threshold sits in the gap between the largest encoding the pass can write
|
|
226
|
+
// and the sentinel, so it clips no real measurement.
|
|
227
|
+
this.$if(pb.greaterThan(this.thickness, 0.5 * (1 + SKIN_TRANSMISSION_NO_DATA_ENCODING)), function() {
|
|
228
|
+
this.$return(pb.vec3(0));
|
|
229
|
+
});
|
|
230
|
+
this.$l.refracV = pb.refract(this.viewVec, pb.neg(this.normal), this.params.w);
|
|
231
|
+
this.$l.cosJ = pb.dot(pb.neg(this.lightDir), this.refracV);
|
|
232
|
+
this.$l.g = this.params.z;
|
|
233
|
+
this.$l.g2 = pb.mul(this.g, this.g);
|
|
234
|
+
this.$l.gcos = pb.sub(1, pb.mul(this.g, this.cosJ));
|
|
235
|
+
this.$l.gcos2 = pb.mul(this.gcos, this.gcos);
|
|
236
|
+
this.$l.phase = pb.div(pb.mul(0.5, pb.sub(1, this.g2)), pb.max(this.gcos2, 1e-5));
|
|
237
|
+
this.$return(pb.mul(this.profile, this.phase));
|
|
238
|
+
});
|
|
239
|
+
return pb.getGlobalScope()[funcName](profile, params, thickness, normal, viewVec, lightDir);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export { skinDiffuseBRDF, skinDualLobeSpecular, skinDualSpecularRoughness, skinSpecularEnergyTerms, skinTransmission };
|
|
243
|
+
//# sourceMappingURL=skin_brdf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skin_brdf.js","sources":["../../src/shaders/skin_brdf.ts"],"sourcesContent":["import type { PBInsideFunctionScope, PBShaderExp } from '@zephyr3d/device';\r\nimport { distributionGGX, fresnelSchlick, visGGX } from './pbr';\r\nimport { SKIN_TRANSMISSION_NO_DATA_ENCODING, SSSProfile } from '../material/sssprofile';\r\n\r\n/** Opacity below which the dual-lobe specular fades back to a single lobe. */\r\nconst OPACITY_THRESHOLD_EPS = 0.1;\r\n\r\n/**\r\n * Multiple-scattering energy terms for a GGX specular lobe.\r\n *\r\n * @param scope - Shader scope.\r\n * @param roughness - Roughness of the lobe being corrected.\r\n * @param NoV - Clamped dot(normal, viewDir).\r\n * @param F0 - Fresnel reflectance at normal incidence.\r\n * @returns `vec2(W, A)`: specular gain and reflected share.\r\n *\r\n * @internal\r\n */\r\nexport function skinSpecularEnergyTerms(\r\n scope: PBInsideFunctionScope,\r\n roughness: PBShaderExp,\r\n NoV: PBShaderExp,\r\n F0: PBShaderExp\r\n): PBShaderExp {\r\n const pb = scope.$builder;\r\n const funcName = 'lib_skinSpecularEnergyTerms';\r\n pb.func(funcName, [pb.float('roughness'), pb.float('NoV'), pb.float('F0')], function () {\r\n this.$l.r = pb.max(this.roughness, 1e-3);\r\n this.$l.c = pb.max(this.NoV, 1e-3);\r\n this.$l.E = pb.sub(\r\n 1,\r\n pb.clamp(\r\n pb.mul(\r\n pb.pow(this.r, pb.div(this.c, this.r)),\r\n pb.div(pb.add(pb.mul(this.r, this.c), 0.0266916), pb.add(0.466495, this.c))\r\n ),\r\n 0,\r\n 1\r\n )\r\n );\r\n this.E = pb.max(this.E, 1e-4);\r\n this.$l.oneMinusC = pb.sub(1, this.c);\r\n this.$l.pow5 = pb.mul(\r\n pb.mul(this.oneMinusC, this.oneMinusC),\r\n pb.mul(this.oneMinusC, this.oneMinusC),\r\n this.oneMinusC\r\n );\r\n this.$l.Ef = pb.mul(\r\n this.pow5,\r\n pb.pow(pb.add(pb.mul(2.36651, pb.pow(this.c, pb.mul(4.7703, this.r))), 0.0387332), this.r)\r\n );\r\n this.$l.F90 = pb.clamp(pb.mul(50, this.F0), 0, 1);\r\n this.$l.W = pb.add(1, pb.mul(this.F0, pb.div(pb.sub(1, this.E), this.E)));\r\n this.$l.A = pb.mul(this.W, pb.add(pb.mul(this.E, this.F0), pb.mul(this.Ef, pb.sub(this.F90, this.F0))));\r\n this.$return(pb.vec2(this.W, pb.clamp(this.A, 0, 1)));\r\n });\r\n return pb.getGlobalScope()[funcName](roughness, NoV, F0) as PBShaderExp;\r\n}\r\n\r\n/**\r\n * Burley diffuse BRDF.\r\n *\r\n * @param scope - Shader scope.\r\n * @param NdotV - Clamped dot(normal, viewDir).\r\n * @param NdotL - Clamped dot(normal, lightDir).\r\n * @param VdotH - dot(viewDir, halfVector).\r\n * @param roughness - Material roughness.\r\n * @returns Scalar diffuse BRDF value; the caller applies albedo and `NoL`.\r\n *\r\n * @internal\r\n */\r\nexport function skinDiffuseBRDF(\r\n scope: PBInsideFunctionScope,\r\n NdotV: PBShaderExp,\r\n NdotL: PBShaderExp,\r\n VdotH: PBShaderExp,\r\n roughness: PBShaderExp\r\n): PBShaderExp {\r\n const pb = scope.$builder;\r\n const funcName = 'lib_skinDiffuseBurley';\r\n pb.func(\r\n funcName,\r\n [pb.float('NdotV'), pb.float('NdotL'), pb.float('VdotH'), pb.float('roughness')],\r\n function () {\r\n this.$l.fd90 = pb.add(0.5, pb.mul(2, this.VdotH, this.VdotH, this.roughness));\r\n this.$l.fd90m1 = pb.sub(this.fd90, 1);\r\n this.$l.oneMinusNoV = pb.sub(1, this.NdotV);\r\n this.$l.pow5V = pb.mul(\r\n pb.mul(this.oneMinusNoV, this.oneMinusNoV),\r\n pb.mul(this.oneMinusNoV, this.oneMinusNoV),\r\n this.oneMinusNoV\r\n );\r\n this.$l.oneMinusNoL = pb.sub(1, this.NdotL);\r\n this.$l.pow5L = pb.mul(\r\n pb.mul(this.oneMinusNoL, this.oneMinusNoL),\r\n pb.mul(this.oneMinusNoL, this.oneMinusNoL),\r\n this.oneMinusNoL\r\n );\r\n this.$l.fdV = pb.add(1, pb.mul(this.fd90m1, this.pow5V));\r\n this.$l.fdL = pb.add(1, pb.mul(this.fd90m1, this.pow5L));\r\n this.$return(pb.mul(1 / Math.PI, this.fdV, this.fdL));\r\n }\r\n );\r\n return pb.getGlobalScope()[funcName](NdotV, NdotL, VdotH, roughness) as PBShaderExp;\r\n}\r\n\r\n/**\r\n * Resolves the two specular lobe roughnesses from the profile.\r\n *\r\n * @param scope - Shader scope.\r\n * @param roughness - Material roughness.\r\n * @param opacity - Subsurface opacity, used to fade the effect out.\r\n * @param lobe0Scale - Profile roughness multiplier for the narrow lobe.\r\n * @param lobe1Scale - Profile roughness multiplier for the wide lobe.\r\n * @returns `vec2(lobe0Roughness, lobe1Roughness)`.\r\n *\r\n * @internal\r\n */\r\nexport function skinDualSpecularRoughness(\r\n scope: PBInsideFunctionScope,\r\n roughness: PBShaderExp,\r\n opacity: PBShaderExp,\r\n lobe0Scale: PBShaderExp,\r\n lobe1Scale: PBShaderExp\r\n): PBShaderExp {\r\n const pb = scope.$builder;\r\n const funcName = 'lib_skinDualSpecularRoughness';\r\n pb.func(\r\n funcName,\r\n [pb.float('roughness'), pb.float('opacity'), pb.float('lobe0Scale'), pb.float('lobe1Scale')],\r\n function () {\r\n this.$l.fade = pb.clamp(pb.mul(pb.sub(this.opacity, OPACITY_THRESHOLD_EPS), 10), 0, 1);\r\n this.$l.scale0 = pb.mix(pb.float(1), this.lobe0Scale, this.fade);\r\n this.$l.scale1 = pb.mix(pb.float(1), this.lobe1Scale, this.fade);\r\n this.$return(\r\n pb.vec2(\r\n pb.max(pb.clamp(pb.mul(this.roughness, this.scale0), 0, 1), 0.02),\r\n pb.clamp(pb.mul(this.roughness, this.scale1), 0, 1)\r\n )\r\n );\r\n }\r\n );\r\n return pb.getGlobalScope()[funcName](roughness, opacity, lobe0Scale, lobe1Scale) as PBShaderExp;\r\n}\r\n\r\n/**\r\n * Dual-lobe GGX specular for skin.\r\n *\r\n * @param scope - Shader scope.\r\n * @param NoH - dot(normal, halfVector).\r\n * @param NoV - dot(normal, viewDir).\r\n * @param NoL - dot(normal, lightDir).\r\n * @param VoH - dot(viewDir, halfVector).\r\n * @param lobeRoughness - `vec2` of the two lobe roughnesses.\r\n * @param lobeMix - Blend between the narrow and wide lobe.\r\n * @param F0 - Specular colour at normal incidence.\r\n * @returns vec3 specular contribution; the caller applies light colour and `NoL`.\r\n *\r\n * @internal\r\n */\r\nexport function skinDualLobeSpecular(\r\n scope: PBInsideFunctionScope,\r\n NoH: PBShaderExp,\r\n NoV: PBShaderExp,\r\n NoL: PBShaderExp,\r\n VoH: PBShaderExp,\r\n lobeRoughness: PBShaderExp,\r\n lobeMix: PBShaderExp,\r\n F0: PBShaderExp\r\n): PBShaderExp {\r\n const pb = scope.$builder;\r\n const funcName = 'lib_skinDualLobeSpecular';\r\n pb.func(\r\n funcName,\r\n [\r\n pb.float('NoH'),\r\n pb.float('NoV'),\r\n pb.float('NoL'),\r\n pb.float('VoH'),\r\n pb.vec2('lobeRoughness'),\r\n pb.float('lobeMix'),\r\n pb.float('F0')\r\n ],\r\n function () {\r\n this.$l.a0 = pb.mul(this.lobeRoughness.x, this.lobeRoughness.x);\r\n this.$l.a1 = pb.mul(this.lobeRoughness.y, this.lobeRoughness.y);\r\n this.$l.avgRoughness = pb.mix(this.lobeRoughness.x, this.lobeRoughness.y, this.lobeMix);\r\n this.$l.avgAlpha = pb.mul(this.avgRoughness, this.avgRoughness);\r\n this.$l.D = pb.mix(\r\n distributionGGX(this, this.NoH, this.a0),\r\n distributionGGX(this, this.NoH, this.a1),\r\n this.lobeMix\r\n );\r\n this.$l.Vis = visGGX(this, this.NoV, this.NoL, this.avgAlpha);\r\n this.$l.F = fresnelSchlick(this, this.VoH, pb.vec3(this.F0), pb.vec3(1));\r\n this.$return(pb.mul(this.F, pb.mul(this.D, this.Vis)));\r\n }\r\n );\r\n return pb.getGlobalScope()[funcName](NoH, NoV, NoL, VoH, lobeRoughness, lobeMix, F0) as PBShaderExp;\r\n}\r\n\r\n/**\r\n * Fetches one column of a profile row from the packed table.\r\n *\r\n * @remarks\r\n * The table is `rgba32f`, hence `unfilterable-float` on WebGPU: the sampler must\r\n * be non-filtering, so this is an exact texel fetch and anything wanting\r\n * interpolation between columns has to lerp two fetches by hand.\r\n *\r\n * Emitted inline rather than behind a shader function: on WebGPU a texture\r\n * parameter needs its sampler passed alongside it, and `textureSampleLevel` on\r\n * the parameter alone compiles to nothing usable.\r\n *\r\n * @param scope - Shader scope.\r\n * @param tex - The packed profile table, as declared in the caller's scope.\r\n * @param texelSize - `vec2(1 / columns, 1 / rows)`.\r\n * @param row - Precomputed `v` coordinate of the profile's row.\r\n * @param column - Column to read, as a float.\r\n * @returns The `vec4` stored at that column.\r\n *\r\n * @internal\r\n */\r\nfunction readSSSProfileColumn(\r\n scope: PBInsideFunctionScope,\r\n tex: PBShaderExp,\r\n texelSize: PBShaderExp,\r\n row: PBShaderExp,\r\n column: PBShaderExp\r\n): PBShaderExp {\r\n const pb = scope.$builder;\r\n return pb.textureSampleLevel(tex, pb.vec2(pb.mul(pb.add(column, 0.5), texelSize.x), row), 0);\r\n}\r\n\r\n/**\r\n * Back-lit subsurface transmission.\r\n *\r\n * @param scope - Shader scope.\r\n * @param profileTex - The packed profile table.\r\n * @param profileTexelSize - `vec2(1 / columns, 1 / rows)` of that table.\r\n * @param profileId - Normalized profile id.\r\n * @param thickness - Encoded optical depth from the thickness pass, where 1\r\n * means \"nothing in the way\".\r\n * @param normal - Shading normal.\r\n * @param viewVec - Unit vector from the surface towards the eye.\r\n * @param lightDir - Unit vector from the surface towards the light.\r\n * @returns vec3 transmitted radiance; the caller applies light colour,\r\n * attenuation and the transmission shadow.\r\n *\r\n * @internal\r\n */\r\nexport function skinTransmission(\r\n scope: PBInsideFunctionScope,\r\n profileTex: PBShaderExp,\r\n profileTexelSize: PBShaderExp,\r\n profileId: PBShaderExp,\r\n thickness: PBShaderExp,\r\n normal: PBShaderExp,\r\n viewVec: PBShaderExp,\r\n lightDir: PBShaderExp\r\n): PBShaderExp {\r\n const pb = scope.$builder;\r\n const lutOffset = SSSProfile.transmissionLutOffset;\r\n const lutSize = SSSProfile.transmissionLutSize;\r\n const lastLutColumn = lutOffset + lutSize - 1;\r\n // Table reads stay inline (see readSSSProfileColumn); the locals are prefixed\r\n // so they cannot collide with the caller's. Rows are addressed by the profile\r\n // id, which arrives normalized because it rides in an 8-bit channel.\r\n scope.$l.zSkinTrRow = pb.mul(pb.add(pb.mul(pb.clamp(profileId, 0, 1), 255), 0.5), profileTexelSize.y);\r\n // GetTransmissionProfile. The index is `opticalDepth / MAX * (size - 1)` and\r\n // the decode is `opticalDepth = (1 - thickness) * MAX`, so the MAX cancels and\r\n // the encoded thickness maps onto the table directly.\r\n scope.$l.zSkinTrIndex = pb.mul(pb.clamp(pb.sub(1, thickness), 0, 1), lutSize - 1);\r\n scope.$l.zSkinTrI0 = pb.floor(scope.zSkinTrIndex);\r\n scope.$l.zSkinTrC0 = pb.add(scope.zSkinTrI0, lutOffset);\r\n scope.$l.zSkinTrC1 = pb.min(pb.add(scope.zSkinTrC0, 1), lastLutColumn);\r\n scope.$l.zSkinTrProfile = pb.mix(\r\n readSSSProfileColumn(scope, profileTex, profileTexelSize, scope.zSkinTrRow, scope.zSkinTrC0).rgb,\r\n readSSSProfileColumn(scope, profileTex, profileTexelSize, scope.zSkinTrRow, scope.zSkinTrC1).rgb,\r\n pb.sub(scope.zSkinTrIndex, scope.zSkinTrI0)\r\n );\r\n // (extinctionScale, normalScale, scatteringDistribution, 1 / ior)\r\n scope.$l.zSkinTrParams = readSSSProfileColumn(\r\n scope,\r\n profileTex,\r\n profileTexelSize,\r\n scope.zSkinTrRow,\r\n pb.float(SSSProfile.transmissionParamColumn)\r\n );\r\n return skinTransmissionPhase(\r\n scope,\r\n scope.zSkinTrProfile,\r\n scope.zSkinTrParams,\r\n thickness,\r\n normal,\r\n viewVec,\r\n lightDir\r\n );\r\n}\r\n\r\n/**\r\n * The part of the transmission BxDF that touches no textures.\r\n *\r\n * @remarks\r\n * Split out so the math can live behind a shader function while the table reads\r\n * stay inline at the call site, where the sampler is in scope.\r\n *\r\n * @param scope - Shader scope.\r\n * @param profile - The interpolated transmission profile, `rgb`.\r\n * @param params - `(extinctionScale, normalScale, scatteringDistribution, 1 / ior)`.\r\n * @param thickness - The raw encoding, still needed to spot the \"no data\" sentinel.\r\n * @param normal - Shading normal.\r\n * @param viewVec - Unit vector from the surface towards the eye.\r\n * @param lightDir - Unit vector from the surface towards the light.\r\n * @returns vec3 transmitted radiance.\r\n *\r\n * @internal\r\n */\r\nfunction skinTransmissionPhase(\r\n scope: PBInsideFunctionScope,\r\n profile: PBShaderExp,\r\n params: PBShaderExp,\r\n thickness: PBShaderExp,\r\n normal: PBShaderExp,\r\n viewVec: PBShaderExp,\r\n lightDir: PBShaderExp\r\n): PBShaderExp {\r\n const pb = scope.$builder;\r\n const funcName = 'lib_skinTransmissionPhase';\r\n pb.func(\r\n funcName,\r\n [\r\n pb.vec3('profile'),\r\n pb.vec4('params'),\r\n pb.float('thickness'),\r\n pb.vec3('normal'),\r\n pb.vec3('viewVec'),\r\n pb.vec3('lightDir')\r\n ],\r\n function () {\r\n // \"No data\" must be rejected rather than decoded: it decodes to zero\r\n // optical depth, the *most* transmissive entry, so letting it through lights\r\n // the subject from behind with a light that was never behind it. The\r\n // threshold sits in the gap between the largest encoding the pass can write\r\n // and the sentinel, so it clips no real measurement.\r\n this.$if(pb.greaterThan(this.thickness, 0.5 * (1 + SKIN_TRANSMISSION_NO_DATA_ENCODING)), function () {\r\n this.$return(pb.vec3(0));\r\n });\r\n this.$l.refracV = pb.refract(this.viewVec, pb.neg(this.normal), this.params.w);\r\n this.$l.cosJ = pb.dot(pb.neg(this.lightDir), this.refracV);\r\n this.$l.g = this.params.z;\r\n this.$l.g2 = pb.mul(this.g, this.g);\r\n this.$l.gcos = pb.sub(1, pb.mul(this.g, this.cosJ));\r\n this.$l.gcos2 = pb.mul(this.gcos, this.gcos);\r\n this.$l.phase = pb.div(pb.mul(0.5, pb.sub(1, this.g2)), pb.max(this.gcos2, 1e-5));\r\n this.$return(pb.mul(this.profile, this.phase));\r\n }\r\n );\r\n return pb.getGlobalScope()[funcName](profile, params, thickness, normal, viewVec, lightDir) as PBShaderExp;\r\n}\r\n"],"names":["OPACITY_THRESHOLD_EPS","skinSpecularEnergyTerms","scope","roughness","NoV","F0","pb","$builder","funcName","func","float","$l","r","max","c","E","sub","clamp","mul","pow","div","add","oneMinusC","pow5","Ef","F90","W","A","$return","vec2","getGlobalScope","skinDiffuseBRDF","NdotV","NdotL","VdotH","fd90","fd90m1","oneMinusNoV","pow5V","oneMinusNoL","pow5L","fdV","fdL","Math","PI","skinDualSpecularRoughness","opacity","lobe0Scale","lobe1Scale","fade","scale0","mix","scale1","skinDualLobeSpecular","NoH","NoL","VoH","lobeRoughness","lobeMix","a0","x","a1","y","avgRoughness","avgAlpha","D","distributionGGX","Vis","visGGX","F","fresnelSchlick","vec3","readSSSProfileColumn","tex","texelSize","row","column","textureSampleLevel","skinTransmission","profileTex","profileTexelSize","profileId","thickness","normal","viewVec","lightDir","lutOffset","SSSProfile","transmissionLutOffset","lutSize","transmissionLutSize","lastLutColumn","zSkinTrRow","zSkinTrIndex","zSkinTrI0","floor","zSkinTrC0","zSkinTrC1","min","zSkinTrProfile","rgb","zSkinTrParams","transmissionParamColumn","skinTransmissionPhase","profile","params","vec4","$if","greaterThan","SKIN_TRANSMISSION_NO_DATA_ENCODING","refracV","refract","neg","w","cosJ","dot","g","z","g2","gcos","gcos2","phase"],"mappings":";;;AAIA,+EACA,MAAMA,qBAA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CAACtB,EAAAA,CAAGY,GAAG,CAAC,IAAI,CAACsF,OAAO,EAAE,IAAI,CAACiB,KAAK,CAAA,CAAA;AAC9C,KAAA,CAAA;IAEF,OAAOnH,EAAAA,CAAGwB,cAAc,EAAE,CAACtB,QAAAA,CAAS,CAACgG,OAASC,EAAAA,MAAAA,EAAQvB,SAAWC,EAAAA,MAAAA,EAAQC,OAASC,EAAAA,QAAAA,CAAAA;AACpF;;;;"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Animated interleaved-gradient-noise pair used to decorrelate SSGI rays.
|
|
3
|
+
*
|
|
4
|
+
* Produces two low-discrepancy random numbers in [0, 1) for a given fragment,
|
|
5
|
+
* advanced per sample/frame through golden-ratio sequences so the temporal
|
|
6
|
+
* resolve pass converges the Monte-Carlo estimate.
|
|
7
|
+
*
|
|
8
|
+
* @param scope - The shader scope
|
|
9
|
+
* @param fragCoord - Fragment coordinate in pixels
|
|
10
|
+
* @param seed - Sequence index (frameIndex * sampleCount + sampleIndex)
|
|
11
|
+
* @returns A vec2 of pseudo random numbers in [0, 1)
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/ function SSGI_rand2(scope, fragCoord, seed) {
|
|
15
|
+
const pb = scope.$builder;
|
|
16
|
+
pb.func('SSGI_ign', [
|
|
17
|
+
pb.vec2('p')
|
|
18
|
+
], function() {
|
|
19
|
+
this.$return(pb.fract(pb.mul(52.9829189, pb.fract(pb.add(pb.mul(0.06711056, this.p.x), pb.mul(0.00583715, this.p.y))))));
|
|
20
|
+
});
|
|
21
|
+
pb.func('SSGI_rand2', [
|
|
22
|
+
pb.vec2('fragCoord'),
|
|
23
|
+
pb.float('seed')
|
|
24
|
+
], function() {
|
|
25
|
+
this.$l.n1 = this.SSGI_ign(this.fragCoord);
|
|
26
|
+
this.$l.n2 = this.SSGI_ign(pb.add(this.fragCoord, pb.vec2(5.588238, 5.588238)));
|
|
27
|
+
// Golden-ratio (and its square) sequences advance the pair every sample
|
|
28
|
+
this.$return(pb.fract(pb.add(pb.vec2(this.n1, this.n2), pb.mul(pb.vec2(0.61803398875, 0.38196601125), this.seed))));
|
|
29
|
+
});
|
|
30
|
+
return scope.SSGI_rand2(fragCoord, seed);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Cosine-weighted hemisphere sampling around a normal.
|
|
34
|
+
*
|
|
35
|
+
* With cosine-weighted sampling the Monte-Carlo estimator of the rendering
|
|
36
|
+
* equation's diffuse term reduces to the plain average of the sampled
|
|
37
|
+
* radiances, so the SSGI trace pass can simply accumulate hit colors.
|
|
38
|
+
*
|
|
39
|
+
* @param scope - The shader scope
|
|
40
|
+
* @param normal - Unit normal the hemisphere is oriented around
|
|
41
|
+
* @param rand - Two random numbers in [0, 1)
|
|
42
|
+
* @returns A unit direction inside the hemisphere
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/ function SSGI_cosineSampleHemisphere(scope, normal, rand) {
|
|
46
|
+
const pb = scope.$builder;
|
|
47
|
+
pb.func('SSGI_cosineSampleHemisphere', [
|
|
48
|
+
pb.vec3('n'),
|
|
49
|
+
pb.vec2('u')
|
|
50
|
+
], function() {
|
|
51
|
+
this.$l.up = this.$choice(pb.lessThan(pb.abs(this.n.z), 0.999), pb.vec3(0, 0, 1), pb.vec3(1, 0, 0));
|
|
52
|
+
this.$l.tangent = pb.normalize(pb.cross(this.up, this.n));
|
|
53
|
+
this.$l.bitangent = pb.cross(this.n, this.tangent);
|
|
54
|
+
this.$l.r = pb.sqrt(this.u.x);
|
|
55
|
+
this.$l.phi = pb.mul(this.u.y, Math.PI * 2);
|
|
56
|
+
this.$l.dir = pb.add(pb.mul(this.tangent, pb.mul(this.r, pb.cos(this.phi))), pb.mul(this.bitangent, pb.mul(this.r, pb.sin(this.phi))), pb.mul(this.n, pb.sqrt(pb.max(0, pb.sub(1, this.u.x)))));
|
|
57
|
+
this.$return(pb.normalize(this.dir));
|
|
58
|
+
});
|
|
59
|
+
return scope.SSGI_cosineSampleHemisphere(normal, rand);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { SSGI_cosineSampleHemisphere, SSGI_rand2 };
|
|
63
|
+
//# sourceMappingURL=ssgi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssgi.js","sources":["../../src/shaders/ssgi.ts"],"sourcesContent":["import type { PBInsideFunctionScope, PBShaderExp } from '@zephyr3d/device';\n\n/**\n * Animated interleaved-gradient-noise pair used to decorrelate SSGI rays.\n *\n * Produces two low-discrepancy random numbers in [0, 1) for a given fragment,\n * advanced per sample/frame through golden-ratio sequences so the temporal\n * resolve pass converges the Monte-Carlo estimate.\n *\n * @param scope - The shader scope\n * @param fragCoord - Fragment coordinate in pixels\n * @param seed - Sequence index (frameIndex * sampleCount + sampleIndex)\n * @returns A vec2 of pseudo random numbers in [0, 1)\n *\n * @internal\n */\nexport function SSGI_rand2(scope: PBInsideFunctionScope, fragCoord: PBShaderExp, seed: PBShaderExp) {\n const pb = scope.$builder;\n pb.func('SSGI_ign', [pb.vec2('p')], function () {\n this.$return(\n pb.fract(\n pb.mul(52.9829189, pb.fract(pb.add(pb.mul(0.06711056, this.p.x), pb.mul(0.00583715, this.p.y))))\n )\n );\n });\n pb.func('SSGI_rand2', [pb.vec2('fragCoord'), pb.float('seed')], function () {\n this.$l.n1 = this.SSGI_ign(this.fragCoord);\n this.$l.n2 = this.SSGI_ign(pb.add(this.fragCoord, pb.vec2(5.588238, 5.588238)));\n // Golden-ratio (and its square) sequences advance the pair every sample\n this.$return(\n pb.fract(pb.add(pb.vec2(this.n1, this.n2), pb.mul(pb.vec2(0.61803398875, 0.38196601125), this.seed)))\n );\n });\n return scope.SSGI_rand2(fragCoord, seed);\n}\n\n/**\n * Cosine-weighted hemisphere sampling around a normal.\n *\n * With cosine-weighted sampling the Monte-Carlo estimator of the rendering\n * equation's diffuse term reduces to the plain average of the sampled\n * radiances, so the SSGI trace pass can simply accumulate hit colors.\n *\n * @param scope - The shader scope\n * @param normal - Unit normal the hemisphere is oriented around\n * @param rand - Two random numbers in [0, 1)\n * @returns A unit direction inside the hemisphere\n *\n * @internal\n */\nexport function SSGI_cosineSampleHemisphere(\n scope: PBInsideFunctionScope,\n normal: PBShaderExp,\n rand: PBShaderExp\n) {\n const pb = scope.$builder;\n pb.func('SSGI_cosineSampleHemisphere', [pb.vec3('n'), pb.vec2('u')], function () {\n this.$l.up = this.$choice(pb.lessThan(pb.abs(this.n.z), 0.999), pb.vec3(0, 0, 1), pb.vec3(1, 0, 0));\n this.$l.tangent = pb.normalize(pb.cross(this.up, this.n));\n this.$l.bitangent = pb.cross(this.n, this.tangent);\n this.$l.r = pb.sqrt(this.u.x);\n this.$l.phi = pb.mul(this.u.y, Math.PI * 2);\n this.$l.dir = pb.add(\n pb.mul(this.tangent, pb.mul(this.r, pb.cos(this.phi))),\n pb.mul(this.bitangent, pb.mul(this.r, pb.sin(this.phi))),\n pb.mul(this.n, pb.sqrt(pb.max(0, pb.sub(1, this.u.x))))\n );\n this.$return(pb.normalize(this.dir));\n });\n return scope.SSGI_cosineSampleHemisphere(normal, rand);\n}\n"],"names":["SSGI_rand2","scope","fragCoord","seed","pb","$builder","func","vec2","$return","fract","mul","add","p","x","y","float","$l","n1","SSGI_ign","n2","SSGI_cosineSampleHemisphere","normal","rand","vec3","up","$choice","lessThan","abs","n","z","tangent","normalize","cross","bitangent","r","sqrt","u","phi","Math","PI","dir","cos","sin","max","sub"],"mappings":"AAEA;;;;;;;;;;;;;AAaC,IACM,SAASA,UAAAA,CAAWC,KAA4B,EAAEC,SAAsB,EAAEC,IAAiB,EAAA;IAChG,MAAMC,EAAAA,GAAKH,MAAMI,QAAQ;IACzBD,EAAGE,CAAAA,IAAI,CAAC,UAAY,EAAA;AAACF,QAAAA,EAAAA,CAAGG,IAAI,CAAC,GAAA;KAAK,EAAE,WAAA;AAClC,QAAA,IAAI,CAACC,OAAO,CACVJ,EAAAA,CAAGK,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AGM,CAAAA,GAAG,CAAC,IAAI,CAACwB,CAAC,EAAE9B,EAAAA,CAAGqC,GAAG,CAAC,IAAI,CAACJ,GAAG,KACnDjC,EAAGM,CAAAA,GAAG,CAAC,IAAI,CAACuB,SAAS,EAAE7B,EAAGM,CAAAA,GAAG,CAAC,IAAI,CAACwB,CAAC,EAAE9B,EAAGsC,CAAAA,GAAG,CAAC,IAAI,CAACL,GAAG,CAAA,CAAA,CAAA,EACrDjC,EAAGM,CAAAA,GAAG,CAAC,IAAI,CAACkB,CAAC,EAAExB,EAAG+B,CAAAA,IAAI,CAAC/B,EAAAA,CAAGuC,GAAG,CAAC,CAAA,EAAGvC,EAAGwC,CAAAA,GAAG,CAAC,CAAG,EAAA,IAAI,CAACR,CAAC,CAACvB,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA;QAErD,IAAI,CAACL,OAAO,CAACJ,EAAAA,CAAG2B,SAAS,CAAC,IAAI,CAACS,GAAG,CAAA,CAAA;AACpC,KAAA,CAAA;IACA,OAAOvC,KAAAA,CAAMmB,2BAA2B,CAACC,MAAQC,EAAAA,IAAAA,CAAAA;AACnD;;;;"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Matrix4x4 } from '@zephyr3d/base';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shared helpers for validating SSGI temporal history across frames.
|
|
5
|
+
*
|
|
6
|
+
* SSGI stores the surface depth of a frame as that frame's view-space Z (the
|
|
7
|
+
* distance along the camera forward axis, in world units). Comparing such a
|
|
8
|
+
* value against the *current* frame's view-space Z is only meaningful while the
|
|
9
|
+
* camera is still: rotating the camera turns the forward axis, so a static world
|
|
10
|
+
* point changes its view-space Z by roughly
|
|
11
|
+
*
|
|
12
|
+
* dz ~ dTheta * viewZ * tan(halfFovX) * |ndc.x|
|
|
13
|
+
*
|
|
14
|
+
* which is zero at the screen center and grows with both depth and screen
|
|
15
|
+
* eccentricity. At a plain mouse-look rate that already exceeds any reasonable
|
|
16
|
+
* absolute tolerance for distant off-center pixels, so history gets rejected in
|
|
17
|
+
* screen-edge bands even though it is perfectly valid. Every consumer therefore
|
|
18
|
+
* has to convert the current depth into the *previous* frame's view space before
|
|
19
|
+
* comparing.
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/ /**
|
|
23
|
+
* Relative share of the compared depth added to the absolute tolerance. 2% keeps
|
|
24
|
+
* a 10m surface within 0.2m, comfortably above rgba16f depth quantization while
|
|
25
|
+
* still separating surfaces that a bounce should not share.
|
|
26
|
+
* @internal
|
|
27
|
+
*/ const SSGI_DEPTH_TOLERANCE_SLOPE = 0.02;
|
|
28
|
+
/**
|
|
29
|
+
* `prevVP * inverse(currentVP)`: maps a current-frame clip position onto the
|
|
30
|
+
* previous frame's clip space, where `w` is the previous view-space Z.
|
|
31
|
+
*
|
|
32
|
+
* The current half uses the jittered inverse VP because every consumer
|
|
33
|
+
* reconstructs from a depth buffer that was rasterized with jitter applied.
|
|
34
|
+
* Jitter only shifts clip x/y, so pairing it with the unjittered `prevVPMatrix`
|
|
35
|
+
* still produces the correct `w`.
|
|
36
|
+
*
|
|
37
|
+
* Falls back to the current VP before any previous transform exists, which
|
|
38
|
+
* degenerates into comparing the current depth against itself - harmless,
|
|
39
|
+
* because the history textures are empty on that frame anyway.
|
|
40
|
+
*
|
|
41
|
+
* @param ctx - Current draw context
|
|
42
|
+
* @returns The reprojection matrix
|
|
43
|
+
* @internal
|
|
44
|
+
*/ function ssgiCurrentToPrevClipMatrix(ctx) {
|
|
45
|
+
const camera = ctx.camera;
|
|
46
|
+
const prevVP = camera.prevVPMatrix ?? camera.viewProjectionMatrix;
|
|
47
|
+
return Matrix4x4.multiply(prevVP, camera.jitteredInvVPMatrix);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Converts the current frame's linear depth at `uv` into the view-space Z it
|
|
51
|
+
* would have had in the previous frame, so it can be compared against the depth
|
|
52
|
+
* stored in the SSGI surface history.
|
|
53
|
+
*
|
|
54
|
+
* `currentToPrevClipMatrix` must be `prevViewProjection * inverse(currentViewProjection)`,
|
|
55
|
+
* mapping a current-frame clip position onto the previous frame's clip space. In
|
|
56
|
+
* a perspective projection the resulting `w` is exactly the previous view-space
|
|
57
|
+
* Z in world units, which is the quantity the surface pass wrote.
|
|
58
|
+
*
|
|
59
|
+
* @param scope - Current shader scope
|
|
60
|
+
* @param currentToPrevClipMatrix - `prevVP * invCurrentVP`, as a mat4
|
|
61
|
+
* @param uv - Screen uv of the pixel being validated
|
|
62
|
+
* @param linearDepth - Normalized linear depth (viewZ / far) at `uv`
|
|
63
|
+
* @param nearFar - Camera near and far planes
|
|
64
|
+
* @returns Previous-frame view-space Z, in world units
|
|
65
|
+
* @internal
|
|
66
|
+
*/ function ssgiPreviousViewDepth(scope, currentToPrevClipMatrix, uv, linearDepth, nearFar) {
|
|
67
|
+
const pb = scope.$builder;
|
|
68
|
+
const funcName = 'Z_ssgiPreviousViewDepth';
|
|
69
|
+
pb.func(funcName, [
|
|
70
|
+
pb.mat4('toPrevClip'),
|
|
71
|
+
pb.vec2('uv'),
|
|
72
|
+
pb.float('linearDepth'),
|
|
73
|
+
pb.vec2('nearFar')
|
|
74
|
+
], function() {
|
|
75
|
+
// Invert the perspective depth mapping. `linearDepth` is the normalized
|
|
76
|
+
// viewZ / far that the depth prepass stored, so the non-linear depth is
|
|
77
|
+
// (near / linearDepth - far) / (near - far) - identical to the
|
|
78
|
+
// reconstruction in SSGI_getPosition. Operating on the normalized value
|
|
79
|
+
// directly matters: converting to world-unit viewZ first and reusing the
|
|
80
|
+
// same expression silently drops a factor of `far`, which pins every
|
|
81
|
+
// pixel at the far plane and rejects all history.
|
|
82
|
+
this.$l.safeLinearDepth = pb.max(this.linearDepth, 1e-6);
|
|
83
|
+
this.$l.ndcZ = pb.div(pb.sub(pb.div(this.nearFar.x, this.safeLinearDepth), this.nearFar.y), pb.sub(this.nearFar.x, this.nearFar.y));
|
|
84
|
+
this.$l.clipPos = pb.vec4(pb.sub(pb.mul(this.uv, 2), pb.vec2(1)), pb.sub(pb.mul(pb.clamp(this.ndcZ, 0, 1), 2), 1), 1);
|
|
85
|
+
// clipPos is already normalized (w = 1 after the NDC divide), so the
|
|
86
|
+
// reprojected w is directly the previous view-space Z.
|
|
87
|
+
this.$return(pb.mul(this.toPrevClip, this.clipPos).w);
|
|
88
|
+
});
|
|
89
|
+
return scope[funcName](currentToPrevClipMatrix, uv, linearDepth, nearFar);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Depth tolerance for a history comparison at a given depth.
|
|
93
|
+
*
|
|
94
|
+
* A single absolute tolerance cannot serve the whole depth range: it is far too
|
|
95
|
+
* loose next to the camera, where a few centimetres separate distinct surfaces,
|
|
96
|
+
* and too tight in the distance, where depth precision and residual reprojection
|
|
97
|
+
* error both scale with viewZ. Scaling the floor by depth keeps the test at a
|
|
98
|
+
* roughly constant relative strictness.
|
|
99
|
+
*
|
|
100
|
+
* @param scope - Current shader scope
|
|
101
|
+
* @param baseTolerance - Configured absolute tolerance, in world units
|
|
102
|
+
* @param viewDepth - View-space Z the comparison happens at, in world units
|
|
103
|
+
* @returns Effective tolerance, in world units
|
|
104
|
+
* @internal
|
|
105
|
+
*/ function ssgiDepthTolerance(scope, baseTolerance, viewDepth) {
|
|
106
|
+
const pb = scope.$builder;
|
|
107
|
+
const funcName = 'Z_ssgiDepthTolerance';
|
|
108
|
+
pb.func(funcName, [
|
|
109
|
+
pb.float('baseTolerance'),
|
|
110
|
+
pb.float('viewDepth')
|
|
111
|
+
], function() {
|
|
112
|
+
this.$return(pb.max(pb.max(this.baseTolerance, 1e-4), pb.mul(pb.abs(this.viewDepth), SSGI_DEPTH_TOLERANCE_SLOPE)));
|
|
113
|
+
});
|
|
114
|
+
return scope[funcName](baseTolerance, viewDepth);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export { SSGI_DEPTH_TOLERANCE_SLOPE, ssgiCurrentToPrevClipMatrix, ssgiDepthTolerance, ssgiPreviousViewDepth };
|
|
118
|
+
//# sourceMappingURL=ssgi_reprojection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssgi_reprojection.js","sources":["../../src/shaders/ssgi_reprojection.ts"],"sourcesContent":["import { Matrix4x4 } from '@zephyr3d/base';\nimport type { PBInsideFunctionScope, PBShaderExp } from '@zephyr3d/device';\nimport type { DrawContext } from '../render/drawable';\n\n/**\n * Shared helpers for validating SSGI temporal history across frames.\n *\n * SSGI stores the surface depth of a frame as that frame's view-space Z (the\n * distance along the camera forward axis, in world units). Comparing such a\n * value against the *current* frame's view-space Z is only meaningful while the\n * camera is still: rotating the camera turns the forward axis, so a static world\n * point changes its view-space Z by roughly\n *\n * dz ~ dTheta * viewZ * tan(halfFovX) * |ndc.x|\n *\n * which is zero at the screen center and grows with both depth and screen\n * eccentricity. At a plain mouse-look rate that already exceeds any reasonable\n * absolute tolerance for distant off-center pixels, so history gets rejected in\n * screen-edge bands even though it is perfectly valid. Every consumer therefore\n * has to convert the current depth into the *previous* frame's view space before\n * comparing.\n *\n * @internal\n */\n\n/**\n * Relative share of the compared depth added to the absolute tolerance. 2% keeps\n * a 10m surface within 0.2m, comfortably above rgba16f depth quantization while\n * still separating surfaces that a bounce should not share.\n * @internal\n */\nexport const SSGI_DEPTH_TOLERANCE_SLOPE = 0.02;\n\n/**\n * `prevVP * inverse(currentVP)`: maps a current-frame clip position onto the\n * previous frame's clip space, where `w` is the previous view-space Z.\n *\n * The current half uses the jittered inverse VP because every consumer\n * reconstructs from a depth buffer that was rasterized with jitter applied.\n * Jitter only shifts clip x/y, so pairing it with the unjittered `prevVPMatrix`\n * still produces the correct `w`.\n *\n * Falls back to the current VP before any previous transform exists, which\n * degenerates into comparing the current depth against itself - harmless,\n * because the history textures are empty on that frame anyway.\n *\n * @param ctx - Current draw context\n * @returns The reprojection matrix\n * @internal\n */\nexport function ssgiCurrentToPrevClipMatrix(ctx: DrawContext): Matrix4x4 {\n const camera = ctx.camera;\n const prevVP = camera.prevVPMatrix ?? camera.viewProjectionMatrix;\n return Matrix4x4.multiply(prevVP, camera.jitteredInvVPMatrix);\n}\n\n/**\n * Converts the current frame's linear depth at `uv` into the view-space Z it\n * would have had in the previous frame, so it can be compared against the depth\n * stored in the SSGI surface history.\n *\n * `currentToPrevClipMatrix` must be `prevViewProjection * inverse(currentViewProjection)`,\n * mapping a current-frame clip position onto the previous frame's clip space. In\n * a perspective projection the resulting `w` is exactly the previous view-space\n * Z in world units, which is the quantity the surface pass wrote.\n *\n * @param scope - Current shader scope\n * @param currentToPrevClipMatrix - `prevVP * invCurrentVP`, as a mat4\n * @param uv - Screen uv of the pixel being validated\n * @param linearDepth - Normalized linear depth (viewZ / far) at `uv`\n * @param nearFar - Camera near and far planes\n * @returns Previous-frame view-space Z, in world units\n * @internal\n */\nexport function ssgiPreviousViewDepth(\n scope: PBInsideFunctionScope,\n currentToPrevClipMatrix: PBShaderExp,\n uv: PBShaderExp,\n linearDepth: PBShaderExp,\n nearFar: PBShaderExp\n): PBShaderExp {\n const pb = scope.$builder;\n const funcName = 'Z_ssgiPreviousViewDepth';\n pb.func(\n funcName,\n [pb.mat4('toPrevClip'), pb.vec2('uv'), pb.float('linearDepth'), pb.vec2('nearFar')],\n function () {\n // Invert the perspective depth mapping. `linearDepth` is the normalized\n // viewZ / far that the depth prepass stored, so the non-linear depth is\n // (near / linearDepth - far) / (near - far) - identical to the\n // reconstruction in SSGI_getPosition. Operating on the normalized value\n // directly matters: converting to world-unit viewZ first and reusing the\n // same expression silently drops a factor of `far`, which pins every\n // pixel at the far plane and rejects all history.\n this.$l.safeLinearDepth = pb.max(this.linearDepth, 1e-6);\n this.$l.ndcZ = pb.div(\n pb.sub(pb.div(this.nearFar.x, this.safeLinearDepth), this.nearFar.y),\n pb.sub(this.nearFar.x, this.nearFar.y)\n );\n this.$l.clipPos = pb.vec4(\n pb.sub(pb.mul(this.uv, 2), pb.vec2(1)),\n pb.sub(pb.mul(pb.clamp(this.ndcZ, 0, 1), 2), 1),\n 1\n );\n // clipPos is already normalized (w = 1 after the NDC divide), so the\n // reprojected w is directly the previous view-space Z.\n this.$return(pb.mul(this.toPrevClip, this.clipPos).w);\n }\n );\n return scope[funcName](currentToPrevClipMatrix, uv, linearDepth, nearFar) as PBShaderExp;\n}\n\n/**\n * Depth tolerance for a history comparison at a given depth.\n *\n * A single absolute tolerance cannot serve the whole depth range: it is far too\n * loose next to the camera, where a few centimetres separate distinct surfaces,\n * and too tight in the distance, where depth precision and residual reprojection\n * error both scale with viewZ. Scaling the floor by depth keeps the test at a\n * roughly constant relative strictness.\n *\n * @param scope - Current shader scope\n * @param baseTolerance - Configured absolute tolerance, in world units\n * @param viewDepth - View-space Z the comparison happens at, in world units\n * @returns Effective tolerance, in world units\n * @internal\n */\nexport function ssgiDepthTolerance(\n scope: PBInsideFunctionScope,\n baseTolerance: PBShaderExp,\n viewDepth: PBShaderExp\n): PBShaderExp {\n const pb = scope.$builder;\n const funcName = 'Z_ssgiDepthTolerance';\n pb.func(funcName, [pb.float('baseTolerance'), pb.float('viewDepth')], function () {\n this.$return(\n pb.max(pb.max(this.baseTolerance, 1e-4), pb.mul(pb.abs(this.viewDepth), SSGI_DEPTH_TOLERANCE_SLOPE))\n );\n });\n return scope[funcName](baseTolerance, viewDepth) as PBShaderExp;\n}\n"],"names":["SSGI_DEPTH_TOLERANCE_SLOPE","ssgiCurrentToPrevClipMatrix","ctx","camera","prevVP","prevVPMatrix","viewProjectionMatrix","Matrix4x4","multiply","jitteredInvVPMatrix","ssgiPreviousViewDepth","scope","currentToPrevClipMatrix","uv","linearDepth","nearFar","pb","$builder","funcName","func","mat4","vec2","float","$l","safeLinearDepth","max","ndcZ","div","sub","x","y","clipPos","vec4","mul","clamp","$return","toPrevClip","w","ssgiDepthTolerance","baseTolerance","viewDepth","abs"],"mappings":";;AAIA;;;;;;;;;;;;;;;;;;;;;;;;IA2BaA,MAAAA,0BAAAA,GAA6B;AAE1C;;;;;;;;;;;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