@zephyr3d/scene 0.9.5 → 0.9.7
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/dist/animation/joint_dynamics/controller.js +92 -32
- package/dist/animation/joint_dynamics/controller.js.map +1 -1
- package/dist/animation/joint_dynamics/convex_collider.js +320 -0
- package/dist/animation/joint_dynamics/convex_collider.js.map +1 -0
- package/dist/animation/joint_dynamics/joint_dynamics_system.js +57 -19
- package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
- package/dist/animation/joint_dynamics/solver.js +71 -27
- package/dist/animation/joint_dynamics/solver.js.map +1 -1
- package/dist/animation/joint_dynamics_modifier.js +21 -20
- package/dist/animation/joint_dynamics_modifier.js.map +1 -1
- package/dist/animation/skeleton.js +7 -10
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/app/engine.js +134 -140
- package/dist/app/engine.js.map +1 -1
- package/dist/app/scriptregistry.js +47 -16
- package/dist/app/scriptregistry.js.map +1 -1
- package/dist/asset/assetmanager.js +3 -1
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/model.js +346 -7
- package/dist/asset/model.js.map +1 -1
- package/dist/avatar/wardrobe.js +20 -16
- package/dist/avatar/wardrobe.js.map +1 -1
- package/dist/camera/camera.js +416 -210
- package/dist/camera/camera.js.map +1 -1
- package/dist/index.d.ts +1350 -621
- package/dist/index.js +6 -11
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +1 -1
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/lambert.js +1 -1
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/material.js +23 -1
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +178 -23
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/albedocolor.js +4 -4
- package/dist/material/mixins/albedocolor.js.map +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js +2 -1
- package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
- package/dist/material/mixins/lightmodel/lambert.js +2 -1
- package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +63 -16
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +105 -32
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +16 -6
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
- package/dist/material/mixins/lit.js +1 -1
- package/dist/material/mixins/lit.js.map +1 -1
- package/dist/material/mixins/pbr/common.js +276 -65
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/mixins/texture.js +3 -3
- package/dist/material/mixins/texture.js.map +1 -1
- package/dist/material/mixins/vertexcolor.js +2 -2
- package/dist/material/mixins/vertexcolor.js.map +1 -1
- package/dist/material/msdf_text.js +3 -3
- package/dist/material/msdf_text.js.map +1 -1
- package/dist/material/mtoon.js +574 -0
- package/dist/material/mtoon.js.map +1 -0
- package/dist/material/pbrblueprint.js +499 -336
- package/dist/material/pbrblueprint.js.map +1 -1
- package/dist/material/pbrmr.js +118 -100
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/pbrsg.js +1 -1
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/shader/helper.js +324 -294
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/subsurfaceprofile.js +812 -0
- package/dist/material/subsurfaceprofile.js.map +1 -0
- package/dist/material/unlit.js +1 -1
- package/dist/material/unlit.js.map +1 -1
- package/dist/posteffect/compositor.js +46 -11
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/ssr.js +422 -96
- package/dist/posteffect/ssr.js.map +1 -1
- package/dist/posteffect/sss.js +1053 -0
- package/dist/posteffect/sss.js.map +1 -0
- package/dist/posteffect/taa.js +61 -60
- package/dist/posteffect/taa.js.map +1 -1
- package/dist/render/abuffer_oit.js +63 -12
- package/dist/render/abuffer_oit.js.map +1 -1
- package/dist/render/cluster_light.js +6 -5
- package/dist/render/cluster_light.js.map +1 -1
- package/dist/render/drawable.js +1 -5
- package/dist/render/drawable.js.map +1 -1
- package/dist/render/drawable_mixin.js +2 -1
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/fbm_wavegenerator.js +2 -1
- package/dist/render/fbm_wavegenerator.js.map +1 -1
- package/dist/render/gerstner_wavegenerator.js +2 -1
- package/dist/render/gerstner_wavegenerator.js.map +1 -1
- package/dist/render/globalbindgroup_allocator.js +2 -1
- package/dist/render/globalbindgroup_allocator.js.map +1 -1
- package/dist/render/lightpass.js +110 -23
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/render_queue.js +51 -8
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +80 -66
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/rendergraph/device_pool_allocator.js +8 -0
- package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
- package/dist/render/rendergraph/forward_plus_builder.js +481 -95
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/render/rendergraph/history_resource_manager.js +55 -0
- package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
- package/dist/render/rendergraph/history_resources.js +3 -1
- package/dist/render/rendergraph/history_resources.js.map +1 -1
- package/dist/render/rendergraph/types.js.map +1 -1
- package/dist/render/renderpass.js +10 -4
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/sky.js +31 -1
- package/dist/render/sky.js.map +1 -1
- package/dist/render/weightedblended_oit.js +23 -5
- package/dist/render/weightedblended_oit.js.map +1 -1
- package/dist/scene/basesprite.js +4 -2
- package/dist/scene/basesprite.js.map +1 -1
- package/dist/scene/batchgroup.js +3 -1
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +11 -1
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/light.js +21 -3
- package/dist/scene/light.js.map +1 -1
- package/dist/scene/mesh.js +29 -14
- 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 +5 -2
- package/dist/scene/msdftext.js.map +1 -1
- package/dist/scene/msdftextsprite.js +5 -3
- package/dist/scene/msdftextsprite.js.map +1 -1
- package/dist/scene/particlesys.js +3 -1
- package/dist/scene/particlesys.js.map +1 -1
- package/dist/scene/scene.js +6 -5
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/terrain-cm/grass.js +4 -2
- package/dist/scene/terrain-cm/grass.js.map +1 -1
- package/dist/scene/terrain-cm/grassmaterial.js +2 -1
- package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
- package/dist/scene/terrain-cm/terrain-cm.js +4 -2
- package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
- package/dist/scene/water.js +4 -2
- package/dist/scene/water.js.map +1 -1
- package/dist/shaders/shadow.js +26 -393
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shadow/esm.js +112 -12
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/pcf_opt.js +2 -2
- package/dist/shadow/pcf_opt.js.map +1 -1
- package/dist/shadow/pcf_pd.js +19 -10
- package/dist/shadow/pcf_pd.js.map +1 -1
- package/dist/shadow/shader.js +58 -7
- package/dist/shadow/shader.js.map +1 -1
- package/dist/shadow/shadow_impl.js +6 -0
- package/dist/shadow/shadow_impl.js.map +1 -1
- package/dist/shadow/shadow_region.js +229 -0
- package/dist/shadow/shadow_region.js.map +1 -0
- package/dist/shadow/shadowmapper.js +67 -59
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/vsm.js +45 -19
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/text/font/cff_font.js +890 -0
- package/dist/text/font/cff_font.js.map +1 -0
- package/dist/text/font/font_asset.js +17 -3
- package/dist/text/font/font_asset.js.map +1 -1
- package/dist/utility/blueprint/common/constants.js +8 -8
- package/dist/utility/blueprint/common/constants.js.map +1 -1
- package/dist/utility/blueprint/material/pbr.js +31 -4
- package/dist/utility/blueprint/material/pbr.js.map +1 -1
- package/dist/utility/blueprint/material/texture.js +1 -17
- package/dist/utility/blueprint/material/texture.js.map +1 -1
- package/dist/utility/serialization/manager.js +327 -359
- package/dist/utility/serialization/manager.js.map +1 -1
- package/dist/utility/serialization/scene/animation.js +5 -2
- package/dist/utility/serialization/scene/animation.js.map +1 -1
- package/dist/utility/serialization/scene/batch.js +4 -1
- package/dist/utility/serialization/scene/batch.js.map +1 -1
- package/dist/utility/serialization/scene/camera.js +249 -54
- package/dist/utility/serialization/scene/camera.js.map +1 -1
- package/dist/utility/serialization/scene/common.js +37 -1
- package/dist/utility/serialization/scene/common.js.map +1 -1
- package/dist/utility/serialization/scene/light.js +42 -3
- package/dist/utility/serialization/scene/light.js.map +1 -1
- package/dist/utility/serialization/scene/material.js +1112 -646
- package/dist/utility/serialization/scene/material.js.map +1 -1
- package/dist/utility/serialization/scene/mesh.js +7 -4
- package/dist/utility/serialization/scene/mesh.js.map +1 -1
- package/dist/utility/serialization/scene/node.js +31 -12
- package/dist/utility/serialization/scene/node.js.map +1 -1
- package/dist/utility/serialization/scene/particle.js +4 -1
- package/dist/utility/serialization/scene/particle.js.map +1 -1
- package/dist/utility/serialization/scene/primitive.js +3 -1
- package/dist/utility/serialization/scene/primitive.js.map +1 -1
- package/dist/utility/serialization/scene/scene.js +18 -0
- package/dist/utility/serialization/scene/scene.js.map +1 -1
- package/dist/utility/serialization/scene/sprite.js +6 -3
- package/dist/utility/serialization/scene/sprite.js.map +1 -1
- package/dist/utility/serialization/scene/terrain.js +5 -2
- package/dist/utility/serialization/scene/terrain.js.map +1 -1
- package/dist/utility/serialization/scene/text.js +3 -1
- package/dist/utility/serialization/scene/text.js.map +1 -1
- package/dist/utility/serialization/scene/water.js +4 -1
- package/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/utility/textures/ltcdata.js +6 -0
- package/dist/utility/textures/ltcdata.js.map +1 -0
- package/dist/utility/textures/ltclut.js +61 -0
- package/dist/utility/textures/ltclut.js.map +1 -0
- package/dist/values.js +9 -1
- package/dist/values.js.map +1 -1
- package/package.json +3 -3
- package/dist/animation/ik/ik_chain_builder.js +0 -68
- package/dist/animation/ik/ik_chain_builder.js.map +0 -1
- package/dist/animation/ik/ik_pole_constraint.js +0 -123
- package/dist/animation/ik/ik_pole_constraint.js.map +0 -1
- package/dist/animation/ik/ik_track.js +0 -96
- package/dist/animation/ik/ik_track.js.map +0 -1
- package/dist/animation/ik_postprocessor.js +0 -71
- package/dist/animation/ik_postprocessor.js.map +0 -1
- package/dist/animation/joint_dynamics/math.js +0 -16
- package/dist/animation/joint_dynamics/math.js.map +0 -1
- package/dist/animation/manual_transform_processor.js +0 -156
- package/dist/animation/manual_transform_processor.js.map +0 -1
- package/dist/animation/skeleton_postprocessor.js +0 -50
- package/dist/animation/skeleton_postprocessor.js.map +0 -1
- package/dist/animation/spring2/collision.js +0 -469
- package/dist/animation/spring2/collision.js.map +0 -1
- package/dist/animation/spring2/constraints.js +0 -329
- package/dist/animation/spring2/constraints.js.map +0 -1
- package/dist/animation/spring2/controller.js +0 -434
- package/dist/animation/spring2/controller.js.map +0 -1
- package/dist/animation/spring2/math.js +0 -16
- package/dist/animation/spring2/math.js.map +0 -1
- package/dist/animation/spring2/solver.js +0 -624
- package/dist/animation/spring2/solver.js.map +0 -1
- package/dist/animation/spring2/spring_system.js +0 -118
- package/dist/animation/spring2/spring_system.js.map +0 -1
- package/dist/animation/spring2/types.js +0 -19
- package/dist/animation/spring2/types.js.map +0 -1
- package/dist/animation/spring_postprocessor.js +0 -54
- package/dist/animation/spring_postprocessor.js.map +0 -1
- package/dist/asset/loaders/gltf/gltf_loader.js +0 -1276
- package/dist/asset/loaders/gltf/gltf_loader.js.map +0 -1
- package/dist/asset/loaders/gltf/helpers.js +0 -331
- package/dist/asset/loaders/gltf/helpers.js.map +0 -1
- package/dist/material/sprite3d.js +0 -301
- package/dist/material/sprite3d.js.map +0 -1
- package/dist/material/sprite3d_std.js +0 -116
- package/dist/material/sprite3d_std.js.map +0 -1
- package/dist/material/sprite3dblueprint.js +0 -235
- package/dist/material/sprite3dblueprint.js.map +0 -1
- package/dist/material/sprite_sdf.js +0 -106
- package/dist/material/sprite_sdf.js.map +0 -1
- package/dist/material/terrainmaterial.js +0 -368
- package/dist/material/terrainmaterial.js.map +0 -1
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js +0 -38
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js.map +0 -1
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js +0 -10
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js.map +0 -1
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js +0 -127
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js.map +0 -1
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js +0 -263
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js.map +0 -1
- package/dist/render/deferredlightpass.js +0 -510
- package/dist/render/deferredlightpass.js.map +0 -1
- package/dist/render/deferredshadowlightpass.js +0 -428
- package/dist/render/deferredshadowlightpass.js.map +0 -1
- package/dist/render/gbufferpass.js +0 -50
- package/dist/render/gbufferpass.js.map +0 -1
- package/dist/scene/sdftextsprite.js +0 -322
- package/dist/scene/sdftextsprite.js.map +0 -1
- package/dist/scene/sprite3d.js +0 -18
- package/dist/scene/sprite3d.js.map +0 -1
- package/dist/scene/terrain/grass.js +0 -280
- package/dist/scene/terrain/grass.js.map +0 -1
- package/dist/scene/terrain/heightfield.js +0 -475
- package/dist/scene/terrain/heightfield.js.map +0 -1
- package/dist/scene/terrain/patch.js +0 -532
- package/dist/scene/terrain/patch.js.map +0 -1
- package/dist/scene/terrain/quadtree.js +0 -461
- package/dist/scene/terrain/quadtree.js.map +0 -1
- package/dist/scene/terrain/terrain.js +0 -231
- package/dist/scene/terrain/terrain.js.map +0 -1
- package/dist/src/animation/animation.js +0 -127
- package/dist/src/animation/animation.js.map +0 -1
- package/dist/src/animation/animationset.js +0 -255
- package/dist/src/animation/animationset.js.map +0 -1
- package/dist/src/animation/animationtrack.js +0 -34
- package/dist/src/animation/animationtrack.js.map +0 -1
- package/dist/src/animation/eulerrotationtrack.js +0 -52
- package/dist/src/animation/eulerrotationtrack.js.map +0 -1
- package/dist/src/animation/morphtarget.js +0 -93
- package/dist/src/animation/morphtarget.js.map +0 -1
- package/dist/src/animation/morphtrack.js +0 -70
- package/dist/src/animation/morphtrack.js.map +0 -1
- package/dist/src/animation/proptrack.js +0 -161
- package/dist/src/animation/proptrack.js.map +0 -1
- package/dist/src/animation/rotationtrack.js +0 -51
- package/dist/src/animation/rotationtrack.js.map +0 -1
- package/dist/src/animation/scaletrack.js +0 -50
- package/dist/src/animation/scaletrack.js.map +0 -1
- package/dist/src/animation/skeleton.js +0 -204
- package/dist/src/animation/skeleton.js.map +0 -1
- package/dist/src/animation/translationtrack.js +0 -50
- package/dist/src/animation/translationtrack.js.map +0 -1
- package/dist/src/app/app.js +0 -129
- package/dist/src/app/app.js.map +0 -1
- package/dist/src/app/inputmgr.js +0 -267
- package/dist/src/app/inputmgr.js.map +0 -1
- package/dist/src/asset/assetmanager.js +0 -404
- package/dist/src/asset/assetmanager.js.map +0 -1
- package/dist/src/asset/builtin.js +0 -337
- package/dist/src/asset/builtin.js.map +0 -1
- package/dist/src/asset/loaders/dds/dds.js +0 -470
- package/dist/src/asset/loaders/dds/dds.js.map +0 -1
- package/dist/src/asset/loaders/dds/dds_loader.js +0 -28
- package/dist/src/asset/loaders/dds/dds_loader.js.map +0 -1
- package/dist/src/asset/loaders/gltf/gltf_loader.js +0 -1265
- package/dist/src/asset/loaders/gltf/gltf_loader.js.map +0 -1
- package/dist/src/asset/loaders/gltf/helpers.js +0 -327
- package/dist/src/asset/loaders/gltf/helpers.js.map +0 -1
- package/dist/src/asset/loaders/hdr/hdr.js +0 -180
- package/dist/src/asset/loaders/hdr/hdr.js.map +0 -1
- package/dist/src/asset/loaders/image/tga_Loader.js +0 -116
- package/dist/src/asset/loaders/image/tga_Loader.js.map +0 -1
- package/dist/src/asset/loaders/image/webimage_loader.js +0 -63
- package/dist/src/asset/loaders/image/webimage_loader.js.map +0 -1
- package/dist/src/asset/loaders/loader.js +0 -45
- package/dist/src/asset/loaders/loader.js.map +0 -1
- package/dist/src/asset/model.js +0 -414
- package/dist/src/asset/model.js.map +0 -1
- package/dist/src/blitter/bilateralblur.js +0 -221
- package/dist/src/blitter/bilateralblur.js.map +0 -1
- package/dist/src/blitter/blitter.js +0 -390
- package/dist/src/blitter/blitter.js.map +0 -1
- package/dist/src/blitter/box.js +0 -118
- package/dist/src/blitter/box.js.map +0 -1
- package/dist/src/blitter/copy.js +0 -22
- package/dist/src/blitter/copy.js.map +0 -1
- package/dist/src/blitter/gaussianblur.js +0 -228
- package/dist/src/blitter/gaussianblur.js.map +0 -1
- package/dist/src/camera/base.js +0 -92
- package/dist/src/camera/base.js.map +0 -1
- package/dist/src/camera/camera.js +0 -1005
- package/dist/src/camera/camera.js.map +0 -1
- package/dist/src/camera/fps.js +0 -238
- package/dist/src/camera/fps.js.map +0 -1
- package/dist/src/camera/orbit.js +0 -245
- package/dist/src/camera/orbit.js.map +0 -1
- package/dist/src/camera/orthocamera.js +0 -167
- package/dist/src/camera/orthocamera.js.map +0 -1
- package/dist/src/camera/perspectivecamera.js +0 -141
- package/dist/src/camera/perspectivecamera.js.map +0 -1
- package/dist/src/index.js +0 -120
- package/dist/src/index.js.map +0 -1
- package/dist/src/material/blinn.js +0 -81
- package/dist/src/material/blinn.js.map +0 -1
- package/dist/src/material/grassmaterial.js +0 -113
- package/dist/src/material/grassmaterial.js.map +0 -1
- package/dist/src/material/lambert.js +0 -92
- package/dist/src/material/lambert.js.map +0 -1
- package/dist/src/material/material.js +0 -301
- package/dist/src/material/material.js.map +0 -1
- package/dist/src/material/meshmaterial.js +0 -704
- package/dist/src/material/meshmaterial.js.map +0 -1
- package/dist/src/material/mixins/albedocolor.js +0 -76
- package/dist/src/material/mixins/albedocolor.js.map +0 -1
- package/dist/src/material/mixins/foliage.js +0 -47
- package/dist/src/material/mixins/foliage.js.map +0 -1
- package/dist/src/material/mixins/lightmodel/blinnphong.js +0 -112
- package/dist/src/material/mixins/lightmodel/blinnphong.js.map +0 -1
- package/dist/src/material/mixins/lightmodel/lambert.js +0 -58
- package/dist/src/material/mixins/lightmodel/lambert.js.map +0 -1
- package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js +0 -178
- package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js.map +0 -1
- package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js +0 -139
- package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js.map +0 -1
- package/dist/src/material/mixins/lit.js +0 -476
- package/dist/src/material/mixins/lit.js.map +0 -1
- package/dist/src/material/mixins/pbr/common.js +0 -918
- package/dist/src/material/mixins/pbr/common.js.map +0 -1
- package/dist/src/material/mixins/texture.js +0 -172
- package/dist/src/material/mixins/texture.js.map +0 -1
- package/dist/src/material/mixins/vertexcolor.js +0 -56
- package/dist/src/material/mixins/vertexcolor.js.map +0 -1
- package/dist/src/material/particle.js +0 -178
- package/dist/src/material/particle.js.map +0 -1
- package/dist/src/material/pbrmr.js +0 -97
- package/dist/src/material/pbrmr.js.map +0 -1
- package/dist/src/material/pbrsg.js +0 -97
- package/dist/src/material/pbrsg.js.map +0 -1
- package/dist/src/material/shader/helper.js +0 -1209
- package/dist/src/material/shader/helper.js.map +0 -1
- package/dist/src/material/terrain-cm.js +0 -606
- package/dist/src/material/terrain-cm.js.map +0 -1
- package/dist/src/material/terrainmaterial.js +0 -375
- package/dist/src/material/terrainmaterial.js.map +0 -1
- package/dist/src/material/unlit.js +0 -41
- package/dist/src/material/unlit.js.map +0 -1
- package/dist/src/material/water.js +0 -417
- package/dist/src/material/water.js.map +0 -1
- package/dist/src/posteffect/bloom.js +0 -361
- package/dist/src/posteffect/bloom.js.map +0 -1
- package/dist/src/posteffect/compositor.js +0 -226
- package/dist/src/posteffect/compositor.js.map +0 -1
- package/dist/src/posteffect/fxaa.js +0 -273
- package/dist/src/posteffect/fxaa.js.map +0 -1
- package/dist/src/posteffect/grayscale.js +0 -69
- package/dist/src/posteffect/grayscale.js.map +0 -1
- package/dist/src/posteffect/motionblur.js +0 -96
- package/dist/src/posteffect/motionblur.js.map +0 -1
- package/dist/src/posteffect/posteffect.js +0 -126
- package/dist/src/posteffect/posteffect.js.map +0 -1
- package/dist/src/posteffect/sao.js +0 -324
- package/dist/src/posteffect/sao.js.map +0 -1
- package/dist/src/posteffect/ssr.js +0 -489
- package/dist/src/posteffect/ssr.js.map +0 -1
- package/dist/src/posteffect/taa.js +0 -172
- package/dist/src/posteffect/taa.js.map +0 -1
- package/dist/src/posteffect/tonemap.js +0 -94
- package/dist/src/posteffect/tonemap.js.map +0 -1
- package/dist/src/render/abuffer_oit.js +0 -361
- package/dist/src/render/abuffer_oit.js.map +0 -1
- package/dist/src/render/clipmap.js +0 -851
- package/dist/src/render/clipmap.js.map +0 -1
- package/dist/src/render/cluster_light.js +0 -333
- package/dist/src/render/cluster_light.js.map +0 -1
- package/dist/src/render/cull_visitor.js +0 -187
- package/dist/src/render/cull_visitor.js.map +0 -1
- package/dist/src/render/depthpass.js +0 -68
- package/dist/src/render/depthpass.js.map +0 -1
- package/dist/src/render/drawable_mixin.js +0 -227
- package/dist/src/render/drawable_mixin.js.map +0 -1
- package/dist/src/render/envlight.js +0 -463
- package/dist/src/render/envlight.js.map +0 -1
- package/dist/src/render/fbm_wavegenerator.js +0 -251
- package/dist/src/render/fbm_wavegenerator.js.map +0 -1
- package/dist/src/render/fft_wavegenerator.js +0 -1006
- package/dist/src/render/fft_wavegenerator.js.map +0 -1
- package/dist/src/render/fullscreenquad.js +0 -38
- package/dist/src/render/fullscreenquad.js.map +0 -1
- package/dist/src/render/gerstner_wavegenerator.js +0 -314
- package/dist/src/render/gerstner_wavegenerator.js.map +0 -1
- package/dist/src/render/globalbindgroup_allocator.js +0 -60
- package/dist/src/render/globalbindgroup_allocator.js.map +0 -1
- package/dist/src/render/hzb.js +0 -273
- package/dist/src/render/hzb.js.map +0 -1
- package/dist/src/render/lightpass.js +0 -172
- package/dist/src/render/lightpass.js.map +0 -1
- package/dist/src/render/objectcolorpass.js +0 -51
- package/dist/src/render/objectcolorpass.js.map +0 -1
- package/dist/src/render/primitive.js +0 -364
- package/dist/src/render/primitive.js.map +0 -1
- package/dist/src/render/render_queue.js +0 -467
- package/dist/src/render/render_queue.js.map +0 -1
- package/dist/src/render/renderbundle_wrapper.js +0 -152
- package/dist/src/render/renderbundle_wrapper.js.map +0 -1
- package/dist/src/render/renderer.js +0 -455
- package/dist/src/render/renderer.js.map +0 -1
- package/dist/src/render/renderpass.js +0 -200
- package/dist/src/render/renderpass.js.map +0 -1
- package/dist/src/render/shadowmap_pass.js +0 -56
- package/dist/src/render/shadowmap_pass.js.map +0 -1
- package/dist/src/render/sky.js +0 -1103
- package/dist/src/render/sky.js.map +0 -1
- package/dist/src/render/weightedblended_oit.js +0 -168
- package/dist/src/render/weightedblended_oit.js.map +0 -1
- package/dist/src/scene/batchgroup.js +0 -162
- package/dist/src/scene/batchgroup.js.map +0 -1
- package/dist/src/scene/environment.js +0 -209
- package/dist/src/scene/environment.js.map +0 -1
- package/dist/src/scene/graph_node.js +0 -72
- package/dist/src/scene/graph_node.js.map +0 -1
- package/dist/src/scene/light.js +0 -416
- package/dist/src/scene/light.js.map +0 -1
- package/dist/src/scene/mesh.js +0 -341
- package/dist/src/scene/mesh.js.map +0 -1
- package/dist/src/scene/octree.js +0 -649
- package/dist/src/scene/octree.js.map +0 -1
- package/dist/src/scene/particlesys.js +0 -738
- package/dist/src/scene/particlesys.js.map +0 -1
- package/dist/src/scene/raycast_visitor.js +0 -103
- package/dist/src/scene/raycast_visitor.js.map +0 -1
- package/dist/src/scene/scene.js +0 -284
- package/dist/src/scene/scene.js.map +0 -1
- package/dist/src/scene/scene_node.js +0 -732
- package/dist/src/scene/scene_node.js.map +0 -1
- package/dist/src/scene/terrain/grass.js +0 -278
- package/dist/src/scene/terrain/grass.js.map +0 -1
- package/dist/src/scene/terrain/heightfield.js +0 -475
- package/dist/src/scene/terrain/heightfield.js.map +0 -1
- package/dist/src/scene/terrain/patch.js +0 -530
- package/dist/src/scene/terrain/patch.js.map +0 -1
- package/dist/src/scene/terrain/quadtree.js +0 -461
- package/dist/src/scene/terrain/quadtree.js.map +0 -1
- package/dist/src/scene/terrain/terrain.js +0 -246
- package/dist/src/scene/terrain/terrain.js.map +0 -1
- package/dist/src/scene/terrain-cm/grass.js +0 -594
- package/dist/src/scene/terrain-cm/grass.js.map +0 -1
- package/dist/src/scene/terrain-cm/grassmaterial.js +0 -159
- package/dist/src/scene/terrain-cm/grassmaterial.js.map +0 -1
- package/dist/src/scene/terrain-cm/terrain-cm.js +0 -538
- package/dist/src/scene/terrain-cm/terrain-cm.js.map +0 -1
- package/dist/src/scene/water.js +0 -374
- package/dist/src/scene/water.js.map +0 -1
- package/dist/src/shaders/atmosphere.js +0 -957
- package/dist/src/shaders/atmosphere.js.map +0 -1
- package/dist/src/shaders/fog.js +0 -112
- package/dist/src/shaders/fog.js.map +0 -1
- package/dist/src/shaders/misc.js +0 -266
- package/dist/src/shaders/misc.js.map +0 -1
- package/dist/src/shaders/noise.js +0 -222
- package/dist/src/shaders/noise.js.map +0 -1
- package/dist/src/shaders/pbr.js +0 -51
- package/dist/src/shaders/pbr.js.map +0 -1
- package/dist/src/shaders/shadow.js +0 -636
- package/dist/src/shaders/shadow.js.map +0 -1
- package/dist/src/shaders/ssr.js +0 -490
- package/dist/src/shaders/ssr.js.map +0 -1
- package/dist/src/shaders/temporal.js +0 -215
- package/dist/src/shaders/temporal.js.map +0 -1
- package/dist/src/shaders/water.js +0 -756
- package/dist/src/shaders/water.js.map +0 -1
- package/dist/src/shadow/esm.js +0 -237
- package/dist/src/shadow/esm.js.map +0 -1
- package/dist/src/shadow/pcf_opt.js +0 -181
- package/dist/src/shadow/pcf_opt.js.map +0 -1
- package/dist/src/shadow/pcf_pd.js +0 -189
- package/dist/src/shadow/pcf_pd.js.map +0 -1
- package/dist/src/shadow/shader.js +0 -37
- package/dist/src/shadow/shader.js.map +0 -1
- package/dist/src/shadow/shadow_impl.js +0 -15
- package/dist/src/shadow/shadow_impl.js.map +0 -1
- package/dist/src/shadow/shadowmapper.js +0 -790
- package/dist/src/shadow/shadowmapper.js.map +0 -1
- package/dist/src/shadow/ssm.js +0 -159
- package/dist/src/shadow/ssm.js.map +0 -1
- package/dist/src/shadow/vsm.js +0 -297
- package/dist/src/shadow/vsm.js.map +0 -1
- package/dist/src/shapes/box.js +0 -386
- package/dist/src/shapes/box.js.map +0 -1
- package/dist/src/shapes/cylinder.js +0 -125
- package/dist/src/shapes/cylinder.js.map +0 -1
- package/dist/src/shapes/plane.js +0 -88
- package/dist/src/shapes/plane.js.map +0 -1
- package/dist/src/shapes/shape.js +0 -87
- package/dist/src/shapes/shape.js.map +0 -1
- package/dist/src/shapes/sphere.js +0 -114
- package/dist/src/shapes/sphere.js.map +0 -1
- package/dist/src/shapes/tetrahedron.js +0 -188
- package/dist/src/shapes/tetrahedron.js.map +0 -1
- package/dist/src/shapes/torus.js +0 -111
- package/dist/src/shapes/torus.js.map +0 -1
- package/dist/src/utility/aabbtree.js +0 -400
- package/dist/src/utility/aabbtree.js.map +0 -1
- package/dist/src/utility/bounding_volume.js +0 -29
- package/dist/src/utility/bounding_volume.js.map +0 -1
- package/dist/src/utility/debug.js +0 -28
- package/dist/src/utility/debug.js.map +0 -1
- package/dist/src/utility/draco/decoder.js +0 -116
- package/dist/src/utility/draco/decoder.js.map +0 -1
- package/dist/src/utility/misc.js +0 -105
- package/dist/src/utility/misc.js.map +0 -1
- package/dist/src/utility/panorama.js +0 -163
- package/dist/src/utility/panorama.js.map +0 -1
- package/dist/src/utility/pmrem.js +0 -354
- package/dist/src/utility/pmrem.js.map +0 -1
- package/dist/src/utility/rendermipmap.js +0 -115
- package/dist/src/utility/rendermipmap.js.map +0 -1
- package/dist/src/utility/serialization/json.js +0 -402
- package/dist/src/utility/serialization/json.js.map +0 -1
- package/dist/src/utility/serialization/manager.js +0 -623
- package/dist/src/utility/serialization/manager.js.map +0 -1
- package/dist/src/utility/serialization/scene/animation.js +0 -248
- package/dist/src/utility/serialization/scene/animation.js.map +0 -1
- package/dist/src/utility/serialization/scene/batch.js +0 -59
- package/dist/src/utility/serialization/scene/batch.js.map +0 -1
- package/dist/src/utility/serialization/scene/camera.js +0 -790
- package/dist/src/utility/serialization/scene/camera.js.map +0 -1
- package/dist/src/utility/serialization/scene/common.js +0 -222
- package/dist/src/utility/serialization/scene/common.js.map +0 -1
- package/dist/src/utility/serialization/scene/light.js +0 -575
- package/dist/src/utility/serialization/scene/light.js.map +0 -1
- package/dist/src/utility/serialization/scene/material.js +0 -1111
- package/dist/src/utility/serialization/scene/material.js.map +0 -1
- package/dist/src/utility/serialization/scene/mesh.js +0 -148
- package/dist/src/utility/serialization/scene/mesh.js.map +0 -1
- package/dist/src/utility/serialization/scene/misc.js +0 -39
- package/dist/src/utility/serialization/scene/misc.js.map +0 -1
- package/dist/src/utility/serialization/scene/node.js +0 -451
- package/dist/src/utility/serialization/scene/node.js.map +0 -1
- package/dist/src/utility/serialization/scene/particle.js +0 -425
- package/dist/src/utility/serialization/scene/particle.js.map +0 -1
- package/dist/src/utility/serialization/scene/primitive.js +0 -692
- package/dist/src/utility/serialization/scene/primitive.js.map +0 -1
- package/dist/src/utility/serialization/scene/scene.js +0 -704
- package/dist/src/utility/serialization/scene/scene.js.map +0 -1
- package/dist/src/utility/serialization/scene/terrain.js +0 -488
- package/dist/src/utility/serialization/scene/terrain.js.map +0 -1
- package/dist/src/utility/serialization/scene/water.js +0 -465
- package/dist/src/utility/serialization/scene/water.js.map +0 -1
- package/dist/src/utility/shprojector.js +0 -297
- package/dist/src/utility/shprojector.js.map +0 -1
- package/dist/src/utility/textures/ggxlut.js +0 -213
- package/dist/src/utility/textures/ggxlut.js.map +0 -1
- package/dist/src/utility/textures/gradientnoise.js +0 -62
- package/dist/src/utility/textures/gradientnoise.js.map +0 -1
- package/dist/src/utility/textures/randomnoise.js +0 -41
- package/dist/src/utility/textures/randomnoise.js.map +0 -1
- package/dist/src/values.js +0 -162
- package/dist/src/values.js.map +0 -1
- package/dist/utility/blueprint/material/common.js +0 -7
- package/dist/utility/blueprint/material/common.js.map +0 -1
- package/dist/utility/serialization/blueprint/constants.js +0 -255
- package/dist/utility/serialization/blueprint/constants.js.map +0 -1
- package/dist/utility/serialization/blueprint/material/constants.js +0 -203
- package/dist/utility/serialization/blueprint/material/constants.js.map +0 -1
- package/dist/utility/serialization/blueprint/material/texture.js +0 -165
- package/dist/utility/serialization/blueprint/material/texture.js.map +0 -1
- package/dist/utility/serialization/scene/cloth_script.js +0 -834
- package/dist/utility/serialization/scene/cloth_script.js.map +0 -1
- package/dist/utility/serialization/scene/spring_script.js +0 -596
- package/dist/utility/serialization/scene/spring_script.js.map +0 -1
|
@@ -1,790 +0,0 @@
|
|
|
1
|
-
import { Matrix4x4, Frustum, Vector3, AABB, Vector4, retainObject, CubeFace } from '@zephyr3d/base';
|
|
2
|
-
import { Camera } from '../camera/camera.js';
|
|
3
|
-
import { SSM } from './ssm.js';
|
|
4
|
-
import { ESM } from './esm.js';
|
|
5
|
-
import { VSM } from './vsm.js';
|
|
6
|
-
import { PCFPD } from './pcf_pd.js';
|
|
7
|
-
import { PCFOPT } from './pcf_opt.js';
|
|
8
|
-
import { Application } from '../app/app.js';
|
|
9
|
-
import { LIGHT_TYPE_NONE, LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_POINT } from '../values.js';
|
|
10
|
-
import { ShaderHelper } from '../material/shader/helper.js';
|
|
11
|
-
|
|
12
|
-
const tmpMatrix = new Matrix4x4();
|
|
13
|
-
const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
14
|
-
// const zeroPosition = Vector3.zero();
|
|
15
|
-
/**
|
|
16
|
-
* The shadow map generator
|
|
17
|
-
* @public
|
|
18
|
-
*/ class ShadowMapper {
|
|
19
|
-
/** @internal */ static _snapMatrix = new Matrix4x4();
|
|
20
|
-
/** @internal */ static _target = new Vector3();
|
|
21
|
-
/** @internal */ static _up = new Vector3();
|
|
22
|
-
/** @internal */ static _frustumMin = new Vector3();
|
|
23
|
-
/** @internal */ static _frustumMax = new Vector3();
|
|
24
|
-
/** @internal */ static _frustumCenter = new Vector3();
|
|
25
|
-
/** @internal */ static _lightCameras = new WeakMap();
|
|
26
|
-
/** @internal */ static _shadowMapParams = [];
|
|
27
|
-
/** @internal */ _light;
|
|
28
|
-
/** @internal */ _config;
|
|
29
|
-
/** @internal */ _resourceDirty;
|
|
30
|
-
/** @internal */ _shadowMode;
|
|
31
|
-
/** @internal */ _shadowDistance;
|
|
32
|
-
/** @internal */ _impl;
|
|
33
|
-
/** @internal */ _pdSampleCount;
|
|
34
|
-
/** @internal */ _pdSampleRadius;
|
|
35
|
-
/** @internal */ _pcfKernelSize;
|
|
36
|
-
/** @internal */ _vsmBlurKernelSize;
|
|
37
|
-
/** @internal */ _vsmBlurRadius;
|
|
38
|
-
/** @internal */ _vsmDarkness;
|
|
39
|
-
/** @internal */ _esmBlur;
|
|
40
|
-
/** @internal */ _esmBlurKernelSize;
|
|
41
|
-
/** @internal */ _esmBlurRadius;
|
|
42
|
-
/** @internal */ _esmDepthScale;
|
|
43
|
-
/** @internal */ _shadowRegion;
|
|
44
|
-
/**
|
|
45
|
-
* Creates an instance of ShadowMapper
|
|
46
|
-
* @param light - The light that is used to generate shadow map
|
|
47
|
-
*/ constructor(light){
|
|
48
|
-
this._light = light;
|
|
49
|
-
this._config = {
|
|
50
|
-
shadowMapSize: 1024,
|
|
51
|
-
numCascades: 1,
|
|
52
|
-
splitLambda: 0.5,
|
|
53
|
-
depthBias: 0.5,
|
|
54
|
-
normalBias: 0.2,
|
|
55
|
-
nearClip: 1
|
|
56
|
-
};
|
|
57
|
-
this._resourceDirty = true;
|
|
58
|
-
this._shadowMode = 'hard';
|
|
59
|
-
this._shadowDistance = 2000;
|
|
60
|
-
this._impl = null;
|
|
61
|
-
this._pdSampleCount = 12;
|
|
62
|
-
this._pdSampleRadius = 4;
|
|
63
|
-
this._pcfKernelSize = 5;
|
|
64
|
-
this._vsmBlurKernelSize = 5;
|
|
65
|
-
this._vsmBlurRadius = 4;
|
|
66
|
-
this._vsmDarkness = 0.3;
|
|
67
|
-
this._esmBlur = true;
|
|
68
|
-
this._esmBlurKernelSize = 5;
|
|
69
|
-
this._esmBlurRadius = 4;
|
|
70
|
-
this._esmDepthScale = 200;
|
|
71
|
-
this._shadowRegion = null;
|
|
72
|
-
this.applyMode(this._shadowMode);
|
|
73
|
-
}
|
|
74
|
-
copyFrom(other) {
|
|
75
|
-
this.shadowMapSize = other.shadowMapSize;
|
|
76
|
-
this.shadowRegion = other.shadowRegion ? new AABB(other.shadowRegion) : null;
|
|
77
|
-
this.shadowDistance = other.shadowDistance;
|
|
78
|
-
this.numShadowCascades = other.numShadowCascades;
|
|
79
|
-
this.splitLambda = other.splitLambda;
|
|
80
|
-
this.depthBias = other.depthBias;
|
|
81
|
-
this.normalBias = other.normalBias;
|
|
82
|
-
this.nearClip = other.nearClip;
|
|
83
|
-
this.mode = other.mode;
|
|
84
|
-
this.pdSampleCount = other.pdSampleCount;
|
|
85
|
-
this.pdSampleRadius = other.pdSampleRadius;
|
|
86
|
-
this.pcfKernelSize = other.pcfKernelSize;
|
|
87
|
-
this.vsmBlurKernelSize = other.vsmBlurKernelSize;
|
|
88
|
-
this.vsmBlurRadius = other.vsmBlurRadius;
|
|
89
|
-
this.vsmDarkness = other.vsmDarkness;
|
|
90
|
-
this.esmBlur = other.esmBlur;
|
|
91
|
-
this.esmBlurKernelSize = other.esmBlurKernelSize;
|
|
92
|
-
this.esmBlurRadius = other.esmBlurRadius;
|
|
93
|
-
this.esmDepthScale = other.esmDepthScale;
|
|
94
|
-
}
|
|
95
|
-
/** The light that is used to generate shadow map */ get light() {
|
|
96
|
-
return this._light;
|
|
97
|
-
}
|
|
98
|
-
/** Size of the shadow map */ get shadowMapSize() {
|
|
99
|
-
return this._config.shadowMapSize;
|
|
100
|
-
}
|
|
101
|
-
set shadowMapSize(num) {
|
|
102
|
-
if (!Number.isInteger(num) || num < 1) {
|
|
103
|
-
console.error(`invalid shadow map size: ${num}`);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
if (this._config.shadowMapSize !== num) {
|
|
107
|
-
this._config.shadowMapSize = num;
|
|
108
|
-
this._resourceDirty = true;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
/** Shadow region for directional light */ get shadowRegion() {
|
|
112
|
-
return this._shadowRegion;
|
|
113
|
-
}
|
|
114
|
-
set shadowRegion(region) {
|
|
115
|
-
this._shadowRegion = region;
|
|
116
|
-
}
|
|
117
|
-
/** Maximum distance from the camera, shadow will not be rendered beyond this range */ get shadowDistance() {
|
|
118
|
-
return this._shadowDistance;
|
|
119
|
-
}
|
|
120
|
-
set shadowDistance(val) {
|
|
121
|
-
this._shadowDistance = Math.max(0, val);
|
|
122
|
-
}
|
|
123
|
-
/** Count of the cascades, The maximum value is 4 */ get numShadowCascades() {
|
|
124
|
-
return this._config.numCascades;
|
|
125
|
-
}
|
|
126
|
-
set numShadowCascades(num) {
|
|
127
|
-
if (num !== 1 && num !== 2 && num !== 3 && num !== 4) {
|
|
128
|
-
console.error(`invalid shadow cascade number: ${num}`);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
if (!this._light.isDirectionLight() && num > 1) {
|
|
132
|
-
console.error(`only directional light can have more than one shadow cascades`);
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
if (num !== this._config.numCascades) {
|
|
136
|
-
this._config.numCascades = num;
|
|
137
|
-
this._resourceDirty = true;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
/** The split lambda for cascaded shadow mapping */ get splitLambda() {
|
|
141
|
-
return this._config.splitLambda;
|
|
142
|
-
}
|
|
143
|
-
set splitLambda(val) {
|
|
144
|
-
if (this._config.splitLambda !== val) {
|
|
145
|
-
this._config.splitLambda = val;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/** Depth bias for the shadow map */ get depthBias() {
|
|
149
|
-
return this._config.depthBias;
|
|
150
|
-
}
|
|
151
|
-
set depthBias(val) {
|
|
152
|
-
this._config.depthBias = val;
|
|
153
|
-
}
|
|
154
|
-
/** Normal bias for the shadow map */ get normalBias() {
|
|
155
|
-
return this._config.normalBias;
|
|
156
|
-
}
|
|
157
|
-
set normalBias(val) {
|
|
158
|
-
this._config.normalBias = val;
|
|
159
|
-
}
|
|
160
|
-
/** Near clip plane */ get nearClip() {
|
|
161
|
-
return this._config.nearClip;
|
|
162
|
-
}
|
|
163
|
-
set nearClip(val) {
|
|
164
|
-
if (this._config.nearClip !== val) {
|
|
165
|
-
this._config.nearClip = val;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
/** Shadow map mode */ get mode() {
|
|
169
|
-
return this._shadowMode;
|
|
170
|
-
}
|
|
171
|
-
set mode(mode) {
|
|
172
|
-
if (mode !== this._shadowMode) {
|
|
173
|
-
this._shadowMode = mode;
|
|
174
|
-
this.applyMode(this._shadowMode);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
/** Generated shadow map */ /*
|
|
178
|
-
get shadowMap(): ShadowMapType {
|
|
179
|
-
return (this._impl.getShadowMap(this) ?? this._framebuffer?.getColorAttachments()[0] ?? null) as ShadowMapType;
|
|
180
|
-
}
|
|
181
|
-
*/ /** Sampler of the shadow map */ /*
|
|
182
|
-
get shadowMapSampler(): TextureSampler {
|
|
183
|
-
return this._impl.getShadowMapSampler(this);
|
|
184
|
-
}
|
|
185
|
-
*/ /** @internal */ getShaderHash(shadowMapParams) {
|
|
186
|
-
return `${shadowMapParams.impl.constructor.name}_${shadowMapParams.impl.getShaderHash()}_${shadowMapParams.lightType}_${shadowMapParams.shadowMap.target}_${Number(shadowMapParams.numShadowCascades > 1)}_${Number(Application.instance.device.getDeviceCaps().textureCaps.getTextureFormatInfo(shadowMapParams.shadowMap.format).filterable)}`;
|
|
187
|
-
}
|
|
188
|
-
/** Sample count for poisson disc PCF */ get pdSampleCount() {
|
|
189
|
-
return this._pdSampleCount;
|
|
190
|
-
}
|
|
191
|
-
set pdSampleCount(val) {
|
|
192
|
-
val = Math.min(Math.max(1, Number(val) >> 0), 64);
|
|
193
|
-
if (val !== this._pdSampleCount) {
|
|
194
|
-
this._pdSampleCount = val;
|
|
195
|
-
const pcfpd = this.asPCFPD();
|
|
196
|
-
if (pcfpd) {
|
|
197
|
-
pcfpd.tapCount = this._pdSampleCount;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
/** Radius for poisson disc PCF */ get pdSampleRadius() {
|
|
202
|
-
return this._pdSampleRadius;
|
|
203
|
-
}
|
|
204
|
-
set pdSampleRadius(val) {
|
|
205
|
-
val = Math.max(0, Number(val) >> 0);
|
|
206
|
-
if (val !== this._pdSampleRadius) {
|
|
207
|
-
this._pdSampleRadius = val;
|
|
208
|
-
this.asPCFPD()?.setDepthScale(this._pdSampleRadius);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
/** Kernel size for optimized PCF */ get pcfKernelSize() {
|
|
212
|
-
return this._pcfKernelSize;
|
|
213
|
-
}
|
|
214
|
-
set pcfKernelSize(val) {
|
|
215
|
-
val = val !== 3 && val !== 5 && val !== 7 ? 5 : val;
|
|
216
|
-
if (val !== this._pcfKernelSize) {
|
|
217
|
-
this._pcfKernelSize = val;
|
|
218
|
-
const pcfopt = this.asPCFOPT();
|
|
219
|
-
if (pcfopt) {
|
|
220
|
-
pcfopt.kernelSize = this._pcfKernelSize;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
/** Kernel size of VSM */ get vsmBlurKernelSize() {
|
|
225
|
-
return this._vsmBlurKernelSize;
|
|
226
|
-
}
|
|
227
|
-
set vsmBlurKernelSize(val) {
|
|
228
|
-
val = Math.max(3, Number(val) >> 0) | 1;
|
|
229
|
-
if (val !== this._vsmBlurKernelSize) {
|
|
230
|
-
this._vsmBlurKernelSize = val;
|
|
231
|
-
const vsm = this.asVSM();
|
|
232
|
-
if (vsm) {
|
|
233
|
-
vsm.kernelSize = this._vsmBlurKernelSize;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
/** Blur radius for VSM */ get vsmBlurRadius() {
|
|
238
|
-
return this._vsmBlurRadius;
|
|
239
|
-
}
|
|
240
|
-
set vsmBlurRadius(val) {
|
|
241
|
-
val = Math.max(0, Number(val) || 0);
|
|
242
|
-
if (val !== this._vsmBlurRadius) {
|
|
243
|
-
this._vsmBlurRadius = val;
|
|
244
|
-
const vsm = this.asVSM();
|
|
245
|
-
if (vsm) {
|
|
246
|
-
vsm.blurSize = this._vsmBlurRadius;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
/** Darkness for VSM */ get vsmDarkness() {
|
|
251
|
-
return this._vsmDarkness;
|
|
252
|
-
}
|
|
253
|
-
set vsmDarkness(val) {
|
|
254
|
-
val = Math.min(0.999, Math.max(0, Number(val) || 0));
|
|
255
|
-
if (val !== this._vsmDarkness) {
|
|
256
|
-
this._vsmDarkness = val;
|
|
257
|
-
this.asVSM()?.setDepthScale(this._vsmDarkness);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
/** Whether to enable ESM blur */ get esmBlur() {
|
|
261
|
-
return this._esmBlur;
|
|
262
|
-
}
|
|
263
|
-
set esmBlur(val) {
|
|
264
|
-
if (!!val !== this.esmBlur) {
|
|
265
|
-
this._esmBlur = !!val;
|
|
266
|
-
const esm = this.asESM();
|
|
267
|
-
if (esm) {
|
|
268
|
-
esm.blur = this._esmBlur;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
/** Kernel size for ESM */ get esmBlurKernelSize() {
|
|
273
|
-
return this._esmBlurKernelSize;
|
|
274
|
-
}
|
|
275
|
-
set esmBlurKernelSize(val) {
|
|
276
|
-
val = Math.max(3, Number(val) >> 0) | 1;
|
|
277
|
-
if (val !== this._esmBlurKernelSize) {
|
|
278
|
-
this._esmBlurKernelSize = val;
|
|
279
|
-
const esm = this.asESM();
|
|
280
|
-
if (esm) {
|
|
281
|
-
esm.kernelSize = this._esmBlurKernelSize;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
/** Blur radius for ESM */ get esmBlurRadius() {
|
|
286
|
-
return this._esmBlurRadius;
|
|
287
|
-
}
|
|
288
|
-
set esmBlurRadius(val) {
|
|
289
|
-
val = Math.max(0, Number(val) || 0);
|
|
290
|
-
if (val !== this._esmBlurRadius) {
|
|
291
|
-
this._esmBlurRadius = val;
|
|
292
|
-
const esm = this.asESM();
|
|
293
|
-
if (esm) {
|
|
294
|
-
esm.blurSize = this._esmBlurRadius;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
/** Depth scale for ESM */ get esmDepthScale() {
|
|
299
|
-
return this._esmDepthScale;
|
|
300
|
-
}
|
|
301
|
-
set esmDepthScale(val) {
|
|
302
|
-
val = Math.max(0, Number(val) || 0);
|
|
303
|
-
if (val !== this._esmDepthScale) {
|
|
304
|
-
this._esmDepthScale = val;
|
|
305
|
-
this.asESM()?.setDepthScale(this._esmDepthScale);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
/** @internal */ computeShadow(shadowMapParams, scope, shadowVertex, NdotL) {
|
|
309
|
-
return this._impl.computeShadow(shadowMapParams, scope, shadowVertex, NdotL);
|
|
310
|
-
}
|
|
311
|
-
/** @internal */ computeShadowCSM(shadowMapParams, scope, shadowVertex, NdotL, split) {
|
|
312
|
-
return this._impl.computeShadowCSM(shadowMapParams, scope, shadowVertex, NdotL, split);
|
|
313
|
-
}
|
|
314
|
-
/** @internal */ static releaseTemporalResources(ctx) {
|
|
315
|
-
if (ctx.shadowMapInfo) {
|
|
316
|
-
for (const k of ctx.shadowMapInfo.keys()){
|
|
317
|
-
const shadowMapParams = ctx.shadowMapInfo.get(k);
|
|
318
|
-
//ctx.device.pool.releaseFrameBuffer(shadowMapParams.shadowMapFramebuffer);
|
|
319
|
-
shadowMapParams.lightType = LIGHT_TYPE_NONE;
|
|
320
|
-
shadowMapParams.depthClampEnabled = false;
|
|
321
|
-
shadowMapParams.shaderHash = '';
|
|
322
|
-
shadowMapParams.numShadowCascades = 1;
|
|
323
|
-
shadowMapParams.shadowMapFramebuffer = null;
|
|
324
|
-
shadowMapParams.impl = null;
|
|
325
|
-
shadowMapParams.shadowMap = null;
|
|
326
|
-
shadowMapParams.shadowMapSampler = null;
|
|
327
|
-
shadowMapParams.implData = null;
|
|
328
|
-
this._shadowMapParams.push(shadowMapParams);
|
|
329
|
-
}
|
|
330
|
-
ctx.shadowMapInfo = null;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
/** @internal */ static computeShadowBias(shadowMapParams, scope, z, NdotL, linear) {
|
|
334
|
-
const pb = scope.$builder;
|
|
335
|
-
const depthBiasParam = ShaderHelper.getDepthBiasValues(scope);
|
|
336
|
-
if (shadowMapParams.lightType === LIGHT_TYPE_DIRECTIONAL) {
|
|
337
|
-
return pb.dot(pb.mul(depthBiasParam.xy, pb.vec2(1, pb.sub(1, NdotL))), pb.vec2(1, 1));
|
|
338
|
-
} else {
|
|
339
|
-
const nearFar = ShaderHelper.getShadowCameraParams(scope).xy;
|
|
340
|
-
const linearDepth = linear ? z : ShaderHelper.nonLinearDepthToLinearNormalized(scope, z, nearFar);
|
|
341
|
-
const biasScaleFactor = pb.mix(1, depthBiasParam.w, linearDepth);
|
|
342
|
-
return pb.dot(pb.mul(depthBiasParam.xy, pb.vec2(1, pb.sub(1, NdotL)), biasScaleFactor), pb.vec2(1, 1));
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
/** @internal */ static computeShadowBiasCSM(shadowMapParams, scope, NdotL, split) {
|
|
346
|
-
const pb = scope.$builder;
|
|
347
|
-
const depthBiasParam = ShaderHelper.getDepthBiasValues(scope);
|
|
348
|
-
const splitFlags = pb.vec4(pb.float(pb.equal(split, 0)), pb.float(pb.equal(split, 1)), pb.float(pb.equal(split, 2)), pb.float(pb.equal(split, 3)));
|
|
349
|
-
const depthBiasScale = pb.dot(ShaderHelper.getDepthBiasScales(scope), splitFlags);
|
|
350
|
-
return pb.dot(pb.mul(depthBiasParam.xy, pb.vec2(1, pb.sub(1, NdotL)), depthBiasScale), pb.vec2(1, 1));
|
|
351
|
-
}
|
|
352
|
-
/** @internal */ isTextureInvalid(texture, target, format, width, height) {
|
|
353
|
-
return texture && (texture.target !== target || texture.format !== format || texture.width !== width || texture.height !== height || texture.depth !== this.numShadowCascades);
|
|
354
|
-
}
|
|
355
|
-
/** @internal */ createTexture(target, format, width, height, depth) {
|
|
356
|
-
const device = Application.instance.device;
|
|
357
|
-
const options = {
|
|
358
|
-
samplerOptions: {
|
|
359
|
-
mipFilter: 'none'
|
|
360
|
-
}
|
|
361
|
-
};
|
|
362
|
-
switch(target){
|
|
363
|
-
case '2d':
|
|
364
|
-
return device.createTexture2D(format, width, height, options);
|
|
365
|
-
case 'cube':
|
|
366
|
-
return device.createCubeTexture(format, width, options);
|
|
367
|
-
case '2darray':
|
|
368
|
-
return device.createTexture2DArray(format, width, height, depth, options);
|
|
369
|
-
default:
|
|
370
|
-
return null;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
/** @internal */ static fetchTemporalFramebuffer(autoRelease, lightType, numCascades, width, height, colorFormat, depthFormat, mipmapping) {
|
|
374
|
-
const device = Application.instance.device;
|
|
375
|
-
const useTextureArray = numCascades > 1 && device.type !== 'webgl';
|
|
376
|
-
const colorAttachments = colorFormat ? useTextureArray ? [
|
|
377
|
-
device.pool.fetchTemporalTexture2DArray(false, colorFormat, width, height, numCascades, mipmapping)
|
|
378
|
-
] : lightType === LIGHT_TYPE_POINT ? [
|
|
379
|
-
device.pool.fetchTemporalTextureCube(false, colorFormat, width, mipmapping)
|
|
380
|
-
] : [
|
|
381
|
-
device.pool.fetchTemporalTexture2D(false, colorFormat, width, height, mipmapping)
|
|
382
|
-
] : null;
|
|
383
|
-
const depthAttachment = depthFormat ? useTextureArray ? device.pool.fetchTemporalTexture2DArray(false, depthFormat, width, height, numCascades, false) : device.type !== 'webgl' && lightType === LIGHT_TYPE_POINT ? device.pool.fetchTemporalTextureCube(false, depthFormat, width, false) : device.pool.fetchTemporalTexture2D(false, depthFormat, width, height, false) : null;
|
|
384
|
-
const fb = device.pool.createTemporalFramebuffer(autoRelease, colorAttachments, depthAttachment);
|
|
385
|
-
if (colorAttachments) {
|
|
386
|
-
device.pool.releaseTexture(colorAttachments[0]);
|
|
387
|
-
}
|
|
388
|
-
if (depthAttachment) {
|
|
389
|
-
device.pool.releaseTexture(depthAttachment);
|
|
390
|
-
}
|
|
391
|
-
return fb;
|
|
392
|
-
}
|
|
393
|
-
/** @internal */ updateResources(shadowMapParams) {
|
|
394
|
-
const device = Application.instance.device;
|
|
395
|
-
const colorFormat = shadowMapParams.impl.getShadowMapColorFormat(shadowMapParams);
|
|
396
|
-
const depthFormat = shadowMapParams.impl.getShadowMapDepthFormat(shadowMapParams);
|
|
397
|
-
const numCascades = shadowMapParams.numShadowCascades;
|
|
398
|
-
const useTextureArray = numCascades > 1 && device.type !== 'webgl';
|
|
399
|
-
const shadowMapWidth = numCascades > 1 && !useTextureArray ? 2 * this._config.shadowMapSize : this._config.shadowMapSize;
|
|
400
|
-
const shadowMapHeight = numCascades > 2 && !useTextureArray ? 2 * this._config.shadowMapSize : this._config.shadowMapSize;
|
|
401
|
-
/*
|
|
402
|
-
const colorAttachments = colorFormat
|
|
403
|
-
? useTextureArray
|
|
404
|
-
? [device.pool.fetchTemporalTexture2DArray(false, colorFormat, shadowMapWidth, shadowMapHeight, numCascades, false)]
|
|
405
|
-
: this._light.isPointLight()
|
|
406
|
-
? [device.pool.fetchTemporalTextureCube(false, colorFormat, shadowMapWidth, false)]
|
|
407
|
-
: [device.pool.fetchTemporalTexture2D(false, colorFormat, shadowMapWidth, shadowMapHeight, false)]
|
|
408
|
-
: null;
|
|
409
|
-
const depthAttachment = depthFormat
|
|
410
|
-
? useTextureArray
|
|
411
|
-
? device.pool.fetchTemporalTexture2DArray(false, depthFormat, shadowMapWidth, shadowMapHeight, numCascades, false)
|
|
412
|
-
: device.type !== 'webgl' && this._light.isPointLight()
|
|
413
|
-
? device.pool.fetchTemporalTextureCube(false, depthFormat, shadowMapWidth, false)
|
|
414
|
-
: device.pool.fetchTemporalTexture2D(false, depthFormat, shadowMapWidth, shadowMapHeight, false)
|
|
415
|
-
: null;
|
|
416
|
-
shadowMapParams.shadowMapFramebuffer = device.pool.createTemporalFramebuffer(false, colorAttachments, depthAttachment);
|
|
417
|
-
if (colorAttachments) {
|
|
418
|
-
device.pool.releaseTexture(colorAttachments[0]);
|
|
419
|
-
}
|
|
420
|
-
if (depthAttachment) {
|
|
421
|
-
device.pool.releaseTexture(depthAttachment);
|
|
422
|
-
}
|
|
423
|
-
*/ shadowMapParams.shadowMapFramebuffer = ShadowMapper.fetchTemporalFramebuffer(true, this._light.lightType, numCascades, shadowMapWidth, shadowMapHeight, colorFormat, depthFormat);
|
|
424
|
-
shadowMapParams.impl = this._impl;
|
|
425
|
-
this._impl.updateResources(shadowMapParams);
|
|
426
|
-
}
|
|
427
|
-
/** @internal */ createLightCameraPoint(lightCamera) {
|
|
428
|
-
//lightCamera.reparent(this._light);
|
|
429
|
-
lightCamera.parent = lightCamera.scene.rootNode;
|
|
430
|
-
lightCamera.position.setXYZ(0, 0, 0);
|
|
431
|
-
lightCamera.rotation.identity();
|
|
432
|
-
lightCamera.scale.setXYZ(1, 1, 1);
|
|
433
|
-
lightCamera.setPerspective(Math.PI / 2, 1, this._config.nearClip, Math.min(this._shadowDistance, this._light.range));
|
|
434
|
-
lightCamera.position.set(this._light.positionAndRange.xyz());
|
|
435
|
-
}
|
|
436
|
-
/** @internal */ createLightCameraSpot(lightCamera) {
|
|
437
|
-
lightCamera.parent = this._light;
|
|
438
|
-
lightCamera.position.setXYZ(0, 0, 0);
|
|
439
|
-
lightCamera.rotation.identity();
|
|
440
|
-
lightCamera.scale.setXYZ(1, 1, 1);
|
|
441
|
-
lightCamera.setPerspective(2 * this._light.cutoff, 1, this._config.nearClip, Math.min((this._shadowDistance, this._light).range));
|
|
442
|
-
}
|
|
443
|
-
/** @internal */ createLightCameraDirectional(sceneAABB, sceneCamera, lightCamera, cropMatrix, border) {
|
|
444
|
-
let frustum = sceneCamera.frustumViewSpace;
|
|
445
|
-
if (this._shadowDistance < sceneCamera.getFarPlane()) {
|
|
446
|
-
tmpMatrix.set(sceneCamera.getProjectionMatrix());
|
|
447
|
-
tmpMatrix.setNearFar(tmpMatrix.getNearPlane(), this._shadowDistance);
|
|
448
|
-
//tmpMatrix.multiplyRight(sceneCamera.viewMatrix);
|
|
449
|
-
tmpFrustum.initWithMatrix(tmpMatrix);
|
|
450
|
-
frustum = tmpFrustum;
|
|
451
|
-
}
|
|
452
|
-
border = border || 0;
|
|
453
|
-
const expand = (this.shadowMapSize - 2 * border) / this.shadowMapSize;
|
|
454
|
-
//const frustum = sceneCamera.frustum;
|
|
455
|
-
const frustumMin = ShadowMapper._frustumMin;
|
|
456
|
-
const frustumMax = ShadowMapper._frustumMax;
|
|
457
|
-
const frustumCenter = ShadowMapper._frustumCenter;
|
|
458
|
-
const target = ShadowMapper._target;
|
|
459
|
-
const up = ShadowMapper._up;
|
|
460
|
-
// const frustum = new Frustum(sceneCamera.viewProjectionMatrix);
|
|
461
|
-
frustumMin.setXYZ(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
462
|
-
frustumMax.setXYZ(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
463
|
-
frustum.corners.forEach((p)=>{
|
|
464
|
-
frustumMin.inplaceMin(p);
|
|
465
|
-
frustumMax.inplaceMax(p);
|
|
466
|
-
});
|
|
467
|
-
let radius = Vector3.distance(frustumMin, frustumMax) * 0.5 * expand;
|
|
468
|
-
const center = sceneCamera.thisToWorld(Vector3.add(frustumMin, frustumMax, frustumCenter).scaleBy(0.5), frustumCenter);
|
|
469
|
-
// Bounding sphere of the shadow camera should not be larger than bounding sphere of the scene.
|
|
470
|
-
const sceneRadius = sceneAABB.diagonalLength * 0.5 * expand;
|
|
471
|
-
if (sceneRadius < radius) {
|
|
472
|
-
radius = sceneRadius;
|
|
473
|
-
Vector3.add(sceneAABB.minPoint, sceneAABB.maxPoint, center).scaleBy(0.5);
|
|
474
|
-
}
|
|
475
|
-
target.setXYZ(center.x + this._light.directionAndCutoff.x, center.y + this._light.directionAndCutoff.y, center.z + this._light.directionAndCutoff.z);
|
|
476
|
-
up.setXYZ(0, 1, 0);
|
|
477
|
-
lightCamera.lookAt(center, target, up);
|
|
478
|
-
lightCamera.position.set(center);
|
|
479
|
-
lightCamera.setOrtho(-radius, radius, -radius, radius, -radius, Math.max(Vector3.distance(center, sceneCamera.getWorldPosition()), sceneCamera.getFarPlane()));
|
|
480
|
-
center.setXYZ(0, 0, 0);
|
|
481
|
-
lightCamera.viewProjectionMatrix.transformPointP(center, center);
|
|
482
|
-
if (cropMatrix) {
|
|
483
|
-
const tx = center.x * this.shadowMapSize * 0.5;
|
|
484
|
-
const ty = center.y * this.shadowMapSize * 0.5;
|
|
485
|
-
const rx = Math.round(tx);
|
|
486
|
-
const ry = Math.round(ty);
|
|
487
|
-
center.setXYZ((rx - tx) * 2 / this.shadowMapSize, (ry - ty) * 2 / this.shadowMapSize, 0);
|
|
488
|
-
cropMatrix.translation(center);
|
|
489
|
-
}
|
|
490
|
-
/*
|
|
491
|
-
const minx = frustumMin.x;
|
|
492
|
-
const maxx = frustumMax.x;
|
|
493
|
-
const miny = frustumMin.y;
|
|
494
|
-
const maxy = frustumMax.y;
|
|
495
|
-
const minz = frustumMin.z;
|
|
496
|
-
const maxz = frustumMax.z;
|
|
497
|
-
const texelSizeW = (maxx - minx) / this.shadowMapSize;
|
|
498
|
-
const texelSizeH = (maxy - miny) / this.shadowMapSize;
|
|
499
|
-
const cx = Math.floor((minx + maxx) / 2 / texelSizeW) * texelSizeW;
|
|
500
|
-
const cy = Math.floor((miny + maxy) / 2 / texelSizeH) * texelSizeH;
|
|
501
|
-
const cz = (minz + maxz) / 2;
|
|
502
|
-
const hx = Math.floor(((maxx - minx) * (expand + 0.5)) / texelSizeW) * texelSizeW;
|
|
503
|
-
const hy = Math.floor(((maxy - miny) * (expand + 0.5)) / texelSizeH) * texelSizeH;
|
|
504
|
-
lightCamera.position.setXYZ(cx, cy, cz);
|
|
505
|
-
lightCamera.setOrtho(
|
|
506
|
-
-hx,
|
|
507
|
-
hx,
|
|
508
|
-
-hy,
|
|
509
|
-
hy,
|
|
510
|
-
sceneMax.z - maxz,
|
|
511
|
-
sceneMax.z - minz + 1
|
|
512
|
-
);
|
|
513
|
-
if (cropMatrix) {
|
|
514
|
-
// compute crop matrix
|
|
515
|
-
let clipMaxX = 0,
|
|
516
|
-
clipMaxY = 0;
|
|
517
|
-
let clipMinX = Number.MAX_VALUE,
|
|
518
|
-
clipMinY = Number.MAX_VALUE;
|
|
519
|
-
frustum.corners.forEach((p) => {
|
|
520
|
-
const clipPos = lightCamera.viewProjectionMatrix.transformPoint(p);
|
|
521
|
-
clipPos.x = Math.min(1, Math.max(-1, clipPos.x / clipPos.w));
|
|
522
|
-
clipPos.y = Math.min(1, Math.max(-1, clipPos.y / clipPos.w));
|
|
523
|
-
if (clipPos.x > clipMaxX) {
|
|
524
|
-
clipMaxX = clipPos.x;
|
|
525
|
-
}
|
|
526
|
-
if (clipPos.x < clipMinX) {
|
|
527
|
-
clipMinX = clipPos.x;
|
|
528
|
-
}
|
|
529
|
-
if (clipPos.y > clipMaxY) {
|
|
530
|
-
clipMaxY = clipPos.y;
|
|
531
|
-
}
|
|
532
|
-
if (clipPos.y < clipMinY) {
|
|
533
|
-
clipMinY = clipPos.y;
|
|
534
|
-
}
|
|
535
|
-
});
|
|
536
|
-
const clipW = clipMaxX - clipMinX;
|
|
537
|
-
const clipH = clipMaxY - clipMinY;
|
|
538
|
-
clipMinX -= expand * clipW;
|
|
539
|
-
clipMinY -= expand * clipH;
|
|
540
|
-
clipMaxX += expand * clipW;
|
|
541
|
-
clipMaxY += expand * clipH;
|
|
542
|
-
const scaleX = 2 / (clipMaxX - clipMinX);
|
|
543
|
-
const scaleY = 2 / (clipMaxY - clipMinY);
|
|
544
|
-
const offsetX = -0.5 * (clipMaxX + clipMinX) * scaleX;
|
|
545
|
-
const offsetY = -0.5 * (clipMaxY + clipMinY) * scaleY;
|
|
546
|
-
cropMatrix.identity();
|
|
547
|
-
cropMatrix.m00 = scaleX;
|
|
548
|
-
cropMatrix.m11 = scaleY;
|
|
549
|
-
cropMatrix.m03 = offsetX;
|
|
550
|
-
cropMatrix.m13 = offsetY;
|
|
551
|
-
}
|
|
552
|
-
*/ }
|
|
553
|
-
/** @internal */ static fetchShadowMapParams() {
|
|
554
|
-
if (this._shadowMapParams.length > 0) {
|
|
555
|
-
return this._shadowMapParams.pop();
|
|
556
|
-
} else {
|
|
557
|
-
return {
|
|
558
|
-
lightType: LIGHT_TYPE_NONE,
|
|
559
|
-
depthClampEnabled: false,
|
|
560
|
-
shaderHash: '',
|
|
561
|
-
cameraParams: new Vector4(),
|
|
562
|
-
cascadeDistances: new Vector4(),
|
|
563
|
-
depthBiasScales: new Vector4(),
|
|
564
|
-
depthBiasValues: [
|
|
565
|
-
new Vector4(),
|
|
566
|
-
new Vector4(),
|
|
567
|
-
new Vector4(),
|
|
568
|
-
new Vector4()
|
|
569
|
-
],
|
|
570
|
-
numShadowCascades: 1,
|
|
571
|
-
shadowMatrices: new Float32Array(16 * 4),
|
|
572
|
-
shadowMap: null,
|
|
573
|
-
shadowMapSampler: null,
|
|
574
|
-
shadowMapFramebuffer: null,
|
|
575
|
-
impl: null,
|
|
576
|
-
implData: null
|
|
577
|
-
};
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
/** @internal */ static fetchCameraForScene(scene) {
|
|
581
|
-
const cameras = this._lightCameras.get(scene);
|
|
582
|
-
if (!cameras || cameras.length === 0) {
|
|
583
|
-
const camera = new Camera(scene);
|
|
584
|
-
retainObject(camera);
|
|
585
|
-
return camera;
|
|
586
|
-
} else {
|
|
587
|
-
const camera = cameras.pop();
|
|
588
|
-
camera.parent = scene.rootNode;
|
|
589
|
-
camera.position.setXYZ(0, 0, 0);
|
|
590
|
-
camera.rotation.identity();
|
|
591
|
-
camera.scale.setXYZ(1, 1, 1);
|
|
592
|
-
camera.clipMask = 0;
|
|
593
|
-
return camera;
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
/** @internal */ static releaseCamera(camera) {
|
|
597
|
-
let cameras = this._lightCameras.get(camera.scene);
|
|
598
|
-
if (!cameras) {
|
|
599
|
-
cameras = [];
|
|
600
|
-
this._lightCameras.set(camera.scene, cameras);
|
|
601
|
-
}
|
|
602
|
-
camera.remove();
|
|
603
|
-
cameras.push(camera);
|
|
604
|
-
}
|
|
605
|
-
/** @internal */ calcSplitDistances(nearPlane, farPlane, numCascades) {
|
|
606
|
-
const result = [
|
|
607
|
-
0,
|
|
608
|
-
0,
|
|
609
|
-
0,
|
|
610
|
-
0,
|
|
611
|
-
0
|
|
612
|
-
];
|
|
613
|
-
for(let i = 0; i <= numCascades; ++i){
|
|
614
|
-
const fIDM = i / numCascades;
|
|
615
|
-
const fLog = nearPlane * Math.pow(farPlane / nearPlane, fIDM);
|
|
616
|
-
const fUniform = nearPlane + (farPlane - nearPlane) * fIDM;
|
|
617
|
-
result[i] = fLog * this._config.splitLambda + fUniform * (1 - this._config.splitLambda);
|
|
618
|
-
}
|
|
619
|
-
return result;
|
|
620
|
-
}
|
|
621
|
-
/** @internal */ calcDepthBiasParams(camera, shadowMapSize, depthBias, normalBias, depthScale, result) {
|
|
622
|
-
const sizeNear = Math.min(camera.getProjectionMatrix().getNearPlaneWidth(), camera.getProjectionMatrix().getNearPlaneHeight());
|
|
623
|
-
const sizeFar = Math.min(camera.getProjectionMatrix().getFarPlaneWidth(), camera.getProjectionMatrix().getFarPlaneHeight());
|
|
624
|
-
const scaleFactor = sizeNear / shadowMapSize * 2;
|
|
625
|
-
result.setXYZW(depthBias * scaleFactor, normalBias * 0.0001, depthScale, sizeFar / sizeNear);
|
|
626
|
-
}
|
|
627
|
-
/** @internal */ postRenderShadowMap(shadowMapParams) {
|
|
628
|
-
this._impl.postRenderShadowMap(shadowMapParams);
|
|
629
|
-
}
|
|
630
|
-
/** @internal */ render(ctx, renderPass) {
|
|
631
|
-
if (!ctx.shadowMapInfo) {
|
|
632
|
-
ctx.shadowMapInfo = new Map();
|
|
633
|
-
}
|
|
634
|
-
const shadowMapParams = ShadowMapper.fetchShadowMapParams();
|
|
635
|
-
shadowMapParams.impl = this._impl;
|
|
636
|
-
shadowMapParams.lightType = this.light.lightType;
|
|
637
|
-
shadowMapParams.numShadowCascades = shadowMapParams.lightType === LIGHT_TYPE_DIRECTIONAL ? this._config.numCascades : 1;
|
|
638
|
-
ctx.shadowMapInfo.set(this.light, shadowMapParams);
|
|
639
|
-
const scene = ctx.scene;
|
|
640
|
-
const camera = ctx.camera;
|
|
641
|
-
renderPass.light = this._light;
|
|
642
|
-
this.updateResources(shadowMapParams);
|
|
643
|
-
shadowMapParams.shaderHash = this.getShaderHash(shadowMapParams);
|
|
644
|
-
const device = Application.instance.device;
|
|
645
|
-
const fb = shadowMapParams.shadowMapFramebuffer;
|
|
646
|
-
shadowMapParams.depthClampEnabled = false;
|
|
647
|
-
renderPass.clearColor = fb.getColorAttachments()[0] ? fb.getColorAttachments()[0].isFloatFormat() ? new Vector4(1, 1, 1, 1) : new Vector4(0, 0, 0, 1) : null;
|
|
648
|
-
const depthScale = this._impl.getDepthScale();
|
|
649
|
-
const shadowRegion = this._light.isDirectionLight() && this._shadowRegion && this._shadowRegion.isValid() ? this._shadowRegion : scene.boundingBox;
|
|
650
|
-
if (this._light.isPointLight()) {
|
|
651
|
-
const shadowMapRenderCamera = ShadowMapper.fetchCameraForScene(scene);
|
|
652
|
-
this.createLightCameraPoint(shadowMapRenderCamera);
|
|
653
|
-
this.calcDepthBiasParams(camera, this._config.shadowMapSize, this._config.depthBias, this._config.normalBias, depthScale, shadowMapParams.depthBiasValues[0]);
|
|
654
|
-
shadowMapParams.cameraParams.setXYZW(shadowMapRenderCamera.getNearPlane(), shadowMapRenderCamera.getFarPlane(), this._config.shadowMapSize, this._shadowDistance);
|
|
655
|
-
device.setFramebuffer(fb);
|
|
656
|
-
shadowMapParams.shadowMatrices.set(Matrix4x4.transpose(shadowMapRenderCamera.viewMatrix));
|
|
657
|
-
for (const face of [
|
|
658
|
-
CubeFace.PX,
|
|
659
|
-
CubeFace.NX,
|
|
660
|
-
CubeFace.PY,
|
|
661
|
-
CubeFace.NY,
|
|
662
|
-
CubeFace.PZ,
|
|
663
|
-
CubeFace.NZ
|
|
664
|
-
]){
|
|
665
|
-
shadowMapRenderCamera.lookAtCubeFace(face);
|
|
666
|
-
fb.setColorAttachmentCubeFace(0, face);
|
|
667
|
-
fb.setDepthAttachmentCubeFace(face);
|
|
668
|
-
ctx.camera = shadowMapRenderCamera;
|
|
669
|
-
renderPass.render(ctx);
|
|
670
|
-
}
|
|
671
|
-
shadowMapParams.shadowMatrices.set(Matrix4x4.identity());
|
|
672
|
-
ShadowMapper.releaseCamera(shadowMapRenderCamera);
|
|
673
|
-
} else {
|
|
674
|
-
if (this._config.numCascades > 1) {
|
|
675
|
-
const distances = this.calcSplitDistances(camera.getNearPlane(), Math.min(this._shadowDistance, camera.getFarPlane()), this._config.numCascades);
|
|
676
|
-
const cascadeCamera = ShadowMapper.fetchCameraForScene(scene);
|
|
677
|
-
const shadowMapRenderCamera = ShadowMapper.fetchCameraForScene(scene);
|
|
678
|
-
const shadowMapCullCamera = ShadowMapper.fetchCameraForScene(scene);
|
|
679
|
-
shadowMapCullCamera.clipMask = AABB.ClipLeft | AABB.ClipRight | AABB.ClipBottom | AABB.ClipTop;
|
|
680
|
-
cascadeCamera.parent = camera;
|
|
681
|
-
shadowMapParams.depthClampEnabled = Application.instance.device.getDeviceCaps().shaderCaps.supportFragmentDepth;
|
|
682
|
-
for(let split = 0; split < this._config.numCascades; split++){
|
|
683
|
-
cascadeCamera.setPerspective(camera.getFOV(), camera.getAspect(), distances[split], distances[split + 1]);
|
|
684
|
-
const snapMatrix = ShadowMapper._snapMatrix;
|
|
685
|
-
const border = shadowMapParams.impl.getShadowMapBorder(shadowMapParams); //20 / this._config.shadowMapSize;
|
|
686
|
-
this.createLightCameraDirectional(shadowRegion, cascadeCamera, shadowMapRenderCamera, snapMatrix, border);
|
|
687
|
-
this.createLightCameraDirectional(shadowRegion, cascadeCamera, shadowMapCullCamera, null, border);
|
|
688
|
-
this.calcDepthBiasParams(camera, this._config.shadowMapSize, this._config.depthBias, this._config.normalBias, depthScale, shadowMapParams.depthBiasValues[split]);
|
|
689
|
-
shadowMapParams.depthBiasScales[split] = 1;
|
|
690
|
-
// Incorrect calculation
|
|
691
|
-
// shadowMapParams.depthBiasScales[split] = shadowMapParams.depthBiasValues[0].x !== 0 ? shadowMapParams.depthBiasValues[split].x / shadowMapParams.depthBiasValues[0].x : 1;
|
|
692
|
-
shadowMapParams.cameraParams.setXYZW(shadowMapRenderCamera.getNearPlane(), shadowMapRenderCamera.getFarPlane(), this._config.shadowMapSize, this._shadowDistance);
|
|
693
|
-
let scissor = null;
|
|
694
|
-
if (fb.getColorAttachments()[0]?.isTexture2DArray() || fb.getDepthAttachment()?.isTexture2DArray()) {
|
|
695
|
-
shadowMapRenderCamera.setProjectionMatrix(Matrix4x4.multiply(snapMatrix, shadowMapRenderCamera.getProjectionMatrix()));
|
|
696
|
-
fb.setColorAttachmentLayer(0, split);
|
|
697
|
-
fb.setDepthAttachmentLayer(split);
|
|
698
|
-
} else {
|
|
699
|
-
const numRows = this._config.numCascades > 2 ? 2 : 1;
|
|
700
|
-
const numCols = this._config.numCascades > 1 ? 2 : 1;
|
|
701
|
-
const adjMatrix = new Matrix4x4();
|
|
702
|
-
const col = split % 2;
|
|
703
|
-
const row = split >> 1;
|
|
704
|
-
adjMatrix.setRowXYZW(0, 1.5 - 0.5 * numCols, 0, 0, 0);
|
|
705
|
-
adjMatrix.setRowXYZW(1, 0, 1.5 - 0.5 * numRows, 0, 0);
|
|
706
|
-
adjMatrix.setRowXYZW(2, 0, 0, 1, 0);
|
|
707
|
-
adjMatrix.setRowXYZW(3, col - 0.5 * numCols + 0.5, row - 0.5 * numRows + 0.5, 0, 1);
|
|
708
|
-
shadowMapRenderCamera.setProjectionMatrix(Matrix4x4.multiply(adjMatrix, Matrix4x4.multiply(snapMatrix, shadowMapRenderCamera.getProjectionMatrix())));
|
|
709
|
-
if (device.type === 'webgpu') {
|
|
710
|
-
scissor = [
|
|
711
|
-
col * this._config.shadowMapSize,
|
|
712
|
-
(numRows - 1 - row) * this._config.shadowMapSize,
|
|
713
|
-
this._config.shadowMapSize,
|
|
714
|
-
this._config.shadowMapSize
|
|
715
|
-
];
|
|
716
|
-
} else {
|
|
717
|
-
scissor = [
|
|
718
|
-
col * this._config.shadowMapSize,
|
|
719
|
-
row * this._config.shadowMapSize,
|
|
720
|
-
this._config.shadowMapSize,
|
|
721
|
-
this._config.shadowMapSize
|
|
722
|
-
];
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
device.setFramebuffer(fb);
|
|
726
|
-
device.setScissor(scissor);
|
|
727
|
-
ctx.camera = shadowMapRenderCamera;
|
|
728
|
-
renderPass.render(ctx, shadowMapCullCamera);
|
|
729
|
-
shadowMapParams.shadowMatrices.set(Matrix4x4.transpose(shadowMapRenderCamera.viewProjectionMatrix), split * 16);
|
|
730
|
-
shadowMapParams.cascadeDistances[split] = distances[split + 1];
|
|
731
|
-
}
|
|
732
|
-
ShadowMapper.releaseCamera(cascadeCamera);
|
|
733
|
-
ShadowMapper.releaseCamera(shadowMapRenderCamera);
|
|
734
|
-
ShadowMapper.releaseCamera(shadowMapCullCamera);
|
|
735
|
-
} else {
|
|
736
|
-
const shadowMapRenderCamera = ShadowMapper.fetchCameraForScene(scene);
|
|
737
|
-
const snapMatrix = ShadowMapper._snapMatrix;
|
|
738
|
-
shadowMapRenderCamera.clipMask = AABB.ClipLeft | AABB.ClipRight | AABB.ClipBottom | AABB.ClipTop;
|
|
739
|
-
if (this._light.isDirectionLight()) {
|
|
740
|
-
this.createLightCameraDirectional(shadowRegion, camera, shadowMapRenderCamera, snapMatrix, shadowMapParams.impl.getShadowMapBorder(shadowMapParams));
|
|
741
|
-
} else {
|
|
742
|
-
this.createLightCameraSpot(shadowMapRenderCamera);
|
|
743
|
-
}
|
|
744
|
-
this.calcDepthBiasParams(camera, this._config.shadowMapSize, this._config.depthBias, this._config.normalBias, depthScale, shadowMapParams.depthBiasValues[0]);
|
|
745
|
-
shadowMapParams.cameraParams.setXYZW(shadowMapRenderCamera.getNearPlane(), shadowMapRenderCamera.getFarPlane(), this._config.shadowMapSize, this._shadowDistance);
|
|
746
|
-
device.setFramebuffer(fb);
|
|
747
|
-
shadowMapRenderCamera.setProjectionMatrix(Matrix4x4.multiply(snapMatrix, shadowMapRenderCamera.getProjectionMatrix()));
|
|
748
|
-
ctx.camera = shadowMapRenderCamera;
|
|
749
|
-
renderPass.render(ctx);
|
|
750
|
-
shadowMapParams.shadowMatrices.set(Matrix4x4.transpose(shadowMapRenderCamera.viewProjectionMatrix));
|
|
751
|
-
ShadowMapper.releaseCamera(shadowMapRenderCamera);
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
ctx.camera = camera;
|
|
755
|
-
this.postRenderShadowMap(shadowMapParams);
|
|
756
|
-
}
|
|
757
|
-
/** @internal */ applyMode(mode) {
|
|
758
|
-
if (mode !== 'hard' && mode !== 'vsm' && mode !== 'esm' && mode !== 'pcf-pd' && mode !== 'pcf-opt') {
|
|
759
|
-
console.error(`ShadowMapper.setShadowMode() failed: invalid mode: ${mode}`);
|
|
760
|
-
return;
|
|
761
|
-
}
|
|
762
|
-
this._impl = null;
|
|
763
|
-
if (mode === 'hard') {
|
|
764
|
-
this._impl = new SSM();
|
|
765
|
-
} else if (mode === 'vsm') {
|
|
766
|
-
this._impl = new VSM(this._vsmBlurKernelSize, this._vsmBlurRadius, this._vsmDarkness);
|
|
767
|
-
} else if (mode === 'esm') {
|
|
768
|
-
this._impl = new ESM(this._esmBlurKernelSize, this._esmBlurRadius, this._esmDepthScale);
|
|
769
|
-
} else if (mode === 'pcf-pd') {
|
|
770
|
-
this._impl = new PCFPD(this._pdSampleCount, this._pdSampleRadius);
|
|
771
|
-
} else if (mode === 'pcf-opt') {
|
|
772
|
-
this._impl = new PCFOPT(this._pcfKernelSize);
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
/** @internal */ asVSM() {
|
|
776
|
-
return this._impl?.getType() === 'vsm' ? this._impl : null;
|
|
777
|
-
}
|
|
778
|
-
/** @internal */ asESM() {
|
|
779
|
-
return this._impl?.getType() === 'esm' ? this._impl : null;
|
|
780
|
-
}
|
|
781
|
-
/** @internal */ asPCFPD() {
|
|
782
|
-
return this._impl?.getType() === 'pcf-pd' ? this._impl : null;
|
|
783
|
-
}
|
|
784
|
-
/** @internal */ asPCFOPT() {
|
|
785
|
-
return this._impl?.getType() === 'pcf-opt' ? this._impl : null;
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
export { ShadowMapper };
|
|
790
|
-
//# sourceMappingURL=shadowmapper.js.map
|