@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
|
@@ -0,0 +1,957 @@
|
|
|
1
|
+
import { drawFullscreenQuad } from '../render/fullscreenquad.js';
|
|
2
|
+
import { fetchSampler } from '../utility/misc.js';
|
|
3
|
+
import { Matrix4x4, Vector3, Vector4 } from '@zephyr3d/base';
|
|
4
|
+
import { uniformSphereSamples } from '../values.js';
|
|
5
|
+
import { getDevice } from '../app/api.js';
|
|
6
|
+
|
|
7
|
+
const TRANSMITTANCE_SAMPLES = 16;
|
|
8
|
+
const RAYLEIGH_SIGMA = [
|
|
9
|
+
5.802,
|
|
10
|
+
13.558,
|
|
11
|
+
33.1
|
|
12
|
+
];
|
|
13
|
+
const MIE_SIGMA = 3.996;
|
|
14
|
+
const MIE_ABSORPTION_SIGMA = 4.4;
|
|
15
|
+
const OZONE_ABSORPTION_SIGMA = [
|
|
16
|
+
0.65,
|
|
17
|
+
1.881,
|
|
18
|
+
0.085
|
|
19
|
+
];
|
|
20
|
+
/** @internal */ const CAMERA_POS_Y = 1;
|
|
21
|
+
/** @internal */ function getDefaultAtmosphereParams() {
|
|
22
|
+
return {
|
|
23
|
+
plantRadius: 6360000,
|
|
24
|
+
atmosphereHeight: 60000,
|
|
25
|
+
rayleighScatteringHeight: 8000,
|
|
26
|
+
mieScatteringHeight: 1200,
|
|
27
|
+
mieAnstropy: 0.8,
|
|
28
|
+
ozoneCenter: 25000,
|
|
29
|
+
ozoneWidth: 15000,
|
|
30
|
+
apDistance: 4000,
|
|
31
|
+
cameraWorldMatrix: Matrix4x4.identity(),
|
|
32
|
+
lightDir: new Vector3(1, 0, 0),
|
|
33
|
+
lightColor: new Vector4(1, 1, 1, 10),
|
|
34
|
+
cameraAspect: 1,
|
|
35
|
+
cameraHeightScale: 1
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const defaultAtmosphereParams = getDefaultAtmosphereParams();
|
|
39
|
+
let currentAtmosphereParams = null;
|
|
40
|
+
function checkParams(other) {
|
|
41
|
+
const result = {
|
|
42
|
+
transmittance: false,
|
|
43
|
+
multiScattering: false,
|
|
44
|
+
skyView: false,
|
|
45
|
+
aerialPerspective: false
|
|
46
|
+
};
|
|
47
|
+
other = {
|
|
48
|
+
...defaultAtmosphereParams,
|
|
49
|
+
...other
|
|
50
|
+
};
|
|
51
|
+
if (!currentAtmosphereParams) {
|
|
52
|
+
currentAtmosphereParams = {
|
|
53
|
+
...defaultAtmosphereParams,
|
|
54
|
+
lightDir: new Vector3(defaultAtmosphereParams.lightDir),
|
|
55
|
+
lightColor: new Vector4(defaultAtmosphereParams.lightColor),
|
|
56
|
+
cameraWorldMatrix: new Matrix4x4(defaultAtmosphereParams.cameraWorldMatrix)
|
|
57
|
+
};
|
|
58
|
+
result.transmittance = true;
|
|
59
|
+
result.multiScattering = true;
|
|
60
|
+
result.skyView = true;
|
|
61
|
+
result.aerialPerspective = true;
|
|
62
|
+
} else {
|
|
63
|
+
result.transmittance = currentAtmosphereParams.plantRadius !== other.plantRadius || currentAtmosphereParams.atmosphereHeight !== other.atmosphereHeight || currentAtmosphereParams.rayleighScatteringHeight !== other.rayleighScatteringHeight || currentAtmosphereParams.mieScatteringHeight !== other.mieScatteringHeight || currentAtmosphereParams.ozoneCenter !== other.ozoneCenter || currentAtmosphereParams.ozoneWidth !== other.ozoneWidth;
|
|
64
|
+
result.multiScattering = result.transmittance || currentAtmosphereParams.mieAnstropy !== other.mieAnstropy;
|
|
65
|
+
result.skyView = result.transmittance || result.multiScattering || currentAtmosphereParams.cameraHeightScale !== other.cameraHeightScale || !currentAtmosphereParams.lightDir.equalsTo(other.lightDir) || !currentAtmosphereParams.lightColor.equalsTo(other.lightColor) || !currentAtmosphereParams.cameraWorldMatrix.equalsTo(other.cameraWorldMatrix);
|
|
66
|
+
result.aerialPerspective = result.transmittance || result.multiScattering || result.skyView || currentAtmosphereParams.apDistance !== other.apDistance || currentAtmosphereParams.cameraAspect !== other.cameraAspect;
|
|
67
|
+
}
|
|
68
|
+
if (result.transmittance) {
|
|
69
|
+
currentAtmosphereParams.plantRadius = other.plantRadius;
|
|
70
|
+
currentAtmosphereParams.atmosphereHeight = other.atmosphereHeight;
|
|
71
|
+
currentAtmosphereParams.rayleighScatteringHeight = other.rayleighScatteringHeight;
|
|
72
|
+
currentAtmosphereParams.mieScatteringHeight = other.mieScatteringHeight;
|
|
73
|
+
currentAtmosphereParams.ozoneCenter = other.ozoneCenter;
|
|
74
|
+
currentAtmosphereParams.ozoneWidth = other.ozoneWidth;
|
|
75
|
+
}
|
|
76
|
+
if (result.multiScattering) {
|
|
77
|
+
currentAtmosphereParams.mieAnstropy = other.mieAnstropy;
|
|
78
|
+
}
|
|
79
|
+
if (result.skyView) {
|
|
80
|
+
currentAtmosphereParams.cameraHeightScale = other.cameraHeightScale;
|
|
81
|
+
currentAtmosphereParams.lightDir.set(other.lightDir);
|
|
82
|
+
currentAtmosphereParams.lightColor.set(other.lightColor);
|
|
83
|
+
currentAtmosphereParams.cameraWorldMatrix.set(other.cameraWorldMatrix);
|
|
84
|
+
}
|
|
85
|
+
if (result.aerialPerspective) {
|
|
86
|
+
currentAtmosphereParams.apDistance = other.apDistance;
|
|
87
|
+
currentAtmosphereParams.cameraAspect = other.cameraAspect;
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
/** @internal */ function rayIntersectSphere(scope, f3Center, fRadius, f3RayStart, f3RayDir) {
|
|
92
|
+
const pb = scope.$builder;
|
|
93
|
+
const funcName = 'z_rayIntersectSphere';
|
|
94
|
+
pb.func(funcName, [
|
|
95
|
+
pb.vec3('center'),
|
|
96
|
+
pb.float('radius'),
|
|
97
|
+
pb.vec3('rayStart'),
|
|
98
|
+
pb.vec3('rayDir')
|
|
99
|
+
], function() {
|
|
100
|
+
this.$l.OS = pb.length(pb.sub(this.center, this.rayStart));
|
|
101
|
+
this.$l.SH = pb.dot(pb.sub(this.center, this.rayStart), this.rayDir);
|
|
102
|
+
this.$l.OH = pb.sqrt(pb.sub(pb.mul(this.OS, this.OS), pb.mul(this.SH, this.SH)));
|
|
103
|
+
this.$l.PH = pb.sqrt(pb.sub(pb.mul(this.radius, this.radius), pb.mul(this.OH, this.OH)));
|
|
104
|
+
this.$if(pb.greaterThan(this.OH, this.radius), function() {
|
|
105
|
+
this.$return(pb.float(-1));
|
|
106
|
+
});
|
|
107
|
+
this.$l.t1 = pb.sub(this.SH, this.PH);
|
|
108
|
+
this.$l.t2 = pb.add(this.SH, this.PH);
|
|
109
|
+
this.$return(this.$choice(pb.lessThan(this.t1, 0), this.t2, this.t1));
|
|
110
|
+
});
|
|
111
|
+
return scope[funcName](f3Center, fRadius, f3RayStart, f3RayDir);
|
|
112
|
+
}
|
|
113
|
+
/** @internal */ function transmittanceToSky(scope, stParams, f3Pos, f3Dir, texLut) {
|
|
114
|
+
const pb = scope.$builder;
|
|
115
|
+
const funcName = 'z_transmittanceToSky';
|
|
116
|
+
const Params = getAtmosphereParamsStruct(pb);
|
|
117
|
+
pb.func(funcName, [
|
|
118
|
+
Params('params'),
|
|
119
|
+
pb.vec3('p'),
|
|
120
|
+
pb.vec3('dir')
|
|
121
|
+
], function() {
|
|
122
|
+
this.$l.bottomRadius = this.params.plantRadius;
|
|
123
|
+
this.$l.topRadius = pb.add(this.params.plantRadius, this.params.atmosphereHeight);
|
|
124
|
+
this.$l.upVector = pb.normalize(this.p);
|
|
125
|
+
this.$l.cosTheta = pb.dot(this.upVector, this.dir);
|
|
126
|
+
this.$l.r = pb.length(this.p);
|
|
127
|
+
this.$l.uv = transmittanceLutToUV(this, this.bottomRadius, this.topRadius, this.cosTheta, this.r);
|
|
128
|
+
this.$return(pb.textureSampleLevel(texLut, this.uv, 0).rgb);
|
|
129
|
+
});
|
|
130
|
+
return scope[funcName](stParams, f3Pos, f3Dir);
|
|
131
|
+
}
|
|
132
|
+
/** @internal */ function rayleighCoefficient(scope, fRayleighScatteringHeight, fH) {
|
|
133
|
+
const pb = scope.$builder;
|
|
134
|
+
const funcName = 'z_rayleighCoefficient';
|
|
135
|
+
pb.func(funcName, [
|
|
136
|
+
pb.float('rayleighScatteringHeight'),
|
|
137
|
+
pb.float('h')
|
|
138
|
+
], function() {
|
|
139
|
+
this.$l.sigma = pb.mul(pb.vec3(RAYLEIGH_SIGMA[0], RAYLEIGH_SIGMA[1], RAYLEIGH_SIGMA[2]), 1e-6);
|
|
140
|
+
this.$l.rho_h = pb.exp(pb.neg(pb.div(this.h, this.rayleighScatteringHeight)));
|
|
141
|
+
this.$return(pb.mul(this.sigma, this.rho_h));
|
|
142
|
+
});
|
|
143
|
+
return scope[funcName](fRayleighScatteringHeight, fH);
|
|
144
|
+
}
|
|
145
|
+
/** @internal */ function rayleighPhase(scope, fCosTheta) {
|
|
146
|
+
const pb = scope.$builder;
|
|
147
|
+
const funcName = 'z_rayleighPhase';
|
|
148
|
+
pb.func(funcName, [
|
|
149
|
+
pb.float('cosTheta')
|
|
150
|
+
], function() {
|
|
151
|
+
this.$return(pb.mul(3 / (16 * Math.PI), pb.add(1, pb.mul(this.cosTheta, this.cosTheta))));
|
|
152
|
+
});
|
|
153
|
+
return scope[funcName](fCosTheta);
|
|
154
|
+
}
|
|
155
|
+
/** @internal */ function mieCoefficient(scope, fMieScatteringHeight, fH) {
|
|
156
|
+
const pb = scope.$builder;
|
|
157
|
+
const funcName = 'z_mieCoefficient';
|
|
158
|
+
pb.func(funcName, [
|
|
159
|
+
pb.float('mieScatteringHeight'),
|
|
160
|
+
pb.float('h')
|
|
161
|
+
], function() {
|
|
162
|
+
this.$l.sigma = pb.mul(pb.vec3(MIE_SIGMA), 1e-6);
|
|
163
|
+
this.$l.rho_h = pb.exp(pb.neg(pb.div(this.h, this.mieScatteringHeight)));
|
|
164
|
+
this.$return(pb.mul(this.sigma, this.rho_h));
|
|
165
|
+
});
|
|
166
|
+
return scope[funcName](fMieScatteringHeight, fH);
|
|
167
|
+
}
|
|
168
|
+
/** @internal */ function miePhase(scope, fMieAnstropy, fCosTheta) {
|
|
169
|
+
const pb = scope.$builder;
|
|
170
|
+
const funcName = 'z_miePhase';
|
|
171
|
+
pb.func(funcName, [
|
|
172
|
+
pb.float('g'),
|
|
173
|
+
pb.float('cosTheta')
|
|
174
|
+
], function() {
|
|
175
|
+
this.$l.g2 = pb.mul(this.g, this.g);
|
|
176
|
+
this.$l.a = 3 / (8 * Math.PI);
|
|
177
|
+
this.$l.b = pb.div(pb.sub(1, this.g2), pb.add(2, this.g2));
|
|
178
|
+
this.$l.c = pb.add(1, pb.mul(this.cosTheta, this.cosTheta));
|
|
179
|
+
this.$l.d = pb.pow(pb.sub(pb.add(1, this.g2), pb.mul(this.g, this.cosTheta, 2)), 1.5);
|
|
180
|
+
this.$return(pb.div(pb.mul(this.a, this.b, this.c), this.d));
|
|
181
|
+
});
|
|
182
|
+
return scope[funcName](fMieAnstropy, fCosTheta);
|
|
183
|
+
}
|
|
184
|
+
/** @internal */ function mieAbsorption(scope, fMieScatteringHeight, fH) {
|
|
185
|
+
const pb = scope.$builder;
|
|
186
|
+
const funcName = 'z_mieAbsorption';
|
|
187
|
+
pb.func(funcName, [
|
|
188
|
+
pb.float('mieScatteringHeight'),
|
|
189
|
+
pb.float('h')
|
|
190
|
+
], function() {
|
|
191
|
+
this.$l.sigma = pb.mul(pb.vec3(MIE_ABSORPTION_SIGMA), 1e-6);
|
|
192
|
+
this.$l.rho_h = pb.exp(pb.neg(pb.div(this.h, this.mieScatteringHeight)));
|
|
193
|
+
this.$return(pb.mul(this.sigma, this.rho_h));
|
|
194
|
+
});
|
|
195
|
+
return scope[funcName](fMieScatteringHeight, fH);
|
|
196
|
+
}
|
|
197
|
+
/** @internal */ function ozoneAbsorption(scope, fOzoneLevelCenterHeight, fOzoneLevelWidth, fH) {
|
|
198
|
+
const pb = scope.$builder;
|
|
199
|
+
const funcName = 'z_ozoneAbsorption';
|
|
200
|
+
pb.func(funcName, [
|
|
201
|
+
pb.float('center'),
|
|
202
|
+
pb.float('width'),
|
|
203
|
+
pb.float('h')
|
|
204
|
+
], function() {
|
|
205
|
+
this.$l.sigma = pb.mul(pb.vec3(OZONE_ABSORPTION_SIGMA[0], OZONE_ABSORPTION_SIGMA[1], OZONE_ABSORPTION_SIGMA[2]), 1e-6);
|
|
206
|
+
this.$l.rho_h = pb.max(0, pb.sub(1, pb.div(pb.abs(pb.sub(this.h, this.center)), this.width)));
|
|
207
|
+
this.$return(pb.mul(this.sigma, this.rho_h));
|
|
208
|
+
});
|
|
209
|
+
return scope[funcName](fOzoneLevelCenterHeight, fOzoneLevelWidth, fH);
|
|
210
|
+
}
|
|
211
|
+
/** @internal */ function getSkyView(scope, stParams, f3EyePos, f3ViewDir, fMaxDis, texTransmittanceLut, texMultiScatteringLut, withGround = true) {
|
|
212
|
+
const pb = scope.$builder;
|
|
213
|
+
const Params = getAtmosphereParamsStruct(pb);
|
|
214
|
+
const funcName = 'z_getSkyView';
|
|
215
|
+
pb.func(funcName, [
|
|
216
|
+
Params('params'),
|
|
217
|
+
pb.vec3('eyePos'),
|
|
218
|
+
pb.vec3('viewDir'),
|
|
219
|
+
pb.float('maxDis')
|
|
220
|
+
], function() {
|
|
221
|
+
const N_SAMPLE = 32;
|
|
222
|
+
this.$l.color = pb.vec3(0);
|
|
223
|
+
this.$l.dis = rayIntersectSphere(this, pb.vec3(0), pb.add(this.params.plantRadius, this.params.atmosphereHeight), this.eyePos, this.viewDir);
|
|
224
|
+
this.$if(pb.lessThan(this.dis, 0), function() {
|
|
225
|
+
this.$return(pb.vec3(0));
|
|
226
|
+
});
|
|
227
|
+
if (withGround) {
|
|
228
|
+
this.$l.d = rayIntersectSphere(this, pb.vec3(0), this.params.plantRadius, this.eyePos, this.viewDir);
|
|
229
|
+
this.$if(pb.greaterThan(this.d, 0), function() {
|
|
230
|
+
this.dis = pb.min(this.dis, this.d);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
this.$if(pb.greaterThanEqual(this.maxDis, 0), function() {
|
|
234
|
+
this.dis = pb.min(this.dis, this.maxDis);
|
|
235
|
+
});
|
|
236
|
+
this.$l.ds = pb.div(this.dis, N_SAMPLE);
|
|
237
|
+
this.$l.p = pb.add(this.eyePos, pb.mul(this.viewDir, this.ds, 0.5));
|
|
238
|
+
this.$l.sunLuminance = pb.mul(this.params.lightColor.rgb, this.params.lightColor.a);
|
|
239
|
+
this.$l.opticalDepth = pb.vec3(0);
|
|
240
|
+
this.$for(pb.int('i'), 0, N_SAMPLE, function() {
|
|
241
|
+
this.$l.h = pb.sub(pb.length(this.p), this.params.plantRadius);
|
|
242
|
+
this.$l.extinction = pb.add(rayleighCoefficient(this, this.params.rayleighScatteringHeight, this.h), mieCoefficient(this, this.params.mieScatteringHeight, this.h), ozoneAbsorption(this, this.params.ozoneCenter, this.params.ozoneWidth, this.h), mieAbsorption(this, this.params.mieScatteringHeight, this.h));
|
|
243
|
+
this.opticalDepth = pb.add(this.opticalDepth, pb.mul(this.extinction, this.ds));
|
|
244
|
+
this.$l.t1 = transmittanceToSky(this, this.params, this.p, this.params.lightDir, texTransmittanceLut);
|
|
245
|
+
this.$l.s = scattering(this, this.params, this.p, this.viewDir);
|
|
246
|
+
this.$l.t2 = pb.exp(pb.neg(this.opticalDepth));
|
|
247
|
+
this.$l.inScattering = pb.mul(this.t1, this.s, this.t2, this.ds, this.sunLuminance);
|
|
248
|
+
this.color = pb.add(this.color, this.inScattering);
|
|
249
|
+
this.$l.multiScattering = getMultiScattering(this, this.params, this.p, texMultiScatteringLut);
|
|
250
|
+
this.color = pb.add(this.color, pb.mul(this.multiScattering, this.t2, this.ds, this.sunLuminance));
|
|
251
|
+
this.p = pb.add(this.p, pb.mul(this.viewDir, this.ds));
|
|
252
|
+
});
|
|
253
|
+
this.$return(this.color);
|
|
254
|
+
});
|
|
255
|
+
return scope[funcName](stParams, f3EyePos, f3ViewDir, fMaxDis);
|
|
256
|
+
}
|
|
257
|
+
/** @internal */ function getMultiScattering(scope, stParams, f3Pos, texMultiScatteringLut) {
|
|
258
|
+
const pb = scope.$builder;
|
|
259
|
+
const funcName = 'z_getMultiScattering';
|
|
260
|
+
const Params = getAtmosphereParamsStruct(pb);
|
|
261
|
+
pb.func(funcName, [
|
|
262
|
+
Params('params'),
|
|
263
|
+
pb.vec3('p')
|
|
264
|
+
], function() {
|
|
265
|
+
this.$l.h = pb.sub(pb.length(this.p), this.params.plantRadius);
|
|
266
|
+
this.$l.sigma_s = pb.add(rayleighCoefficient(this, this.params.rayleighScatteringHeight, this.h), mieCoefficient(this, this.params.mieScatteringHeight, this.h));
|
|
267
|
+
this.$l.zenithAngle = pb.dot(pb.normalize(this.p), this.params.lightDir);
|
|
268
|
+
this.$l.uv = pb.vec2(pb.add(pb.mul(this.zenithAngle, 0.5), 0.5), pb.div(this.h, this.params.atmosphereHeight));
|
|
269
|
+
this.$l.G_ALL = pb.textureSampleLevel(texMultiScatteringLut, this.uv, 0).rgb;
|
|
270
|
+
this.$return(pb.mul(this.G_ALL, this.sigma_s));
|
|
271
|
+
});
|
|
272
|
+
return scope[funcName](stParams, f3Pos);
|
|
273
|
+
}
|
|
274
|
+
/** @internal */ function integralMultiScattering(scope, stParams, f3LightDir, f3SamplePoint, texTransmittanceLut) {
|
|
275
|
+
const N_DIRECTION = 64;
|
|
276
|
+
const N_SAMPLE = 32;
|
|
277
|
+
const pb = scope.$builder;
|
|
278
|
+
const Params = getAtmosphereParamsStruct(pb);
|
|
279
|
+
const funcName = 'z_integralMultiScattering';
|
|
280
|
+
pb.func(funcName, [
|
|
281
|
+
Params('params'),
|
|
282
|
+
pb.vec3('lightDir'),
|
|
283
|
+
pb.vec3('samplePoint')
|
|
284
|
+
], function() {
|
|
285
|
+
const uniformPhase = 1 / (4 * Math.PI);
|
|
286
|
+
const sphereSolidAngle = 4 * Math.PI / N_DIRECTION;
|
|
287
|
+
this.$l.G_2 = pb.vec3(0);
|
|
288
|
+
this.$l.f_ms = pb.vec3(0);
|
|
289
|
+
this.$for(pb.int('i'), 0, N_DIRECTION, function() {
|
|
290
|
+
this.$l.viewDir = this.uniformSphereSamples.at(this.i).xyz;
|
|
291
|
+
this.$l.dis = rayIntersectSphere(this, pb.vec3(0), pb.add(this.params.plantRadius, this.params.atmosphereHeight), this.samplePoint, this.viewDir);
|
|
292
|
+
this.$l.d = rayIntersectSphere(this, pb.vec3(0), this.params.plantRadius, this.samplePoint, this.viewDir);
|
|
293
|
+
this.$if(pb.greaterThan(this.d, 0), function() {
|
|
294
|
+
this.dis = pb.min(this.dis, this.d);
|
|
295
|
+
});
|
|
296
|
+
this.$l.ds = pb.div(this.dis, N_SAMPLE);
|
|
297
|
+
this.$l.p = pb.add(this.samplePoint, pb.mul(this.viewDir, this.ds, 0.5));
|
|
298
|
+
this.$l.opticalDepth = pb.vec3(0);
|
|
299
|
+
this.$for(pb.int('j'), 0, N_SAMPLE, function() {
|
|
300
|
+
this.$l.h = pb.sub(pb.length(this.p), this.params.plantRadius);
|
|
301
|
+
this.$l.sigma_s = pb.add(rayleighCoefficient(this, this.params.rayleighScatteringHeight, this.h), mieCoefficient(this, this.params.mieScatteringHeight, this.h));
|
|
302
|
+
this.$l.sigma_a = pb.add(ozoneAbsorption(this, this.params.ozoneCenter, this.params.ozoneWidth, this.h), mieAbsorption(this, this.params.mieScatteringHeight, this.h));
|
|
303
|
+
this.$l.sigma_t = pb.add(this.sigma_s, this.sigma_a);
|
|
304
|
+
this.opticalDepth = pb.add(this.opticalDepth, pb.mul(this.sigma_t, this.ds));
|
|
305
|
+
this.$l.t1 = transmittanceToSky(this, this.params, this.p, this.lightDir, texTransmittanceLut);
|
|
306
|
+
this.$l.s = scattering(this, this.params, this.p, this.viewDir);
|
|
307
|
+
this.$l.t2 = pb.exp(pb.neg(this.opticalDepth));
|
|
308
|
+
this.G_2 = pb.add(this.G_2, pb.mul(this.t1, this.s, this.t2, uniformPhase, this.ds));
|
|
309
|
+
this.f_ms = pb.add(this.f_ms, pb.mul(this.t2, this.sigma_s, uniformPhase, this.ds));
|
|
310
|
+
this.p = pb.add(this.p, pb.mul(this.viewDir, this.ds));
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
this.G_2 = pb.mul(this.G_2, sphereSolidAngle);
|
|
314
|
+
this.f_ms = pb.mul(this.f_ms, sphereSolidAngle);
|
|
315
|
+
this.$return(pb.div(this.G_2, pb.sub(pb.vec3(1), this.f_ms)));
|
|
316
|
+
});
|
|
317
|
+
return scope[funcName](stParams, f3LightDir, f3SamplePoint);
|
|
318
|
+
}
|
|
319
|
+
/** @internal */ function scattering(scope, stParams, f3Pos, f3ViewDir) {
|
|
320
|
+
const pb = scope.$builder;
|
|
321
|
+
const Params = getAtmosphereParamsStruct(pb);
|
|
322
|
+
const funcName = 'z_scattering';
|
|
323
|
+
pb.func(funcName, [
|
|
324
|
+
Params('params'),
|
|
325
|
+
pb.vec3('p'),
|
|
326
|
+
pb.vec3('viewDir')
|
|
327
|
+
], function() {
|
|
328
|
+
this.$l.cosTheta = pb.dot(this.params.lightDir, this.viewDir);
|
|
329
|
+
this.$l.h = pb.sub(pb.length(this.p), this.params.plantRadius);
|
|
330
|
+
this.$l.rayleigh = pb.mul(rayleighCoefficient(this, this.params.rayleighScatteringHeight, this.h), rayleighPhase(this, this.cosTheta));
|
|
331
|
+
this.$l.mie = pb.mul(mieCoefficient(this, this.params.mieScatteringHeight, this.h), miePhase(this, this.params.mieAnstropy, this.cosTheta));
|
|
332
|
+
this.$return(pb.add(this.rayleigh, this.mie));
|
|
333
|
+
});
|
|
334
|
+
return scope[funcName](stParams, f3Pos, f3ViewDir);
|
|
335
|
+
}
|
|
336
|
+
/** @internal */ function transmittance(scope, stParams, f3P1, f3P2) {
|
|
337
|
+
const pb = scope.$builder;
|
|
338
|
+
const Params = getAtmosphereParamsStruct(pb);
|
|
339
|
+
const funcName = 'z_transmittance';
|
|
340
|
+
pb.func(funcName, [
|
|
341
|
+
Params('params'),
|
|
342
|
+
pb.vec3('p1'),
|
|
343
|
+
pb.vec3('p2')
|
|
344
|
+
], function() {
|
|
345
|
+
this.$l.dir = pb.normalize(pb.sub(this.p2, this.p1));
|
|
346
|
+
this.$l.distance = pb.length(pb.sub(this.p2, this.p1));
|
|
347
|
+
this.$l.ds = pb.div(this.distance, TRANSMITTANCE_SAMPLES);
|
|
348
|
+
this.$l.sum = pb.vec3(0);
|
|
349
|
+
this.$l.p = pb.add(this.p1, pb.mul(this.dir, this.ds, 0.5));
|
|
350
|
+
this.$for(pb.int('i'), 0, TRANSMITTANCE_SAMPLES, function() {
|
|
351
|
+
this.$l.h = pb.sub(pb.length(this.p), this.params.plantRadius);
|
|
352
|
+
this.$l.scattering = pb.add(rayleighCoefficient(this, this.params.rayleighScatteringHeight, this.h), mieCoefficient(this, this.params.mieScatteringHeight, this.h));
|
|
353
|
+
this.$l.absorption = pb.add(ozoneAbsorption(this, this.params.ozoneCenter, this.params.ozoneWidth, this.h), mieAbsorption(this, this.params.mieScatteringHeight, this.h));
|
|
354
|
+
this.$l.extinction = pb.add(this.scattering, this.absorption);
|
|
355
|
+
this.sum = pb.add(this.sum, pb.mul(this.extinction, this.ds));
|
|
356
|
+
this.p = pb.add(this.p, pb.mul(this.dir, this.ds));
|
|
357
|
+
});
|
|
358
|
+
this.$return(pb.exp(pb.neg(this.sum)));
|
|
359
|
+
});
|
|
360
|
+
return scope[funcName](stParams, f3P1, f3P2);
|
|
361
|
+
}
|
|
362
|
+
/** @internal */ function transmittanceLutToUV(scope, fBottomRadius, fTopRadius, fMu, fR) {
|
|
363
|
+
const pb = scope.$builder;
|
|
364
|
+
const funcName = 'z_transmittanceToUV';
|
|
365
|
+
pb.func(funcName, [
|
|
366
|
+
pb.float('bottomRadius'),
|
|
367
|
+
pb.float('topRadius'),
|
|
368
|
+
pb.float('mu'),
|
|
369
|
+
pb.float('r')
|
|
370
|
+
], function() {
|
|
371
|
+
this.$l.H = pb.sqrt(pb.max(0, pb.sub(pb.mul(this.topRadius, this.topRadius), pb.mul(this.bottomRadius, this.bottomRadius))));
|
|
372
|
+
this.$l.rho = pb.sqrt(pb.max(0, pb.sub(pb.mul(this.r, this.r), pb.mul(this.bottomRadius, this.bottomRadius))));
|
|
373
|
+
this.$l.discriminant = pb.add(pb.mul(this.r, this.r, pb.sub(pb.mul(this.mu, this.mu), 1)), pb.mul(this.topRadius, this.topRadius));
|
|
374
|
+
this.$l.d = pb.max(0, pb.sub(pb.sqrt(this.discriminant), pb.mul(this.mu, this.r)));
|
|
375
|
+
this.$l.d_min = pb.sub(this.topRadius, this.r);
|
|
376
|
+
this.$l.d_max = pb.add(this.rho, this.H);
|
|
377
|
+
this.$l.x_mu = pb.div(pb.sub(this.d, this.d_min), pb.sub(this.d_max, this.d_min));
|
|
378
|
+
this.$l.x_r = pb.div(this.rho, this.H);
|
|
379
|
+
this.$return(pb.vec2(this.x_mu, this.x_r));
|
|
380
|
+
});
|
|
381
|
+
return scope[funcName](fBottomRadius, fTopRadius, fMu, fR);
|
|
382
|
+
}
|
|
383
|
+
/** @internal */ function viewDirToUV(scope, f3ViewDir) {
|
|
384
|
+
const pb = scope.$builder;
|
|
385
|
+
const funcName = 'z_viewDirToUV';
|
|
386
|
+
pb.func(funcName, [
|
|
387
|
+
pb.vec3('viewDir')
|
|
388
|
+
], function() {
|
|
389
|
+
this.$l.uv = pb.vec2(pb.atan2(this.viewDir.z, this.viewDir.x), pb.asin(this.viewDir.y));
|
|
390
|
+
this.uv = pb.div(this.uv, pb.vec2(2 * Math.PI, Math.PI));
|
|
391
|
+
this.uv = pb.add(this.uv, pb.vec2(0.5));
|
|
392
|
+
this.$return(this.uv);
|
|
393
|
+
});
|
|
394
|
+
return scope[funcName](f3ViewDir);
|
|
395
|
+
}
|
|
396
|
+
/** @internal */ function uvToViewDir(scope, f2UV) {
|
|
397
|
+
const pb = scope.$builder;
|
|
398
|
+
const funcName = 'z_uvToViewDir';
|
|
399
|
+
pb.func(funcName, [
|
|
400
|
+
pb.vec2('uv')
|
|
401
|
+
], function() {
|
|
402
|
+
this.$l.theta = pb.mul(pb.sub(1, this.uv.y), Math.PI);
|
|
403
|
+
this.$l.phi = pb.mul(pb.sub(pb.mul(this.uv.x, 2), 1), Math.PI);
|
|
404
|
+
this.$l.x = pb.mul(pb.sin(this.theta), pb.cos(this.phi));
|
|
405
|
+
this.$l.z = pb.mul(pb.sin(this.theta), pb.sin(this.phi));
|
|
406
|
+
this.$l.y = pb.cos(this.theta);
|
|
407
|
+
this.$return(pb.vec3(this.x, this.y, this.z));
|
|
408
|
+
});
|
|
409
|
+
return scope[funcName](f2UV);
|
|
410
|
+
}
|
|
411
|
+
/** @internal */ function uvToTransmittanceLut(scope, f2UV, fBottomRadius, fTopRadius) {
|
|
412
|
+
const pb = scope.$builder;
|
|
413
|
+
const funcName = 'z_uvToTransmittanceLut';
|
|
414
|
+
pb.func(funcName, [
|
|
415
|
+
pb.vec2('uv'),
|
|
416
|
+
pb.float('bottomRadius'),
|
|
417
|
+
pb.float('topRadius')
|
|
418
|
+
], function() {
|
|
419
|
+
this.$l.x_mu = this.uv.x;
|
|
420
|
+
this.$l.x_r = this.uv.y;
|
|
421
|
+
this.$l.H = pb.sqrt(pb.max(0, pb.sub(pb.mul(this.topRadius, this.topRadius), pb.mul(this.bottomRadius, this.bottomRadius))));
|
|
422
|
+
this.$l.rho = pb.mul(this.H, this.x_r);
|
|
423
|
+
this.$l.r = pb.sqrt(pb.max(0, pb.add(pb.mul(this.rho, this.rho), pb.mul(this.bottomRadius, this.bottomRadius))));
|
|
424
|
+
this.$l.d_min = pb.sub(this.topRadius, this.r);
|
|
425
|
+
this.$l.d_max = pb.add(this.rho, this.H);
|
|
426
|
+
this.$l.d = pb.add(this.d_min, pb.mul(this.x_mu, pb.sub(this.d_max, this.d_min)));
|
|
427
|
+
this.$l.mu = this.$choice(pb.equal(this.d, 0), pb.float(1), pb.div(pb.sub(pb.mul(this.H, this.H), pb.add(pb.mul(this.rho, this.rho), pb.mul(this.d, this.d))), pb.mul(this.r, this.d, 2)));
|
|
428
|
+
this.mu = pb.clamp(this.mu, -1, 1);
|
|
429
|
+
this.$return(pb.vec2(this.mu, this.r));
|
|
430
|
+
});
|
|
431
|
+
return scope[funcName](f2UV, fBottomRadius, fTopRadius);
|
|
432
|
+
}
|
|
433
|
+
function sunBloom(scope, f3ViewDir, f3LightDir, f4LightColorAndIntensity, fSunSolidAngle) {
|
|
434
|
+
const pb = scope.$builder;
|
|
435
|
+
const funcName = 'v_sunBloom';
|
|
436
|
+
pb.func(funcName, [
|
|
437
|
+
pb.vec3('viewDir'),
|
|
438
|
+
pb.vec3('lightDir'),
|
|
439
|
+
pb.vec4('sunColorAndIntensity'),
|
|
440
|
+
pb.float('sunSolidAngle')
|
|
441
|
+
], function() {
|
|
442
|
+
this.$l.minSunCosTheta = pb.cos(this.sunSolidAngle);
|
|
443
|
+
this.$l.cosTheta = pb.dot(this.viewDir, this.lightDir);
|
|
444
|
+
this.$l.luminance = pb.mul(this.sunColorAndIntensity.rgb, this.sunColorAndIntensity.a);
|
|
445
|
+
this.$if(pb.lessThan(this.cosTheta, this.minSunCosTheta), function() {
|
|
446
|
+
this.$l.offset = pb.sub(this.minSunCosTheta, this.cosTheta);
|
|
447
|
+
this.$l.gaussianBloom = pb.mul(pb.exp(pb.mul(this.offset, -5e4)), 0.5);
|
|
448
|
+
this.$l.invBloom = pb.mul(pb.div(1, pb.add(0.02, pb.mul(this.offset, 300))), 0.01);
|
|
449
|
+
this.luminance = pb.mul(this.luminance, pb.add(this.gaussianBloom, this.invBloom));
|
|
450
|
+
});
|
|
451
|
+
this.$return(this.luminance);
|
|
452
|
+
});
|
|
453
|
+
return scope[funcName](f3ViewDir, f3LightDir, f4LightColorAndIntensity, fSunSolidAngle);
|
|
454
|
+
}
|
|
455
|
+
/** @internal */ function skyBox(scope, stParams, f4SunColor, f3SkyBoxWorldPos, fSunSolidAngle, texTransmittanceLut, texSkyViewLut) {
|
|
456
|
+
const pb = scope.$builder;
|
|
457
|
+
const funcName = 'v_skybox';
|
|
458
|
+
const Params = getAtmosphereParamsStruct(pb);
|
|
459
|
+
pb.func(funcName, [
|
|
460
|
+
Params('params'),
|
|
461
|
+
pb.vec4('sunColor').out(),
|
|
462
|
+
pb.vec3('worldPos'),
|
|
463
|
+
pb.float('sunSolidAngle')
|
|
464
|
+
], function() {
|
|
465
|
+
this.$l.rgb = pb.vec3(0);
|
|
466
|
+
this.$l.viewDir = pb.normalize(this.worldPos);
|
|
467
|
+
this.rgb = pb.add(this.rgb, pb.textureSampleLevel(texSkyViewLut, viewDirToUV(this, this.viewDir), 0).rgb);
|
|
468
|
+
this.$l.groundDistance = rayIntersectSphere(this, pb.vec3(0), this.params.plantRadius, pb.vec3(0, pb.add(this.params.plantRadius, pb.mul(CAMERA_POS_Y, this.params.cameraHeightScale)), 0), this.viewDir);
|
|
469
|
+
this.$l.sunTransmittance = transmittanceToSky(this, this.params, pb.vec3(0, pb.add(this.params.cameraHeightScale, this.params.plantRadius), 0), this.params.lightDir, texTransmittanceLut);
|
|
470
|
+
this.sunColor = pb.mul(this.params.lightColor, pb.vec4(this.sunTransmittance, 1));
|
|
471
|
+
this.$if(pb.lessThan(this.groundDistance, 0), function() {
|
|
472
|
+
this.rgb = pb.add(this.rgb, sunBloom(this, this.viewDir, this.params.lightDir, this.sunColor, this.sunSolidAngle));
|
|
473
|
+
});
|
|
474
|
+
this.$return(pb.vec4(this.rgb, 1));
|
|
475
|
+
});
|
|
476
|
+
return scope[funcName](stParams, f4SunColor, f3SkyBoxWorldPos, fSunSolidAngle);
|
|
477
|
+
}
|
|
478
|
+
/** @internal */ function aerialPerspective(scope, f2UV, stParams, f3CameraPos, f3WorldPos, f3Dim, texAerialPerspectiveLut) {
|
|
479
|
+
const pb = scope.$builder;
|
|
480
|
+
const Params = getAtmosphereParamsStruct(pb);
|
|
481
|
+
const funcName = 'z_aerialPerspective';
|
|
482
|
+
pb.func(funcName, [
|
|
483
|
+
Params('params'),
|
|
484
|
+
pb.vec2('uv'),
|
|
485
|
+
pb.vec3('cameraPos'),
|
|
486
|
+
pb.vec3('worldPos'),
|
|
487
|
+
pb.vec3('dim')
|
|
488
|
+
], function() {
|
|
489
|
+
this.$l.V = pb.sub(this.worldPos, this.cameraPos);
|
|
490
|
+
this.$l.dis = pb.length(this.V);
|
|
491
|
+
this.$l.viewDir = pb.normalize(this.V);
|
|
492
|
+
this.$l.apDistance = pb.div(this.params.apDistance, this.params.cameraHeightScale);
|
|
493
|
+
this.$l.d0 = pb.clamp(pb.div(this.dis, this.apDistance), 0, 1);
|
|
494
|
+
this.$l.weight = pb.clamp(pb.mul(this.d0, 2), 0, 1);
|
|
495
|
+
this.$l.dz = pb.mul(this.d0, pb.sub(this.dim.z, 1));
|
|
496
|
+
this.$l.slice = pb.floor(this.dz);
|
|
497
|
+
this.$l.nextSlice = pb.min(pb.add(this.slice, 1), pb.sub(this.dim.z, 1));
|
|
498
|
+
this.$l.factor = pb.sub(this.dz, pb.floor(this.dz));
|
|
499
|
+
this.t = pb.div(this.uv, pb.vec2(this.dim.x, 1));
|
|
500
|
+
this.$l.uv1 = pb.add(this.t, pb.vec2(pb.div(this.slice, this.dim.z), 0));
|
|
501
|
+
this.$l.uv2 = pb.add(this.t, pb.vec2(pb.div(this.nextSlice, this.dim.z), 0));
|
|
502
|
+
this.$l.data1 = pb.textureSampleLevel(texAerialPerspectiveLut, this.uv1, 0);
|
|
503
|
+
this.$l.data2 = pb.textureSampleLevel(texAerialPerspectiveLut, this.uv2, 0);
|
|
504
|
+
this.$l.data = pb.mix(this.data1, this.data2, this.factor);
|
|
505
|
+
this.$l.inscattering = pb.mul(this.data.rgb, this.weight);
|
|
506
|
+
//this.$l.transmittance = pb.sub(1, pb.mul(this.weight, pb.sub(1, this.data.a)));
|
|
507
|
+
this.$l.planetTranslate = pb.vec3(0, this.params.plantRadius, 0);
|
|
508
|
+
this.$l.transmittance = pb.dot(transmittance(this, this.params, pb.add(this.cameraPos, this.planetTranslate), pb.add(this.worldPos, this.planetTranslate)), pb.vec3(1 / 3, 1 / 3, 1 / 3));
|
|
509
|
+
this.$return(pb.vec4(this.inscattering, this.transmittance));
|
|
510
|
+
});
|
|
511
|
+
return scope[funcName](stParams, f2UV, f3CameraPos, f3WorldPos, f3Dim);
|
|
512
|
+
}
|
|
513
|
+
/** @internal */ function aerialPerspectiveLut(scope, stParams, f2UV, f3VoxelDim, texTransmittanceLut, texMultiScatteringLut) {
|
|
514
|
+
const pb = scope.$builder;
|
|
515
|
+
const Params = getAtmosphereParamsStruct(pb);
|
|
516
|
+
const funcNameFixVoxel = 'z_fixVoxel';
|
|
517
|
+
pb.func(funcNameFixVoxel, [
|
|
518
|
+
Params('params'),
|
|
519
|
+
pb.vec3('eyePos'),
|
|
520
|
+
pb.vec3('viewDir').inout(),
|
|
521
|
+
pb.float('maxDis'),
|
|
522
|
+
pb.float('adjustedMaxDis').inout()
|
|
523
|
+
], function() {
|
|
524
|
+
this.$l.voxelPos = pb.add(this.eyePos, pb.mul(this.viewDir, this.maxDis));
|
|
525
|
+
this.$l.voxelHeight = pb.length(this.voxelPos);
|
|
526
|
+
this.$l.underGround = pb.lessThan(this.voxelHeight, this.params.plantRadius);
|
|
527
|
+
this.$l.cameraToVoxel = pb.sub(this.voxelPos, this.eyePos);
|
|
528
|
+
this.$l.cameraToVoxelLen = pb.length(this.cameraToVoxel);
|
|
529
|
+
this.$l.cameraToVoxelDir = pb.div(this.cameraToVoxel, this.cameraToVoxelLen);
|
|
530
|
+
this.$l.planetNearT = rayIntersectSphere(this, pb.vec3(0), this.params.plantRadius, this.eyePos, this.cameraToVoxelDir);
|
|
531
|
+
this.$l.belowHorizon = pb.and(pb.greaterThan(this.planetNearT, 0), pb.greaterThan(this.cameraToVoxelLen, this.planetNearT));
|
|
532
|
+
this.$l.eyePos2 = this.eyePos;
|
|
533
|
+
this.$if(pb.or(this.underGround, this.belowHorizon), function() {
|
|
534
|
+
this.eyePos2 = pb.add(this.eyePos2, pb.mul(pb.normalize(this.eyePos2), 0.02));
|
|
535
|
+
this.$if(this.belowHorizon, function() {
|
|
536
|
+
this.$l.voxelWorldPosNorm = pb.normalize(this.voxelPos);
|
|
537
|
+
this.$l.camProjOnGround = pb.mul(pb.normalize(this.eyePos2), this.params.plantRadius);
|
|
538
|
+
this.$l.voxProjOnGround = pb.mul(this.voxelWorldPosNorm, this.params.plantRadius);
|
|
539
|
+
this.$l.voxelGroundToRayStart = pb.sub(this.eyePos2, this.voxProjOnGround);
|
|
540
|
+
this.$if(pb.lessThan(pb.dot(pb.normalize(this.voxelGroundToRayStart), this.voxelWorldPosNorm), 0.0001), function() {
|
|
541
|
+
this.$l.middlePoint = pb.mul(pb.add(this.camProjOnGround, this.voxProjOnGround), 0.5);
|
|
542
|
+
this.$l.middlePointOnGround = pb.mul(pb.normalize(this.middlePoint), this.params.plantRadius);
|
|
543
|
+
this.voxelPos = pb.add(this.eyePos2, pb.mul(pb.sub(this.middlePointOnGround, this.eyePos2), 2));
|
|
544
|
+
});
|
|
545
|
+
}).$else(function() {
|
|
546
|
+
this.voxelPos = pb.mul(pb.normalize(this.voxelPos), this.params.plantRadius);
|
|
547
|
+
});
|
|
548
|
+
this.$l.V = pb.sub(this.voxelPos, this.eyePos2);
|
|
549
|
+
this.adjustedMaxDis = pb.length(this.V);
|
|
550
|
+
this.viewDir = pb.div(this.V, this.adjustedMaxDis);
|
|
551
|
+
});
|
|
552
|
+
this.$return(this.eyePos2);
|
|
553
|
+
});
|
|
554
|
+
const funcName = 'z_aerialPerspectiveLut';
|
|
555
|
+
pb.func(funcName, [
|
|
556
|
+
Params('params'),
|
|
557
|
+
pb.vec2('uv'),
|
|
558
|
+
pb.vec3('dim'),
|
|
559
|
+
pb.float('cameraPosY')
|
|
560
|
+
], function() {
|
|
561
|
+
this.$l.uvw = pb.vec3(this.uv, 0);
|
|
562
|
+
this.uvw.x = pb.mul(this.uvw.x, this.dim.x, this.dim.z);
|
|
563
|
+
this.uvw.z = pb.div(pb.floor(pb.div(this.uvw.x, this.dim.z)), this.dim.x);
|
|
564
|
+
this.uvw.x = pb.div(pb.mod(this.uvw.x, this.dim.z), this.dim.x);
|
|
565
|
+
this.uvw = pb.add(this.uvw, pb.div(pb.vec3(0.5), this.dim));
|
|
566
|
+
this.$l.slice = this.uvw.z; //pb.mul(this.uvw.z, this.uvw.z);
|
|
567
|
+
this.$l.viewDir = pb.normalize(pb.mul(this.params.cameraWorldMatrix, pb.vec4(pb.sub(pb.mul(this.uvw.x, 2), 1), pb.div(pb.sub(pb.mul(this.uvw.y, 2), 1), this.params.cameraAspect), -1, 0)).xyz);
|
|
568
|
+
this.$l.eyePos = pb.vec3(0, pb.add(pb.mul(this.cameraPosY, this.params.cameraHeightScale), this.params.plantRadius), 0);
|
|
569
|
+
this.$l.maxDis = pb.mul(this.slice, this.params.apDistance);
|
|
570
|
+
this.$l.voxelPos = pb.add(this.eyePos, pb.mul(this.viewDir, this.maxDis));
|
|
571
|
+
this.$if(pb.lessThan(pb.length(this.voxelPos), this.params.plantRadius), function() {
|
|
572
|
+
this.voxelPos = pb.mul(pb.normalize(this.voxelPos), this.params.plantRadius);
|
|
573
|
+
this.maxDis = pb.length(pb.sub(this.eyePos, this.voxelPos));
|
|
574
|
+
});
|
|
575
|
+
this.$l.color = getSkyView(this, this.params, this.eyePos, this.viewDir, this.maxDis, texTransmittanceLut, texMultiScatteringLut);
|
|
576
|
+
this.$l.t1 = transmittanceToSky(this, this.params, this.eyePos, this.viewDir, texTransmittanceLut);
|
|
577
|
+
this.$l.t2 = transmittanceToSky(this, this.params, this.voxelPos, this.viewDir, texTransmittanceLut);
|
|
578
|
+
this.$l.t = pb.clamp(pb.div(this.t1, pb.max(this.t2, pb.vec3(0.0001))), pb.vec3(0), pb.vec3(1));
|
|
579
|
+
this.$return(pb.vec4(this.color, pb.dot(this.t, pb.vec3(1 / 3, 1 / 3, 1 / 3))));
|
|
580
|
+
});
|
|
581
|
+
return scope[funcName](stParams, f2UV, f3VoxelDim, CAMERA_POS_Y);
|
|
582
|
+
}
|
|
583
|
+
/** @internal */ function skyViewLut(scope, stParams, f2UV, texTransmittanceLut, texMultiScatteringLut) {
|
|
584
|
+
const pb = scope.$builder;
|
|
585
|
+
const Params = getAtmosphereParamsStruct(pb);
|
|
586
|
+
const funcName = 'v_skyViewLut';
|
|
587
|
+
pb.func(funcName, [
|
|
588
|
+
Params('params'),
|
|
589
|
+
pb.vec2('uv'),
|
|
590
|
+
pb.float('cameraPosY')
|
|
591
|
+
], function() {
|
|
592
|
+
this.$l.viewDir = uvToViewDir(this, this.uv);
|
|
593
|
+
this.$l.h = pb.add(this.params.plantRadius, pb.mul(this.cameraPosY, this.params.cameraHeightScale));
|
|
594
|
+
this.$l.eyePos = pb.vec3(0, this.h, 0);
|
|
595
|
+
this.$l.rgb = getSkyView(this, this.params, this.eyePos, this.viewDir, pb.float(-1), texTransmittanceLut, texMultiScatteringLut);
|
|
596
|
+
this.$return(pb.vec4(this.rgb, 1));
|
|
597
|
+
});
|
|
598
|
+
return scope[funcName](stParams, f2UV, CAMERA_POS_Y);
|
|
599
|
+
}
|
|
600
|
+
/** @internal */ function multiScatteringLut(scope, stParams, f2UV, texTransmittanceLut) {
|
|
601
|
+
const pb = scope.$builder;
|
|
602
|
+
const Params = getAtmosphereParamsStruct(pb);
|
|
603
|
+
const funcName = 'v_multiScatteringLut';
|
|
604
|
+
pb.func(funcName, [
|
|
605
|
+
Params('params'),
|
|
606
|
+
pb.vec2('uv')
|
|
607
|
+
], function() {
|
|
608
|
+
this.$l.mu_s = pb.sub(pb.mul(this.uv.x, 2), 1);
|
|
609
|
+
this.$l.r = pb.add(pb.mul(this.uv.y, this.params.atmosphereHeight), this.params.plantRadius);
|
|
610
|
+
this.$l.cosTheta = this.mu_s;
|
|
611
|
+
this.$l.sinTheta = pb.sqrt(pb.sub(1, pb.mul(this.cosTheta, this.cosTheta)));
|
|
612
|
+
this.$l.lightDir = pb.vec3(this.sinTheta, this.cosTheta, 0);
|
|
613
|
+
this.$l.p = pb.vec3(0, this.r, 0);
|
|
614
|
+
this.$l.rgb = integralMultiScattering(this, this.params, this.lightDir, this.p, texTransmittanceLut);
|
|
615
|
+
this.$return(pb.vec4(this.rgb, 1));
|
|
616
|
+
});
|
|
617
|
+
return scope[funcName](stParams, f2UV);
|
|
618
|
+
}
|
|
619
|
+
/** @internal */ function transmittanceLut(scope, stParams, f2UV) {
|
|
620
|
+
const pb = scope.$builder;
|
|
621
|
+
const Params = getAtmosphereParamsStruct(pb);
|
|
622
|
+
const funcName = 'transmittanceLut';
|
|
623
|
+
pb.func(funcName, [
|
|
624
|
+
Params('params'),
|
|
625
|
+
pb.vec2('uv')
|
|
626
|
+
], function() {
|
|
627
|
+
this.$l.color = pb.vec4(0, 0, 0, 1);
|
|
628
|
+
this.$l.bottomRadius = this.params.plantRadius;
|
|
629
|
+
this.$l.topRadius = pb.add(this.bottomRadius, this.params.atmosphereHeight);
|
|
630
|
+
this.$l.lutParams = uvToTransmittanceLut(this, this.uv, this.bottomRadius, this.topRadius);
|
|
631
|
+
this.$l.cos_theta = this.lutParams.x;
|
|
632
|
+
this.$l.r = this.lutParams.y;
|
|
633
|
+
this.$l.sin_theta = pb.sqrt(pb.sub(1, pb.mul(this.cos_theta, this.cos_theta)));
|
|
634
|
+
this.$l.viewDir = pb.vec3(this.sin_theta, this.cos_theta, 0);
|
|
635
|
+
this.$l.eyePos = pb.vec3(0, this.r, 0);
|
|
636
|
+
this.$l.dis = rayIntersectSphere(this, pb.vec3(0), this.topRadius, this.eyePos, this.viewDir);
|
|
637
|
+
this.$l.hitPoint = pb.add(this.eyePos, pb.mul(this.viewDir, this.dis));
|
|
638
|
+
this.$return(pb.vec4(transmittance(this, this.params, this.eyePos, this.hitPoint), 1));
|
|
639
|
+
});
|
|
640
|
+
return scope[funcName](stParams, f2UV);
|
|
641
|
+
}
|
|
642
|
+
/** @internal */ function atmosphereLUTRendered() {
|
|
643
|
+
return !!transmittanceLUT && !!multiScatteringLUT && !!skyViewLUT && !!ApLut;
|
|
644
|
+
}
|
|
645
|
+
/** @internal */ function renderAtmosphereLUTs(params) {
|
|
646
|
+
const checkResult = checkParams(params);
|
|
647
|
+
if (checkResult.transmittance || !transmittanceLUT) {
|
|
648
|
+
renderTransmittanceLut(currentAtmosphereParams);
|
|
649
|
+
}
|
|
650
|
+
if (checkResult.multiScattering || !multiScatteringLUT) {
|
|
651
|
+
renderMultiScatteringLut(currentAtmosphereParams);
|
|
652
|
+
}
|
|
653
|
+
if (checkResult.skyView || !skyViewLUT) {
|
|
654
|
+
renderSkyViewLut(currentAtmosphereParams);
|
|
655
|
+
}
|
|
656
|
+
if (checkResult.aerialPerspective || !ApLut) {
|
|
657
|
+
renderAPLut(currentAtmosphereParams);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
/* For debug */ let transmittanceLutProgram = undefined;
|
|
661
|
+
let multiScatteringLutProgram = undefined;
|
|
662
|
+
let skyViewLutProgram = undefined;
|
|
663
|
+
let APLutProgram = undefined;
|
|
664
|
+
let transmittanceLutBindGroup = undefined;
|
|
665
|
+
let transmittanceLUT = undefined;
|
|
666
|
+
let transmittanceFramebuffer = undefined;
|
|
667
|
+
let multiScatteringLutBindGroup = undefined;
|
|
668
|
+
let multiScatteringLUT = undefined;
|
|
669
|
+
let uniformSphereSampleBuffer = undefined;
|
|
670
|
+
let multiScatteringFramebuffer = undefined;
|
|
671
|
+
let skyViewLutBindGroup = undefined;
|
|
672
|
+
let skyViewLUT = undefined;
|
|
673
|
+
let skyViewFramebuffer = undefined;
|
|
674
|
+
let APLutBindGroup = undefined;
|
|
675
|
+
let ApLut = undefined;
|
|
676
|
+
let APFramebuffer = undefined;
|
|
677
|
+
/** @internal */ function getTransmittanceLut() {
|
|
678
|
+
return transmittanceLUT;
|
|
679
|
+
}
|
|
680
|
+
/** @internal */ function getMultiScatteringLut() {
|
|
681
|
+
return multiScatteringLUT;
|
|
682
|
+
}
|
|
683
|
+
/** @internal */ function getSkyViewLut() {
|
|
684
|
+
return skyViewLUT;
|
|
685
|
+
}
|
|
686
|
+
/** @internal */ function getAerialPerspectiveLut() {
|
|
687
|
+
return ApLut;
|
|
688
|
+
}
|
|
689
|
+
/** @internal */ function getAtmosphereParamsStruct(pb) {
|
|
690
|
+
return pb.defineStruct([
|
|
691
|
+
pb.mat4('cameraWorldMatrix'),
|
|
692
|
+
pb.vec4('lightColor'),
|
|
693
|
+
pb.vec3('lightDir'),
|
|
694
|
+
pb.float('cameraAspect'),
|
|
695
|
+
pb.float('plantRadius'),
|
|
696
|
+
pb.float('atmosphereHeight'),
|
|
697
|
+
pb.float('rayleighScatteringHeight'),
|
|
698
|
+
pb.float('mieScatteringHeight'),
|
|
699
|
+
pb.float('mieAnstropy'),
|
|
700
|
+
pb.float('ozoneCenter'),
|
|
701
|
+
pb.float('ozoneWidth'),
|
|
702
|
+
pb.float('apDistance'),
|
|
703
|
+
pb.float('cameraHeightScale')
|
|
704
|
+
]);
|
|
705
|
+
}
|
|
706
|
+
/** @internal */ function createTransmittanceLutProgram(device) {
|
|
707
|
+
const program = device.buildRenderProgram({
|
|
708
|
+
vertex (pb) {
|
|
709
|
+
this.flip = pb.int().uniform(0);
|
|
710
|
+
this.$inputs.pos = pb.vec2().attrib('position');
|
|
711
|
+
this.$outputs.uv = pb.vec2();
|
|
712
|
+
pb.main(function() {
|
|
713
|
+
this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);
|
|
714
|
+
this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
|
|
715
|
+
this.$if(pb.notEqual(this.flip, 0), function() {
|
|
716
|
+
this.$builtins.position.y = pb.neg(this.$builtins.position.y);
|
|
717
|
+
});
|
|
718
|
+
});
|
|
719
|
+
},
|
|
720
|
+
fragment (pb) {
|
|
721
|
+
const Params = getAtmosphereParamsStruct(pb);
|
|
722
|
+
this.params = Params().uniform(0);
|
|
723
|
+
this.$outputs.outColor = pb.vec4();
|
|
724
|
+
pb.main(function() {
|
|
725
|
+
this.$outputs.outColor = transmittanceLut(this, this.params, this.$inputs.uv);
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
program.name = '@TransmittanceLutProgram';
|
|
730
|
+
return program;
|
|
731
|
+
}
|
|
732
|
+
/** @internal */ function renderTransmittanceLut(params) {
|
|
733
|
+
const device = getDevice();
|
|
734
|
+
if (transmittanceLutProgram === undefined) {
|
|
735
|
+
try {
|
|
736
|
+
transmittanceLutProgram = createTransmittanceLutProgram(device);
|
|
737
|
+
transmittanceLutBindGroup = device.createBindGroup(transmittanceLutProgram.bindGroupLayouts[0]);
|
|
738
|
+
transmittanceLUT = device.createTexture2D('rgba16f', 256, 64, {
|
|
739
|
+
mipmapping: false
|
|
740
|
+
});
|
|
741
|
+
transmittanceLUT.name = 'DebugTransmittanceLut';
|
|
742
|
+
transmittanceFramebuffer = device.createFrameBuffer([
|
|
743
|
+
transmittanceLUT
|
|
744
|
+
], null);
|
|
745
|
+
} catch (err) {
|
|
746
|
+
console.error(err);
|
|
747
|
+
transmittanceLutProgram = null;
|
|
748
|
+
transmittanceLutBindGroup = null;
|
|
749
|
+
transmittanceFramebuffer = null;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
if (transmittanceLutProgram) {
|
|
753
|
+
transmittanceLutBindGroup.setValue('flip', device.type === 'webgpu' ? 1 : 0);
|
|
754
|
+
transmittanceLutBindGroup.setValue('params', params);
|
|
755
|
+
device.pushDeviceStates();
|
|
756
|
+
device.setFramebuffer(transmittanceFramebuffer);
|
|
757
|
+
device.setProgram(transmittanceLutProgram);
|
|
758
|
+
device.setBindGroup(0, transmittanceLutBindGroup);
|
|
759
|
+
drawFullscreenQuad();
|
|
760
|
+
device.popDeviceStates();
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
/** @internal */ function createMultiScatteringLutProgram(device) {
|
|
764
|
+
const program = device.buildRenderProgram({
|
|
765
|
+
vertex (pb) {
|
|
766
|
+
this.flip = pb.int().uniform(0);
|
|
767
|
+
this.$inputs.pos = pb.vec2().attrib('position');
|
|
768
|
+
this.$outputs.uv = pb.vec2();
|
|
769
|
+
pb.main(function() {
|
|
770
|
+
this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);
|
|
771
|
+
this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
|
|
772
|
+
this.$if(pb.notEqual(this.flip, 0), function() {
|
|
773
|
+
this.$builtins.position.y = pb.neg(this.$builtins.position.y);
|
|
774
|
+
});
|
|
775
|
+
});
|
|
776
|
+
},
|
|
777
|
+
fragment (pb) {
|
|
778
|
+
const Params = getAtmosphereParamsStruct(pb);
|
|
779
|
+
this.params = Params().uniform(0);
|
|
780
|
+
this.uniformSphereSamples = pb.vec4[64]().uniformBuffer(0);
|
|
781
|
+
this.transmittanceLut = pb.tex2D().uniform(0);
|
|
782
|
+
this.$outputs.outColor = pb.vec4();
|
|
783
|
+
pb.main(function() {
|
|
784
|
+
this.$outputs.outColor = multiScatteringLut(this, this.params, this.$inputs.uv, this.transmittanceLut);
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
});
|
|
788
|
+
program.name = '@MultiScatteringLutProgram';
|
|
789
|
+
return program;
|
|
790
|
+
}
|
|
791
|
+
/** @internal */ function renderMultiScatteringLut(params) {
|
|
792
|
+
const device = getDevice();
|
|
793
|
+
if (multiScatteringLutProgram === undefined) {
|
|
794
|
+
try {
|
|
795
|
+
multiScatteringLutProgram = createMultiScatteringLutProgram(device);
|
|
796
|
+
multiScatteringLutBindGroup = device.createBindGroup(multiScatteringLutProgram.bindGroupLayouts[0]);
|
|
797
|
+
multiScatteringLUT = device.createTexture2D('rgba16f', 32, 32, {
|
|
798
|
+
mipmapping: false
|
|
799
|
+
});
|
|
800
|
+
multiScatteringLUT.name = 'DebugMultiScatteringLut';
|
|
801
|
+
multiScatteringFramebuffer = device.createFrameBuffer([
|
|
802
|
+
multiScatteringLUT
|
|
803
|
+
], null);
|
|
804
|
+
uniformSphereSampleBuffer = multiScatteringLutBindGroup.getBuffer('uniformSphereSamples', false);
|
|
805
|
+
const sphereSamples = new Float32Array(64 * 4);
|
|
806
|
+
for(let i = 0; i < 64; i++){
|
|
807
|
+
sphereSamples[i * 4 + 0] = uniformSphereSamples[i].x;
|
|
808
|
+
sphereSamples[i * 4 + 1] = uniformSphereSamples[i].y;
|
|
809
|
+
sphereSamples[i * 4 + 2] = uniformSphereSamples[i].z;
|
|
810
|
+
sphereSamples[i * 4 + 3] = 0;
|
|
811
|
+
}
|
|
812
|
+
uniformSphereSampleBuffer.bufferSubData(0, sphereSamples);
|
|
813
|
+
} catch (err) {
|
|
814
|
+
console.error(err);
|
|
815
|
+
multiScatteringLutProgram = null;
|
|
816
|
+
multiScatteringLutBindGroup = null;
|
|
817
|
+
multiScatteringFramebuffer = null;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
if (multiScatteringLutProgram) {
|
|
821
|
+
multiScatteringLutBindGroup.setValue('flip', device.type === 'webgpu' ? 1 : 0);
|
|
822
|
+
multiScatteringLutBindGroup.setValue('params', params);
|
|
823
|
+
//multiScatteringLutBindGroup.setBuffer('uniformSphereSamples', uniformSphereSampleBuffer);
|
|
824
|
+
multiScatteringLutBindGroup.setTexture('transmittanceLut', transmittanceLUT, fetchSampler('clamp_linear_nomip'));
|
|
825
|
+
device.pushDeviceStates();
|
|
826
|
+
device.setFramebuffer(multiScatteringFramebuffer);
|
|
827
|
+
device.setProgram(multiScatteringLutProgram);
|
|
828
|
+
device.setBindGroup(0, multiScatteringLutBindGroup);
|
|
829
|
+
drawFullscreenQuad();
|
|
830
|
+
device.popDeviceStates();
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
/** @internal */ function createSkyViewLutProgram(device) {
|
|
834
|
+
const program = device.buildRenderProgram({
|
|
835
|
+
vertex (pb) {
|
|
836
|
+
this.flip = pb.int().uniform(0);
|
|
837
|
+
this.$inputs.pos = pb.vec2().attrib('position');
|
|
838
|
+
this.$outputs.uv = pb.vec2();
|
|
839
|
+
pb.main(function() {
|
|
840
|
+
this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);
|
|
841
|
+
this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
|
|
842
|
+
this.$if(pb.notEqual(this.flip, 0), function() {
|
|
843
|
+
this.$builtins.position.y = pb.neg(this.$builtins.position.y);
|
|
844
|
+
});
|
|
845
|
+
});
|
|
846
|
+
},
|
|
847
|
+
fragment (pb) {
|
|
848
|
+
const Params = getAtmosphereParamsStruct(pb);
|
|
849
|
+
this.params = Params().uniform(0);
|
|
850
|
+
this.transmittanceLut = pb.tex2D().uniform(0);
|
|
851
|
+
this.multiScatteringLut = pb.tex2D().uniform(0);
|
|
852
|
+
this.$outputs.outColor = pb.vec4();
|
|
853
|
+
pb.main(function() {
|
|
854
|
+
this.$outputs.outColor = skyViewLut(this, this.params, this.$inputs.uv, this.transmittanceLut, this.multiScatteringLut);
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
});
|
|
858
|
+
program.name = '@SkyViewLutProgram';
|
|
859
|
+
return program;
|
|
860
|
+
}
|
|
861
|
+
/** @internal */ function renderSkyViewLut(params) {
|
|
862
|
+
const device = getDevice();
|
|
863
|
+
if (skyViewLutProgram === undefined) {
|
|
864
|
+
try {
|
|
865
|
+
skyViewLutProgram = createSkyViewLutProgram(device);
|
|
866
|
+
skyViewLutBindGroup = device.createBindGroup(skyViewLutProgram.bindGroupLayouts[0]);
|
|
867
|
+
skyViewLUT = device.createTexture2D('rgba16f', 256, 128, {
|
|
868
|
+
mipmapping: false
|
|
869
|
+
});
|
|
870
|
+
skyViewLUT.name = 'DebugSkyViewLut';
|
|
871
|
+
skyViewFramebuffer = device.createFrameBuffer([
|
|
872
|
+
skyViewLUT
|
|
873
|
+
], null);
|
|
874
|
+
} catch (err) {
|
|
875
|
+
console.error(err);
|
|
876
|
+
skyViewLutProgram = null;
|
|
877
|
+
skyViewLutBindGroup = null;
|
|
878
|
+
skyViewFramebuffer = null;
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
if (skyViewLutProgram) {
|
|
882
|
+
skyViewLutBindGroup.setValue('flip', device.type === 'webgpu' ? 1 : 0);
|
|
883
|
+
skyViewLutBindGroup.setValue('params', params);
|
|
884
|
+
skyViewLutBindGroup.setTexture('transmittanceLut', transmittanceLUT, fetchSampler('clamp_linear_nomip'));
|
|
885
|
+
skyViewLutBindGroup.setTexture('multiScatteringLut', multiScatteringLUT, fetchSampler('clamp_linear_nomip'));
|
|
886
|
+
device.pushDeviceStates();
|
|
887
|
+
device.setFramebuffer(skyViewFramebuffer);
|
|
888
|
+
device.setProgram(skyViewLutProgram);
|
|
889
|
+
device.setBindGroup(0, skyViewLutBindGroup);
|
|
890
|
+
drawFullscreenQuad();
|
|
891
|
+
device.popDeviceStates();
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
/** @internal */ function createAPLutProgram(device) {
|
|
895
|
+
const program = device.buildRenderProgram({
|
|
896
|
+
vertex (pb) {
|
|
897
|
+
this.flip = pb.int().uniform(0);
|
|
898
|
+
this.$inputs.pos = pb.vec2().attrib('position');
|
|
899
|
+
this.$outputs.uv = pb.vec2();
|
|
900
|
+
pb.main(function() {
|
|
901
|
+
this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);
|
|
902
|
+
this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
|
|
903
|
+
this.$if(pb.notEqual(this.flip, 0), function() {
|
|
904
|
+
this.$builtins.position.y = pb.neg(this.$builtins.position.y);
|
|
905
|
+
});
|
|
906
|
+
});
|
|
907
|
+
},
|
|
908
|
+
fragment (pb) {
|
|
909
|
+
const Params = getAtmosphereParamsStruct(pb);
|
|
910
|
+
this.params = Params().uniform(0);
|
|
911
|
+
this.transmittanceLut = pb.tex2D().uniform(0);
|
|
912
|
+
this.multiScatteringLut = pb.tex2D().uniform(0);
|
|
913
|
+
this.$outputs.outColor = pb.vec4();
|
|
914
|
+
pb.main(function() {
|
|
915
|
+
this.$outputs.outColor = aerialPerspectiveLut(this, this.params, this.$inputs.uv, pb.vec3(32, 32, 32), this.transmittanceLut, this.multiScatteringLut);
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
});
|
|
919
|
+
program.name = '@APLutProgram';
|
|
920
|
+
return program;
|
|
921
|
+
}
|
|
922
|
+
/** @internal */ function renderAPLut(params) {
|
|
923
|
+
const device = getDevice();
|
|
924
|
+
if (APLutProgram === undefined) {
|
|
925
|
+
try {
|
|
926
|
+
APLutProgram = createAPLutProgram(device);
|
|
927
|
+
APLutBindGroup = device.createBindGroup(APLutProgram.bindGroupLayouts[0]);
|
|
928
|
+
ApLut = device.createTexture2D('rgba16f', 32 * 32, 32, {
|
|
929
|
+
mipmapping: false
|
|
930
|
+
});
|
|
931
|
+
ApLut.name = 'DebugAPLut';
|
|
932
|
+
APFramebuffer = device.createFrameBuffer([
|
|
933
|
+
ApLut
|
|
934
|
+
], null);
|
|
935
|
+
} catch (err) {
|
|
936
|
+
console.error(err);
|
|
937
|
+
APLutProgram = null;
|
|
938
|
+
APLutBindGroup = null;
|
|
939
|
+
APFramebuffer = null;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
if (APLutProgram) {
|
|
943
|
+
APLutBindGroup.setValue('flip', device.type === 'webgpu' ? 1 : 0);
|
|
944
|
+
APLutBindGroup.setValue('params', params);
|
|
945
|
+
APLutBindGroup.setTexture('transmittanceLut', transmittanceLUT, fetchSampler('clamp_linear_nomip'));
|
|
946
|
+
APLutBindGroup.setTexture('multiScatteringLut', multiScatteringLUT, fetchSampler('clamp_linear_nomip'));
|
|
947
|
+
device.pushDeviceStates();
|
|
948
|
+
device.setFramebuffer(APFramebuffer);
|
|
949
|
+
device.setProgram(APLutProgram);
|
|
950
|
+
device.setBindGroup(0, APLutBindGroup);
|
|
951
|
+
drawFullscreenQuad();
|
|
952
|
+
device.popDeviceStates();
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
export { CAMERA_POS_Y, aerialPerspective, aerialPerspectiveLut, atmosphereLUTRendered, createAPLutProgram, createMultiScatteringLutProgram, createSkyViewLutProgram, createTransmittanceLutProgram, getAerialPerspectiveLut, getAtmosphereParamsStruct, getDefaultAtmosphereParams, getMultiScattering, getMultiScatteringLut, getSkyView, getSkyViewLut, getTransmittanceLut, integralMultiScattering, mieAbsorption, mieCoefficient, miePhase, multiScatteringLut, ozoneAbsorption, rayIntersectSphere, rayleighCoefficient, rayleighPhase, renderAPLut, renderAtmosphereLUTs, renderMultiScatteringLut, renderSkyViewLut, renderTransmittanceLut, scattering, skyBox, skyViewLut, transmittance, transmittanceLut, transmittanceLutToUV, transmittanceToSky, uvToTransmittanceLut, uvToViewDir, viewDirToUV };
|
|
957
|
+
//# sourceMappingURL=atmosphere.js.map
|