@zephyr3d/scene 0.9.26 → 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 +146 -30
- 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 +300 -56
- 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 +177 -3
- 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 +178 -200
- 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 +30475 -19865
- package/dist/index.js +67 -12
- 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/hairstrand.js +235 -235
- package/dist/material/hairstrand.js.map +1 -1
- package/dist/material/lambert.js +4 -1
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/material.js +362 -300
- 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 +223 -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 +733 -190
- 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 +2009 -201
- 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 +668 -63
- package/dist/posteffect/motionblur.js.map +1 -1
- package/dist/posteffect/posteffect.js +12 -1
- package/dist/posteffect/posteffect.js.map +1 -1
- package/dist/posteffect/postsss.js +572 -0
- package/dist/posteffect/postsss.js.map +1 -0
- package/dist/posteffect/sao.js +48 -50
- 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 +34 -15
- 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 +40 -39
- package/dist/render/abuffer_oit.js.map +1 -1
- package/dist/render/clipmap.js +328 -62
- 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 +26 -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 +53 -53
- 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 +8 -13
- package/dist/render/fbm_wavegenerator.js.map +1 -1
- package/dist/render/fft_wavegenerator.js +268 -136
- package/dist/render/fft_wavegenerator.js.map +1 -1
- package/dist/render/gerstner_wavegenerator.js +113 -28
- 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/hzb.js +80 -22
- package/dist/render/hzb.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 +23 -9
- 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/oit.js +11 -11
- package/dist/render/oit.js.map +1 -1
- 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 +198 -11
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +14 -7
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/rendergraph/blackboard.js +15 -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 +585 -59
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/render/rendergraph/frame_resource_requirements.js +1 -0
- package/dist/render/rendergraph/frame_resource_requirements.js.map +1 -1
- package/dist/render/rendergraph/history_resources.js +8 -1
- package/dist/render/rendergraph/history_resources.js.map +1 -1
- 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 +524 -0
- package/dist/render/underwater.js.map +1 -0
- 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 +1195 -0
- package/dist/render/water_caustics.js.map +1 -0
- 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 +36 -36
- 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 +997 -96
- 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/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 +40 -87
- package/dist/shaders/water.js.map +1 -1
- package/dist/shaders/water_medium.js +42 -0
- package/dist/shaders/water_medium.js.map +1 -0
- 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 +87 -49
- 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 +36 -6
- package/dist/utility/serialization/manager.js.map +1 -1
- package/dist/utility/serialization/scene/animation.js +77 -7
- 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 +140 -279
- 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 +2473 -114
- package/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/utility/serialization/types.js.map +1 -1
- package/dist/utility/shprojector.js +97 -109
- 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
|
@@ -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","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AAI,CAAC2G,KAAK,EAAE,IAAA,CAAA,CAAA;AAC3E,QAAA,IAAI,CAAC5F,OAAO,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;;;;"}
|
package/dist/shaders/ssr.js
CHANGED
|
@@ -220,12 +220,7 @@ import { REVERSE_Z } from '@zephyr3d/base';
|
|
|
220
220
|
this.$l.hitZ = pb.float();
|
|
221
221
|
this.numIterations = 0;
|
|
222
222
|
this.skippedIterations = pb.min(this.maxIterations, 1);
|
|
223
|
-
this.$for(pb.float('i'), 0,
|
|
224
|
-
if (pb.getDevice().type === 'webgl') {
|
|
225
|
-
this.$if(pb.greaterThanEqual(this.i, this.maxIterations), function() {
|
|
226
|
-
this.$break();
|
|
227
|
-
});
|
|
228
|
-
}
|
|
223
|
+
this.$for(pb.float('i'), 0, this.maxIterations, function() {
|
|
229
224
|
this.$if(pb.and(this.intersected, pb.greaterThanEqual(this.i, this.skippedIterations)), function() {
|
|
230
225
|
this.$break();
|
|
231
226
|
});
|
|
@@ -316,7 +311,7 @@ import { REVERSE_Z } from '@zephyr3d/base';
|
|
|
316
311
|
return giTraceOut ? scope.SSR_Linear2D_GI(viewPos, traceRay, viewMatrix, projMatrix, invProjMatrix, stride, maxDistance, maxIterations, thickness, cameraNearFar, textureSize, giTraceOut) : scope.SSR_Linear2D(viewPos, traceRay, viewMatrix, projMatrix, invProjMatrix, stride, maxDistance, maxIterations, thickness, cameraNearFar, textureSize);
|
|
317
312
|
}
|
|
318
313
|
/**
|
|
319
|
-
*
|
|
314
|
+
* InterleavedGradientNoise. Used as the temporal jitter
|
|
320
315
|
* (StepOffset) for the fixed-step HZB march below.
|
|
321
316
|
*/ function SSR_interleavedGradientNoise(scope, uv, frameId) {
|
|
322
317
|
const pb = scope.$builder;
|
|
@@ -330,33 +325,9 @@ import { REVERSE_Z } from '@zephyr3d/base';
|
|
|
330
325
|
return scope.SSR_IGN(uv, frameId);
|
|
331
326
|
}
|
|
332
327
|
/**
|
|
333
|
-
* Screen space ray intersection against the HZB
|
|
334
|
-
* SSRTRayCast.ush (InitScreenSpaceRayFromWorldSpace + CastScreenSpaceRay):
|
|
335
|
-
* a fixed-step linear march over the ray clipped/extended to the screen
|
|
336
|
-
* border, sampling the furthest-depth pyramid at a mip level that grows with
|
|
337
|
-
* roughness, with a slope-based CompareTolerance hit window and line-segment
|
|
338
|
-
* hit refinement.
|
|
339
|
-
*
|
|
340
|
-
* Convention differences vs UE5:
|
|
341
|
-
* - UE is reversed-Z (larger = closer); we use standard Z, so every depth
|
|
342
|
-
* difference is mirrored (`Diff = SampleDepth - SampleZ`).
|
|
343
|
-
* - UE view space has +z forward; ours has -z forward.
|
|
344
|
-
* - UE's HZB is a half-res pow2 pyramid and starts marching at its mip 1;
|
|
345
|
-
* ours is full-res at mip0. Under standard-Z the march starts at
|
|
346
|
-
* START_MIP = 0, because the coarse furthest-depth blocks quantize into a
|
|
347
|
-
* staircase that grazing rays periodically self-intersect, showing up as
|
|
348
|
-
* regular stripes TAA cannot converge. Under reverse-Z depth precision is
|
|
349
|
-
* nearly uniform, so the march starts at mip 1 like UE; rough reflections
|
|
350
|
-
* still climb the pyramid via the roughness mip ramp in both cases.
|
|
351
|
-
*
|
|
352
|
-
* `maxIterations` is the number of linear samples along the ray (UE NumSteps,
|
|
353
|
-
* typically 8..64), no longer the traversal iteration cap of the previous
|
|
354
|
-
* FidelityFX-style implementation.
|
|
328
|
+
* Screen space ray intersection against the HZB
|
|
355
329
|
*/ function screenSpaceRayTracing_HiZ(scope, viewPos, traceRay, viewMatrix, projMatrix, invProjMatrix, cameraNearFar, maxMipLevel, maxIterations, maxDistance, thickness, textureSize, HiZTexture, normalTexture, giTraceOut, roughness, stepOffset) {
|
|
356
330
|
const pb = scope.$builder;
|
|
357
|
-
// The r32f pyramid stores the furthest depth (max reduction; mip0 is the
|
|
358
|
-
// raw depth). Matches UE5 marching against the FurthestHZBTexture (UE is
|
|
359
|
-
// reversed-Z, so its furthest pyramid is the min reduction instead).
|
|
360
331
|
pb.func('SSR_loadDepth', [
|
|
361
332
|
pb.vec2('uv'),
|
|
362
333
|
pb.float('level')
|
|
@@ -372,9 +343,6 @@ import { REVERSE_Z } from '@zephyr3d/base';
|
|
|
372
343
|
this.u = pb.div(this.u, this.u.w);
|
|
373
344
|
this.$return(this.u.xyz);
|
|
374
345
|
});
|
|
375
|
-
// Port of UE5 GetStepScreenFactorToClipAtScreenEdge. Returns the multiplier
|
|
376
|
-
// for rayStepNDC so the ray ends exactly at the screen border. A factor
|
|
377
|
-
// above 1 extends short rays to the border (UE bExtendRayToScreenBorder).
|
|
378
346
|
pb.func('SSR_clipRayToScreenEdge', [
|
|
379
347
|
pb.vec2('rayStartNDC'),
|
|
380
348
|
pb.vec2('rayStepNDC')
|
|
@@ -384,9 +352,6 @@ import { REVERSE_Z } from '@zephyr3d/base';
|
|
|
384
352
|
this.$l.s = pb.sub(pb.vec2(1), pb.div(pb.max(pb.sub(pb.abs(pb.add(this.rayStepNDC, pb.mul(this.rayStartNDC, this.rayStepInvFactor))), pb.vec2(this.rayStepInvFactor)), pb.vec2(0)), this.absStep));
|
|
385
353
|
this.$return(pb.div(pb.min(this.s.x, this.s.y), pb.max(this.rayStepInvFactor, 1e-8)));
|
|
386
354
|
});
|
|
387
|
-
// Port of UE5 InitScreenSpaceRayFromWorldSpace, in view space (-z forward).
|
|
388
|
-
// Outputs the ray in "texture space": uv in [0,1], z = device depth in
|
|
389
|
-
// [0,1], the same mapping the HZB stores.
|
|
390
355
|
pb.func('SSR_initScreenSpaceRay', [
|
|
391
356
|
pb.vec3('viewPos'),
|
|
392
357
|
pb.vec3('rayDirection'),
|
|
@@ -397,8 +362,6 @@ import { REVERSE_Z } from '@zephyr3d/base';
|
|
|
397
362
|
pb.vec3('rayStepTS').out(),
|
|
398
363
|
pb.float('compareTolerance').out()
|
|
399
364
|
], function() {
|
|
400
|
-
// Rays heading towards the camera stop before reaching 5% of the
|
|
401
|
-
// surface view depth (UE: min(-0.95 * SceneDepth / ViewDirZ, TMax)).
|
|
402
365
|
this.$l.rayLength = this.$choice(pb.greaterThan(this.rayDirection.z, 0), pb.min(this.maxDistance, pb.div(pb.mul(-0.95, this.viewPos.z), pb.max(this.rayDirection.z, 1e-6))), this.maxDistance);
|
|
403
366
|
this.$l.rayEnd = pb.add(this.viewPos, pb.mul(this.rayDirection, this.rayLength));
|
|
404
367
|
this.$l.startH = pb.mul(this.projMatrix, pb.vec4(this.viewPos, 1));
|
|
@@ -406,8 +369,6 @@ import { REVERSE_Z } from '@zephyr3d/base';
|
|
|
406
369
|
this.$l.startNDC = pb.div(this.startH.xyz, this.startH.w);
|
|
407
370
|
this.$l.endNDC = pb.div(this.endH.xyz, this.endH.w);
|
|
408
371
|
this.$l.stepNDC = pb.sub(this.endNDC, this.startNDC);
|
|
409
|
-
// Always extend/clip the ray to the screen border so NumSteps samples
|
|
410
|
-
// cover the whole visible segment.
|
|
411
372
|
this.stepNDC = pb.mul(this.stepNDC, this.SSR_clipRayToScreenEdge(this.startNDC.xy, this.stepNDC.xy));
|
|
412
373
|
if (REVERSE_Z) {
|
|
413
374
|
// Reverse ZO canonical clip space: NDC z is already the device depth.
|
|
@@ -417,23 +378,11 @@ import { REVERSE_Z } from '@zephyr3d/base';
|
|
|
417
378
|
this.rayStartTS = pb.add(pb.mul(this.startNDC, 0.5), pb.vec3(0.5));
|
|
418
379
|
this.rayStepTS = pb.mul(this.stepNDC, 0.5);
|
|
419
380
|
}
|
|
420
|
-
// Depth-only step
|
|
421
|
-
// straight along the view forward axis for the slope tolerance.
|
|
381
|
+
// Depth-only step: project the point at rayLength straight along the view forward axis for the slope tolerance.
|
|
422
382
|
this.$l.depthH = pb.mul(this.projMatrix, pb.vec4(this.viewPos.xy, pb.sub(this.viewPos.z, this.rayLength), 1));
|
|
423
383
|
this.$l.depthTSz = REVERSE_Z ? pb.div(this.depthH.z, this.depthH.w) : pb.add(pb.mul(pb.div(this.depthH.z, this.depthH.w), 0.5), 0.5);
|
|
424
|
-
// Under standard Z depth grows away from the camera, mirroring UE's
|
|
425
|
-
// reversed-Z expression (RayStartScreen.z - RayDepthScreen.z); under
|
|
426
|
-
// reverse-Z the UE orientation applies directly.
|
|
427
384
|
this.compareTolerance = pb.max(pb.abs(this.rayStepTS.z), pb.mul(REVERSE_Z ? pb.sub(this.rayStartTS.z, this.depthTSz) : pb.sub(this.depthTSz, this.rayStartTS.z), this.slopeCompareToleranceScale));
|
|
428
385
|
});
|
|
429
|
-
// Port of UE5 CastScreenSpaceRay: NumSteps uniform samples in batches of 4,
|
|
430
|
-
// mip level ramped by roughness, tolerance-window hit test, uncertainty
|
|
431
|
-
// tracking and line-segment hit refinement.
|
|
432
|
-
// Standard-Z keeps 0 instead of UE's StartMipLevel=1: coarse-mip depth
|
|
433
|
-
// staircases combined with the poor far-depth resolution near 1.0 cause
|
|
434
|
-
// grazing-angle stripe artifacts. Under reverse-Z depth precision is nearly
|
|
435
|
-
// uniform along the ray, so the march starts at mip 1 like UE for better
|
|
436
|
-
// texture cache behavior.
|
|
437
386
|
const START_MIP = REVERSE_Z ? 1 : 0;
|
|
438
387
|
pb.func('SSR_castScreenSpaceRay', [
|
|
439
388
|
pb.vec3('rayStartTS'),
|
|
@@ -469,14 +418,8 @@ import { REVERSE_Z } from '@zephyr3d/base';
|
|
|
469
418
|
this.$l.hit2 = pb.bool(false);
|
|
470
419
|
this.$l.hit3 = pb.bool(false);
|
|
471
420
|
this.$l.numBatches = pb.ceil(pb.mul(this.numSteps, 0.25));
|
|
472
|
-
this.$for(pb.float('i'), 0,
|
|
473
|
-
if (pb.getDevice().type === 'webgl') {
|
|
474
|
-
this.$if(pb.greaterThanEqual(this.i, this.numBatches), function() {
|
|
475
|
-
this.$break();
|
|
476
|
-
});
|
|
477
|
-
}
|
|
421
|
+
this.$for(pb.float('i'), 0, this.numBatches, function() {
|
|
478
422
|
this.marchBase = pb.mul(this.i, 4);
|
|
479
|
-
// Two samples per mip step (UE: SamplesMip.xy = Level; Level += inc).
|
|
480
423
|
this.$l.mip01 = pb.min(this.level, this.maxMipLevel);
|
|
481
424
|
this.$l.mip23 = pb.min(pb.add(this.level, this.mipInc), this.maxMipLevel);
|
|
482
425
|
this.level = pb.add(this.level, pb.mul(this.mipInc, 2));
|
|
@@ -484,14 +427,9 @@ import { REVERSE_Z } from '@zephyr3d/base';
|
|
|
484
427
|
this.$l[`sampleT${j}`] = pb.add(this.marchBase, j + 1);
|
|
485
428
|
this.$l[`sampleUV${j}`] = pb.add(this.rayUVz.xy, pb.mul(this.rayStepUVz.xy, this[`sampleT${j}`]));
|
|
486
429
|
this.$l[`sampleZ${j}`] = pb.add(this.rayUVz.z, pb.mul(this.rayStepUVz.z, this[`sampleT${j}`]));
|
|
487
|
-
// Negative when the ray is behind the surface, hit window (-2T, 0).
|
|
488
|
-
// Under reverse-Z this is UE's original `SamplesZ - SampleDepth`;
|
|
489
|
-
// under standard Z the difference is mirrored.
|
|
490
430
|
this[`diff${j}`] = REVERSE_Z ? pb.sub(this[`sampleZ${j}`], this.SSR_loadDepth(this[`sampleUV${j}`], j < 2 ? this.mip01 : this.mip23)) : pb.sub(this.SSR_loadDepth(this[`sampleUV${j}`], j < 2 ? this.mip01 : this.mip23), this[`sampleZ${j}`]);
|
|
491
431
|
this[`hit${j}`] = pb.lessThan(pb.abs(pb.add(this[`diff${j}`], this.compareTolerance)), this.compareTolerance);
|
|
492
432
|
this.foundHit = pb.or(this.foundHit, this[`hit${j}`]);
|
|
493
|
-
// The ray went far behind geometry before any hit: its outcome
|
|
494
|
-
// cannot be resolved from the depth buffer (UE bUncertain).
|
|
495
433
|
this.uncertain = pb.or(this.uncertain, pb.and(pb.lessThan(pb.add(this[`diff${j}`], this.compareTolerance), pb.neg(this.compareTolerance)), pb.not(this.foundHit)));
|
|
496
434
|
}
|
|
497
435
|
this.$if(this.foundHit, function() {
|
|
@@ -500,8 +438,6 @@ import { REVERSE_Z } from '@zephyr3d/base';
|
|
|
500
438
|
this.lastDiff = this.diff3;
|
|
501
439
|
});
|
|
502
440
|
this.$if(this.foundHit, function() {
|
|
503
|
-
// Locate the first hit sample of the batch, then refine with a line
|
|
504
|
-
// segment intersection (UE: TimeLerp = saturate(D0 / (D0 - D1))).
|
|
505
441
|
this.$l.depthDiff0 = this.diff2;
|
|
506
442
|
this.$l.depthDiff1 = this.diff3;
|
|
507
443
|
this.$l.time0 = pb.float(3);
|
|
@@ -527,7 +463,6 @@ import { REVERSE_Z } from '@zephyr3d/base';
|
|
|
527
463
|
this.hitUVz = pb.add(this.rayUVz, pb.mul(this.rayStepUVz, this.intersectTime));
|
|
528
464
|
this.numIterations = this.intersectTime;
|
|
529
465
|
}).$else(function() {
|
|
530
|
-
// No certain intersection - the march covered the whole clipped ray.
|
|
531
466
|
this.hitUVz = pb.add(this.rayUVz, pb.mul(this.rayStepUVz, this.numSteps));
|
|
532
467
|
this.numIterations = this.numSteps;
|
|
533
468
|
});
|
|
@@ -557,7 +492,6 @@ import { REVERSE_Z } from '@zephyr3d/base';
|
|
|
557
492
|
this.$l.rayStartTS = pb.vec3();
|
|
558
493
|
this.$l.rayStepTS = pb.vec3();
|
|
559
494
|
this.$l.compareTolerance = pb.float();
|
|
560
|
-
// UE uses SlopeCompareToleranceScale 4 for SSR and 2 for SSGI.
|
|
561
495
|
this.SSR_initScreenSpaceRay(this.viewPos, this.rayDirection, this.maxDistance, pb.float(giTraceOut ? 2 : 4), this.projMatrix, this.rayStartTS, this.rayStepTS, this.compareTolerance);
|
|
562
496
|
this.$l.hitUVz = pb.vec3();
|
|
563
497
|
this.$l.foundHit = pb.bool();
|
|
@@ -569,7 +503,6 @@ import { REVERSE_Z } from '@zephyr3d/base';
|
|
|
569
503
|
this.$l.surfaceZ = this.SSR_loadDepth(this.hitUVz.xy, 0);
|
|
570
504
|
this.$if(ShaderHelper.isFarthestDepth(this, this.surfaceZ), function() {
|
|
571
505
|
if (giTraceOut) {
|
|
572
|
-
// The intersection resolved onto a sky texel, so the ray escaped.
|
|
573
506
|
this.giTrace = pb.vec3(0, 1, 0);
|
|
574
507
|
}
|
|
575
508
|
this.$return(pb.vec4(0));
|
|
@@ -577,10 +510,6 @@ import { REVERSE_Z } from '@zephyr3d/base';
|
|
|
577
510
|
this.$l.hit3D = invProjectPosition(this, this.hitUVz, this.invProjMatrix);
|
|
578
511
|
this.confidence = validateHit(this, this.hitUVz.xy, this.hit3D, this.surfaceZ, this.thickness, this.rayStartTS.xy, this.rayDirection, this.viewMatrix, this.invProjMatrix, this.textureSize, normalTexture);
|
|
579
512
|
if (giTraceOut) {
|
|
580
|
-
// Keep only the thickness term of validateHit: a hit far from the
|
|
581
|
-
// sampled surface may be a thin-object false positive, which is a
|
|
582
|
-
// genuine geometric doubt. The border, near-self and backface vetoes
|
|
583
|
-
// bound reflection artifacts and must not gate diffuse occlusion.
|
|
584
513
|
this.$l.giSurfaceVS = invProjectPosition(this, pb.vec3(this.hitUVz.xy, this.surfaceZ), this.invProjMatrix);
|
|
585
514
|
this.$l.giThicknessFade = pb.sub(1, pb.smoothStep(0, this.thickness, pb.distance(this.giSurfaceVS, this.hit3D)));
|
|
586
515
|
this.giTrace = pb.vec3(1, 0, pb.mul(this.giThicknessFade, this.giThicknessFade));
|
|
@@ -588,10 +517,6 @@ import { REVERSE_Z } from '@zephyr3d/base';
|
|
|
588
517
|
});
|
|
589
518
|
if (giTraceOut) {
|
|
590
519
|
hitBranch.$else(function() {
|
|
591
|
-
// The ray is always extended to the screen border, so a march that
|
|
592
|
-
// finished without ever going behind geometry is a proven escape.
|
|
593
|
-
// An uncertain march (went far behind geometry before any hit) is
|
|
594
|
-
// indeterminate, not unoccluded (UE bUncertain semantics).
|
|
595
520
|
this.giTrace = pb.vec3(0, pb.float(pb.not(this.uncertain)), 0);
|
|
596
521
|
});
|
|
597
522
|
}
|
|
@@ -605,85 +530,7 @@ import { REVERSE_Z } from '@zephyr3d/base';
|
|
|
605
530
|
const roughnessArg = roughness ?? 0;
|
|
606
531
|
const stepOffsetArg = stepOffset ?? 0.5;
|
|
607
532
|
return giTraceOut ? scope.SSR_HiZ_GI(viewPos, traceRay, viewMatrix, projMatrix, invProjMatrix, cameraNearFar, maxDistance, thickness, textureSize, pb.sub(maxMipLevel, 1), maxIterations, roughnessArg, stepOffsetArg, giTraceOut) : scope.SSR_HiZ(viewPos, traceRay, viewMatrix, projMatrix, invProjMatrix, cameraNearFar, maxDistance, thickness, textureSize, pb.sub(maxMipLevel, 1), maxIterations, roughnessArg, stepOffsetArg);
|
|
608
|
-
}
|
|
609
|
-
float2 cell(float2 ray, float2 cell_count, uint camera) {
|
|
610
|
-
return floor(ray.xy * cell_count);
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
float2 cell_count(float level) {
|
|
614
|
-
return input_texture2_size / (level == 0.0 ? 1.0 : exp2(level));
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
float3 intersect_cell_boundary(float3 pos, float3 dir, float2 cell_id, float2 cell_count, float2 cross_step, float2 cross_offset, uint camera) {
|
|
618
|
-
float2 cell_size = 1.0 / cell_count;
|
|
619
|
-
float2 planes = cell_id/cell_count + cell_size * cross_step;
|
|
620
|
-
|
|
621
|
-
float2 solutions = (planes - pos)/dir.xy;
|
|
622
|
-
float3 intersection_pos = pos + dir * min(solutions.x, solutions.y);
|
|
623
|
-
|
|
624
|
-
intersection_pos.xy += (solutions.x < solutions.y) ? float2(cross_offset.x, 0.0) : float2(0.0, cross_offset.y);
|
|
625
|
-
|
|
626
|
-
return intersection_pos;
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
bool crossed_cell_boundary(float2 cell_id_one, float2 cell_id_two) {
|
|
630
|
-
return (int)cell_id_one.x != (int)cell_id_two.x || (int)cell_id_one.y != (int)cell_id_two.y;
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
float minimum_depth_plane(float2 ray, float level, float2 cell_count, uint camera) {
|
|
634
|
-
return input_texture2.Load(int3(vr_stereo_to_mono(ray.xy, camera) * cell_count, level)).r;
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
float3 hi_z_trace(float3 p, float3 v, in uint camera, out uint iterations) {
|
|
638
|
-
float level = HIZ_START_LEVEL;
|
|
639
|
-
float3 v_z = v/v.z;
|
|
640
|
-
float2 hi_z_size = cell_count(level);
|
|
641
|
-
float3 ray = p;
|
|
642
|
-
|
|
643
|
-
float2 cross_step = float2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);
|
|
644
|
-
float2 cross_offset = cross_step * 0.00001;
|
|
645
|
-
cross_step = saturate(cross_step);
|
|
646
|
-
|
|
647
|
-
float2 ray_cell = cell(ray.xy, hi_z_size.xy, camera);
|
|
648
|
-
ray = intersect_cell_boundary(ray, v, ray_cell, hi_z_size, cross_step, cross_offset, camera);
|
|
649
|
-
|
|
650
|
-
iterations = 0;
|
|
651
|
-
while(level >= HIZ_STOP_LEVEL && iterations < MAX_ITERATIONS) {
|
|
652
|
-
// get the cell number of the current ray
|
|
653
|
-
float2 current_cell_count = cell_count(level);
|
|
654
|
-
float2 old_cell_id = cell(ray.xy, current_cell_count, camera);
|
|
655
|
-
|
|
656
|
-
// get the minimum depth plane in which the current ray resides
|
|
657
|
-
float min_z = minimum_depth_plane(ray.xy, level, current_cell_count, camera);
|
|
658
|
-
|
|
659
|
-
// intersect only if ray depth is below the minimum depth plane
|
|
660
|
-
float3 tmp_ray = ray;
|
|
661
|
-
if(v.z > 0) {
|
|
662
|
-
float min_minus_ray = min_z - ray.z;
|
|
663
|
-
tmp_ray = min_minus_ray > 0 ? ray + v_z*min_minus_ray : tmp_ray;
|
|
664
|
-
float2 new_cell_id = cell(tmp_ray.xy, current_cell_count, camera);
|
|
665
|
-
if(crossed_cell_boundary(old_cell_id, new_cell_id)) {
|
|
666
|
-
tmp_ray = intersect_cell_boundary(ray, v, old_cell_id, current_cell_count, cross_step, cross_offset, camera);
|
|
667
|
-
level = min(HIZ_MAX_LEVEL, level + 2.0f);
|
|
668
|
-
}else{
|
|
669
|
-
if(level == 1 && abs(min_minus_ray) > 0.0001) {
|
|
670
|
-
tmp_ray = intersect_cell_boundary(ray, v, old_cell_id, current_cell_count, cross_step, cross_offset, camera);
|
|
671
|
-
level = 2;
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
} else if(ray.z < min_z) {
|
|
675
|
-
tmp_ray = intersect_cell_boundary(ray, v, old_cell_id, current_cell_count, cross_step, cross_offset, camera);
|
|
676
|
-
level = min(HIZ_MAX_LEVEL, level + 2.0f);
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
ray.xyz = tmp_ray.xyz;
|
|
680
|
-
--level;
|
|
681
|
-
|
|
682
|
-
++iterations;
|
|
683
|
-
}
|
|
684
|
-
return ray;
|
|
685
|
-
}
|
|
686
|
-
*/
|
|
533
|
+
}
|
|
687
534
|
|
|
688
535
|
export { SSR_calcJitter, SSR_interleavedGradientNoise, screenSpaceRayTracing_HiZ, screenSpaceRayTracing_Linear2D };
|
|
689
536
|
//# sourceMappingURL=ssr.js.map
|