@zephyr3d/scene 0.6.1 → 0.7.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/dist/animation/animation.js +149 -27
- package/dist/animation/animation.js.map +1 -1
- package/dist/animation/animationset.js +173 -73
- package/dist/animation/animationset.js.map +1 -1
- package/dist/animation/animationtrack.js +65 -10
- package/dist/animation/animationtrack.js.map +1 -1
- package/dist/animation/eulerrotationtrack.js +41 -20
- package/dist/animation/eulerrotationtrack.js.map +1 -1
- package/dist/animation/morphtarget.js +14 -38
- package/dist/animation/morphtarget.js.map +1 -1
- package/dist/animation/morphtrack.js +59 -22
- package/dist/animation/morphtrack.js.map +1 -1
- package/dist/animation/proptrack.js +190 -0
- package/dist/animation/proptrack.js.map +1 -0
- package/dist/animation/rotationtrack.js +29 -11
- package/dist/animation/rotationtrack.js.map +1 -1
- package/dist/animation/scaletrack.js +29 -11
- package/dist/animation/scaletrack.js.map +1 -1
- package/dist/animation/skeleton.js +241 -78
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/animation/translationtrack.js +30 -11
- package/dist/animation/translationtrack.js.map +1 -1
- package/dist/app/api.js +43 -0
- package/dist/app/api.js.map +1 -0
- package/dist/app/app.js +153 -0
- package/dist/app/app.js.map +1 -0
- package/dist/app/engine.js +312 -0
- package/dist/app/engine.js.map +1 -0
- package/dist/app/inputmgr.js +351 -0
- package/dist/app/inputmgr.js.map +1 -0
- package/dist/app/runtimescript.js +62 -0
- package/dist/app/runtimescript.js.map +1 -0
- package/dist/app/scriptingsystem.js +220 -0
- package/dist/app/scriptingsystem.js.map +1 -0
- package/dist/app/scriptregistry.js +432 -0
- package/dist/app/scriptregistry.js.map +1 -0
- package/dist/asset/assetmanager.js +772 -291
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/builtin.js +7 -43
- package/dist/asset/builtin.js.map +1 -1
- package/dist/asset/loaders/dds/dds.js +17 -93
- package/dist/asset/loaders/dds/dds.js.map +1 -1
- package/dist/asset/loaders/dds/dds_loader.js +8 -18
- package/dist/asset/loaders/dds/dds_loader.js.map +1 -1
- package/dist/asset/loaders/gltf/gltf_loader.js +36 -42
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
- package/dist/asset/loaders/gltf/helpers.js +27 -14
- package/dist/asset/loaders/gltf/helpers.js.map +1 -1
- package/dist/asset/loaders/hdr/hdr.js +17 -12
- package/dist/asset/loaders/hdr/hdr.js.map +1 -1
- package/dist/asset/loaders/image/tga_Loader.js +13 -16
- package/dist/asset/loaders/image/tga_Loader.js.map +1 -1
- package/dist/asset/loaders/image/webimage_loader.js +51 -50
- package/dist/asset/loaders/image/webimage_loader.js.map +1 -1
- package/dist/asset/loaders/loader.js.map +1 -1
- package/dist/asset/model.js +158 -4
- package/dist/asset/model.js.map +1 -1
- package/dist/blitter/bilateralblur.js +0 -1
- package/dist/blitter/bilateralblur.js.map +1 -1
- package/dist/blitter/blitter.js +22 -23
- package/dist/blitter/blitter.js.map +1 -1
- package/dist/blitter/box.js.map +1 -1
- package/dist/blitter/copy.js.map +1 -1
- package/dist/blitter/gaussianblur.js +23 -23
- package/dist/blitter/gaussianblur.js.map +1 -1
- package/dist/camera/base.js +141 -34
- package/dist/camera/base.js.map +1 -1
- package/dist/camera/camera.js +653 -149
- package/dist/camera/camera.js.map +1 -1
- package/dist/camera/fps.js +2 -10
- package/dist/camera/fps.js.map +1 -1
- package/dist/camera/orbit.js +132 -59
- package/dist/camera/orbit.js.map +1 -1
- package/dist/camera/orthocamera.js +37 -12
- package/dist/camera/orthocamera.js.map +1 -1
- package/dist/camera/perspectivecamera.js +37 -20
- package/dist/camera/perspectivecamera.js.map +1 -1
- package/dist/index.d.ts +18268 -6982
- package/dist/index.js +49 -16
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +5 -0
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/grassmaterial.js +6 -1
- package/dist/material/grassmaterial.js.map +1 -1
- package/dist/material/lambert.js +6 -1
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/material.js +346 -73
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +498 -156
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/albedocolor.js +5 -1
- package/dist/material/mixins/albedocolor.js.map +1 -1
- package/dist/material/mixins/foliage.js +3 -3
- package/dist/material/mixins/foliage.js.map +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js +18 -5
- package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
- package/dist/material/mixins/lightmodel/lambert.js +6 -6
- package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +235 -0
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -0
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +52 -15
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +27 -9
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
- package/dist/material/mixins/lit.js +16 -4
- package/dist/material/mixins/lit.js.map +1 -1
- package/dist/material/mixins/pbr/brdf.js +134 -0
- package/dist/material/mixins/pbr/brdf.js.map +1 -0
- package/dist/material/mixins/pbr/common.js +68 -85
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/mixins/texture.js +98 -83
- package/dist/material/mixins/texture.js.map +1 -1
- package/dist/material/mixins/vertexcolor.js +6 -2
- package/dist/material/mixins/vertexcolor.js.map +1 -1
- package/dist/material/particle.js +272 -0
- package/dist/material/particle.js.map +1 -0
- package/dist/material/pbrblueprint.js +186 -0
- package/dist/material/pbrblueprint.js.map +1 -0
- package/dist/material/pbrmr.js +10 -0
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/pbrsg.js +10 -0
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/shader/helper.js +521 -287
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/terrain-cm.js +607 -0
- package/dist/material/terrain-cm.js.map +1 -0
- package/dist/material/terrainmaterial.js +59 -54
- package/dist/material/terrainmaterial.js.map +1 -1
- package/dist/material/unlit.js +5 -0
- package/dist/material/unlit.js.map +1 -1
- package/dist/material/water.js +415 -0
- package/dist/material/water.js.map +1 -0
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js +38 -0
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js.map +1 -0
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js +10 -0
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js.map +1 -0
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js +127 -0
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js.map +1 -0
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js +263 -0
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js.map +1 -0
- package/dist/node_modules/es-module-lexer/dist/lexer.js +5 -0
- package/dist/node_modules/es-module-lexer/dist/lexer.js.map +1 -0
- package/dist/posteffect/bloom.js +39 -54
- package/dist/posteffect/bloom.js.map +1 -1
- package/dist/posteffect/compositor.js +95 -128
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/fxaa.js +10 -18
- package/dist/posteffect/fxaa.js.map +1 -1
- package/dist/posteffect/grayscale.js +9 -17
- package/dist/posteffect/grayscale.js.map +1 -1
- package/dist/posteffect/motionblur.js +105 -0
- package/dist/posteffect/motionblur.js.map +1 -0
- package/dist/posteffect/posteffect.js +66 -35
- package/dist/posteffect/posteffect.js.map +1 -1
- package/dist/posteffect/sao.js +13 -21
- package/dist/posteffect/sao.js.map +1 -1
- package/dist/posteffect/ssr.js +60 -100
- package/dist/posteffect/ssr.js.map +1 -1
- package/dist/posteffect/taa.js +175 -0
- package/dist/posteffect/taa.js.map +1 -0
- package/dist/posteffect/tonemap.js +12 -20
- package/dist/posteffect/tonemap.js.map +1 -1
- package/dist/render/abuffer_oit.js +30 -19
- package/dist/render/abuffer_oit.js.map +1 -1
- package/dist/render/clipmap.js +429 -101
- package/dist/render/clipmap.js.map +1 -1
- package/dist/render/cluster_light.js +7 -5
- package/dist/render/cluster_light.js.map +1 -1
- package/dist/render/cull_visitor.js +43 -3
- package/dist/render/cull_visitor.js.map +1 -1
- package/dist/render/depthpass.js +14 -5
- package/dist/render/depthpass.js.map +1 -1
- package/dist/render/drawable_mixin.js +113 -40
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/envlight.js +86 -141
- package/dist/render/envlight.js.map +1 -1
- package/dist/render/fbm_wavegenerator.js +234 -0
- package/dist/render/fbm_wavegenerator.js.map +1 -0
- package/dist/render/fft_wavegenerator.js +64 -50
- package/dist/render/fft_wavegenerator.js.map +1 -1
- package/dist/render/fullscreenquad.js +2 -2
- package/dist/render/fullscreenquad.js.map +1 -1
- package/dist/render/gerstner_wavegenerator.js +98 -48
- package/dist/render/gerstner_wavegenerator.js.map +1 -1
- package/dist/render/globalbindgroup_allocator.js +4 -2
- package/dist/render/globalbindgroup_allocator.js.map +1 -1
- package/dist/render/hzb.js +6 -3
- package/dist/render/hzb.js.map +1 -1
- package/dist/render/lightpass.js +19 -18
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/objectcolorpass.js +4 -4
- package/dist/render/objectcolorpass.js.map +1 -1
- package/dist/render/primitive.js +213 -104
- package/dist/render/primitive.js.map +1 -1
- package/dist/render/render_queue.js +40 -20
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderbundle_wrapper.js +65 -15
- package/dist/render/renderbundle_wrapper.js.map +1 -1
- package/dist/render/renderer.js +326 -185
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/renderpass.js +20 -36
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/shadowmap_pass.js +3 -3
- package/dist/render/shadowmap_pass.js.map +1 -1
- package/dist/render/sky.js +864 -541
- package/dist/render/sky.js.map +1 -1
- package/dist/render/weightedblended_oit.js +13 -15
- package/dist/render/weightedblended_oit.js.map +1 -1
- package/dist/scene/batchgroup.js +18 -5
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +78 -48
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/graph_node.js +2 -3
- package/dist/scene/graph_node.js.map +1 -1
- package/dist/scene/light.js +28 -89
- package/dist/scene/light.js.map +1 -1
- package/dist/scene/mesh.js +218 -87
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/octree.js +371 -162
- package/dist/scene/octree.js.map +1 -1
- package/dist/scene/particlesys.js +684 -0
- package/dist/scene/particlesys.js.map +1 -0
- package/dist/scene/raycast_visitor.js +34 -5
- package/dist/scene/raycast_visitor.js.map +1 -1
- package/dist/scene/scene.js +309 -85
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/scene_node.js +675 -102
- package/dist/scene/scene_node.js.map +1 -1
- package/dist/scene/terrain/grass.js +48 -49
- package/dist/scene/terrain/grass.js.map +1 -1
- package/dist/scene/terrain/heightfield.js +46 -44
- package/dist/scene/terrain/heightfield.js.map +1 -1
- package/dist/scene/terrain/patch.js +20 -29
- package/dist/scene/terrain/patch.js.map +1 -1
- package/dist/scene/terrain/quadtree.js +58 -27
- package/dist/scene/terrain/quadtree.js.map +1 -1
- package/dist/scene/terrain/terrain.js +31 -45
- package/dist/scene/terrain/terrain.js.map +1 -1
- package/dist/scene/terrain-cm/grass.js +603 -0
- package/dist/scene/terrain-cm/grass.js.map +1 -0
- package/dist/scene/terrain-cm/grassmaterial.js +160 -0
- package/dist/scene/terrain-cm/grassmaterial.js.map +1 -0
- package/dist/scene/terrain-cm/terrain-cm.js +533 -0
- package/dist/scene/terrain-cm/terrain-cm.js.map +1 -0
- package/dist/scene/water.js +378 -0
- package/dist/scene/water.js.map +1 -0
- package/dist/shaders/atmosphere.js +957 -0
- package/dist/shaders/atmosphere.js.map +1 -0
- package/dist/shaders/fog.js +116 -0
- package/dist/shaders/fog.js.map +1 -0
- package/dist/shaders/misc.js.map +1 -1
- package/dist/shaders/noise.js +217 -8
- package/dist/shaders/noise.js.map +1 -1
- package/dist/shaders/pbr.js.map +1 -1
- package/dist/shaders/shadow.js +8 -8
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shaders/ssr.js +87 -39
- package/dist/shaders/ssr.js.map +1 -1
- package/dist/shaders/temporal.js +216 -0
- package/dist/shaders/temporal.js.map +1 -0
- package/dist/shaders/water.js +42 -20
- package/dist/shaders/water.js.map +1 -1
- package/dist/shadow/esm.js +31 -13
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/pcf_opt.js +12 -13
- package/dist/shadow/pcf_opt.js.map +1 -1
- package/dist/shadow/pcf_pd.js +12 -13
- package/dist/shadow/pcf_pd.js.map +1 -1
- package/dist/shadow/shader.js +38 -0
- package/dist/shadow/shader.js.map +1 -0
- package/dist/shadow/shadow_impl.js.map +1 -1
- package/dist/shadow/shadowmapper.js +67 -26
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/ssm.js +15 -16
- package/dist/shadow/ssm.js.map +1 -1
- package/dist/shadow/vsm.js +33 -16
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/shapes/box.js +181 -83
- package/dist/shapes/box.js.map +1 -1
- package/dist/shapes/cylinder.js +101 -43
- package/dist/shapes/cylinder.js.map +1 -1
- package/dist/shapes/plane.js +70 -29
- package/dist/shapes/plane.js.map +1 -1
- package/dist/shapes/shape.js +120 -17
- package/dist/shapes/shape.js.map +1 -1
- package/dist/shapes/sphere.js +78 -44
- package/dist/shapes/sphere.js.map +1 -1
- package/dist/shapes/tetrahedron.js +256 -0
- package/dist/shapes/tetrahedron.js.map +1 -0
- package/dist/shapes/torus.js +76 -55
- package/dist/shapes/torus.js.map +1 -1
- package/dist/src/animation/animation.js +127 -0
- package/dist/src/animation/animation.js.map +1 -0
- package/dist/src/animation/animationset.js +255 -0
- package/dist/src/animation/animationset.js.map +1 -0
- package/dist/src/animation/animationtrack.js +34 -0
- package/dist/src/animation/animationtrack.js.map +1 -0
- package/dist/src/animation/eulerrotationtrack.js +52 -0
- package/dist/src/animation/eulerrotationtrack.js.map +1 -0
- package/dist/src/animation/morphtarget.js +93 -0
- package/dist/src/animation/morphtarget.js.map +1 -0
- package/dist/src/animation/morphtrack.js +70 -0
- package/dist/src/animation/morphtrack.js.map +1 -0
- package/dist/src/animation/proptrack.js +161 -0
- package/dist/src/animation/proptrack.js.map +1 -0
- package/dist/src/animation/rotationtrack.js +51 -0
- package/dist/src/animation/rotationtrack.js.map +1 -0
- package/dist/src/animation/scaletrack.js +50 -0
- package/dist/src/animation/scaletrack.js.map +1 -0
- package/dist/src/animation/skeleton.js +204 -0
- package/dist/src/animation/skeleton.js.map +1 -0
- package/dist/src/animation/translationtrack.js +50 -0
- package/dist/src/animation/translationtrack.js.map +1 -0
- package/dist/{app.js → src/app/app.js} +18 -40
- package/dist/src/app/app.js.map +1 -0
- package/dist/{input → src/app}/inputmgr.js +41 -16
- package/dist/src/app/inputmgr.js.map +1 -0
- package/dist/src/asset/assetmanager.js +404 -0
- package/dist/src/asset/assetmanager.js.map +1 -0
- package/dist/src/asset/builtin.js +337 -0
- package/dist/src/asset/builtin.js.map +1 -0
- package/dist/src/asset/loaders/dds/dds.js +470 -0
- package/dist/src/asset/loaders/dds/dds.js.map +1 -0
- package/dist/src/asset/loaders/dds/dds_loader.js +28 -0
- package/dist/src/asset/loaders/dds/dds_loader.js.map +1 -0
- package/dist/src/asset/loaders/gltf/gltf_loader.js +1265 -0
- package/dist/src/asset/loaders/gltf/gltf_loader.js.map +1 -0
- package/dist/src/asset/loaders/gltf/helpers.js +327 -0
- package/dist/src/asset/loaders/gltf/helpers.js.map +1 -0
- package/dist/src/asset/loaders/hdr/hdr.js +180 -0
- package/dist/src/asset/loaders/hdr/hdr.js.map +1 -0
- package/dist/src/asset/loaders/image/tga_Loader.js +116 -0
- package/dist/src/asset/loaders/image/tga_Loader.js.map +1 -0
- package/dist/src/asset/loaders/image/webimage_loader.js +63 -0
- package/dist/src/asset/loaders/image/webimage_loader.js.map +1 -0
- package/dist/src/asset/loaders/loader.js +45 -0
- package/dist/src/asset/loaders/loader.js.map +1 -0
- package/dist/src/asset/model.js +414 -0
- package/dist/src/asset/model.js.map +1 -0
- package/dist/{blitter/depthlimitedgaussion.js → src/blitter/bilateralblur.js} +1 -2
- package/dist/src/blitter/bilateralblur.js.map +1 -0
- package/dist/src/blitter/blitter.js +390 -0
- package/dist/src/blitter/blitter.js.map +1 -0
- package/dist/src/blitter/box.js +118 -0
- package/dist/src/blitter/box.js.map +1 -0
- package/dist/src/blitter/copy.js +22 -0
- package/dist/src/blitter/copy.js.map +1 -0
- package/dist/src/blitter/gaussianblur.js +228 -0
- package/dist/src/blitter/gaussianblur.js.map +1 -0
- package/dist/src/camera/base.js +92 -0
- package/dist/src/camera/base.js.map +1 -0
- package/dist/src/camera/camera.js +1005 -0
- package/dist/src/camera/camera.js.map +1 -0
- package/dist/src/camera/fps.js +238 -0
- package/dist/src/camera/fps.js.map +1 -0
- package/dist/src/camera/orbit.js +245 -0
- package/dist/src/camera/orbit.js.map +1 -0
- package/dist/src/camera/orthocamera.js +167 -0
- package/dist/src/camera/orthocamera.js.map +1 -0
- package/dist/src/camera/perspectivecamera.js +141 -0
- package/dist/src/camera/perspectivecamera.js.map +1 -0
- package/dist/src/index.js +120 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/material/blinn.js +81 -0
- package/dist/src/material/blinn.js.map +1 -0
- package/dist/src/material/grassmaterial.js +113 -0
- package/dist/src/material/grassmaterial.js.map +1 -0
- package/dist/src/material/lambert.js +92 -0
- package/dist/src/material/lambert.js.map +1 -0
- package/dist/src/material/material.js +301 -0
- package/dist/src/material/material.js.map +1 -0
- package/dist/src/material/meshmaterial.js +704 -0
- package/dist/src/material/meshmaterial.js.map +1 -0
- package/dist/src/material/mixins/albedocolor.js +76 -0
- package/dist/src/material/mixins/albedocolor.js.map +1 -0
- package/dist/src/material/mixins/foliage.js +47 -0
- package/dist/src/material/mixins/foliage.js.map +1 -0
- package/dist/src/material/mixins/lightmodel/blinnphong.js +112 -0
- package/dist/src/material/mixins/lightmodel/blinnphong.js.map +1 -0
- package/dist/src/material/mixins/lightmodel/lambert.js +58 -0
- package/dist/src/material/mixins/lightmodel/lambert.js.map +1 -0
- package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js +178 -0
- package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -0
- package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js +139 -0
- package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -0
- package/dist/src/material/mixins/lit.js +476 -0
- package/dist/src/material/mixins/lit.js.map +1 -0
- package/dist/src/material/mixins/pbr/common.js +918 -0
- package/dist/src/material/mixins/pbr/common.js.map +1 -0
- package/dist/src/material/mixins/texture.js +172 -0
- package/dist/src/material/mixins/texture.js.map +1 -0
- package/dist/src/material/mixins/vertexcolor.js +56 -0
- package/dist/src/material/mixins/vertexcolor.js.map +1 -0
- package/dist/src/material/particle.js +178 -0
- package/dist/src/material/particle.js.map +1 -0
- package/dist/src/material/pbrmr.js +97 -0
- package/dist/src/material/pbrmr.js.map +1 -0
- package/dist/src/material/pbrsg.js +97 -0
- package/dist/src/material/pbrsg.js.map +1 -0
- package/dist/src/material/shader/helper.js +1209 -0
- package/dist/src/material/shader/helper.js.map +1 -0
- package/dist/src/material/terrain-cm.js +606 -0
- package/dist/src/material/terrain-cm.js.map +1 -0
- package/dist/src/material/terrainmaterial.js +375 -0
- package/dist/src/material/terrainmaterial.js.map +1 -0
- package/dist/src/material/unlit.js +41 -0
- package/dist/src/material/unlit.js.map +1 -0
- package/dist/src/material/water.js +417 -0
- package/dist/src/material/water.js.map +1 -0
- package/dist/src/posteffect/bloom.js +361 -0
- package/dist/src/posteffect/bloom.js.map +1 -0
- package/dist/src/posteffect/compositor.js +226 -0
- package/dist/src/posteffect/compositor.js.map +1 -0
- package/dist/src/posteffect/fxaa.js +273 -0
- package/dist/src/posteffect/fxaa.js.map +1 -0
- package/dist/src/posteffect/grayscale.js +69 -0
- package/dist/src/posteffect/grayscale.js.map +1 -0
- package/dist/src/posteffect/motionblur.js +96 -0
- package/dist/src/posteffect/motionblur.js.map +1 -0
- package/dist/src/posteffect/posteffect.js +126 -0
- package/dist/src/posteffect/posteffect.js.map +1 -0
- package/dist/src/posteffect/sao.js +324 -0
- package/dist/src/posteffect/sao.js.map +1 -0
- package/dist/src/posteffect/ssr.js +489 -0
- package/dist/src/posteffect/ssr.js.map +1 -0
- package/dist/src/posteffect/taa.js +172 -0
- package/dist/src/posteffect/taa.js.map +1 -0
- package/dist/src/posteffect/tonemap.js +94 -0
- package/dist/src/posteffect/tonemap.js.map +1 -0
- package/dist/src/render/abuffer_oit.js +361 -0
- package/dist/src/render/abuffer_oit.js.map +1 -0
- package/dist/src/render/clipmap.js +851 -0
- package/dist/src/render/clipmap.js.map +1 -0
- package/dist/src/render/cluster_light.js +333 -0
- package/dist/src/render/cluster_light.js.map +1 -0
- package/dist/src/render/cull_visitor.js +187 -0
- package/dist/src/render/cull_visitor.js.map +1 -0
- package/dist/src/render/depthpass.js +68 -0
- package/dist/src/render/depthpass.js.map +1 -0
- package/dist/src/render/drawable_mixin.js +227 -0
- package/dist/src/render/drawable_mixin.js.map +1 -0
- package/dist/src/render/envlight.js +463 -0
- package/dist/src/render/envlight.js.map +1 -0
- package/dist/src/render/fbm_wavegenerator.js +251 -0
- package/dist/src/render/fbm_wavegenerator.js.map +1 -0
- package/dist/src/render/fft_wavegenerator.js +1006 -0
- package/dist/src/render/fft_wavegenerator.js.map +1 -0
- package/dist/src/render/fullscreenquad.js +38 -0
- package/dist/src/render/fullscreenquad.js.map +1 -0
- package/dist/src/render/gerstner_wavegenerator.js +314 -0
- package/dist/src/render/gerstner_wavegenerator.js.map +1 -0
- package/dist/src/render/globalbindgroup_allocator.js +60 -0
- package/dist/src/render/globalbindgroup_allocator.js.map +1 -0
- package/dist/src/render/hzb.js +273 -0
- package/dist/src/render/hzb.js.map +1 -0
- package/dist/src/render/lightpass.js +172 -0
- package/dist/src/render/lightpass.js.map +1 -0
- package/dist/src/render/objectcolorpass.js +51 -0
- package/dist/src/render/objectcolorpass.js.map +1 -0
- package/dist/src/render/primitive.js +364 -0
- package/dist/src/render/primitive.js.map +1 -0
- package/dist/src/render/render_queue.js +467 -0
- package/dist/src/render/render_queue.js.map +1 -0
- package/dist/src/render/renderbundle_wrapper.js +152 -0
- package/dist/src/render/renderbundle_wrapper.js.map +1 -0
- package/dist/src/render/renderer.js +455 -0
- package/dist/src/render/renderer.js.map +1 -0
- package/dist/src/render/renderpass.js +200 -0
- package/dist/src/render/renderpass.js.map +1 -0
- package/dist/src/render/shadowmap_pass.js +56 -0
- package/dist/src/render/shadowmap_pass.js.map +1 -0
- package/dist/src/render/sky.js +1103 -0
- package/dist/src/render/sky.js.map +1 -0
- package/dist/src/render/weightedblended_oit.js +168 -0
- package/dist/src/render/weightedblended_oit.js.map +1 -0
- package/dist/src/scene/batchgroup.js +162 -0
- package/dist/src/scene/batchgroup.js.map +1 -0
- package/dist/src/scene/environment.js +209 -0
- package/dist/src/scene/environment.js.map +1 -0
- package/dist/src/scene/graph_node.js +72 -0
- package/dist/src/scene/graph_node.js.map +1 -0
- package/dist/src/scene/light.js +416 -0
- package/dist/src/scene/light.js.map +1 -0
- package/dist/src/scene/mesh.js +341 -0
- package/dist/src/scene/mesh.js.map +1 -0
- package/dist/src/scene/octree.js +649 -0
- package/dist/src/scene/octree.js.map +1 -0
- package/dist/src/scene/particlesys.js +738 -0
- package/dist/src/scene/particlesys.js.map +1 -0
- package/dist/src/scene/raycast_visitor.js +103 -0
- package/dist/src/scene/raycast_visitor.js.map +1 -0
- package/dist/src/scene/scene.js +284 -0
- package/dist/src/scene/scene.js.map +1 -0
- package/dist/src/scene/scene_node.js +732 -0
- package/dist/src/scene/scene_node.js.map +1 -0
- package/dist/src/scene/terrain/grass.js +278 -0
- package/dist/src/scene/terrain/grass.js.map +1 -0
- package/dist/src/scene/terrain/heightfield.js +475 -0
- package/dist/src/scene/terrain/heightfield.js.map +1 -0
- package/dist/src/scene/terrain/patch.js +530 -0
- package/dist/src/scene/terrain/patch.js.map +1 -0
- package/dist/src/scene/terrain/quadtree.js +461 -0
- package/dist/src/scene/terrain/quadtree.js.map +1 -0
- package/dist/src/scene/terrain/terrain.js +246 -0
- package/dist/src/scene/terrain/terrain.js.map +1 -0
- package/dist/src/scene/terrain-cm/grass.js +594 -0
- package/dist/src/scene/terrain-cm/grass.js.map +1 -0
- package/dist/src/scene/terrain-cm/grassmaterial.js +159 -0
- package/dist/src/scene/terrain-cm/grassmaterial.js.map +1 -0
- package/dist/src/scene/terrain-cm/terrain-cm.js +538 -0
- package/dist/src/scene/terrain-cm/terrain-cm.js.map +1 -0
- package/dist/src/scene/water.js +374 -0
- package/dist/src/scene/water.js.map +1 -0
- package/dist/src/shaders/atmosphere.js +957 -0
- package/dist/src/shaders/atmosphere.js.map +1 -0
- package/dist/src/shaders/fog.js +112 -0
- package/dist/src/shaders/fog.js.map +1 -0
- package/dist/src/shaders/misc.js +266 -0
- package/dist/src/shaders/misc.js.map +1 -0
- package/dist/src/shaders/noise.js +222 -0
- package/dist/src/shaders/noise.js.map +1 -0
- package/dist/src/shaders/pbr.js +51 -0
- package/dist/src/shaders/pbr.js.map +1 -0
- package/dist/src/shaders/shadow.js +636 -0
- package/dist/src/shaders/shadow.js.map +1 -0
- package/dist/src/shaders/ssr.js +490 -0
- package/dist/src/shaders/ssr.js.map +1 -0
- package/dist/src/shaders/temporal.js +215 -0
- package/dist/src/shaders/temporal.js.map +1 -0
- package/dist/src/shaders/water.js +756 -0
- package/dist/src/shaders/water.js.map +1 -0
- package/dist/src/shadow/esm.js +237 -0
- package/dist/src/shadow/esm.js.map +1 -0
- package/dist/src/shadow/pcf_opt.js +181 -0
- package/dist/src/shadow/pcf_opt.js.map +1 -0
- package/dist/src/shadow/pcf_pd.js +189 -0
- package/dist/src/shadow/pcf_pd.js.map +1 -0
- package/dist/src/shadow/shader.js +37 -0
- package/dist/src/shadow/shader.js.map +1 -0
- package/dist/src/shadow/shadow_impl.js +15 -0
- package/dist/src/shadow/shadow_impl.js.map +1 -0
- package/dist/src/shadow/shadowmapper.js +790 -0
- package/dist/src/shadow/shadowmapper.js.map +1 -0
- package/dist/src/shadow/ssm.js +159 -0
- package/dist/src/shadow/ssm.js.map +1 -0
- package/dist/src/shadow/vsm.js +297 -0
- package/dist/src/shadow/vsm.js.map +1 -0
- package/dist/src/shapes/box.js +386 -0
- package/dist/src/shapes/box.js.map +1 -0
- package/dist/src/shapes/cylinder.js +125 -0
- package/dist/src/shapes/cylinder.js.map +1 -0
- package/dist/src/shapes/plane.js +88 -0
- package/dist/src/shapes/plane.js.map +1 -0
- package/dist/src/shapes/shape.js +87 -0
- package/dist/src/shapes/shape.js.map +1 -0
- package/dist/src/shapes/sphere.js +114 -0
- package/dist/src/shapes/sphere.js.map +1 -0
- package/dist/src/shapes/tetrahedron.js +188 -0
- package/dist/src/shapes/tetrahedron.js.map +1 -0
- package/dist/src/shapes/torus.js +111 -0
- package/dist/src/shapes/torus.js.map +1 -0
- package/dist/src/utility/aabbtree.js +400 -0
- package/dist/src/utility/aabbtree.js.map +1 -0
- package/dist/src/utility/bounding_volume.js +29 -0
- package/dist/src/utility/bounding_volume.js.map +1 -0
- package/dist/src/utility/debug.js +28 -0
- package/dist/src/utility/debug.js.map +1 -0
- package/dist/src/utility/draco/decoder.js +116 -0
- package/dist/src/utility/draco/decoder.js.map +1 -0
- package/dist/src/utility/misc.js +105 -0
- package/dist/src/utility/misc.js.map +1 -0
- package/dist/src/utility/panorama.js +163 -0
- package/dist/src/utility/panorama.js.map +1 -0
- package/dist/src/utility/pmrem.js +354 -0
- package/dist/src/utility/pmrem.js.map +1 -0
- package/dist/src/utility/rendermipmap.js +115 -0
- package/dist/src/utility/rendermipmap.js.map +1 -0
- package/dist/src/utility/serialization/json.js +402 -0
- package/dist/src/utility/serialization/json.js.map +1 -0
- package/dist/src/utility/serialization/manager.js +623 -0
- package/dist/src/utility/serialization/manager.js.map +1 -0
- package/dist/src/utility/serialization/scene/animation.js +248 -0
- package/dist/src/utility/serialization/scene/animation.js.map +1 -0
- package/dist/src/utility/serialization/scene/batch.js +59 -0
- package/dist/src/utility/serialization/scene/batch.js.map +1 -0
- package/dist/src/utility/serialization/scene/camera.js +790 -0
- package/dist/src/utility/serialization/scene/camera.js.map +1 -0
- package/dist/src/utility/serialization/scene/common.js +222 -0
- package/dist/src/utility/serialization/scene/common.js.map +1 -0
- package/dist/src/utility/serialization/scene/light.js +575 -0
- package/dist/src/utility/serialization/scene/light.js.map +1 -0
- package/dist/src/utility/serialization/scene/material.js +1111 -0
- package/dist/src/utility/serialization/scene/material.js.map +1 -0
- package/dist/src/utility/serialization/scene/mesh.js +148 -0
- package/dist/src/utility/serialization/scene/mesh.js.map +1 -0
- package/dist/src/utility/serialization/scene/misc.js +39 -0
- package/dist/src/utility/serialization/scene/misc.js.map +1 -0
- package/dist/src/utility/serialization/scene/node.js +451 -0
- package/dist/src/utility/serialization/scene/node.js.map +1 -0
- package/dist/src/utility/serialization/scene/particle.js +425 -0
- package/dist/src/utility/serialization/scene/particle.js.map +1 -0
- package/dist/src/utility/serialization/scene/primitive.js +692 -0
- package/dist/src/utility/serialization/scene/primitive.js.map +1 -0
- package/dist/src/utility/serialization/scene/scene.js +704 -0
- package/dist/src/utility/serialization/scene/scene.js.map +1 -0
- package/dist/src/utility/serialization/scene/terrain.js +488 -0
- package/dist/src/utility/serialization/scene/terrain.js.map +1 -0
- package/dist/src/utility/serialization/scene/water.js +465 -0
- package/dist/src/utility/serialization/scene/water.js.map +1 -0
- package/dist/src/utility/shprojector.js +297 -0
- package/dist/src/utility/shprojector.js.map +1 -0
- package/dist/{material/mixins → src/utility/textures}/ggxlut.js +1 -1
- package/dist/src/utility/textures/ggxlut.js.map +1 -0
- package/dist/src/utility/textures/gradientnoise.js +62 -0
- package/dist/src/utility/textures/gradientnoise.js.map +1 -0
- package/dist/src/utility/textures/randomnoise.js +41 -0
- package/dist/src/utility/textures/randomnoise.js.map +1 -0
- package/dist/src/values.js +162 -0
- package/dist/src/values.js.map +1 -0
- package/dist/utility/aabbtree.js +15 -5
- package/dist/utility/aabbtree.js.map +1 -1
- package/dist/utility/blueprint/common/constants.js +851 -0
- package/dist/utility/blueprint/common/constants.js.map +1 -0
- package/dist/utility/blueprint/common/math.js +2045 -0
- package/dist/utility/blueprint/common/math.js.map +1 -0
- package/dist/utility/blueprint/common.js +7 -0
- package/dist/utility/blueprint/common.js.map +1 -0
- package/dist/utility/blueprint/material/common.js +7 -0
- package/dist/utility/blueprint/material/common.js.map +1 -0
- package/dist/utility/blueprint/material/func.js +521 -0
- package/dist/utility/blueprint/material/func.js.map +1 -0
- package/dist/utility/blueprint/material/inputs.js +1659 -0
- package/dist/utility/blueprint/material/inputs.js.map +1 -0
- package/dist/utility/blueprint/material/ir.js +1311 -0
- package/dist/utility/blueprint/material/ir.js.map +1 -0
- package/dist/utility/blueprint/material/pbr.js +362 -0
- package/dist/utility/blueprint/material/pbr.js.map +1 -0
- package/dist/utility/blueprint/material/texture.js +1099 -0
- package/dist/utility/blueprint/material/texture.js.map +1 -0
- package/dist/utility/blueprint/node.js +187 -0
- package/dist/utility/blueprint/node.js.map +1 -0
- package/dist/utility/bounding_volume.js +0 -1
- package/dist/utility/bounding_volume.js.map +1 -1
- package/dist/utility/debug.js +26 -0
- package/dist/utility/debug.js.map +1 -0
- package/dist/utility/draco/decoder.js +1 -1
- package/dist/utility/draco/decoder.js.map +1 -1
- package/dist/utility/misc.js +18 -6
- package/dist/utility/misc.js.map +1 -1
- package/dist/utility/panorama.js +8 -6
- package/dist/utility/panorama.js.map +1 -1
- package/dist/utility/pmrem.js +30 -18
- package/dist/utility/pmrem.js.map +1 -1
- package/dist/utility/rendermipmap.js +116 -0
- package/dist/utility/rendermipmap.js.map +1 -0
- package/dist/utility/serialization/blueprint/constants.js +255 -0
- package/dist/utility/serialization/blueprint/constants.js.map +1 -0
- package/dist/utility/serialization/blueprint/material/constants.js +203 -0
- package/dist/utility/serialization/blueprint/material/constants.js.map +1 -0
- package/dist/utility/serialization/blueprint/material/texture.js +165 -0
- package/dist/utility/serialization/blueprint/material/texture.js.map +1 -0
- package/dist/utility/serialization/json.js +402 -0
- package/dist/utility/serialization/json.js.map +1 -0
- package/dist/utility/serialization/manager.js +1176 -0
- package/dist/utility/serialization/manager.js.map +1 -0
- package/dist/utility/serialization/scene/animation.js +699 -0
- package/dist/utility/serialization/scene/animation.js.map +1 -0
- package/dist/utility/serialization/scene/batch.js +53 -0
- package/dist/utility/serialization/scene/batch.js.map +1 -0
- package/dist/utility/serialization/scene/camera.js +808 -0
- package/dist/utility/serialization/scene/camera.js.map +1 -0
- package/dist/utility/serialization/scene/common.js +224 -0
- package/dist/utility/serialization/scene/common.js.map +1 -0
- package/dist/utility/serialization/scene/light.js +589 -0
- package/dist/utility/serialization/scene/light.js.map +1 -0
- package/dist/utility/serialization/scene/material.js +942 -0
- package/dist/utility/serialization/scene/material.js.map +1 -0
- package/dist/utility/serialization/scene/mesh.js +374 -0
- package/dist/utility/serialization/scene/mesh.js.map +1 -0
- package/dist/utility/serialization/scene/misc.js +39 -0
- package/dist/utility/serialization/scene/misc.js.map +1 -0
- package/dist/utility/serialization/scene/node.js +391 -0
- package/dist/utility/serialization/scene/node.js.map +1 -0
- package/dist/utility/serialization/scene/particle.js +425 -0
- package/dist/utility/serialization/scene/particle.js.map +1 -0
- package/dist/utility/serialization/scene/primitive.js +582 -0
- package/dist/utility/serialization/scene/primitive.js.map +1 -0
- package/dist/utility/serialization/scene/scene.js +763 -0
- package/dist/utility/serialization/scene/scene.js.map +1 -0
- package/dist/utility/serialization/scene/terrain.js +495 -0
- package/dist/utility/serialization/scene/terrain.js.map +1 -0
- package/dist/utility/serialization/scene/water.js +465 -0
- package/dist/utility/serialization/scene/water.js.map +1 -0
- package/dist/utility/shprojector.js +313 -0
- package/dist/utility/shprojector.js.map +1 -0
- package/dist/utility/textures/ggxlut.js +4 -5
- package/dist/utility/textures/ggxlut.js.map +1 -1
- package/dist/utility/textures/gradientnoise.js +2 -1
- package/dist/utility/textures/gradientnoise.js.map +1 -1
- package/dist/utility/textures/randomnoise.js +1 -0
- package/dist/utility/textures/randomnoise.js.map +1 -1
- package/dist/values.js +91 -4
- package/dist/values.js.map +1 -1
- package/package.json +29 -15
- package/dist/app.js.map +0 -1
- package/dist/blitter/depthlimitedgaussion.js.map +0 -1
- package/dist/input/inputmgr.js.map +0 -1
- package/dist/material/mixins/ggxlut.js.map +0 -1
- package/dist/posteffect/water.js +0 -508
- package/dist/posteffect/water.js.map +0 -1
- package/dist/render/oit.js +0 -16
- package/dist/render/oit.js.map +0 -1
- package/dist/render/scatteringlut.js +0 -634
- package/dist/render/scatteringlut.js.map +0 -1
- package/dist/render/watermesh.js +0 -193
- package/dist/render/watermesh.js.map +0 -1
- package/dist/render/wavegenerator.js +0 -8
- package/dist/render/wavegenerator.js.map +0 -1
- package/dist/scene/xform.js +0 -247
- package/dist/scene/xform.js.map +0 -1
- package/dist/utility/shprojection.js +0 -442
- package/dist/utility/shprojection.js.map +0 -1
|
@@ -1,16 +1,28 @@
|
|
|
1
|
-
import { Vector3, Vector4 } from '@zephyr3d/base';
|
|
2
|
-
import {
|
|
3
|
-
import { ScatteringLut } from '../../render/scatteringlut.js';
|
|
1
|
+
import { Vector3, Vector4, Vector2 } from '@zephyr3d/base';
|
|
2
|
+
import { RENDER_PASS_TYPE_DEPTH, RENDER_PASS_TYPE_SHADOWMAP, RENDER_PASS_TYPE_OBJECT_COLOR, RENDER_PASS_TYPE_LIGHT, MaterialVaryingFlags, MAX_CLUSTERED_LIGHTS, MORPH_WEIGHTS_VECTOR_COUNT, MORPH_TARGET_POSITION, MORPH_TARGET_NORMAL, MORPH_TARGET_TANGENT, MORPH_ATTRIBUTE_VECTOR_COUNT } from '../../values.js';
|
|
4
3
|
import { ProgramBuilder } from '@zephyr3d/device';
|
|
5
|
-
import { linearToGamma } from '../../shaders/misc.js';
|
|
6
|
-
import {
|
|
4
|
+
import { decodeNormalizedFloatFromRGBA, linearToGamma } from '../../shaders/misc.js';
|
|
5
|
+
import { fetchSampler } from '../../utility/misc.js';
|
|
6
|
+
import { getDevice } from '../../app/api.js';
|
|
7
|
+
import { getDefaultAtmosphereParams, getAtmosphereParamsStruct } from '../../shaders/atmosphere.js';
|
|
8
|
+
import { getDefaultHeightFogParams, getHeightFogParamsStruct, calculateFog } from '../../shaders/fog.js';
|
|
7
9
|
|
|
8
|
-
const UNIFORM_NAME_GLOBAL = 'Z_UniformGlobal';
|
|
9
10
|
const UNIFORM_NAME_LIGHT_BUFFER = 'Z_UniformLightBuffer';
|
|
10
11
|
const UNIFORM_NAME_LIGHT_INDEX_TEXTURE = 'Z_UniformLightIndexTex';
|
|
12
|
+
const UNIFORM_NAME_BAKED_SKY_MAP = 'Z_UniformBakedSky';
|
|
11
13
|
const UNIFORM_NAME_AERIALPERSPECTIVE_LUT = 'Z_UniformAerialPerspectiveLUT';
|
|
14
|
+
const UNIFORM_NAME_SKYDISTANTLIGHT_LUT = 'Z_UniformSkyDistantLightLUT';
|
|
12
15
|
const UNIFORM_NAME_SHADOW_MAP = 'Z_UniformShadowMap';
|
|
16
|
+
const UNIFORM_NAME_LINEAR_DEPTH_MAP = 'Z_UniformLinearDepth';
|
|
17
|
+
const UNIFORM_NAME_LINEAR_DEPTH_MAP_SIZE = 'Z_UniformLinearDepthSize';
|
|
18
|
+
const UNIFORM_NAME_SCENE_COLOR_MAP = 'Z_UniformSceneColor';
|
|
19
|
+
const UNIFORM_NAME_SCENE_COLOR_MAP_SIZE = 'Z_UniformSceneColorSize';
|
|
20
|
+
const UNIFORM_NAME_HIZ_DEPTH_MAP = 'Z_UniformHiZDepth';
|
|
21
|
+
const UNIFORM_NAME_HIZ_DEPTH_MAP_INFO = 'Z_UniformHiZDepthInfo';
|
|
22
|
+
const UNIFORM_NAME_OBJECT_COLOR = 'Z_ObjectColor';
|
|
13
23
|
const UNIFORM_NAME_WORLD_MATRIX = 'Z_UniformWorldMatrix';
|
|
24
|
+
const UNIFORM_NAME_PREV_WORLD_MATRIX = 'Z_UniformPrevWorldMatrix';
|
|
25
|
+
const UNIFORM_NAME_PREV_WORLD_MATRXI_FRAME = 'Z_UniformPrevWorldMatrixFrame';
|
|
14
26
|
const UNIFORM_NAME_INSTANCE_DATA_STRIDE = 'Z_UniformInstanceDataStride';
|
|
15
27
|
const UNIFORM_NAME_INSTANCE_DATA = 'Z_UniformInstanceData';
|
|
16
28
|
const UNIFORM_NAME_INSTANCE_DATA_OFFSET = 'Z_UniformInstanceDataOffset';
|
|
@@ -23,44 +35,46 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
23
35
|
* Helper shader functions for the builtin material system
|
|
24
36
|
* @public
|
|
25
37
|
*/ class ShaderHelper {
|
|
26
|
-
static FOG_TYPE_NONE = 0;
|
|
27
|
-
static FOG_TYPE_LINEAR = 1;
|
|
28
|
-
static FOG_TYPE_EXP = 2;
|
|
29
|
-
static FOG_TYPE_EXP2 = 3;
|
|
30
|
-
static FOG_TYPE_SCATTER = 4;
|
|
31
38
|
static BILLBOARD_SPHERICAL = 1;
|
|
32
39
|
static BILLBOARD_SYLINDRAL = 2;
|
|
40
|
+
static MATERIAL_INSTANCE_DATA_OFFSET = 9;
|
|
33
41
|
/** @internal */ static defaultSunDir = Vector3.one().inplaceNormalize();
|
|
34
42
|
/** @internal */ static SKIN_MATRIX_NAME = 'Z_SkinMatrix';
|
|
43
|
+
static SKIN_PREV_MATRIX_NAME = 'Z_PrevSkinMatrix';
|
|
44
|
+
static SKIN_BONE_OFFSET = 'Z_boneOffset';
|
|
35
45
|
/** @internal */ static _drawableBindGroupLayouts = {};
|
|
36
46
|
/** @internal */ static _lightUniformShadow = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
shadowMatrices: new Float32Array(16 * 4)
|
|
49
|
-
}
|
|
47
|
+
sunDir: new Vector3(),
|
|
48
|
+
envLightStrength: 1,
|
|
49
|
+
shadowCascades: 1,
|
|
50
|
+
positionAndRange: new Vector4(),
|
|
51
|
+
directionAndCutoff: new Vector4(),
|
|
52
|
+
diffuseAndIntensity: new Vector4(),
|
|
53
|
+
cascadeDistances: new Vector4(),
|
|
54
|
+
depthBiasValues: new Vector4(),
|
|
55
|
+
shadowCameraParams: new Vector4(),
|
|
56
|
+
depthBiasScales: new Vector4(),
|
|
57
|
+
shadowMatrices: new Float32Array(16 * 4)
|
|
50
58
|
};
|
|
51
59
|
/** @internal */ static _fogUniforms = {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// aerial perspective density
|
|
58
|
-
apDensity: 1
|
|
59
|
-
}
|
|
60
|
+
withAerialPerspective: 0,
|
|
61
|
+
fogType: 0,
|
|
62
|
+
additive: 0,
|
|
63
|
+
atmosphereParams: getDefaultAtmosphereParams(),
|
|
64
|
+
heightFogParams: getDefaultHeightFogParams()
|
|
60
65
|
};
|
|
66
|
+
static getObjectColorUniformName() {
|
|
67
|
+
return UNIFORM_NAME_OBJECT_COLOR;
|
|
68
|
+
}
|
|
61
69
|
static getWorldMatrixUniformName() {
|
|
62
70
|
return UNIFORM_NAME_WORLD_MATRIX;
|
|
63
71
|
}
|
|
72
|
+
static getPrevWorldMatrixUniformName() {
|
|
73
|
+
return UNIFORM_NAME_PREV_WORLD_MATRIX;
|
|
74
|
+
}
|
|
75
|
+
static getPrevWorldMatrixFrameUniformName() {
|
|
76
|
+
return UNIFORM_NAME_PREV_WORLD_MATRXI_FRAME;
|
|
77
|
+
}
|
|
64
78
|
static getInstanceDataUniformName() {
|
|
65
79
|
return UNIFORM_NAME_INSTANCE_DATA;
|
|
66
80
|
}
|
|
@@ -92,7 +106,7 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
92
106
|
const hash = `${skinning ? 1 : 0}${morphing ? 1 : 0}${instancing ? 1 : 0}`;
|
|
93
107
|
let bindGroupLayout = this._drawableBindGroupLayouts[hash];
|
|
94
108
|
if (!bindGroupLayout) {
|
|
95
|
-
const device =
|
|
109
|
+
const device = getDevice();
|
|
96
110
|
const buildInfo = new ProgramBuilder(device).buildRender({
|
|
97
111
|
vertex (pb) {
|
|
98
112
|
ShaderHelper.vertexShaderDrawableStuff(this, skinning, morphing, instancing);
|
|
@@ -136,10 +150,23 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
136
150
|
pb.vec4('position'),
|
|
137
151
|
pb.vec4('clipPlane'),
|
|
138
152
|
pb.mat4('viewProjectionMatrix'),
|
|
153
|
+
pb.mat4('invViewProjectionMatrix'),
|
|
154
|
+
pb.mat4('unjitteredVPMatrix'),
|
|
155
|
+
pb.mat4('jitteredInvVPMatrix'),
|
|
139
156
|
pb.mat4('viewMatrix'),
|
|
157
|
+
pb.mat4('worldMatrix'),
|
|
140
158
|
pb.mat4('projectionMatrix'),
|
|
159
|
+
pb.mat4('invProjectionMatrix'),
|
|
141
160
|
pb.vec4('params'),
|
|
142
|
-
|
|
161
|
+
...ctx.motionVectors && ctx.renderPass.type === RENDER_PASS_TYPE_DEPTH ? [
|
|
162
|
+
pb.mat4('prevUnjitteredVPMatrix')
|
|
163
|
+
] : [],
|
|
164
|
+
pb.vec2('renderSize'),
|
|
165
|
+
pb.vec2('jitterValue'),
|
|
166
|
+
pb.float('roughnessFactor'),
|
|
167
|
+
pb.float('frameDeltaTime'),
|
|
168
|
+
pb.float('elapsedTime'),
|
|
169
|
+
pb.int('framestamp')
|
|
143
170
|
]);
|
|
144
171
|
if (ctx.renderPass.type === RENDER_PASS_TYPE_SHADOWMAP) {
|
|
145
172
|
const lightStruct = pb.defineStruct([
|
|
@@ -149,24 +176,25 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
149
176
|
pb.vec4('depthBias'),
|
|
150
177
|
pb.int('lightType')
|
|
151
178
|
]);
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
lightStruct('light')
|
|
155
|
-
]);
|
|
156
|
-
scope[UNIFORM_NAME_GLOBAL] = globalStruct().uniform(0);
|
|
179
|
+
scope.camera = cameraStruct().uniform(0);
|
|
180
|
+
scope.light = lightStruct().uniform(0);
|
|
157
181
|
} else if (ctx.renderPass.type === RENDER_PASS_TYPE_DEPTH || ctx.renderPass.type === RENDER_PASS_TYPE_OBJECT_COLOR) {
|
|
158
|
-
|
|
159
|
-
cameraStruct('camera')
|
|
160
|
-
]);
|
|
161
|
-
scope[UNIFORM_NAME_GLOBAL] = globalStruct().uniform(0);
|
|
182
|
+
scope.camera = cameraStruct().uniform(0);
|
|
162
183
|
} else if (ctx.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
|
|
163
184
|
const useClusteredLighting = !ctx.currentShadowLight;
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
185
|
+
if (ctx.materialFlags & MaterialVaryingFlags.APPLY_FOG) {
|
|
186
|
+
const fogStructMembers = [
|
|
187
|
+
pb.int('withAerialPerspective'),
|
|
188
|
+
pb.int('fogType'),
|
|
189
|
+
pb.int('additive'),
|
|
190
|
+
getAtmosphereParamsStruct(pb)('atmosphereParams'),
|
|
191
|
+
getHeightFogParamsStruct(pb)('heightFogParams')
|
|
192
|
+
];
|
|
193
|
+
const fogStruct = pb.defineStruct(fogStructMembers);
|
|
194
|
+
scope.fog = fogStruct().uniform(0);
|
|
195
|
+
scope[UNIFORM_NAME_AERIALPERSPECTIVE_LUT] = pb.tex2D().uniform(0);
|
|
196
|
+
scope[UNIFORM_NAME_SKYDISTANTLIGHT_LUT] = pb.tex2D().uniform(0);
|
|
197
|
+
}
|
|
170
198
|
const lightStruct = ctx.currentShadowLight ? pb.defineStruct([
|
|
171
199
|
pb.vec3('sunDir'),
|
|
172
200
|
pb.int('shadowCascades'),
|
|
@@ -186,19 +214,13 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
186
214
|
pb.ivec4('countParams'),
|
|
187
215
|
pb.ivec2('lightIndexTexSize')
|
|
188
216
|
]);
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
lightStruct('light'),
|
|
192
|
-
fogStruct('fog')
|
|
193
|
-
]);
|
|
194
|
-
scope[UNIFORM_NAME_GLOBAL] = globalStruct().uniform(0);
|
|
217
|
+
scope.camera = cameraStruct().uniform(0);
|
|
218
|
+
scope.light = lightStruct().uniform(0);
|
|
195
219
|
if (useClusteredLighting) {
|
|
196
220
|
scope[UNIFORM_NAME_LIGHT_BUFFER] = pb.vec4[(MAX_CLUSTERED_LIGHTS + 1) * 3]().uniformBuffer(0);
|
|
197
221
|
scope[UNIFORM_NAME_LIGHT_INDEX_TEXTURE] = (pb.getDevice().type === 'webgl' ? pb.tex2D() : pb.utex2D()).uniform(0);
|
|
198
222
|
}
|
|
199
|
-
|
|
200
|
-
scope[UNIFORM_NAME_AERIALPERSPECTIVE_LUT] = pb.tex2D().uniform(0);
|
|
201
|
-
}
|
|
223
|
+
scope[UNIFORM_NAME_BAKED_SKY_MAP] = pb.texCube().uniform(0);
|
|
202
224
|
if (ctx.currentShadowLight) {
|
|
203
225
|
const scope = pb.getGlobalScope();
|
|
204
226
|
const shadowMapParams = ctx.shadowMapInfo.get(ctx.currentShadowLight);
|
|
@@ -208,7 +230,21 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
208
230
|
}
|
|
209
231
|
scope[UNIFORM_NAME_SHADOW_MAP] = tex.uniform(0);
|
|
210
232
|
}
|
|
211
|
-
ctx.drawEnvLight
|
|
233
|
+
if (ctx.drawEnvLight) {
|
|
234
|
+
ctx.env.light.envLight.initShaderBindings(pb);
|
|
235
|
+
}
|
|
236
|
+
if (ctx.linearDepthTexture) {
|
|
237
|
+
scope[UNIFORM_NAME_LINEAR_DEPTH_MAP] = pb.tex2D().uniform(0);
|
|
238
|
+
scope[UNIFORM_NAME_LINEAR_DEPTH_MAP_SIZE] = pb.vec2().uniform(0);
|
|
239
|
+
}
|
|
240
|
+
if (ctx.sceneColorTexture) {
|
|
241
|
+
scope[UNIFORM_NAME_SCENE_COLOR_MAP] = pb.tex2D().uniform(0);
|
|
242
|
+
scope[UNIFORM_NAME_SCENE_COLOR_MAP_SIZE] = pb.vec2().uniform(0);
|
|
243
|
+
}
|
|
244
|
+
if (ctx.HiZTexture) {
|
|
245
|
+
scope[UNIFORM_NAME_HIZ_DEPTH_MAP] = pb.tex2D().uniform(0);
|
|
246
|
+
scope[UNIFORM_NAME_HIZ_DEPTH_MAP_INFO] = pb.vec4().uniform(0);
|
|
247
|
+
}
|
|
212
248
|
}
|
|
213
249
|
}
|
|
214
250
|
/**
|
|
@@ -245,8 +281,10 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
245
281
|
pb.int('boneIndex')
|
|
246
282
|
], function() {
|
|
247
283
|
const boneTexture = this[UNIFORM_NAME_BONE_MATRICES];
|
|
248
|
-
this.$l.
|
|
249
|
-
this.$l.
|
|
284
|
+
this.$l.uvOffsets = pb.textureSampleLevel(boneTexture, pb.div(pb.vec2(0.5), this[UNIFORM_NAME_BONE_TEXTURE_SIZE]), 0);
|
|
285
|
+
this.$l.currentOffset = pb.int(this.uvOffsets.x);
|
|
286
|
+
this.$l.w = this[UNIFORM_NAME_BONE_TEXTURE_SIZE].x;
|
|
287
|
+
this.$l.pixelIndex = pb.float(pb.mul(pb.add(this.boneIndex, this.currentOffset), 4));
|
|
250
288
|
this.$l.xIndex = pb.mod(this.pixelIndex, this.w);
|
|
251
289
|
this.$l.yIndex = pb.floor(pb.div(this.pixelIndex, this.w));
|
|
252
290
|
this.$l.u1 = pb.div(pb.add(this.xIndex, 0.5), this.w);
|
|
@@ -334,38 +372,116 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
334
372
|
const offset = scope[this.getMorphInfoUniformName()][pos][comp];
|
|
335
373
|
return scope[funcName](pb.int(offset));
|
|
336
374
|
}
|
|
375
|
+
/** @internal */ static prepareSkinAnimation(scope) {
|
|
376
|
+
if (!this.hasSkinning(scope)) {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
const that = this;
|
|
380
|
+
const pb = scope.$builder;
|
|
381
|
+
const funcNameGetBoneMatrixFromTexture = 'Z_getBoneMatrixFromTexture';
|
|
382
|
+
pb.func(funcNameGetBoneMatrixFromTexture, [
|
|
383
|
+
pb.float('boneIndex'),
|
|
384
|
+
pb.float('boneOffset')
|
|
385
|
+
], function() {
|
|
386
|
+
const boneTexture = this[UNIFORM_NAME_BONE_MATRICES];
|
|
387
|
+
this.$l.w = this[UNIFORM_NAME_BONE_TEXTURE_SIZE].x;
|
|
388
|
+
this.$l.pixelIndex = pb.mul(pb.add(this.boneIndex, this.boneOffset), 4);
|
|
389
|
+
this.$l.xIndex = pb.mod(this.pixelIndex, this.w);
|
|
390
|
+
this.$l.yIndex = pb.floor(pb.div(this.pixelIndex, this.w));
|
|
391
|
+
this.$l.u1 = pb.div(pb.add(this.xIndex, 0.5), this.w);
|
|
392
|
+
this.$l.u2 = pb.div(pb.add(this.xIndex, 1.5), this.w);
|
|
393
|
+
this.$l.u3 = pb.div(pb.add(this.xIndex, 2.5), this.w);
|
|
394
|
+
this.$l.u4 = pb.div(pb.add(this.xIndex, 3.5), this.w);
|
|
395
|
+
this.$l.v = pb.div(pb.add(this.yIndex, 0.5), this.w);
|
|
396
|
+
this.$l.row1 = pb.textureSampleLevel(boneTexture, pb.vec2(this.u1, this.v), 0);
|
|
397
|
+
this.$l.row2 = pb.textureSampleLevel(boneTexture, pb.vec2(this.u2, this.v), 0);
|
|
398
|
+
this.$l.row3 = pb.textureSampleLevel(boneTexture, pb.vec2(this.u3, this.v), 0);
|
|
399
|
+
this.$l.row4 = pb.textureSampleLevel(boneTexture, pb.vec2(this.u4, this.v), 0);
|
|
400
|
+
this.$return(pb.mat4(this.row1, this.row2, this.row3, this.row4));
|
|
401
|
+
});
|
|
402
|
+
const funcNameGetSkinningMatrix = 'Z_getSkinningMatrix';
|
|
403
|
+
pb.func(funcNameGetSkinningMatrix, [
|
|
404
|
+
pb.float('boneOffset')
|
|
405
|
+
], function() {
|
|
406
|
+
const invBindMatrix = this[UNIFORM_NAME_BONE_INV_BIND_MATRIX];
|
|
407
|
+
const blendIndices = scope.$getVertexAttrib('blendIndices');
|
|
408
|
+
const blendWeights = scope.$getVertexAttrib('blendWeights');
|
|
409
|
+
this.$l.m0 = scope.$g[funcNameGetBoneMatrixFromTexture](blendIndices[0], this.boneOffset);
|
|
410
|
+
this.$l.m1 = scope.$g[funcNameGetBoneMatrixFromTexture](blendIndices[1], this.boneOffset);
|
|
411
|
+
this.$l.m2 = scope.$g[funcNameGetBoneMatrixFromTexture](blendIndices[2], this.boneOffset);
|
|
412
|
+
this.$l.m3 = scope.$g[funcNameGetBoneMatrixFromTexture](blendIndices[3], this.boneOffset);
|
|
413
|
+
this.$l.m = pb.add(pb.mul(this.m0, blendWeights.x), pb.mul(this.m1, blendWeights.y), pb.mul(this.m2, blendWeights.z), pb.mul(this.m3, blendWeights.w));
|
|
414
|
+
this.$return(pb.mul(invBindMatrix, this.m));
|
|
415
|
+
});
|
|
416
|
+
const motionVector = !!this.getUnjitteredViewProjectionMatrix(scope);
|
|
417
|
+
const boneTexture = scope[UNIFORM_NAME_BONE_MATRICES];
|
|
418
|
+
scope.$l[that.SKIN_BONE_OFFSET] = pb.textureSampleLevel(boneTexture, pb.div(pb.vec2(0.5), scope[UNIFORM_NAME_BONE_TEXTURE_SIZE]), 0).xy;
|
|
419
|
+
scope.$l[that.SKIN_MATRIX_NAME] = scope[funcNameGetSkinningMatrix](scope[that.SKIN_BONE_OFFSET].x);
|
|
420
|
+
if (motionVector) {
|
|
421
|
+
scope.$l[that.SKIN_PREV_MATRIX_NAME] = scope[funcNameGetSkinningMatrix](scope[that.SKIN_BONE_OFFSET].y);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
337
424
|
/**
|
|
338
425
|
* Calculates the vertex position of type vec3 in object space
|
|
339
426
|
*
|
|
340
427
|
* @param scope - Current shader scope
|
|
341
|
-
* @param pos - Vertex position input, must be type of vec3, null if no vertex position input
|
|
342
428
|
* @param skinMatrix - The skinning matrix if there is skeletal animation, otherwise null
|
|
343
429
|
* @returns The calculated vertex position in object space, or null if pos is null
|
|
344
|
-
*/ static resolveVertexPosition(scope
|
|
430
|
+
*/ static resolveVertexPosition(scope) {
|
|
345
431
|
const pb = scope.$builder;
|
|
346
432
|
if (pb.shaderKind !== 'vertex') {
|
|
347
433
|
throw new Error(`ShaderHelper.resolveVertexPosition(): must be called at vertex stage`);
|
|
348
434
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
throw new Error(`ShaderHelper.resolveVertexPosition(): must be called at entry function`);
|
|
435
|
+
if (!pb.getGlobalScope().$getVertexAttrib('position')) {
|
|
436
|
+
pb.getGlobalScope().$inputs.Z_pos = pb.vec3().attrib('position');
|
|
352
437
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
438
|
+
const that = this;
|
|
439
|
+
const params = scope[that.SKIN_MATRIX_NAME] && scope[that.SKIN_PREV_MATRIX_NAME] ? [
|
|
440
|
+
pb.mat4('skinMatrix'),
|
|
441
|
+
pb.mat4('prevSkinMatrix')
|
|
442
|
+
] : scope[that.SKIN_MATRIX_NAME] ? [
|
|
443
|
+
pb.mat4('skinMatrix')
|
|
444
|
+
] : [];
|
|
445
|
+
pb.func('Z_resolveVertexPosition', params, function() {
|
|
446
|
+
this.$l.opos = this.$getVertexAttrib('position').xyz;
|
|
447
|
+
if (that.hasMorphing(scope)) {
|
|
448
|
+
this.opos = pb.add(this.opos, that.calculateMorphDelta(this, MORPH_TARGET_POSITION).xyz);
|
|
356
449
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
}
|
|
362
|
-
if (this.hasSkinning(scope)) {
|
|
363
|
-
if (!funcScope[this.SKIN_MATRIX_NAME]) {
|
|
364
|
-
funcScope[this.SKIN_MATRIX_NAME] = this.calculateSkinMatrix(funcScope);
|
|
450
|
+
if (this.skinMatrix) {
|
|
451
|
+
this.$l.pos = pb.mul(this.skinMatrix, pb.vec4(this.opos, 1)).xyz;
|
|
452
|
+
} else {
|
|
453
|
+
this.$l.pos = this.opos;
|
|
365
454
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
455
|
+
const prevUnjitteredVPMatrix = that.getPrevUnjitteredViewProjectionMatrix(this);
|
|
456
|
+
if (prevUnjitteredVPMatrix) {
|
|
457
|
+
this.$l.unjitteredVPMatrix = that.getUnjitteredViewProjectionMatrix(this);
|
|
458
|
+
this.$l.worldPos = pb.mul(that.getWorldMatrix(this), pb.vec4(this.pos, 1));
|
|
459
|
+
if (this.prevSkinMatrix) {
|
|
460
|
+
this.$l.prevWorldPos = pb.mul(that.getPrevWorldMatrix(this), pb.mul(this.prevSkinMatrix, pb.vec4(this.opos, 1)));
|
|
461
|
+
} else {
|
|
462
|
+
this.$l.prevWorldPos = pb.mul(that.getPrevWorldMatrix(this), pb.vec4(this.pos, 1));
|
|
463
|
+
}
|
|
464
|
+
this.$outputs.zMotionVectorPosCurrent = pb.mul(this.unjitteredVPMatrix, this.worldPos);
|
|
465
|
+
this.$outputs.zMotionVectorPosPrev = pb.mul(prevUnjitteredVPMatrix, this.prevWorldPos);
|
|
466
|
+
}
|
|
467
|
+
this.$return(this.pos);
|
|
468
|
+
});
|
|
469
|
+
return scope[that.SKIN_MATRIX_NAME] && scope[that.SKIN_PREV_MATRIX_NAME] ? scope.Z_resolveVertexPosition(scope[that.SKIN_MATRIX_NAME], scope[that.SKIN_PREV_MATRIX_NAME]) : scope[that.SKIN_MATRIX_NAME] ? scope.Z_resolveVertexPosition(scope[that.SKIN_MATRIX_NAME]) : scope.Z_resolveVertexPosition();
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Resolve motion vector
|
|
473
|
+
*
|
|
474
|
+
* @param scope - Current shader scope
|
|
475
|
+
* @param worldPos - Current object position in world space
|
|
476
|
+
* @param prevWorldPos - Previous object position in world space
|
|
477
|
+
*/ static resolveMotionVector(scope, worldPos, prevWorldPos) {
|
|
478
|
+
const that = this;
|
|
479
|
+
const pb = scope.$builder;
|
|
480
|
+
const prevUnjitteredVPMatrix = that.getPrevUnjitteredViewProjectionMatrix(scope);
|
|
481
|
+
if (prevUnjitteredVPMatrix) {
|
|
482
|
+
const unjitteredVPMatrix = that.getUnjitteredViewProjectionMatrix(scope);
|
|
483
|
+
scope.$outputs.zMotionVectorPosCurrent = pb.mul(unjitteredVPMatrix, pb.vec4(worldPos.xyz, 1));
|
|
484
|
+
scope.$outputs.zMotionVectorPosPrev = pb.mul(prevUnjitteredVPMatrix, pb.vec4(prevWorldPos.xyz, 1));
|
|
369
485
|
}
|
|
370
486
|
}
|
|
371
487
|
/**
|
|
@@ -393,10 +509,7 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
393
509
|
if (this.hasMorphing(scope)) {
|
|
394
510
|
normal = pb.normalize(pb.add(normal, this.calculateMorphDelta(scope, MORPH_TARGET_NORMAL).xyz));
|
|
395
511
|
}
|
|
396
|
-
if (this.
|
|
397
|
-
if (!funcScope[this.SKIN_MATRIX_NAME]) {
|
|
398
|
-
funcScope[this.SKIN_MATRIX_NAME] = this.calculateSkinMatrix(funcScope);
|
|
399
|
-
}
|
|
512
|
+
if (scope[this.SKIN_MATRIX_NAME]) {
|
|
400
513
|
return pb.mul(scope[this.SKIN_MATRIX_NAME], pb.vec4(normal, 0)).xyz;
|
|
401
514
|
} else {
|
|
402
515
|
return normal;
|
|
@@ -427,10 +540,7 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
427
540
|
if (this.hasMorphing(scope)) {
|
|
428
541
|
tangent = pb.normalize(pb.add(tangent, pb.vec4(this.calculateMorphDelta(scope, MORPH_TARGET_TANGENT).xyz, 0)));
|
|
429
542
|
}
|
|
430
|
-
if (this.
|
|
431
|
-
if (!funcScope[this.SKIN_MATRIX_NAME]) {
|
|
432
|
-
funcScope[this.SKIN_MATRIX_NAME] = this.calculateSkinMatrix(funcScope);
|
|
433
|
-
}
|
|
543
|
+
if (scope[this.SKIN_MATRIX_NAME]) {
|
|
434
544
|
return pb.vec4(pb.mul(scope[this.SKIN_MATRIX_NAME], pb.vec4(tangent.xyz, 0)).xyz, tangent.w);
|
|
435
545
|
} else {
|
|
436
546
|
return tangent;
|
|
@@ -445,12 +555,46 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
445
555
|
return scope[UNIFORM_NAME_WORLD_MATRIX] ?? pb.mat4(this.getInstancedUniform(scope, 0), this.getInstancedUniform(scope, 1), this.getInstancedUniform(scope, 2), this.getInstancedUniform(scope, 3));
|
|
446
556
|
}
|
|
447
557
|
/**
|
|
558
|
+
* Gets the uniform variable of type mat4 which holds the world matrix at previous frame of current object to be drawn
|
|
559
|
+
* @param scope - Current shader scope
|
|
560
|
+
* @returns The world matrix at previous frame of current object to be drawn
|
|
561
|
+
*/ static getPrevWorldMatrix(scope) {
|
|
562
|
+
const pb = scope.$builder;
|
|
563
|
+
const that = this;
|
|
564
|
+
const framestamp = this.getFramestamp(scope);
|
|
565
|
+
if (scope[UNIFORM_NAME_WORLD_MATRIX]) {
|
|
566
|
+
if (pb.getDevice().type === 'webgpu') {
|
|
567
|
+
pb.func('Z_getPrevWorldMatrix', [
|
|
568
|
+
pb.int('framestamp')
|
|
569
|
+
], function() {
|
|
570
|
+
this.$if(pb.equal(this.framestamp, this[UNIFORM_NAME_PREV_WORLD_MATRXI_FRAME]), function() {
|
|
571
|
+
this.$return(this[UNIFORM_NAME_PREV_WORLD_MATRIX]);
|
|
572
|
+
}).$else(function() {
|
|
573
|
+
this.$return(this[UNIFORM_NAME_WORLD_MATRIX]);
|
|
574
|
+
});
|
|
575
|
+
});
|
|
576
|
+
return scope.Z_getPrevWorldMatrix(framestamp);
|
|
577
|
+
} else {
|
|
578
|
+
return scope.$choice(pb.equal(framestamp, scope[UNIFORM_NAME_PREV_WORLD_MATRXI_FRAME]), scope[UNIFORM_NAME_PREV_WORLD_MATRIX], scope[UNIFORM_NAME_WORLD_MATRIX]);
|
|
579
|
+
}
|
|
580
|
+
} else {
|
|
581
|
+
pb.func('Z_getPrevWorldMatrix', [
|
|
582
|
+
pb.int('framestamp')
|
|
583
|
+
], function() {
|
|
584
|
+
this.$l.prevFrame = pb.floatBitsToInt(that.getInstancedUniform(this, 4).x);
|
|
585
|
+
this.$l.index = this.$choice(pb.equal(this.framestamp, this.prevFrame), pb.int(5), pb.int(0));
|
|
586
|
+
this.$return(pb.mat4(that.getInstancedUniform(scope, this.index), that.getInstancedUniform(scope, pb.add(this.index, 1)), that.getInstancedUniform(scope, pb.add(this.index, 2)), that.getInstancedUniform(scope, pb.add(this.index, 3))));
|
|
587
|
+
});
|
|
588
|
+
return scope.Z_getPrevWorldMatrix(framestamp);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
448
592
|
* Gets the instance uniform value of type vec4 by uniform index
|
|
449
593
|
* @param scope - Current shader scope
|
|
450
594
|
* @returns instance uniform value
|
|
451
595
|
*/ static getInstancedUniform(scope, uniformIndex) {
|
|
452
596
|
const pb = scope.$builder;
|
|
453
|
-
return scope[UNIFORM_NAME_INSTANCE_DATA].at(pb.add(pb.mul(scope[UNIFORM_NAME_INSTANCE_DATA_STRIDE], pb.uint(scope.$builtins.instanceIndex)), scope[UNIFORM_NAME_INSTANCE_DATA_OFFSET], uniformIndex));
|
|
597
|
+
return scope[UNIFORM_NAME_INSTANCE_DATA].at(pb.add(pb.mul(scope[UNIFORM_NAME_INSTANCE_DATA_STRIDE], pb.uint(scope.$builtins.instanceIndex)), scope[UNIFORM_NAME_INSTANCE_DATA_OFFSET], pb.uint(uniformIndex)));
|
|
454
598
|
}
|
|
455
599
|
/**
|
|
456
600
|
* Gets the uniform variable of type mat4 which holds the normal matrix of current object to be drawn
|
|
@@ -474,11 +618,14 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
474
618
|
scope[UNIFORM_NAME_INSTANCE_DATA] = pb.vec4[65536 >> 4]().uniformBuffer(3);
|
|
475
619
|
} else {
|
|
476
620
|
scope[UNIFORM_NAME_WORLD_MATRIX] = pb.mat4().uniform(1);
|
|
621
|
+
scope[UNIFORM_NAME_PREV_WORLD_MATRIX] = pb.mat4().uniform(1);
|
|
622
|
+
scope[UNIFORM_NAME_PREV_WORLD_MATRXI_FRAME] = pb.int().uniform(1);
|
|
623
|
+
scope[UNIFORM_NAME_OBJECT_COLOR] = pb.vec4().uniform(1);
|
|
477
624
|
}
|
|
478
625
|
if (skinning) {
|
|
479
626
|
scope[UNIFORM_NAME_BONE_MATRICES] = pb.tex2D().uniform(1).sampleType('unfilterable-float');
|
|
480
627
|
scope[UNIFORM_NAME_BONE_INV_BIND_MATRIX] = pb.mat4().uniform(1);
|
|
481
|
-
scope[UNIFORM_NAME_BONE_TEXTURE_SIZE] = pb.
|
|
628
|
+
scope[UNIFORM_NAME_BONE_TEXTURE_SIZE] = pb.vec2().uniform(1);
|
|
482
629
|
}
|
|
483
630
|
if (morphing) {
|
|
484
631
|
scope[UNIFORM_NAME_MORPH_DATA] = pb.tex2D().uniform(1).sampleType('unfilterable-float');
|
|
@@ -488,77 +635,106 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
488
635
|
/** @internal */ static prepareVertexShaderCommon(pb, ctx) {
|
|
489
636
|
this.vertexShaderDrawableStuff(pb.getGlobalScope(), !!(ctx.materialFlags & MaterialVaryingFlags.SKIN_ANIMATION), !!(ctx.materialFlags & MaterialVaryingFlags.MORPH_ANIMATION), !!(ctx.materialFlags & MaterialVaryingFlags.INSTANCING));
|
|
490
637
|
}
|
|
491
|
-
/** @internal */ static setCameraUniforms(bindGroup,
|
|
492
|
-
const pos = camera.getWorldPosition();
|
|
638
|
+
/** @internal */ static setCameraUniforms(bindGroup, ctx, linear) {
|
|
639
|
+
const pos = ctx.camera.getWorldPosition();
|
|
640
|
+
const useJitter = ctx.motionVectors && ctx.renderPass.type !== RENDER_PASS_TYPE_SHADOWMAP && ctx.renderPass.type !== RENDER_PASS_TYPE_OBJECT_COLOR;
|
|
493
641
|
const cameraStruct = {
|
|
494
|
-
position: new Vector4(pos.x, pos.y, pos.z, camera.clipPlane ? 1 : 0),
|
|
495
|
-
clipPlane: camera.clipPlane ?? Vector4.zero(),
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
642
|
+
position: new Vector4(pos.x, pos.y, pos.z, ctx.camera.clipPlane ? 1 : 0),
|
|
643
|
+
clipPlane: ctx.camera.clipPlane ?? Vector4.zero(),
|
|
644
|
+
renderSize: new Vector2(ctx.renderWidth, ctx.renderHeight),
|
|
645
|
+
viewProjectionMatrix: useJitter ? ctx.camera.jitteredVPMatrix : ctx.camera.viewProjectionMatrix,
|
|
646
|
+
unjitteredVPMatrix: ctx.camera.viewProjectionMatrix,
|
|
647
|
+
jitteredInvVPMatrix: useJitter ? ctx.camera.jitteredInvVPMatrix : ctx.camera.invViewProjectionMatrix,
|
|
648
|
+
jitterValue: ctx.camera.jitterValue,
|
|
649
|
+
invViewProjectionMatrix: ctx.camera.invViewProjectionMatrix,
|
|
650
|
+
projectionMatrix: ctx.camera.getProjectionMatrix(),
|
|
651
|
+
invProjectionMatrix: ctx.camera.getInvProjectionMatrix(),
|
|
652
|
+
viewMatrix: ctx.camera.viewMatrix,
|
|
653
|
+
worldMatrix: ctx.camera.worldMatrix,
|
|
654
|
+
params: new Vector4(ctx.camera.getNearPlane(), ctx.camera.getFarPlane(), ctx.flip ? -1 : 1, linear ? 0 : 1),
|
|
655
|
+
roughnessFactor: ctx.camera.SSR ? ctx.camera.ssrRoughnessFactor : 1,
|
|
656
|
+
frameDeltaTime: getDevice().frameInfo.elapsedFrame * 0.001,
|
|
657
|
+
elapsedTime: getDevice().frameInfo.elapsedOverall * 0.001,
|
|
658
|
+
framestamp: getDevice().frameInfo.frameCounter
|
|
501
659
|
};
|
|
502
|
-
|
|
503
|
-
camera
|
|
504
|
-
}
|
|
660
|
+
if (ctx.motionVectors && ctx.renderPass.type === RENDER_PASS_TYPE_DEPTH) {
|
|
661
|
+
cameraStruct.prevUnjitteredVPMatrix = ctx.camera.prevVPMatrix;
|
|
662
|
+
}
|
|
663
|
+
if (ctx.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
|
|
664
|
+
if (ctx.linearDepthTexture) {
|
|
665
|
+
bindGroup.setTexture(UNIFORM_NAME_LINEAR_DEPTH_MAP, ctx.linearDepthTexture);
|
|
666
|
+
bindGroup.setValue(UNIFORM_NAME_LINEAR_DEPTH_MAP_SIZE, new Vector2(ctx.linearDepthTexture.width, ctx.linearDepthTexture.height));
|
|
667
|
+
}
|
|
668
|
+
if (ctx.sceneColorTexture) {
|
|
669
|
+
bindGroup.setTexture(UNIFORM_NAME_SCENE_COLOR_MAP, ctx.sceneColorTexture);
|
|
670
|
+
bindGroup.setValue(UNIFORM_NAME_SCENE_COLOR_MAP_SIZE, new Vector2(ctx.sceneColorTexture.width, ctx.sceneColorTexture.height));
|
|
671
|
+
}
|
|
672
|
+
if (ctx.HiZTexture) {
|
|
673
|
+
bindGroup.setTexture(UNIFORM_NAME_HIZ_DEPTH_MAP, ctx.HiZTexture, fetchSampler('clamp_nearest'));
|
|
674
|
+
bindGroup.setValue(UNIFORM_NAME_HIZ_DEPTH_MAP_INFO, new Vector4(ctx.HiZTexture.width, ctx.HiZTexture.height, ctx.HiZTexture.mipLevelCount, 0));
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
bindGroup.setValue('camera', cameraStruct);
|
|
505
678
|
}
|
|
506
679
|
/** @internal */ static setLightUniformsShadowMap(bindGroup, ctx, light) {
|
|
507
680
|
if (light) {
|
|
508
681
|
const shadowMapParams = ctx.shadowMapInfo.get(light);
|
|
509
|
-
bindGroup.setValue(
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
lightType: light.lightType
|
|
516
|
-
}
|
|
682
|
+
bindGroup.setValue('light', {
|
|
683
|
+
positionAndRange: light.positionAndRange,
|
|
684
|
+
directionCutoff: light.directionAndCutoff,
|
|
685
|
+
viewMatrix: light.viewMatrix,
|
|
686
|
+
depthBias: shadowMapParams.depthBiasValues[0],
|
|
687
|
+
lightType: light.lightType
|
|
517
688
|
});
|
|
518
689
|
}
|
|
519
690
|
}
|
|
520
|
-
/** @internal */ static setFogUniforms(bindGroup, fogType,
|
|
521
|
-
this._fogUniforms.
|
|
522
|
-
this._fogUniforms.
|
|
523
|
-
this._fogUniforms.
|
|
524
|
-
this._fogUniforms.
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
691
|
+
/** @internal */ static setFogUniforms(bindGroup, withAerialPerspective, fogType, additive, atmosphereParams, heightFogParams, aerialPerspectiveLUT, skyDistantLightLUT) {
|
|
692
|
+
this._fogUniforms.withAerialPerspective = withAerialPerspective;
|
|
693
|
+
this._fogUniforms.fogType = fogType;
|
|
694
|
+
this._fogUniforms.additive = additive;
|
|
695
|
+
this._fogUniforms.atmosphereParams = atmosphereParams;
|
|
696
|
+
this._fogUniforms.heightFogParams = heightFogParams;
|
|
697
|
+
bindGroup.setValue('fog', this._fogUniforms);
|
|
698
|
+
bindGroup.setTexture(UNIFORM_NAME_AERIALPERSPECTIVE_LUT, aerialPerspectiveLUT);
|
|
699
|
+
bindGroup.setTexture(UNIFORM_NAME_SKYDISTANTLIGHT_LUT, skyDistantLightLUT);
|
|
529
700
|
}
|
|
530
701
|
/** @internal */ static setLightUniforms(bindGroup, ctx, clusterParams, countParams, lightBuffer, lightIndexTexture) {
|
|
531
|
-
bindGroup.setValue(
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
])
|
|
541
|
-
}
|
|
702
|
+
bindGroup.setValue('light', {
|
|
703
|
+
sunDir: ctx.sunLight ? ctx.sunLight.directionAndCutoff.xyz().scaleBy(-1) : this.defaultSunDir,
|
|
704
|
+
clusterParams: clusterParams,
|
|
705
|
+
countParams: countParams,
|
|
706
|
+
envLightStrength: ctx.env.light.strength ?? 0,
|
|
707
|
+
lightIndexTexSize: new Int32Array([
|
|
708
|
+
lightIndexTexture.width,
|
|
709
|
+
lightIndexTexture.height
|
|
710
|
+
])
|
|
542
711
|
});
|
|
543
712
|
bindGroup.setBuffer(UNIFORM_NAME_LIGHT_BUFFER, lightBuffer);
|
|
544
713
|
bindGroup.setTexture(UNIFORM_NAME_LIGHT_INDEX_TEXTURE, lightIndexTexture);
|
|
545
|
-
|
|
714
|
+
bindGroup.setTexture(UNIFORM_NAME_BAKED_SKY_MAP, ctx.scene.env.sky.getBakedSkyTexture(ctx));
|
|
715
|
+
if (ctx.drawEnvLight) {
|
|
716
|
+
ctx.env.light.envLight.updateBindGroup(bindGroup);
|
|
717
|
+
}
|
|
546
718
|
}
|
|
547
719
|
/** @internal */ static setLightUniformsShadow(bindGroup, ctx, light) {
|
|
548
720
|
const shadowMapParams = ctx.shadowMapInfo.get(light);
|
|
549
|
-
this._lightUniformShadow.
|
|
550
|
-
this._lightUniformShadow.light.
|
|
551
|
-
this._lightUniformShadow.
|
|
552
|
-
this._lightUniformShadow.
|
|
553
|
-
this._lightUniformShadow.
|
|
554
|
-
this._lightUniformShadow.
|
|
555
|
-
this._lightUniformShadow.
|
|
556
|
-
this._lightUniformShadow.
|
|
557
|
-
this._lightUniformShadow.
|
|
558
|
-
this._lightUniformShadow.
|
|
559
|
-
|
|
721
|
+
this._lightUniformShadow.sunDir = ctx.sunLight ? ctx.sunLight.directionAndCutoff.xyz().scaleBy(-1) : this.defaultSunDir;
|
|
722
|
+
this._lightUniformShadow.envLightStrength = ctx.env?.light.strength ?? 0;
|
|
723
|
+
this._lightUniformShadow.shadowCascades = shadowMapParams.numShadowCascades;
|
|
724
|
+
this._lightUniformShadow.positionAndRange.set(light.positionAndRange);
|
|
725
|
+
this._lightUniformShadow.directionAndCutoff.set(light.directionAndCutoff);
|
|
726
|
+
this._lightUniformShadow.diffuseAndIntensity.set(light.diffuseAndIntensity);
|
|
727
|
+
this._lightUniformShadow.cascadeDistances.set(shadowMapParams.cascadeDistances);
|
|
728
|
+
this._lightUniformShadow.depthBiasValues.set(shadowMapParams.depthBiasValues[0]);
|
|
729
|
+
this._lightUniformShadow.shadowCameraParams.set(shadowMapParams.cameraParams);
|
|
730
|
+
this._lightUniformShadow.depthBiasScales.set(shadowMapParams.depthBiasScales);
|
|
731
|
+
this._lightUniformShadow.shadowMatrices.set(shadowMapParams.shadowMatrices);
|
|
732
|
+
bindGroup.setValue('light', this._lightUniformShadow);
|
|
560
733
|
bindGroup.setTexture(UNIFORM_NAME_SHADOW_MAP, shadowMapParams.shadowMap, shadowMapParams.shadowMapSampler);
|
|
561
|
-
|
|
734
|
+
bindGroup.setTexture(UNIFORM_NAME_BAKED_SKY_MAP, ctx.scene.env.sky.getBakedSkyTexture(ctx));
|
|
735
|
+
if (ctx.drawEnvLight) {
|
|
736
|
+
ctx.env.light.envLight.updateBindGroup(bindGroup);
|
|
737
|
+
}
|
|
562
738
|
}
|
|
563
739
|
/**
|
|
564
740
|
* Gets the uniform variable of type float which holds the strength of the environment light
|
|
@@ -569,21 +745,105 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
569
745
|
* @param scope - Current shader scope
|
|
570
746
|
* @returns The uniform variable of which presents the strength of the environment light
|
|
571
747
|
*/ static getEnvLightStrength(scope) {
|
|
572
|
-
return scope
|
|
748
|
+
return scope.light.envLightStrength;
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Gets current scene color texture
|
|
752
|
+
* @param scope - Current shader scope
|
|
753
|
+
* @returns current scene color texture
|
|
754
|
+
*/ static getSceneColorTexture(scope) {
|
|
755
|
+
return scope[UNIFORM_NAME_SCENE_COLOR_MAP];
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Gets the size of current scene color texture
|
|
759
|
+
* @param scope - Current shader scope
|
|
760
|
+
* @returns The size of current scene color texture
|
|
761
|
+
*/ static getSceneColorTextureSize(scope) {
|
|
762
|
+
return scope[UNIFORM_NAME_SCENE_COLOR_MAP_SIZE];
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Gets current linear depth texture
|
|
766
|
+
* @param scope - Current shader scope
|
|
767
|
+
* @returns current linear depth texture
|
|
768
|
+
*/ static getLinearDepthTexture(scope) {
|
|
769
|
+
return scope[UNIFORM_NAME_LINEAR_DEPTH_MAP];
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Gets the size of current linear depth texture
|
|
773
|
+
* @param scope - Current shader scope
|
|
774
|
+
* @returns The size of current linear depth texture
|
|
775
|
+
*/ static getLinearDepthTextureSize(scope) {
|
|
776
|
+
return scope[UNIFORM_NAME_LINEAR_DEPTH_MAP_SIZE];
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Gets current HiZ depth texture
|
|
780
|
+
* @param scope - Current shader scope
|
|
781
|
+
* @returns current HiZ depth texture
|
|
782
|
+
*/ static getHiZDepthTexture(scope) {
|
|
783
|
+
return scope[UNIFORM_NAME_HIZ_DEPTH_MAP];
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Gets the size of current HiZ depth texture
|
|
787
|
+
* @param scope - Current shader scope
|
|
788
|
+
* @returns The size of current HiZ depth texture
|
|
789
|
+
*/ static getHiZDepthTextureSize(scope) {
|
|
790
|
+
return scope[UNIFORM_NAME_HIZ_DEPTH_MAP_INFO].xy;
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* Gets the mipmap levels count of current HiZ depth texture
|
|
794
|
+
* @param scope - Current shader scope
|
|
795
|
+
* @returns The mipmap levels count of current HiZ depth texture
|
|
796
|
+
*/ static getHiZDepthTextureMipLevelCount(scope) {
|
|
797
|
+
return scope[UNIFORM_NAME_HIZ_DEPTH_MAP_INFO].z;
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Gets current baked skybox texture
|
|
801
|
+
* @param scope - Current shader scope
|
|
802
|
+
* @returns current baked skybox texture
|
|
803
|
+
*/ static getBakedSkyTexture(scope) {
|
|
804
|
+
return scope[UNIFORM_NAME_BAKED_SKY_MAP];
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* Gets the elapsed time in seconds
|
|
808
|
+
* @param scope - Current shader scope
|
|
809
|
+
* @returns The elapsed time in seconds
|
|
810
|
+
*/ static getElapsedTime(scope) {
|
|
811
|
+
return scope.camera.elapsedTime;
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Gets the elapsed time since last frame in seconds
|
|
815
|
+
* @param scope - Current shader scope
|
|
816
|
+
* @returns The elapsed time since last frame in seconds
|
|
817
|
+
*/ static getElapsedTimeFrame(scope) {
|
|
818
|
+
return scope.camera.frameDeltaTime;
|
|
573
819
|
}
|
|
574
820
|
/**
|
|
575
821
|
* Gets the uniform variable of type vec3 which holds the camera position
|
|
576
822
|
* @param scope - Current shader scope
|
|
577
823
|
* @returns The camera position
|
|
578
824
|
*/ static getCameraPosition(scope) {
|
|
579
|
-
return scope
|
|
825
|
+
return scope.camera.position.xyz;
|
|
580
826
|
}
|
|
581
827
|
/**
|
|
582
828
|
* Gets the uniform variable of type float which holds the roughness factor
|
|
583
829
|
* @param scope - Current shader scope
|
|
584
830
|
* @returns The roughness factor
|
|
585
831
|
*/ static getCameraRoughnessFactor(scope) {
|
|
586
|
-
return scope
|
|
832
|
+
return scope.camera.roughnessFactor;
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* Gets framebuffer size for rendering
|
|
836
|
+
* @param scope - Current shader scope
|
|
837
|
+
* @returns The roughness factor
|
|
838
|
+
*/ static getRenderSize(scope) {
|
|
839
|
+
return scope.camera.renderSize;
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Gets the uniform variable of type uint which holds the framestamp
|
|
843
|
+
* @param scope - Current shader scope
|
|
844
|
+
* @returns The framestamp
|
|
845
|
+
*/ static getFramestamp(scope) {
|
|
846
|
+
return scope.camera.framestamp;
|
|
587
847
|
}
|
|
588
848
|
/**
|
|
589
849
|
* Discard the fragment if it was clipped by the clip plane
|
|
@@ -609,44 +869,37 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
609
869
|
* @param scope - Current shader scope
|
|
610
870
|
* @returns A float value of 1 indices the clip plane presents, otherwise 0
|
|
611
871
|
*/ static getCameraClipPlaneFlag(scope) {
|
|
612
|
-
return scope
|
|
872
|
+
return scope.camera.position.w;
|
|
613
873
|
}
|
|
614
874
|
/**
|
|
615
875
|
* Gets the clip plane
|
|
616
876
|
* @param scope - Current shader scope
|
|
617
877
|
* @returns A vec4 presents the clip plane
|
|
618
878
|
*/ static getCameraClipPlane(scope) {
|
|
619
|
-
return scope
|
|
879
|
+
return scope.camera.clipPlane;
|
|
620
880
|
}
|
|
621
881
|
/**
|
|
622
882
|
* Gets the uniform variable of type vec4 which holds the camera parameters
|
|
623
883
|
* @param scope - Current shader scope
|
|
624
884
|
* @returns The camera parameters
|
|
625
885
|
*/ static getCameraParams(scope) {
|
|
626
|
-
return scope
|
|
627
|
-
}
|
|
628
|
-
/**
|
|
629
|
-
* Gets the uniform variable of type vec4 which holds the fog color
|
|
630
|
-
* @param scope - Current shader scope
|
|
631
|
-
* @returns The fog color
|
|
632
|
-
*/ static getFogColor(scope) {
|
|
633
|
-
return scope[UNIFORM_NAME_GLOBAL].fog.fogColor;
|
|
886
|
+
return scope.camera.params;
|
|
634
887
|
}
|
|
635
888
|
/** @internal */ static getClusterParams(scope) {
|
|
636
|
-
return scope
|
|
889
|
+
return scope.light.clusterParams;
|
|
637
890
|
}
|
|
638
891
|
/** @internal */ static getCountParams(scope) {
|
|
639
|
-
return scope
|
|
892
|
+
return scope.light.countParams;
|
|
640
893
|
}
|
|
641
894
|
/** @internal */ static getClusteredLightIndexTexture(scope) {
|
|
642
895
|
return scope[UNIFORM_NAME_LIGHT_INDEX_TEXTURE];
|
|
643
896
|
}
|
|
644
897
|
/**
|
|
645
|
-
* Gets the uniform variable
|
|
898
|
+
* Gets the uniform variable that contains atmosphere parameters
|
|
646
899
|
* @param scope - Current shader scope
|
|
647
|
-
* @returns The
|
|
648
|
-
*/ static
|
|
649
|
-
return scope
|
|
900
|
+
* @returns The atmosphere parameters
|
|
901
|
+
*/ static getAtmosphereParams(scope) {
|
|
902
|
+
return scope.fog.atmosphereParams;
|
|
650
903
|
}
|
|
651
904
|
/**
|
|
652
905
|
* Gets the aerial perspective LUT
|
|
@@ -656,134 +909,109 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
656
909
|
return scope[UNIFORM_NAME_AERIALPERSPECTIVE_LUT];
|
|
657
910
|
}
|
|
658
911
|
/**
|
|
659
|
-
* Gets the uniform variable of type
|
|
912
|
+
* Gets the uniform variable of type mat4 which holds the view projection matrix of current camera
|
|
660
913
|
* @param scope - Current shader scope
|
|
661
|
-
* @returns The
|
|
662
|
-
*/ static
|
|
663
|
-
return scope
|
|
914
|
+
* @returns The view projection matrix of current camera
|
|
915
|
+
*/ static getViewProjectionMatrix(scope) {
|
|
916
|
+
return scope.camera.viewProjectionMatrix;
|
|
664
917
|
}
|
|
665
918
|
/**
|
|
666
|
-
* Gets the uniform variable of type
|
|
919
|
+
* Gets the uniform variable of type mat4 which holds the inversed view projection matrix of current camera
|
|
667
920
|
* @param scope - Current shader scope
|
|
668
|
-
* @returns
|
|
669
|
-
*/ static
|
|
670
|
-
return scope
|
|
921
|
+
* @returns The inversed view projection matrix of current camera
|
|
922
|
+
*/ static getInvViewProjectionMatrix(scope) {
|
|
923
|
+
return scope.camera.invViewProjectionMatrix;
|
|
671
924
|
}
|
|
672
925
|
/**
|
|
673
|
-
*
|
|
926
|
+
* Gets the uniform variable of type mat4 which holds the projection matrix of current camera
|
|
674
927
|
* @param scope - Current shader scope
|
|
675
|
-
* @
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
* @returns The computed fog factor
|
|
679
|
-
*/ static computeFogFactor(scope, viewDir, fogType, fogParams) {
|
|
680
|
-
const pb = scope.$builder;
|
|
681
|
-
const funcName = 'Z_computeFogFactor';
|
|
682
|
-
const that = this;
|
|
683
|
-
pb.func(funcName, [
|
|
684
|
-
pb.vec3('viewDir'),
|
|
685
|
-
pb.int('fogType'),
|
|
686
|
-
pb.vec4('fogParams')
|
|
687
|
-
], function() {
|
|
688
|
-
this.$l.distance = pb.length(this.viewDir);
|
|
689
|
-
this.$l.top = pb.max(this.viewDir.y, 0.0001);
|
|
690
|
-
this.$l.distance = pb.mul(this.$l.distance, pb.min(1, pb.div(this.fogParams.z, this.top)));
|
|
691
|
-
this.$if(pb.equal(this.fogType, that.FOG_TYPE_LINEAR), function() {
|
|
692
|
-
this.$return(pb.clamp(pb.div(pb.sub(this.distance, this.fogParams.x), pb.sub(this.fogParams.y, this.fogParams.x)), 0, 1));
|
|
693
|
-
}).$elseif(pb.equal(this.fogType, that.FOG_TYPE_EXP), function() {
|
|
694
|
-
this.$l.e = pb.mul(this.distance, this.fogParams.w);
|
|
695
|
-
this.$return(pb.sub(1, pb.div(1, pb.exp(this.e))));
|
|
696
|
-
}).$elseif(pb.equal(this.fogType, that.FOG_TYPE_EXP2), function() {
|
|
697
|
-
this.$l.e = pb.mul(this.distance, this.fogParams.w);
|
|
698
|
-
this.$return(pb.sub(1, pb.div(1, pb.exp(pb.mul(this.e, this.e)))));
|
|
699
|
-
}).$else(function() {
|
|
700
|
-
this.$return(0);
|
|
701
|
-
});
|
|
702
|
-
});
|
|
703
|
-
return pb.getGlobalScope()[funcName](viewDir, fogType, fogParams);
|
|
928
|
+
* @returns The projection matrix of current camera
|
|
929
|
+
*/ static getProjectionMatrix(scope) {
|
|
930
|
+
return scope.camera.projectionMatrix;
|
|
704
931
|
}
|
|
705
932
|
/**
|
|
706
|
-
*
|
|
933
|
+
* Gets the uniform variable of type mat4 which holds the inversed projection matrix of current camera
|
|
707
934
|
* @param scope - Current shader scope
|
|
708
|
-
* @
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
* @returns The computed fog factor
|
|
712
|
-
*/ static computeFogFactorForType(scope, viewDir, fogParams, fogType) {
|
|
713
|
-
const pb = scope.$builder;
|
|
714
|
-
const funcName = `Z_computeFogFactor${fogType[0].toUpperCase()}${fogType.slice(1)}`;
|
|
715
|
-
pb.func(funcName, [
|
|
716
|
-
pb.vec3('viewDir'),
|
|
717
|
-
pb.vec4('fogParams')
|
|
718
|
-
], function() {
|
|
719
|
-
this.$l.distance = pb.length(this.viewDir);
|
|
720
|
-
this.$l.top = pb.max(this.viewDir.y, 0.0001);
|
|
721
|
-
this.$l.distance = pb.mul(this.$l.distance, pb.min(1, pb.div(this.fogParams.z, this.top)));
|
|
722
|
-
if (fogType === 'linear') {
|
|
723
|
-
this.$return(pb.clamp(pb.div(pb.sub(this.distance, this.fogParams.x), pb.sub(this.fogParams.y, this.fogParams.x)), 0, 1));
|
|
724
|
-
} else if (fogType === 'exp') {
|
|
725
|
-
this.$l.e = pb.mul(this.distance, this.fogParams.w);
|
|
726
|
-
this.$return(pb.sub(1, pb.div(1, pb.exp(this.e))));
|
|
727
|
-
} else if (fogType === 'exp2') {
|
|
728
|
-
this.$l.e = pb.mul(this.distance, this.fogParams.w);
|
|
729
|
-
this.$return(pb.sub(1, pb.div(1, pb.exp(pb.mul(this.e, this.e)))));
|
|
730
|
-
} else {
|
|
731
|
-
this.$return(0);
|
|
732
|
-
}
|
|
733
|
-
});
|
|
734
|
-
return pb.getGlobalScope()[funcName](viewDir, fogParams);
|
|
935
|
+
* @returns The inversed projection matrix of current camera
|
|
936
|
+
*/ static getInvProjectionMatrix(scope) {
|
|
937
|
+
return scope.camera.invProjectionMatrix;
|
|
735
938
|
}
|
|
736
939
|
/**
|
|
737
|
-
* Gets the uniform variable of type mat4 which holds the view projection matrix of current camera
|
|
940
|
+
* Gets the uniform variable of type mat4 which holds the unjittered view projection matrix of current camera
|
|
738
941
|
* @param scope - Current shader scope
|
|
739
|
-
* @returns The view projection matrix of current camera
|
|
740
|
-
*/ static
|
|
741
|
-
return scope
|
|
942
|
+
* @returns The unjittered view projection matrix of current camera
|
|
943
|
+
*/ static getUnjitteredViewProjectionMatrix(scope) {
|
|
944
|
+
return scope.camera.unjitteredVPMatrix;
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* Gets the uniform variable of type vec2 which holds the jitter value of the projection matrix of current camera
|
|
948
|
+
* @param scope - Current shader scope
|
|
949
|
+
* @returns The jitter value of projection matrix of current camera
|
|
950
|
+
*/ static getProjectionMatrixJitterValue(scope) {
|
|
951
|
+
return scope.camera.jitterValue;
|
|
742
952
|
}
|
|
743
953
|
/**
|
|
744
|
-
* Gets the uniform variable of type mat4 which holds the view matrix
|
|
954
|
+
* Gets the uniform variable of type mat4 which holds the jittered inversed view-projection matrix
|
|
955
|
+
* @param scope - Current shader scope
|
|
956
|
+
* @returns The jittered inversed view-projection matrix
|
|
957
|
+
*/ static getJitteredInvVPMatrix(scope) {
|
|
958
|
+
return scope.camera.jitteredInvVPMatrix;
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* Gets the uniform variable of type mat4 which holds the unjittered view projection at previous frame matrix of current camera
|
|
962
|
+
* @param scope - Current shader scope
|
|
963
|
+
* @returns The unjittered view projection matrix at previous frame of current camera
|
|
964
|
+
*/ static getPrevUnjitteredViewProjectionMatrix(scope) {
|
|
965
|
+
return scope.camera.prevUnjitteredVPMatrix;
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Gets the uniform variable of type mat4 which holds the view matrix of current camera (world space to camera space)
|
|
745
969
|
* @param scope - Current shader scope
|
|
746
970
|
* @returns The view matrix of current camera
|
|
747
971
|
*/ static getViewMatrix(scope) {
|
|
748
|
-
return scope
|
|
972
|
+
return scope.camera.viewMatrix;
|
|
749
973
|
}
|
|
750
974
|
/**
|
|
751
|
-
* Gets the uniform variable of type mat4 which holds the
|
|
975
|
+
* Gets the uniform variable of type mat4 which holds the inv-view matrix of current camera (camera space to world space)
|
|
752
976
|
* @param scope - Current shader scope
|
|
753
|
-
* @returns The
|
|
754
|
-
*/ static
|
|
755
|
-
return scope
|
|
977
|
+
* @returns The inv-view matrix of current camera
|
|
978
|
+
*/ static getInvViewMatrix(scope) {
|
|
979
|
+
return scope.camera.worldMatrix;
|
|
756
980
|
}
|
|
757
981
|
/** @internal */ static getCascadeDistances(scope) {
|
|
758
|
-
return scope
|
|
982
|
+
return scope.light.cascadeDistances;
|
|
759
983
|
}
|
|
760
984
|
/** @internal */ static getDepthBiasValues(scope) {
|
|
761
|
-
return scope
|
|
985
|
+
return scope.light.depthBiasValues;
|
|
762
986
|
}
|
|
763
987
|
/** @internal */ static getShadowCameraParams(scope) {
|
|
764
|
-
return scope
|
|
988
|
+
return scope.light.shadowCameraParams;
|
|
765
989
|
}
|
|
766
990
|
/** @internal */ static getDepthBiasScales(scope) {
|
|
767
|
-
return scope
|
|
991
|
+
return scope.light.depthBiasScales;
|
|
768
992
|
}
|
|
769
993
|
/** @internal */ static getNumLights(scope) {
|
|
770
|
-
return scope
|
|
994
|
+
return scope.light.numLights;
|
|
771
995
|
}
|
|
772
996
|
/** @internal */ static getSunLightDir(scope) {
|
|
773
|
-
return scope
|
|
997
|
+
return scope.light.sunDir;
|
|
774
998
|
}
|
|
775
999
|
/** @internal */ static getLightTypeForShadow(scope) {
|
|
776
|
-
return scope
|
|
1000
|
+
return scope.light.lightType;
|
|
777
1001
|
}
|
|
778
1002
|
/** @internal */ static getLightPositionAndRangeForShadow(scope) {
|
|
779
|
-
return scope
|
|
1003
|
+
return scope.light.positionAndRange;
|
|
780
1004
|
}
|
|
781
1005
|
/** @internal */ static getLightViewMatrixForShadow(scope) {
|
|
782
|
-
return scope
|
|
1006
|
+
return scope.light.viewMatrix;
|
|
783
1007
|
}
|
|
784
1008
|
/** @internal */ static calculateShadowSpaceVertex(scope, worldPos, cascade = 0) {
|
|
785
1009
|
const pb = scope.$builder;
|
|
786
|
-
|
|
1010
|
+
if (typeof cascade === 'number') {
|
|
1011
|
+
return pb.vec4(pb.dot(scope.light.shadowMatrices.at(cascade * 4 + 0), worldPos), pb.dot(scope.light.shadowMatrices.at(cascade * 4 + 1), worldPos), pb.dot(scope.light.shadowMatrices.at(cascade * 4 + 2), worldPos), pb.dot(scope.light.shadowMatrices.at(cascade * 4 + 3), worldPos));
|
|
1012
|
+
} else {
|
|
1013
|
+
return pb.vec4(pb.dot(scope.light.shadowMatrices.at(pb.add(pb.mul(cascade, 4), 0)), worldPos), pb.dot(scope.light.shadowMatrices.at(pb.add(pb.mul(cascade, 4), 1)), worldPos), pb.dot(scope.light.shadowMatrices.at(pb.add(pb.mul(cascade, 4), 2)), worldPos), pb.dot(scope.light.shadowMatrices.at(pb.add(pb.mul(cascade, 4), 3)), worldPos));
|
|
1014
|
+
}
|
|
787
1015
|
}
|
|
788
1016
|
/** @internal */ static getLightPositionAndRange(scope, lightIndex) {
|
|
789
1017
|
return scope[UNIFORM_NAME_LIGHT_BUFFER].at(scope.$builder.mul(lightIndex, 3));
|
|
@@ -818,13 +1046,6 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
818
1046
|
}
|
|
819
1047
|
}
|
|
820
1048
|
/**
|
|
821
|
-
* Get global uniforms
|
|
822
|
-
*
|
|
823
|
-
* @param scope - Shader scope
|
|
824
|
-
*/ static getGlobalUniforms(scope) {
|
|
825
|
-
return scope[UNIFORM_NAME_GLOBAL];
|
|
826
|
-
}
|
|
827
|
-
/**
|
|
828
1049
|
* Get shadow map uniform value
|
|
829
1050
|
*
|
|
830
1051
|
* @param scope - Shader scope
|
|
@@ -848,7 +1069,7 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
848
1069
|
pb.float('NoL')
|
|
849
1070
|
], function() {
|
|
850
1071
|
if (shadowMapParams.numShadowCascades > 1) {
|
|
851
|
-
this.$l.shadowCascades =
|
|
1072
|
+
this.$l.shadowCascades = this.light.shadowCascades;
|
|
852
1073
|
this.$l.shadowBound = pb.vec4(0, 0, 1, 1);
|
|
853
1074
|
this.$l.linearDepth = that.nonLinearDepthToLinear(this, this.$builtins.fragCoord.z);
|
|
854
1075
|
this.$l.splitDistances = that.getCascadeDistances(this);
|
|
@@ -885,42 +1106,16 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
885
1106
|
static applyFog(scope, worldPos, color, ctx) {
|
|
886
1107
|
const pb = scope.$builder;
|
|
887
1108
|
const that = this;
|
|
888
|
-
if (ctx.
|
|
889
|
-
const funcName = 'Z_applySkyFog';
|
|
890
|
-
pb.func(funcName, [
|
|
891
|
-
pb.vec3('worldPos'),
|
|
892
|
-
pb.vec4('color').inout()
|
|
893
|
-
], function() {
|
|
894
|
-
this.$l.viewDir = pb.sub(this.worldPos, that.getCameraPosition(this));
|
|
895
|
-
this.viewDir.y = pb.max(this.viewDir.y, 0);
|
|
896
|
-
this.$l.distance = pb.mul(pb.length(this.viewDir), that.getAPDensity(this));
|
|
897
|
-
this.$l.sliceDist = pb.div(pb.mul(that.getCameraParams(this).y, that.getAPDensity(this)), ScatteringLut.aerialPerspectiveSliceZ);
|
|
898
|
-
this.$l.slice0 = pb.floor(pb.div(this.distance, this.sliceDist));
|
|
899
|
-
this.$l.slice1 = pb.add(this.slice0, 1);
|
|
900
|
-
this.$l.factor = pb.sub(pb.div(this.distance, this.sliceDist), this.slice0);
|
|
901
|
-
this.$l.viewNormal = pb.normalize(this.viewDir);
|
|
902
|
-
this.$l.horizonAngle = pb.acos(pb.clamp(pb.dot(pb.normalize(that.getSunLightDir(this).xz), pb.normalize(this.viewNormal.xz)), 0, 1));
|
|
903
|
-
this.$l.zenithAngle = pb.asin(this.viewNormal.y);
|
|
904
|
-
this.$l.sliceU = pb.max(pb.div(this.horizonAngle, Math.PI * 2), 0.5 / ScatteringLut.aerialPerspectiveSliceZ);
|
|
905
|
-
this.$l.u0 = pb.div(pb.add(this.slice0, this.sliceU), ScatteringLut.aerialPerspectiveSliceZ);
|
|
906
|
-
this.$l.u1 = pb.add(this.u0, 1 / ScatteringLut.aerialPerspectiveSliceZ);
|
|
907
|
-
this.$l.v = pb.div(this.zenithAngle, Math.PI / 2);
|
|
908
|
-
this.$l.t0 = pb.textureSampleLevel(that.getAerialPerspectiveLUT(this), pb.vec2(this.u0, this.v), 0);
|
|
909
|
-
this.$l.t1 = pb.textureSampleLevel(that.getAerialPerspectiveLUT(this), pb.vec2(this.u1, this.v), 0);
|
|
910
|
-
this.$l.t = pb.mix(this.t0, this.t1, this.factor);
|
|
911
|
-
this.color = pb.vec4(pb.add(pb.mul(this.color.rgb, this.t.a), this.t.rgb), this.color.a);
|
|
912
|
-
//this.color = pb.vec4(pb.vec3(pb.mix(this.u0, this.u1, this.factor)), this.color.a);
|
|
913
|
-
});
|
|
914
|
-
scope[funcName](worldPos, color);
|
|
915
|
-
} else if (ctx.applyFog) {
|
|
1109
|
+
if (ctx.materialFlags & MaterialVaryingFlags.APPLY_FOG) {
|
|
916
1110
|
const funcName = 'Z_applyFog';
|
|
917
1111
|
pb.func(funcName, [
|
|
918
1112
|
pb.vec3('worldPos'),
|
|
919
1113
|
pb.vec4('color').inout()
|
|
920
1114
|
], function() {
|
|
921
|
-
this.$l.
|
|
922
|
-
this.$l.
|
|
923
|
-
this.color = pb.vec4(pb.
|
|
1115
|
+
this.$l.uv = pb.div(pb.vec2(this.$builtins.fragCoord.xy), that.getRenderSize(this));
|
|
1116
|
+
this.$l.fogging = calculateFog(this, this.fog.withAerialPerspective, this.fog.fogType, this.fog.atmosphereParams, this.fog.heightFogParams, this.uv, false, that.getCameraPosition(this).xyz, this.worldPos, this.fog.additive, this[UNIFORM_NAME_AERIALPERSPECTIVE_LUT], this[UNIFORM_NAME_SKYDISTANTLIGHT_LUT]);
|
|
1117
|
+
this.color = pb.vec4(pb.add(pb.mul(this.color.rgb, this.fogging.a), this.fogging.rgb), this.color.a);
|
|
1118
|
+
//this.color = pb.vec4(pb.vec3(pb.mix(this.u0, this.u1, this.factor)), this.color.a);
|
|
924
1119
|
});
|
|
925
1120
|
scope[funcName](worldPos, color);
|
|
926
1121
|
}
|
|
@@ -962,6 +1157,45 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
962
1157
|
return pb.div(nearFar.x, pb.mix(nearFar.y, nearFar.x, depth));
|
|
963
1158
|
}
|
|
964
1159
|
/**
|
|
1160
|
+
* Sample linear depth from linear depth texture
|
|
1161
|
+
* @param scope - Current shader scope
|
|
1162
|
+
* @param tex - The linear depth texture
|
|
1163
|
+
* @param uv - The uv coordinates
|
|
1164
|
+
* @param level - The mipmap level to sample
|
|
1165
|
+
* @returns Linear depth value
|
|
1166
|
+
*/ static sampleLinearDepth(scope, tex, uv, level) {
|
|
1167
|
+
const pb = scope.$builder;
|
|
1168
|
+
const depth = pb.textureSampleLevel(tex, uv, level);
|
|
1169
|
+
return pb.getDevice().type === 'webgl' ? decodeNormalizedFloatFromRGBA(scope, depth) : depth.r;
|
|
1170
|
+
}
|
|
1171
|
+
static samplePositionFromDepth(scope, depthTex, uv, mat, cameraNearFar) {
|
|
1172
|
+
const pb = scope.$builder;
|
|
1173
|
+
const that = this;
|
|
1174
|
+
pb.func('zSamplePositionFromDepth', [
|
|
1175
|
+
pb.vec2('uv'),
|
|
1176
|
+
pb.vec2('cameraNearFar'),
|
|
1177
|
+
pb.mat4('mat')
|
|
1178
|
+
], function() {
|
|
1179
|
+
this.$l.linearDepth = that.sampleLinearDepth(this, depthTex, this.uv, 0);
|
|
1180
|
+
this.$l.nonLinearDepth = pb.div(pb.sub(pb.div(this.cameraNearFar.x, this.linearDepth), this.cameraNearFar.y), pb.sub(this.cameraNearFar.x, this.cameraNearFar.y));
|
|
1181
|
+
this.$l.clipSpacePos = pb.vec4(pb.sub(pb.mul(this.uv, 2), pb.vec2(1)), pb.sub(pb.mul(pb.clamp(this.nonLinearDepth, 0, 1), 2), 1), 1);
|
|
1182
|
+
this.$l.wPos = pb.mul(this.mat, this.clipSpacePos);
|
|
1183
|
+
this.$return(pb.vec4(pb.div(this.wPos.xyz, this.wPos.w), this.linearDepth));
|
|
1184
|
+
});
|
|
1185
|
+
return scope.zSamplePositionFromDepth(uv, cameraNearFar, mat);
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Sample linear depth from linear depth texture with backface
|
|
1189
|
+
* @param scope - Current shader scope
|
|
1190
|
+
* @param tex - The linear depth texture
|
|
1191
|
+
* @param uv - The uv coordinates
|
|
1192
|
+
* @param level - The mipmap level to sample
|
|
1193
|
+
* @returns Linear depth value
|
|
1194
|
+
*/ static sampleLinearDepthWithBackface(scope, tex, uv, level) {
|
|
1195
|
+
const pb = scope.$builder;
|
|
1196
|
+
return pb.textureSampleLevel(tex, uv, level).rg;
|
|
1197
|
+
}
|
|
1198
|
+
/**
|
|
965
1199
|
* Transform color to sRGB color space if nessesary
|
|
966
1200
|
*
|
|
967
1201
|
* @param scope - Current shader scope
|