@zephyr3d/scene 0.9.1 → 0.9.3
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/animationset.js +2 -0
- package/dist/animation/animationset.js.map +1 -1
- package/dist/animation/cloth/gpu_cloth_system.js +9 -1
- package/dist/animation/cloth/gpu_cloth_system.js.map +1 -1
- package/dist/animation/fixed_geometry_cache_track.js +5 -1
- package/dist/animation/fixed_geometry_cache_track.js.map +1 -1
- package/dist/animation/geometry_cache_utils.js +20 -4
- package/dist/animation/geometry_cache_utils.js.map +1 -1
- package/dist/animation/ik/ik_angle_constraint.js +2 -6
- package/dist/animation/ik/ik_angle_constraint.js.map +1 -1
- package/dist/animation/ik/ik_chain_builder.js +68 -0
- package/dist/animation/ik/ik_chain_builder.js.map +1 -0
- package/dist/animation/ik/ik_pole_constraint.js +2 -7
- package/dist/animation/ik/ik_pole_constraint.js.map +1 -1
- package/dist/animation/ik/two_bone_ik_solver.js +2 -6
- package/dist/animation/ik/two_bone_ik_solver.js.map +1 -1
- package/dist/animation/joint_dynamics/collision.js +60 -12
- package/dist/animation/joint_dynamics/collision.js.map +1 -1
- package/dist/animation/joint_dynamics/constraints.js +20 -4
- package/dist/animation/joint_dynamics/constraints.js.map +1 -1
- package/dist/animation/joint_dynamics/controller.js +94 -46
- package/dist/animation/joint_dynamics/controller.js.map +1 -1
- package/dist/animation/joint_dynamics/math.js +16 -0
- package/dist/animation/joint_dynamics/math.js.map +1 -0
- package/dist/animation/joint_dynamics/solver.js +21 -11
- package/dist/animation/joint_dynamics/solver.js.map +1 -1
- package/dist/animation/joint_dynamics/types.js +15 -3
- package/dist/animation/joint_dynamics/types.js.map +1 -1
- package/dist/animation/pca_geometry_cache_track.js +5 -1
- package/dist/animation/pca_geometry_cache_track.js.map +1 -1
- package/dist/animation/skeleton.js +2 -2
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/animation/skeleton_modifier.js +2 -6
- package/dist/animation/skeleton_modifier.js.map +1 -1
- package/dist/animation/spring/spring_particle.js +4 -4
- package/dist/animation/spring/spring_particle.js.map +1 -1
- package/dist/animation/spring/spring_system.js +13 -40
- package/dist/animation/spring/spring_system.js.map +1 -1
- package/dist/animation/spring2/constraints.js.map +1 -1
- package/dist/animation/spring2/controller.js +64 -64
- package/dist/animation/spring2/controller.js.map +1 -1
- package/dist/animation/spring2/math.js.map +1 -1
- package/dist/animation/spring2/spring_system.js +8 -8
- package/dist/animation/spring2/spring_system.js.map +1 -1
- package/dist/app/app.js.map +1 -1
- package/dist/app/engine.js +1 -1
- package/dist/app/engine.js.map +1 -1
- package/dist/app/screen.js +4 -4
- package/dist/app/screen.js.map +1 -1
- package/dist/app/scriptingsystem.js +24 -1
- package/dist/app/scriptingsystem.js.map +1 -1
- package/dist/app/scriptregistry.js +22 -1
- package/dist/app/scriptregistry.js.map +1 -1
- package/dist/asset/assetmanager.js +2 -2
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/model.js +60 -60
- package/dist/asset/model.js.map +1 -1
- package/dist/camera/camera.js +1 -1
- package/dist/camera/camera.js.map +1 -1
- package/dist/camera/orbit.js.map +1 -1
- package/dist/index.d.ts +795 -266
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/material/material.js +3 -1
- package/dist/material/material.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/shader/helper.js +281 -278
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/sprite.js +6 -6
- package/dist/material/sprite.js.map +1 -1
- package/dist/material/terrain-cm.js +2 -2
- package/dist/material/terrain-cm.js.map +1 -1
- 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/posteffect/taa.js +31 -39
- package/dist/posteffect/taa.js.map +1 -1
- package/dist/render/cluster_light.js +3 -4
- package/dist/render/cluster_light.js.map +1 -1
- package/dist/render/drawable.js +5 -1
- package/dist/render/drawable.js.map +1 -1
- package/dist/render/rendergraph/device_pool_allocator.js +29 -3
- package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
- package/dist/render/rendergraph/executor.js +283 -33
- package/dist/render/rendergraph/executor.js.map +1 -1
- package/dist/render/rendergraph/forward_plus_builder.js +338 -108
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/render/rendergraph/history_resource_manager.js +195 -115
- package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
- package/dist/render/rendergraph/history_resources.js +10 -0
- package/dist/render/rendergraph/history_resources.js.map +1 -0
- package/dist/render/rendergraph/rendergraph.js +162 -35
- package/dist/render/rendergraph/rendergraph.js.map +1 -1
- package/dist/render/rendergraph/types.js +25 -5
- package/dist/render/rendergraph/types.js.map +1 -1
- package/dist/render/rendertarget.js +5 -1
- package/dist/render/rendertarget.js.map +1 -1
- package/dist/render/screenrendertarget.js +5 -1
- package/dist/render/screenrendertarget.js.map +1 -1
- package/dist/render/sky.js +4 -4
- package/dist/render/sky.js.map +1 -1
- package/dist/scene/basesprite.js +2 -2
- package/dist/scene/basesprite.js.map +1 -1
- package/dist/scene/graph_node.js +1 -1
- package/dist/scene/graph_node.js.map +1 -1
- package/dist/scene/mesh.js +81 -97
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/particlesys.js +1 -1
- package/dist/scene/particlesys.js.map +1 -1
- package/dist/scene/scene_node.js +228 -228
- package/dist/scene/scene_node.js.map +1 -1
- package/dist/scene/script_attachment.js +15 -3
- package/dist/scene/script_attachment.js.map +1 -1
- package/dist/scene/terrain-cm/terrain-cm.js +3 -3
- package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shapes/box.js +1 -1
- package/dist/shapes/box.js.map +1 -1
- package/dist/shapes/capsule.js +0 -3
- package/dist/shapes/capsule.js.map +1 -1
- package/dist/shapes/cylinder.js +0 -3
- package/dist/shapes/cylinder.js.map +1 -1
- package/dist/shapes/plane.js +0 -3
- package/dist/shapes/plane.js.map +1 -1
- package/dist/shapes/tetrahedron.js +3 -9
- package/dist/shapes/tetrahedron.js.map +1 -1
- package/dist/shapes/torus.js +94 -66
- 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/src/app/app.js +129 -0
- package/dist/src/app/app.js.map +1 -0
- package/dist/src/app/inputmgr.js +267 -0
- 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/src/blitter/bilateralblur.js +221 -0
- 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/src/utility/textures/ggxlut.js +213 -0
- 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/blueprint/material/common.js +7 -0
- package/dist/utility/blueprint/material/common.js.map +1 -0
- package/dist/utility/blueprint/material/inputs.js +3 -3
- package/dist/utility/blueprint/material/inputs.js.map +1 -1
- package/dist/utility/blueprint/material/ir.js +4 -4
- package/dist/utility/blueprint/material/ir.js.map +1 -1
- 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/manager.js +299 -268
- package/dist/utility/serialization/manager.js.map +1 -1
- package/dist/utility/serialization/scene/animation.js +45 -0
- package/dist/utility/serialization/scene/animation.js.map +1 -1
- package/dist/utility/serialization/scene/camera.js +53 -0
- package/dist/utility/serialization/scene/camera.js.map +1 -1
- package/dist/utility/serialization/scene/common.js +10 -0
- package/dist/utility/serialization/scene/common.js.map +1 -1
- package/dist/utility/serialization/scene/light.js +30 -0
- package/dist/utility/serialization/scene/light.js.map +1 -1
- package/dist/utility/serialization/scene/material.js +63 -0
- package/dist/utility/serialization/scene/material.js.map +1 -1
- package/dist/utility/serialization/scene/mesh.js +11 -0
- package/dist/utility/serialization/scene/mesh.js.map +1 -1
- package/dist/utility/serialization/scene/misc.js +2 -0
- package/dist/utility/serialization/scene/misc.js.map +1 -1
- package/dist/utility/serialization/scene/node.js +19 -0
- package/dist/utility/serialization/scene/node.js.map +1 -1
- package/dist/utility/serialization/scene/particle.js +22 -0
- package/dist/utility/serialization/scene/particle.js.map +1 -1
- package/dist/utility/serialization/scene/primitive.js +33 -0
- package/dist/utility/serialization/scene/primitive.js.map +1 -1
- package/dist/utility/serialization/scene/scene.js +39 -0
- package/dist/utility/serialization/scene/scene.js.map +1 -1
- package/dist/utility/serialization/scene/script.js +2 -0
- package/dist/utility/serialization/scene/script.js.map +1 -1
- package/dist/utility/serialization/scene/sprite.js +6 -0
- package/dist/utility/serialization/scene/sprite.js.map +1 -1
- package/dist/utility/serialization/scene/terrain.js +9 -0
- package/dist/utility/serialization/scene/terrain.js.map +1 -1
- package/dist/utility/serialization/scene/water.js +21 -0
- package/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/utility/serialization/types.js +5 -1
- package/dist/utility/serialization/types.js.map +1 -1
- package/dist/values.js +49 -53
- package/dist/values.js.map +1 -1
- package/package.json +2 -2
- package/dist/animation/joint_dynamics/vrm_spring_bone.js +0 -46
- package/dist/animation/joint_dynamics/vrm_spring_bone.js.map +0 -1
- package/dist/animation/spring/spring_bone.js +0 -240
- package/dist/animation/spring/spring_bone.js.map +0 -1
- package/dist/animation/spring/spring_bone_collider.js +0 -198
- package/dist/animation/spring/spring_bone_collider.js.map +0 -1
- package/dist/animation/spring/spring_bone_constraint.js +0 -170
- package/dist/animation/spring/spring_bone_constraint.js.map +0 -1
- package/dist/animation/spring/spring_bone_system.js +0 -328
- package/dist/animation/spring/spring_bone_system.js.map +0 -1
- package/dist/render/sky_motion_vector.js +0 -85
- package/dist/render/sky_motion_vector.js.map +0 -1
|
@@ -0,0 +1,1103 @@
|
|
|
1
|
+
import { Application } from '../app/app.js';
|
|
2
|
+
import { linearToGamma } from '../shaders/misc.js';
|
|
3
|
+
import { smoothNoise3D } from '../shaders/noise.js';
|
|
4
|
+
import { getDefaultAtmosphereParams, getAerialPerspectiveLut, renderAtmosphereLUTs, getAtmosphereParamsStruct, createTransmittanceLutProgram, createMultiScatteringLutProgram, createSkyViewLutProgram, createAPLutProgram, skyBox, atmosphereLUTRendered, getTransmittanceLut, getSkyViewLut } from '../shaders/atmosphere.js';
|
|
5
|
+
import { Matrix4x4, Vector4, DRef, Vector2, Vector3, CubeFace, Quaternion } from '@zephyr3d/base';
|
|
6
|
+
import { Primitive } from './primitive.js';
|
|
7
|
+
import { BoxShape } from '../shapes/box.js';
|
|
8
|
+
import '../shapes/cylinder.js';
|
|
9
|
+
import '../shapes/torus.js';
|
|
10
|
+
import '../shapes/plane.js';
|
|
11
|
+
import '../shapes/sphere.js';
|
|
12
|
+
import '../shapes/tetrahedron.js';
|
|
13
|
+
import { Camera } from '../camera/camera.js';
|
|
14
|
+
import { prefilterCubemap } from '../utility/pmrem.js';
|
|
15
|
+
import { ShaderHelper } from '../material/shader/helper.js';
|
|
16
|
+
import { fetchSampler } from '../utility/misc.js';
|
|
17
|
+
import { CubemapSHProjector } from '../utility/shprojector.js';
|
|
18
|
+
import { uniformSphereSamples, Fog } from '../values.js';
|
|
19
|
+
import { getDefaultHeightFogParams, getHeightFogParamsStruct, calculateFog } from '../shaders/fog.js';
|
|
20
|
+
|
|
21
|
+
const fogTypeMap = {
|
|
22
|
+
height_fog: Fog.FOG_TYPE_HEIGHT,
|
|
23
|
+
none: Fog.FOG_TYPE_NONE
|
|
24
|
+
};
|
|
25
|
+
const defaultSkyWorldMatrix = Matrix4x4.identity();
|
|
26
|
+
/**
|
|
27
|
+
* The sky renderer
|
|
28
|
+
* @public
|
|
29
|
+
*/ class SkyRenderer {
|
|
30
|
+
static _skyCamera = (()=>{
|
|
31
|
+
const camera = new Camera(null);
|
|
32
|
+
camera.setPerspective(Math.PI / 2, 1, 1, 20);
|
|
33
|
+
return camera;
|
|
34
|
+
})();
|
|
35
|
+
static transmittanceLutProgram = null;
|
|
36
|
+
static multiScatteringLutProgram = null;
|
|
37
|
+
static skyViewLutProgram = null;
|
|
38
|
+
static APLutProgram = null;
|
|
39
|
+
static _programSky = {};
|
|
40
|
+
static _programDistantLight = null;
|
|
41
|
+
static _programFog = null;
|
|
42
|
+
static _vertexLayout = null;
|
|
43
|
+
static _primitiveSky = null;
|
|
44
|
+
static _primitiveDistantLight = null;
|
|
45
|
+
static _renderStatesSky = null;
|
|
46
|
+
static _renderStatesSkyNoDepthTest = null;
|
|
47
|
+
static _renderStatesFog = null;
|
|
48
|
+
static _renderStatesFogScatter = null;
|
|
49
|
+
static _renderStatesDistantLight = null;
|
|
50
|
+
_skyType;
|
|
51
|
+
_skyColor;
|
|
52
|
+
_bakedSkyboxDirty;
|
|
53
|
+
_scatterSkyboxTextureWidth;
|
|
54
|
+
_skyboxTexture;
|
|
55
|
+
_bakedSkyboxTexture;
|
|
56
|
+
_bakedSkyboxFrameBuffer;
|
|
57
|
+
_radianceMap;
|
|
58
|
+
_radianceFrameBuffer;
|
|
59
|
+
_irradianceMap;
|
|
60
|
+
_irradianceSH;
|
|
61
|
+
_irradianceSHFB;
|
|
62
|
+
_skyDistantLightLut;
|
|
63
|
+
_irradianceFrameBuffer;
|
|
64
|
+
_radianceMapWidth;
|
|
65
|
+
_irradianceMapWidth;
|
|
66
|
+
_atmosphereParams;
|
|
67
|
+
_atmosphereExposure;
|
|
68
|
+
_fogType;
|
|
69
|
+
_heightFogParams;
|
|
70
|
+
_cloudy;
|
|
71
|
+
_cloudIntensity;
|
|
72
|
+
_debugAerialPerspective;
|
|
73
|
+
_wind;
|
|
74
|
+
_skyWorldMatrix;
|
|
75
|
+
_lastSunDir;
|
|
76
|
+
_lastSunColor;
|
|
77
|
+
_panoramaAsset;
|
|
78
|
+
_shProjector;
|
|
79
|
+
_shWindowWeights;
|
|
80
|
+
_radianceConvSamples;
|
|
81
|
+
_irradianceConvSamples;
|
|
82
|
+
_bindgroupDistantLight = null;
|
|
83
|
+
_bindgroupSky = {};
|
|
84
|
+
_bindgroupFog = null;
|
|
85
|
+
/**
|
|
86
|
+
* Creates an instance of SkyRenderer
|
|
87
|
+
*/ constructor(){
|
|
88
|
+
this._skyType = 'scatter';
|
|
89
|
+
this._skyColor = Vector4.zero();
|
|
90
|
+
this._skyboxTexture = new DRef();
|
|
91
|
+
this._bakedSkyboxTexture = new DRef();
|
|
92
|
+
this._bakedSkyboxFrameBuffer = new DRef();
|
|
93
|
+
this._bakedSkyboxDirty = true;
|
|
94
|
+
this._scatterSkyboxTextureWidth = 256;
|
|
95
|
+
this._radianceMap = new DRef();
|
|
96
|
+
this._radianceFrameBuffer = new DRef();
|
|
97
|
+
this._radianceMapWidth = 128;
|
|
98
|
+
this._irradianceMap = new DRef();
|
|
99
|
+
this._irradianceSH = new DRef();
|
|
100
|
+
this._irradianceSHFB = new DRef();
|
|
101
|
+
this._skyDistantLightLut = new DRef();
|
|
102
|
+
this._irradianceFrameBuffer = new DRef();
|
|
103
|
+
this._irradianceMapWidth = 64;
|
|
104
|
+
this._atmosphereParams = getDefaultAtmosphereParams();
|
|
105
|
+
this._atmosphereExposure = 1;
|
|
106
|
+
this._debugAerialPerspective = 0;
|
|
107
|
+
this._fogType = 'none';
|
|
108
|
+
this._heightFogParams = getDefaultHeightFogParams();
|
|
109
|
+
this._cloudy = 0.45;
|
|
110
|
+
this._cloudIntensity = 15;
|
|
111
|
+
this._wind = new Vector2(0, 0);
|
|
112
|
+
this._skyWorldMatrix = defaultSkyWorldMatrix;
|
|
113
|
+
this._lastSunDir = SkyRenderer._getSunDir(null);
|
|
114
|
+
this._lastSunColor = SkyRenderer._getSunColor(null);
|
|
115
|
+
this._panoramaAsset = '';
|
|
116
|
+
this._shProjector = new CubemapSHProjector(10000);
|
|
117
|
+
this._shWindowWeights = new Vector3(1, 0.8, 0.6);
|
|
118
|
+
this._radianceConvSamples = 64;
|
|
119
|
+
this._irradianceConvSamples = 256;
|
|
120
|
+
this._bindgroupDistantLight = new DRef();
|
|
121
|
+
this._bindgroupSky = {};
|
|
122
|
+
this._bindgroupFog = new DRef();
|
|
123
|
+
}
|
|
124
|
+
/** @internal */ dispose() {
|
|
125
|
+
this._skyboxTexture.dispose();
|
|
126
|
+
this._bakedSkyboxTexture.dispose();
|
|
127
|
+
this._bakedSkyboxFrameBuffer.dispose();
|
|
128
|
+
this._radianceMap.dispose();
|
|
129
|
+
this._radianceFrameBuffer.dispose();
|
|
130
|
+
this._irradianceMap.dispose();
|
|
131
|
+
this._irradianceSH.dispose();
|
|
132
|
+
this._irradianceSHFB.dispose();
|
|
133
|
+
this._irradianceFrameBuffer.dispose();
|
|
134
|
+
this._shProjector.dispose();
|
|
135
|
+
if (this._skyDistantLightLut.get()) {
|
|
136
|
+
this._skyDistantLightLut.get().getColorAttachments()[0].dispose();
|
|
137
|
+
this._skyDistantLightLut.dispose();
|
|
138
|
+
}
|
|
139
|
+
this._bindgroupDistantLight.dispose();
|
|
140
|
+
for(const k in this._bindgroupSky){
|
|
141
|
+
this._bindgroupSky[k].dispose();
|
|
142
|
+
}
|
|
143
|
+
this._bindgroupSky = {};
|
|
144
|
+
this._bindgroupFog.dispose();
|
|
145
|
+
}
|
|
146
|
+
/** @internal */ getHash(_ctx) {
|
|
147
|
+
return `${this.skyType}:${this.fogType}`;
|
|
148
|
+
}
|
|
149
|
+
/** Which type of the sky should be rendered */ get skyType() {
|
|
150
|
+
return this._skyType;
|
|
151
|
+
}
|
|
152
|
+
set skyType(val) {
|
|
153
|
+
if (val !== this._skyType) {
|
|
154
|
+
this._skyType = val;
|
|
155
|
+
this.invalidate();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/** @internal */ get panoramaTextureAsset() {
|
|
159
|
+
return this._panoramaAsset;
|
|
160
|
+
}
|
|
161
|
+
set panoramaTextureAsset(id) {
|
|
162
|
+
this._panoramaAsset = id;
|
|
163
|
+
}
|
|
164
|
+
/** Whether ground should be rendered */ /** Baked sky texture */ getBakedSkyTexture(ctx) {
|
|
165
|
+
if (this._bakedSkyboxDirty) {
|
|
166
|
+
this.update(ctx);
|
|
167
|
+
}
|
|
168
|
+
return this._bakedSkyboxTexture.get();
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The solid sky color
|
|
172
|
+
*/ get skyColor() {
|
|
173
|
+
return this._skyColor;
|
|
174
|
+
}
|
|
175
|
+
set skyColor(val) {
|
|
176
|
+
if (!val.equalsTo(this._skyColor)) {
|
|
177
|
+
this._skyColor.set(val);
|
|
178
|
+
this.invalidate();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Window weights for SH projection
|
|
183
|
+
*/ get shWindowWeights() {
|
|
184
|
+
return this._shWindowWeights;
|
|
185
|
+
}
|
|
186
|
+
set shWindowWeights(weights) {
|
|
187
|
+
this._shWindowWeights.set(weights);
|
|
188
|
+
this.invalidate();
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Sample count for radiance convolution
|
|
192
|
+
*/ get radianceConvSamples() {
|
|
193
|
+
return this._radianceConvSamples;
|
|
194
|
+
}
|
|
195
|
+
set radianceConvSamples(val) {
|
|
196
|
+
if (val !== this._radianceConvSamples) {
|
|
197
|
+
this._radianceConvSamples = val;
|
|
198
|
+
this.invalidate();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Sample count for irradiance convolution
|
|
203
|
+
*/ get irradianceConvSamples() {
|
|
204
|
+
return this._irradianceConvSamples;
|
|
205
|
+
}
|
|
206
|
+
set irradianceConvSamples(val) {
|
|
207
|
+
if (val !== this._irradianceConvSamples) {
|
|
208
|
+
this._irradianceConvSamples = val;
|
|
209
|
+
this.invalidate();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/** Aerial perspective density */ get aerialPerspectiveDistance() {
|
|
213
|
+
return this._atmosphereParams.apDistance;
|
|
214
|
+
}
|
|
215
|
+
set aerialPerspectiveDistance(val) {
|
|
216
|
+
this._atmosphereParams.apDistance = val;
|
|
217
|
+
}
|
|
218
|
+
/** Atmosphere exposure */ get atmosphereExposure() {
|
|
219
|
+
return this._atmosphereExposure;
|
|
220
|
+
}
|
|
221
|
+
set atmosphereExposure(val) {
|
|
222
|
+
if (val !== this._atmosphereExposure) {
|
|
223
|
+
this._atmosphereExposure = val;
|
|
224
|
+
this.invalidate();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/** Aerial perspective density */ get cameraHeightScale() {
|
|
228
|
+
return this._atmosphereParams.cameraHeightScale;
|
|
229
|
+
}
|
|
230
|
+
set cameraHeightScale(val) {
|
|
231
|
+
if (val !== this._atmosphereParams.cameraHeightScale) {
|
|
232
|
+
this._atmosphereParams.cameraHeightScale = val;
|
|
233
|
+
this.invalidate();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/** Height fog color */ get heightFogColor() {
|
|
237
|
+
return this._heightFogParams.parameter1.xyz();
|
|
238
|
+
}
|
|
239
|
+
set heightFogColor(val) {
|
|
240
|
+
this._heightFogParams.parameter1.set(val);
|
|
241
|
+
}
|
|
242
|
+
/** Height fog density */ get heightFogDensity() {
|
|
243
|
+
return this._heightFogParams.parameter2.x;
|
|
244
|
+
}
|
|
245
|
+
set heightFogDensity(val) {
|
|
246
|
+
this._heightFogParams.parameter2.x = val;
|
|
247
|
+
}
|
|
248
|
+
/** Height fog falloff */ get heightFogFalloff() {
|
|
249
|
+
return this._heightFogParams.parameter1.w;
|
|
250
|
+
}
|
|
251
|
+
set heightFogFalloff(val) {
|
|
252
|
+
this._heightFogParams.parameter1.w = val;
|
|
253
|
+
}
|
|
254
|
+
/** Height fog start height */ get heightFogStartHeight() {
|
|
255
|
+
return this._heightFogParams.parameter2.y;
|
|
256
|
+
}
|
|
257
|
+
set heightFogStartHeight(val) {
|
|
258
|
+
this._heightFogParams.parameter2.y = val;
|
|
259
|
+
}
|
|
260
|
+
/** Height fog start distance */ get heightFogStartDistance() {
|
|
261
|
+
return this._heightFogParams.parameter2.z;
|
|
262
|
+
}
|
|
263
|
+
set heightFogStartDistance(val) {
|
|
264
|
+
this._heightFogParams.parameter2.z = val;
|
|
265
|
+
}
|
|
266
|
+
/** Height fog maximum opacity */ get heightFogMaxOpacity() {
|
|
267
|
+
return this._heightFogParams.parameter3.x;
|
|
268
|
+
}
|
|
269
|
+
set heightFogMaxOpacity(val) {
|
|
270
|
+
this._heightFogParams.parameter3.x = val;
|
|
271
|
+
}
|
|
272
|
+
/** Height fog atmosphere contribution strength */ get heightFogAtmosphereContribution() {
|
|
273
|
+
return this._heightFogParams.parameter3.y;
|
|
274
|
+
}
|
|
275
|
+
set heightFogAtmosphereContribution(val) {
|
|
276
|
+
this._heightFogParams.parameter3.y = val;
|
|
277
|
+
}
|
|
278
|
+
/** Height fog directional exponent */ get heightFogDirExponent() {
|
|
279
|
+
return this._heightFogParams.parameter3.w;
|
|
280
|
+
}
|
|
281
|
+
set heightFogDirExponent(val) {
|
|
282
|
+
this._heightFogParams.parameter3.w = val;
|
|
283
|
+
}
|
|
284
|
+
/** Height fog directional inscattering color */ get heightFogDirColor() {
|
|
285
|
+
return this._heightFogParams.parameter4.xyz();
|
|
286
|
+
}
|
|
287
|
+
set heightFogDirColor(val) {
|
|
288
|
+
this._heightFogParams.parameter4.set(val);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Light density of the sky.
|
|
292
|
+
*
|
|
293
|
+
* @remarks
|
|
294
|
+
* This value controls how much cloud should be rendered when the sky type is scatter.
|
|
295
|
+
* Typically, the value should be in the range of 0 to 1.
|
|
296
|
+
*/ get cloudy() {
|
|
297
|
+
return this._cloudy;
|
|
298
|
+
}
|
|
299
|
+
set cloudy(val) {
|
|
300
|
+
if (val !== this._cloudy && this._skyType === 'scatter') {
|
|
301
|
+
this._cloudy = val;
|
|
302
|
+
this.invalidate();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Intensity of the sky color
|
|
307
|
+
*/ get cloudIntensity() {
|
|
308
|
+
return this._cloudIntensity;
|
|
309
|
+
}
|
|
310
|
+
set cloudIntensity(val) {
|
|
311
|
+
if (val !== this._cloudIntensity && this._skyType === 'scatter') {
|
|
312
|
+
this._cloudIntensity = val;
|
|
313
|
+
this.invalidate();
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Wind velocity
|
|
318
|
+
*
|
|
319
|
+
* @remarks
|
|
320
|
+
* This value affects the movement of the cloud
|
|
321
|
+
*/ get wind() {
|
|
322
|
+
return this._wind;
|
|
323
|
+
}
|
|
324
|
+
set wind(val) {
|
|
325
|
+
this._wind.set(val);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Radiance map of the sky.
|
|
329
|
+
*/ get radianceMap() {
|
|
330
|
+
if (!this._radianceMap.get()) {
|
|
331
|
+
this._radianceMap.set(Application.instance.device.createCubeTexture('rgba16f', this._radianceMapWidth));
|
|
332
|
+
this._radianceMap.get().name = 'SkyRadianceMap';
|
|
333
|
+
}
|
|
334
|
+
return this._radianceMap.get();
|
|
335
|
+
}
|
|
336
|
+
/** @internal */ get atmosphereParams() {
|
|
337
|
+
return this._atmosphereParams;
|
|
338
|
+
}
|
|
339
|
+
/** @internal */ get heightFogParams() {
|
|
340
|
+
return this._heightFogParams;
|
|
341
|
+
}
|
|
342
|
+
/** @internal */ get radianceFramebuffer() {
|
|
343
|
+
if (!this._radianceFrameBuffer.get()) {
|
|
344
|
+
this._radianceFrameBuffer.set(Application.instance.device.createFrameBuffer([
|
|
345
|
+
this.radianceMap
|
|
346
|
+
], null));
|
|
347
|
+
}
|
|
348
|
+
return this._radianceFrameBuffer.get();
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Irradiance map of the sky.
|
|
352
|
+
*/ get irradianceMap() {
|
|
353
|
+
if (!this._irradianceMap.get()) {
|
|
354
|
+
this._irradianceMap.set(Application.instance.device.createCubeTexture('rgba16f', this._irradianceMapWidth, {
|
|
355
|
+
samplerOptions: {
|
|
356
|
+
mipFilter: 'none'
|
|
357
|
+
}
|
|
358
|
+
}));
|
|
359
|
+
this._irradianceMap.get().name = 'SkyIrradianceMap';
|
|
360
|
+
}
|
|
361
|
+
return this._irradianceMap.get();
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Irradiance SH coeffecients buffer
|
|
365
|
+
*/ get irradianceSH() {
|
|
366
|
+
if (!this._irradianceSH.get()) {
|
|
367
|
+
const buffer = Application.instance.device.createBuffer(4 * 4 * 9, {
|
|
368
|
+
usage: 'uniform'
|
|
369
|
+
});
|
|
370
|
+
this._irradianceSH.set(buffer);
|
|
371
|
+
}
|
|
372
|
+
return this._irradianceSH.get();
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Irradiance SH coeffecients texture
|
|
376
|
+
*/ get irradianceSHFB() {
|
|
377
|
+
if (!this._irradianceSHFB.get()) {
|
|
378
|
+
const device = Application.instance.device;
|
|
379
|
+
const texture = device.createTexture2D('rgba32f', 3, 3, {
|
|
380
|
+
samplerOptions: {
|
|
381
|
+
mipFilter: 'none'
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
this._irradianceSHFB.set(device.createFrameBuffer([
|
|
385
|
+
texture
|
|
386
|
+
], null));
|
|
387
|
+
}
|
|
388
|
+
return this._irradianceSHFB.get();
|
|
389
|
+
}
|
|
390
|
+
/** @internal */ get irradianceFramebuffer() {
|
|
391
|
+
if (!this._irradianceFrameBuffer.get()) {
|
|
392
|
+
this._irradianceFrameBuffer.set(Application.instance.device.createFrameBuffer([
|
|
393
|
+
this.irradianceMap
|
|
394
|
+
], null));
|
|
395
|
+
}
|
|
396
|
+
return this._irradianceFrameBuffer.get();
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Cube texture for skybox.
|
|
400
|
+
*/ get skyboxTexture() {
|
|
401
|
+
return this._skyboxTexture.get();
|
|
402
|
+
}
|
|
403
|
+
set skyboxTexture(tex) {
|
|
404
|
+
if (tex !== this.skyboxTexture) {
|
|
405
|
+
this._skyboxTexture.set(tex);
|
|
406
|
+
if (this._skyType === 'skybox') {
|
|
407
|
+
this.invalidate();
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
/** @internal */ get skyWorldMatrix() {
|
|
412
|
+
return this._skyWorldMatrix;
|
|
413
|
+
}
|
|
414
|
+
set skyWorldMatrix(val) {
|
|
415
|
+
val = val ?? defaultSkyWorldMatrix;
|
|
416
|
+
if (val !== this._skyWorldMatrix) {
|
|
417
|
+
this._skyWorldMatrix = val;
|
|
418
|
+
this.invalidate();
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
/** @internal */ get mappedFogType() {
|
|
422
|
+
return fogTypeMap[this._fogType];
|
|
423
|
+
}
|
|
424
|
+
/** Current fog type */ get fogType() {
|
|
425
|
+
return this._fogType;
|
|
426
|
+
}
|
|
427
|
+
set fogType(val) {
|
|
428
|
+
this._fogType = val;
|
|
429
|
+
}
|
|
430
|
+
/** @internal */ get aerialPerspectiveDebug() {
|
|
431
|
+
return this._debugAerialPerspective;
|
|
432
|
+
}
|
|
433
|
+
set aerialPerspectiveDebug(val) {
|
|
434
|
+
this._debugAerialPerspective = val;
|
|
435
|
+
}
|
|
436
|
+
/** @internal */ get fogPresents() {
|
|
437
|
+
return this._skyType === 'scatter' || this._fogType !== 'none';
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Force the radiance map and irradiance map to be regenerated.
|
|
441
|
+
*/ invalidate() {
|
|
442
|
+
this._bakedSkyboxDirty = true;
|
|
443
|
+
}
|
|
444
|
+
/** @internal */ drawScatteredFog(_ctx) {
|
|
445
|
+
return this.skyType === 'scatter';
|
|
446
|
+
}
|
|
447
|
+
/** @internal */ getAerialPerspectiveLUT(_ctx) {
|
|
448
|
+
return getAerialPerspectiveLut();
|
|
449
|
+
}
|
|
450
|
+
/** @internal */ getSkyDistantLightLUT(_ctx) {
|
|
451
|
+
return this._skyDistantLightLut.get().getColorAttachments()[0];
|
|
452
|
+
}
|
|
453
|
+
update(ctx) {
|
|
454
|
+
const useScatter = this._skyType === 'scatter';
|
|
455
|
+
if (useScatter || !atmosphereLUTRendered()) {
|
|
456
|
+
this.renderAtmosphereLUTs(ctx);
|
|
457
|
+
}
|
|
458
|
+
const oldSunLight = ctx.sunLight && useScatter ? ctx.sunLight.color : null;
|
|
459
|
+
const sunDir = SkyRenderer._getSunDir(ctx.sunLight);
|
|
460
|
+
const sunColor = SkyRenderer._getSunColor(ctx.sunLight);
|
|
461
|
+
if (this._skyType === 'scatter' && (this._wind.x !== 0 || this._wind.y !== 0)) {
|
|
462
|
+
this._bakedSkyboxDirty = true;
|
|
463
|
+
}
|
|
464
|
+
if (!this._skyDistantLightLut.get()) {
|
|
465
|
+
const tex = ctx.device.createTexture2D('rgba32f', 1, 1, {
|
|
466
|
+
samplerOptions: {
|
|
467
|
+
mipFilter: 'none'
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
tex.name = 'DistantSkyLut';
|
|
471
|
+
this._skyDistantLightLut.set(ctx.device.createFrameBuffer([
|
|
472
|
+
tex
|
|
473
|
+
], null));
|
|
474
|
+
this._bakedSkyboxDirty = true;
|
|
475
|
+
}
|
|
476
|
+
if (!sunDir.equalsTo(this._lastSunDir) || !sunColor.equalsTo(this._lastSunColor)) {
|
|
477
|
+
this._lastSunDir.set(sunDir);
|
|
478
|
+
this._lastSunColor.set(sunColor);
|
|
479
|
+
this._bakedSkyboxDirty = true;
|
|
480
|
+
}
|
|
481
|
+
if (this._bakedSkyboxDirty) {
|
|
482
|
+
this._bakedSkyboxDirty = false;
|
|
483
|
+
this.updateBakedSkyMap();
|
|
484
|
+
this.renderSkyDistantLut(ctx, this._bakedSkyboxTexture.get());
|
|
485
|
+
if (ctx.scene.env.light.radianceMap && (ctx.scene.env.light.radianceMap === this.radianceMap || ctx.scene.env.light.irradianceMap === this.irradianceMap || this._irradianceSH.get() && ctx.scene.env.light.irradianceSH === this.irradianceSH || this._irradianceSHFB.get() && ctx.scene.env.light.irradianceSHFB === this.irradianceSHFB)) {
|
|
486
|
+
prefilterCubemap(this._bakedSkyboxTexture.get(), 'ggx', this.radianceFramebuffer, this._radianceConvSamples);
|
|
487
|
+
prefilterCubemap(this._bakedSkyboxTexture.get(), 'lambertian', this.irradianceFramebuffer, this._irradianceConvSamples);
|
|
488
|
+
if (ctx.device.type === 'webgl') {
|
|
489
|
+
this._shProjector.projectCubemapToTexture(this.irradianceFramebuffer.getColorAttachments()[0], this.irradianceSHFB);
|
|
490
|
+
} else {
|
|
491
|
+
this._shProjector.projectCubemap(this.irradianceFramebuffer.getColorAttachments()[0], this.irradianceSH);
|
|
492
|
+
}
|
|
493
|
+
ctx.scene.env.light.irradianceSH = this.irradianceSH;
|
|
494
|
+
ctx.scene.env.light.irradianceWindow = this._shWindowWeights;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
const newSunLight = oldSunLight ? Vector3.mul(ctx.sunLight.color.xyz(), this.sunTransmittance(ctx.sunLight)) : Vector3.zero();
|
|
498
|
+
if (oldSunLight) {
|
|
499
|
+
ctx.sunLight.setColor(newSunLight);
|
|
500
|
+
}
|
|
501
|
+
// Update height fog parameters
|
|
502
|
+
if (this._fogType === 'height_fog') {
|
|
503
|
+
const cameraY = Math.min(this._heightFogParams.parameter2.y + this._heightFogParams.parameter2.w, ctx.camera.getWorldPosition().y);
|
|
504
|
+
const p = Math.max(-125, Math.min(126, -this._heightFogParams.parameter1.w * (cameraY - this._heightFogParams.parameter2.y)));
|
|
505
|
+
this._heightFogParams.parameter3.z = this._heightFogParams.parameter2.x * Math.pow(2, p);
|
|
506
|
+
this._heightFogParams.lightColor.set(newSunLight);
|
|
507
|
+
this._heightFogParams.lightDir.set(SkyRenderer._getSunDir(ctx.sunLight));
|
|
508
|
+
}
|
|
509
|
+
return oldSunLight;
|
|
510
|
+
}
|
|
511
|
+
renderAtmosphereLUTs(ctx) {
|
|
512
|
+
this._atmosphereParams.lightDir.set(SkyRenderer._getSunDir(ctx.sunLight));
|
|
513
|
+
this._atmosphereParams.lightColor.set(SkyRenderer._getSunColor(ctx.sunLight));
|
|
514
|
+
this._atmosphereParams.lightColor.w *= this._atmosphereExposure;
|
|
515
|
+
this._atmosphereParams.cameraAspect = ctx.camera.getAspect();
|
|
516
|
+
this._atmosphereParams.cameraWorldMatrix.set(ctx.camera.worldMatrix);
|
|
517
|
+
renderAtmosphereLUTs(this._atmosphereParams);
|
|
518
|
+
}
|
|
519
|
+
renderSkyDistantLut(ctx, skybox) {
|
|
520
|
+
this._prepareSkyBox(ctx.device);
|
|
521
|
+
ctx.device.pushDeviceStates();
|
|
522
|
+
ctx.device.setRenderStates(SkyRenderer._renderStatesDistantLight);
|
|
523
|
+
ctx.device.setProgram(SkyRenderer._programDistantLight);
|
|
524
|
+
ctx.device.setFramebuffer(this._skyDistantLightLut.get());
|
|
525
|
+
ctx.device.clearFrameBuffer(new Vector4(0, 0, 0, 1), null, null);
|
|
526
|
+
this._bindgroupDistantLight.get().setTexture('skybox', skybox, fetchSampler('clamp_linear_nomip'));
|
|
527
|
+
ctx.device.setBindGroup(0, this._bindgroupDistantLight.get());
|
|
528
|
+
SkyRenderer._primitiveDistantLight.draw();
|
|
529
|
+
ctx.device.popDeviceStates();
|
|
530
|
+
}
|
|
531
|
+
updateBakedSkyMap() {
|
|
532
|
+
if (this._skyType === 'skybox' && this.skyboxTexture) {
|
|
533
|
+
this._bakedSkyboxTexture.set(this.skyboxTexture);
|
|
534
|
+
} else {
|
|
535
|
+
const device = Application.instance.device;
|
|
536
|
+
const texCaps = device.getDeviceCaps().textureCaps;
|
|
537
|
+
const format = texCaps.supportHalfFloatColorBuffer && texCaps.supportLinearHalfFloatTexture ? 'rgba16f' : texCaps.supportFloatColorBuffer && texCaps.supportLinearFloatTexture ? 'rgba32f' : 'rgba8unorm';
|
|
538
|
+
const tex = this._bakedSkyboxTexture.get() && this._bakedSkyboxTexture.get() !== this.skyboxTexture ? this._bakedSkyboxTexture.get() : device.createCubeTexture(format, this._scatterSkyboxTextureWidth, {
|
|
539
|
+
samplerOptions: {
|
|
540
|
+
mipFilter: 'none'
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
tex.name = 'BakedSkyboxTexture';
|
|
544
|
+
if (tex !== this._bakedSkyboxTexture.get()) {
|
|
545
|
+
this._bakedSkyboxFrameBuffer.set(device.createFrameBuffer([
|
|
546
|
+
tex
|
|
547
|
+
], null));
|
|
548
|
+
}
|
|
549
|
+
const camera = SkyRenderer._skyCamera;
|
|
550
|
+
const saveRenderStates = device.getRenderStates();
|
|
551
|
+
device.pushDeviceStates();
|
|
552
|
+
device.setFramebuffer(this._bakedSkyboxFrameBuffer.get());
|
|
553
|
+
for (const face of [
|
|
554
|
+
CubeFace.PX,
|
|
555
|
+
CubeFace.NX,
|
|
556
|
+
CubeFace.PY,
|
|
557
|
+
CubeFace.NY,
|
|
558
|
+
CubeFace.PZ,
|
|
559
|
+
CubeFace.NZ
|
|
560
|
+
]){
|
|
561
|
+
camera.lookAtCubeFace(face);
|
|
562
|
+
this._bakedSkyboxFrameBuffer.get().setColorAttachmentCubeFace(0, face);
|
|
563
|
+
this._renderSky(camera, false);
|
|
564
|
+
}
|
|
565
|
+
device.popDeviceStates();
|
|
566
|
+
device.setRenderStates(saveRenderStates);
|
|
567
|
+
this._bakedSkyboxTexture.set(tex);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
renderUberFog(ctx, depthTexture) {
|
|
571
|
+
const camera = ctx.camera;
|
|
572
|
+
const device = ctx.device;
|
|
573
|
+
const fogProgram = SkyRenderer._programFog;
|
|
574
|
+
const renderStates = SkyRenderer._renderStatesFog;
|
|
575
|
+
const bindgroup = this._bindgroupFog.get();
|
|
576
|
+
bindgroup.setTexture('depthTex', depthTexture, fetchSampler('clamp_nearest_nomip'));
|
|
577
|
+
bindgroup.setTexture('skyDistantLightLut', this._skyDistantLightLut.get().getColorAttachments()[0], fetchSampler('clamp_nearest_nomip'));
|
|
578
|
+
bindgroup.setTexture('apLut', getAerialPerspectiveLut(), fetchSampler('clamp_linear_nomip'));
|
|
579
|
+
bindgroup.setValue('rt', device.getFramebuffer() ? 1 : 0);
|
|
580
|
+
bindgroup.setValue('invProjViewMatrix', camera.invViewProjectionMatrix);
|
|
581
|
+
bindgroup.setValue('cameraNearFar', new Vector2(camera.getNearPlane(), camera.getFarPlane()));
|
|
582
|
+
bindgroup.setValue('cameraPosition', camera.getWorldPosition());
|
|
583
|
+
bindgroup.setValue('srgbOut', device.getFramebuffer() ? 0 : 1);
|
|
584
|
+
bindgroup.setValue('withAerialPerspective', this.skyType === 'scatter' ? 1 : 0);
|
|
585
|
+
bindgroup.setValue('fogType', this.mappedFogType);
|
|
586
|
+
bindgroup.setValue('atmosphereParams', this._atmosphereParams);
|
|
587
|
+
bindgroup.setValue('heightFogParams', this._heightFogParams);
|
|
588
|
+
device.setProgram(fogProgram);
|
|
589
|
+
device.setBindGroup(0, bindgroup);
|
|
590
|
+
device.setVertexLayout(SkyRenderer._vertexLayout);
|
|
591
|
+
device.setRenderStates(renderStates);
|
|
592
|
+
device.draw('triangle-strip', 0, 4);
|
|
593
|
+
}
|
|
594
|
+
/** @internal */ renderFog(ctx) {
|
|
595
|
+
const currentFramebuffer = ctx.device.getFramebuffer();
|
|
596
|
+
const depthBuffer = currentFramebuffer?.getDepthAttachment() ?? null;
|
|
597
|
+
const colorBuffer = currentFramebuffer?.getColorAttachments()[0] ?? null;
|
|
598
|
+
const fogFramebuffer = depthBuffer && colorBuffer ? ctx.device.pool.fetchTemporalFramebuffer(false, 0, 0, colorBuffer, null, false) : null;
|
|
599
|
+
if (fogFramebuffer) {
|
|
600
|
+
const vp = ctx.device.getViewport();
|
|
601
|
+
const scissor = ctx.device.getScissor();
|
|
602
|
+
ctx.device.pushDeviceStates();
|
|
603
|
+
ctx.device.setFramebuffer(fogFramebuffer);
|
|
604
|
+
ctx.device.setViewport(vp);
|
|
605
|
+
ctx.device.setScissor(scissor);
|
|
606
|
+
}
|
|
607
|
+
const savedRenderStates = ctx.device.getRenderStates();
|
|
608
|
+
this._prepareSkyBox(ctx.device);
|
|
609
|
+
this.renderUberFog(ctx, depthBuffer);
|
|
610
|
+
/*
|
|
611
|
+
if (this._skyType === 'scatter') {
|
|
612
|
+
this.renderAtmosphericFog(ctx, depthBuffer);
|
|
613
|
+
}
|
|
614
|
+
*/ /*
|
|
615
|
+
if (this._fogType === 'height_fog') {
|
|
616
|
+
this.renderHeightFog(ctx, depthBuffer);
|
|
617
|
+
}
|
|
618
|
+
*/ ctx.device.setRenderStates(savedRenderStates);
|
|
619
|
+
if (fogFramebuffer) {
|
|
620
|
+
ctx.device.popDeviceStates();
|
|
621
|
+
ctx.device.pool.releaseFrameBuffer(fogFramebuffer);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
/** @internal */ renderSky(ctx) {
|
|
625
|
+
let skyCamera = ctx.camera;
|
|
626
|
+
if (!skyCamera.isPerspective()) {
|
|
627
|
+
skyCamera = SkyRenderer._skyCamera;
|
|
628
|
+
ctx.camera.worldMatrix.decompose(null, skyCamera.rotation, null);
|
|
629
|
+
}
|
|
630
|
+
this._renderSky(skyCamera, true);
|
|
631
|
+
}
|
|
632
|
+
/** @internal */ _renderSky(camera, depthTest) {
|
|
633
|
+
const device = Application.instance.device;
|
|
634
|
+
const savedRenderStates = device.getRenderStates();
|
|
635
|
+
this._prepareSkyBox(device);
|
|
636
|
+
if (this._skyType === 'scatter') {
|
|
637
|
+
this._drawScattering(camera, depthTest);
|
|
638
|
+
} else if (this._skyType === 'skybox' && this.skyboxTexture) {
|
|
639
|
+
this._drawSkybox(camera, depthTest);
|
|
640
|
+
} else {
|
|
641
|
+
this._drawSkyColor(camera, depthTest);
|
|
642
|
+
}
|
|
643
|
+
device.setRenderStates(savedRenderStates);
|
|
644
|
+
}
|
|
645
|
+
/** @internal */ _drawSkyColor(camera, depthTest) {
|
|
646
|
+
const device = Application.instance.device;
|
|
647
|
+
const bindgroup = this._bindgroupSky.color.get();
|
|
648
|
+
const p = new Vector3();
|
|
649
|
+
const s = new Vector3();
|
|
650
|
+
const r = new Quaternion();
|
|
651
|
+
camera.viewMatrix.decompose(s, r, p);
|
|
652
|
+
camera.worldMatrix.decompose(s, r, p);
|
|
653
|
+
bindgroup.setValue('viewProjMatrix', camera.viewProjectionMatrix);
|
|
654
|
+
bindgroup.setValue('worldMatrix', this._skyWorldMatrix);
|
|
655
|
+
bindgroup.setValue('cameraPos', camera.getWorldPosition());
|
|
656
|
+
bindgroup.setValue('color', this._skyColor);
|
|
657
|
+
bindgroup.setValue('srgbOut', device.getFramebuffer() ? 0 : 1);
|
|
658
|
+
device.setProgram(SkyRenderer._programSky.color);
|
|
659
|
+
device.setBindGroup(0, bindgroup);
|
|
660
|
+
device.setRenderStates(depthTest ? SkyRenderer._renderStatesSky : SkyRenderer._renderStatesSkyNoDepthTest);
|
|
661
|
+
SkyRenderer._primitiveSky.draw();
|
|
662
|
+
}
|
|
663
|
+
/** @internal */ _drawSkybox(camera, depthTest) {
|
|
664
|
+
const device = Application.instance.device;
|
|
665
|
+
const bindgroup = this._bindgroupSky.skybox.get();
|
|
666
|
+
bindgroup.setTexture('skyCubeMap', this.skyboxTexture, fetchSampler('clamp_linear_nomip'));
|
|
667
|
+
bindgroup.setValue('flip', device.getFramebuffer() && device.type === 'webgpu' ? new Vector4(1, -1, 1, 1) : new Vector4(1, 1, 1, 1));
|
|
668
|
+
bindgroup.setValue('viewProjMatrix', camera.viewProjectionMatrix);
|
|
669
|
+
bindgroup.setValue('worldMatrix', this._skyWorldMatrix);
|
|
670
|
+
bindgroup.setValue('cameraPos', camera.getWorldPosition());
|
|
671
|
+
bindgroup.setValue('srgbOut', device.getFramebuffer() ? 0 : 1);
|
|
672
|
+
device.setProgram(SkyRenderer._programSky.skybox);
|
|
673
|
+
device.setBindGroup(0, bindgroup);
|
|
674
|
+
device.setRenderStates(depthTest ? SkyRenderer._renderStatesSky : SkyRenderer._renderStatesSkyNoDepthTest);
|
|
675
|
+
SkyRenderer._primitiveSky.draw();
|
|
676
|
+
}
|
|
677
|
+
/** @internal */ _rayIntersectSphere(radius, rayStart, rayDir) {
|
|
678
|
+
const OS = rayStart.magnitude;
|
|
679
|
+
const SH = -Vector3.dot(rayStart, rayDir);
|
|
680
|
+
const OH = Math.sqrt(Math.max(0, OS * OS - SH * SH));
|
|
681
|
+
const PH = Math.sqrt(Math.max(0, radius * radius - OH * OH));
|
|
682
|
+
if (OH > radius) {
|
|
683
|
+
return -1;
|
|
684
|
+
}
|
|
685
|
+
const t1 = SH - PH;
|
|
686
|
+
const t2 = SH + PH;
|
|
687
|
+
return t1 < 0 ? t2 : t1;
|
|
688
|
+
}
|
|
689
|
+
/** @internal */ sunTransmittance(sunLight) {
|
|
690
|
+
const TRANSMITTANCE_SAMPLES = 32;
|
|
691
|
+
const RAYLEIGH_SIGMA = [
|
|
692
|
+
5.802,
|
|
693
|
+
13.558,
|
|
694
|
+
33.1
|
|
695
|
+
];
|
|
696
|
+
const MIE_SIGMA = 3.996;
|
|
697
|
+
const MIE_ABSORPTION_SIGMA = 4.4;
|
|
698
|
+
const OZONE_ABSORPTION_SIGMA = [
|
|
699
|
+
0.65,
|
|
700
|
+
1.881,
|
|
701
|
+
0.085
|
|
702
|
+
];
|
|
703
|
+
function rayleighSc(params, fH) {
|
|
704
|
+
const sigma = new Vector3(RAYLEIGH_SIGMA[0] * 1e-6, RAYLEIGH_SIGMA[1] * 1e-6, RAYLEIGH_SIGMA[2] * 1e-6);
|
|
705
|
+
const rho_h = Math.exp(-fH / params.rayleighScatteringHeight);
|
|
706
|
+
return Vector3.scale(sigma, rho_h);
|
|
707
|
+
}
|
|
708
|
+
function mieSc(params, fH) {
|
|
709
|
+
const sigma = new Vector3(MIE_SIGMA * 1e-6, MIE_SIGMA * 1e-6, MIE_SIGMA * 1e-6);
|
|
710
|
+
const rho_h = Math.exp(-(fH / params.mieScatteringHeight));
|
|
711
|
+
return Vector3.scale(sigma, rho_h);
|
|
712
|
+
}
|
|
713
|
+
function mieAb(params, fH) {
|
|
714
|
+
const sigma = new Vector3(MIE_ABSORPTION_SIGMA * 1e-6, MIE_ABSORPTION_SIGMA * 1e-6, MIE_ABSORPTION_SIGMA * 1e-6);
|
|
715
|
+
const rho_h = Math.exp(-(fH / params.mieScatteringHeight));
|
|
716
|
+
return Vector3.scale(sigma, rho_h);
|
|
717
|
+
}
|
|
718
|
+
function ozoneAb(params, fH) {
|
|
719
|
+
const sigma = new Vector3(OZONE_ABSORPTION_SIGMA[0] * 1e-6, OZONE_ABSORPTION_SIGMA[1] * 1e-6, OZONE_ABSORPTION_SIGMA[2] * 1e-6);
|
|
720
|
+
const rho_h = Math.max(0, 1 - Math.abs(fH - params.ozoneCenter) * 0.5 / params.ozoneWidth);
|
|
721
|
+
return Vector3.scale(sigma, rho_h);
|
|
722
|
+
}
|
|
723
|
+
const eyePos = new Vector3(0, this._atmosphereParams.plantRadius + this._atmosphereParams.cameraHeightScale, 0);
|
|
724
|
+
const lightDir = SkyRenderer._getSunDir(sunLight);
|
|
725
|
+
const d = this._rayIntersectSphere(this._atmosphereParams.plantRadius + this._atmosphereParams.atmosphereHeight, eyePos, lightDir);
|
|
726
|
+
if (d < 0) {
|
|
727
|
+
return new Vector3(0, 0, 0);
|
|
728
|
+
}
|
|
729
|
+
const ds = d / TRANSMITTANCE_SAMPLES;
|
|
730
|
+
const sum = new Vector3(0, 0, 0);
|
|
731
|
+
const p = Vector3.combine(eyePos, lightDir, 1, ds * 0.5);
|
|
732
|
+
for(let i = 0; i < TRANSMITTANCE_SAMPLES; i++){
|
|
733
|
+
const h = p.magnitude - this._atmosphereParams.plantRadius;
|
|
734
|
+
const scattering = Vector3.add(rayleighSc(this._atmosphereParams, h), mieSc(this._atmosphereParams, h));
|
|
735
|
+
const absorption = Vector3.add(ozoneAb(this._atmosphereParams, h), mieAb(this._atmosphereParams, h));
|
|
736
|
+
const extinction = Vector3.add(scattering, absorption);
|
|
737
|
+
Vector3.add(sum, Vector3.scale(extinction, ds), sum);
|
|
738
|
+
Vector3.add(p, Vector3.scale(lightDir, ds), p);
|
|
739
|
+
}
|
|
740
|
+
return new Vector3(Math.exp(-sum.x), Math.exp(-sum.y), Math.exp(-sum.z));
|
|
741
|
+
}
|
|
742
|
+
/** @internal */ _drawScattering(camera, depthTest) {
|
|
743
|
+
const device = Application.instance.device;
|
|
744
|
+
const tLut = getTransmittanceLut();
|
|
745
|
+
const skyLut = getSkyViewLut();
|
|
746
|
+
//const apLut = ScatteringLut.getAerialPerspectiveLut(alpha, 8000);
|
|
747
|
+
const program = SkyRenderer._programSky.scatter;
|
|
748
|
+
const bindgroup = this._bindgroupSky.scatter.get();
|
|
749
|
+
bindgroup.setValue('flip', device.getFramebuffer() && device.type === 'webgpu' ? new Vector4(1, -1, 1, 1) : new Vector4(1, 1, 1, 1));
|
|
750
|
+
bindgroup.setValue('params', this._atmosphereParams);
|
|
751
|
+
bindgroup.setValue('viewProjMatrix', camera.viewProjectionMatrix);
|
|
752
|
+
bindgroup.setValue('worldMatrix', this._skyWorldMatrix);
|
|
753
|
+
bindgroup.setValue('cameraPos', camera.getWorldPosition());
|
|
754
|
+
bindgroup.setValue('srgbOut', device.getFramebuffer() ? 0 : 1);
|
|
755
|
+
bindgroup.setTexture('tLut', tLut, fetchSampler('clamp_linear_nomip'));
|
|
756
|
+
bindgroup.setTexture('skyLut', skyLut, fetchSampler('clamp_linear_nomip'));
|
|
757
|
+
bindgroup.setValue('cloudy', this._cloudy);
|
|
758
|
+
bindgroup.setValue('cloudIntensity', this._cloudIntensity);
|
|
759
|
+
bindgroup.setValue('time', device.frameInfo.elapsedOverall * 0.001);
|
|
760
|
+
bindgroup.setValue('velocity', this._wind);
|
|
761
|
+
device.setProgram(program);
|
|
762
|
+
device.setBindGroup(0, bindgroup);
|
|
763
|
+
device.setRenderStates(depthTest ? SkyRenderer._renderStatesSky : SkyRenderer._renderStatesSkyNoDepthTest);
|
|
764
|
+
SkyRenderer._primitiveSky.draw();
|
|
765
|
+
}
|
|
766
|
+
/** @internal */ _prepareSkyBox(device) {
|
|
767
|
+
SkyRenderer._createAtmosphereLUTPrograms(device);
|
|
768
|
+
if (!SkyRenderer._programDistantLight) {
|
|
769
|
+
SkyRenderer._programDistantLight = device.buildRenderProgram({
|
|
770
|
+
vertex (pb) {
|
|
771
|
+
this.$inputs.vector = pb.vec3().attrib('position');
|
|
772
|
+
pb.main(function() {
|
|
773
|
+
this.$outputs.vector = this.$inputs.vector;
|
|
774
|
+
this.$builtins.position = pb.vec4(0, 0, 0, 1);
|
|
775
|
+
if (pb.getDevice().type !== 'webgpu') {
|
|
776
|
+
this.$builtins.pointSize = 1;
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
},
|
|
780
|
+
fragment (pb) {
|
|
781
|
+
this.$outputs.color = pb.vec4();
|
|
782
|
+
this.skybox = pb.texCube().uniform(0);
|
|
783
|
+
pb.main(function() {
|
|
784
|
+
this.$l.sunColor = pb.vec4();
|
|
785
|
+
this.$l.skyColor = pb.textureSampleLevel(this.skybox, this.$inputs.vector, 0).rgb;
|
|
786
|
+
this.$outputs.color = pb.vec4(pb.mul(this.skyColor, 1 / 32 /*1 / 64*/ ), 1);
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
if (!this._bindgroupDistantLight.get()) {
|
|
792
|
+
this._bindgroupDistantLight.set(device.createBindGroup(SkyRenderer._programDistantLight.bindGroupLayouts[0]));
|
|
793
|
+
}
|
|
794
|
+
if (!SkyRenderer._programFog) {
|
|
795
|
+
SkyRenderer._programFog = device.buildRenderProgram({
|
|
796
|
+
label: 'Fog',
|
|
797
|
+
vertex (pb) {
|
|
798
|
+
this.rt = pb.int().uniform(0);
|
|
799
|
+
this.$inputs.pos = pb.vec2().attrib('position');
|
|
800
|
+
this.$outputs.uv = pb.vec2();
|
|
801
|
+
pb.main(function() {
|
|
802
|
+
this.$builtins.position = pb.vec4(this.$inputs.pos, 1, 1);
|
|
803
|
+
this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
|
|
804
|
+
if (device.type === 'webgpu') {
|
|
805
|
+
this.$if(pb.notEqual(this.rt, 0), function() {
|
|
806
|
+
this.$builtins.position.y = pb.neg(this.$builtins.position.y);
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
},
|
|
811
|
+
fragment (pb) {
|
|
812
|
+
const AtmosphereParams = getAtmosphereParamsStruct(pb);
|
|
813
|
+
const HeightFogParams = getHeightFogParamsStruct(pb);
|
|
814
|
+
this.depthTex = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
815
|
+
this.apLut = pb.tex2D().uniform(0);
|
|
816
|
+
this.skyDistantLightLut = pb.tex2D().uniform(0);
|
|
817
|
+
this.invProjViewMatrix = pb.mat4().uniform(0);
|
|
818
|
+
this.cameraNearFar = pb.vec2().uniform(0);
|
|
819
|
+
this.cameraPosition = pb.vec3().uniform(0);
|
|
820
|
+
this.withAerialPerspective = pb.int().uniform(0);
|
|
821
|
+
this.fogType = pb.int().uniform(0);
|
|
822
|
+
this.atmosphereParams = AtmosphereParams().uniform(0);
|
|
823
|
+
this.heightFogParams = HeightFogParams().uniform(0);
|
|
824
|
+
this.srgbOut = pb.int().uniform(0);
|
|
825
|
+
this.$outputs.outColor = pb.vec4();
|
|
826
|
+
pb.main(function() {
|
|
827
|
+
this.$l.depthValue = pb.textureSample(this.depthTex, this.$inputs.uv).r;
|
|
828
|
+
this.$l.clipSpacePos = pb.vec4(pb.sub(pb.mul(this.$inputs.uv, 2), pb.vec2(1)), pb.sub(pb.mul(this.depthValue, 2), 1), 1);
|
|
829
|
+
this.$l.hPos = pb.mul(this.invProjViewMatrix, this.clipSpacePos);
|
|
830
|
+
this.$l.worldPos = pb.div(this.$l.hPos, this.$l.hPos.w).xyz;
|
|
831
|
+
this.$l.isSky = pb.equal(this.$l.depthValue, 1);
|
|
832
|
+
this.$l.color = calculateFog(this, this.withAerialPerspective, this.fogType, this.atmosphereParams, this.heightFogParams, this.$inputs.uv, this.isSky, this.cameraPosition, this.worldPos, 0, this.apLut, this.skyDistantLightLut);
|
|
833
|
+
this.$if(pb.equal(this.srgbOut, 0), function() {
|
|
834
|
+
this.$outputs.outColor = this.color;
|
|
835
|
+
}).$else(function() {
|
|
836
|
+
this.$outputs.outColor = pb.vec4(linearToGamma(this, this.color.rgb), this.color.a);
|
|
837
|
+
});
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
if (!this._bindgroupFog.get()) {
|
|
843
|
+
this._bindgroupFog.set(device.createBindGroup(SkyRenderer._programFog.bindGroupLayouts[0]));
|
|
844
|
+
}
|
|
845
|
+
if (!SkyRenderer._programSky.color) {
|
|
846
|
+
SkyRenderer._programSky.color = device.buildRenderProgram({
|
|
847
|
+
label: 'SolidColorSky',
|
|
848
|
+
vertex (pb) {
|
|
849
|
+
this.$inputs.pos = pb.vec3().attrib('position');
|
|
850
|
+
this.worldMatrix = pb.mat4().uniform(0);
|
|
851
|
+
this.viewProjMatrix = pb.mat4().uniform(0);
|
|
852
|
+
this.cameraPos = pb.vec3().uniform(0);
|
|
853
|
+
pb.main(function() {
|
|
854
|
+
this.$l.worldDirection = pb.mul(this.worldMatrix, pb.vec4(this.$inputs.pos, 0)).xyz;
|
|
855
|
+
this.$builtins.position = pb.mul(this.viewProjMatrix, pb.vec4(pb.add(this.worldDirection, this.cameraPos), 1));
|
|
856
|
+
this.$builtins.position.z = this.$builtins.position.w;
|
|
857
|
+
});
|
|
858
|
+
},
|
|
859
|
+
fragment (pb) {
|
|
860
|
+
this.$outputs.outColor = pb.vec4();
|
|
861
|
+
this.color = pb.vec4().uniform(0);
|
|
862
|
+
this.srgbOut = pb.int().uniform(0);
|
|
863
|
+
pb.main(function() {
|
|
864
|
+
this.$if(pb.equal(this.srgbOut, 0), function() {
|
|
865
|
+
this.$outputs.outColor = pb.vec4(this.color.rgb, 1);
|
|
866
|
+
}).$else(function() {
|
|
867
|
+
this.$outputs.outColor = pb.vec4(linearToGamma(this, this.color.rgb), 1);
|
|
868
|
+
});
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
if (!this._bindgroupSky.color) {
|
|
874
|
+
this._bindgroupSky.color = new DRef(device.createBindGroup(SkyRenderer._programSky.color.bindGroupLayouts[0]));
|
|
875
|
+
}
|
|
876
|
+
if (!SkyRenderer._programSky.scatter) {
|
|
877
|
+
SkyRenderer._programSky.scatter = SkyRenderer._createScatterProgram(device, true);
|
|
878
|
+
}
|
|
879
|
+
if (!this._bindgroupSky.scatter) {
|
|
880
|
+
this._bindgroupSky.scatter = new DRef(device.createBindGroup(SkyRenderer._programSky.scatter.bindGroupLayouts[0]));
|
|
881
|
+
}
|
|
882
|
+
if (!SkyRenderer._programSky.skybox) {
|
|
883
|
+
SkyRenderer._programSky.skybox = device.buildRenderProgram({
|
|
884
|
+
label: 'SkyBoxSky',
|
|
885
|
+
vertex (pb) {
|
|
886
|
+
this.$inputs.pos = pb.vec3().attrib('position');
|
|
887
|
+
this.$outputs.texCoord = pb.vec3();
|
|
888
|
+
this.worldMatrix = pb.mat4().uniform(0);
|
|
889
|
+
this.viewProjMatrix = pb.mat4().uniform(0);
|
|
890
|
+
this.cameraPos = pb.vec3().uniform(0);
|
|
891
|
+
this.flip = pb.vec4().uniform(0);
|
|
892
|
+
pb.main(function() {
|
|
893
|
+
this.$outputs.texCoord = this.$inputs.pos;
|
|
894
|
+
this.$l.worldPos = pb.add(this.cameraPos, pb.mul(this.worldMatrix, pb.vec4(this.$inputs.pos, 0)).xyz);
|
|
895
|
+
this.$builtins.position = pb.mul(this.viewProjMatrix, pb.vec4(this.worldPos, 1), this.flip);
|
|
896
|
+
this.$builtins.position.z = this.$builtins.position.w;
|
|
897
|
+
});
|
|
898
|
+
},
|
|
899
|
+
fragment (pb) {
|
|
900
|
+
this.$outputs.outColor = pb.vec4();
|
|
901
|
+
this.skyCubeMap = pb.texCube().uniform(0);
|
|
902
|
+
this.srgbOut = pb.int().uniform(0);
|
|
903
|
+
pb.main(function() {
|
|
904
|
+
this.$l.texCoord = pb.normalize(this.$inputs.texCoord);
|
|
905
|
+
this.$l.color = pb.textureSampleLevel(this.skyCubeMap, this.texCoord, 0).rgb;
|
|
906
|
+
this.$if(pb.equal(this.srgbOut, 0), function() {
|
|
907
|
+
this.$outputs.outColor = pb.vec4(this.color, 1);
|
|
908
|
+
}).$else(function() {
|
|
909
|
+
this.$outputs.outColor = pb.vec4(linearToGamma(this, this.color), 1);
|
|
910
|
+
});
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
if (!this._bindgroupSky.skybox) {
|
|
916
|
+
this._bindgroupSky.skybox = new DRef(device.createBindGroup(SkyRenderer._programSky.skybox.bindGroupLayouts[0]));
|
|
917
|
+
}
|
|
918
|
+
if (!SkyRenderer._renderStatesSky) {
|
|
919
|
+
SkyRenderer._renderStatesSky = device.createRenderStateSet();
|
|
920
|
+
SkyRenderer._renderStatesSky.useDepthState().enableTest(true).enableWrite(false).setCompareFunc('le');
|
|
921
|
+
SkyRenderer._renderStatesSky.useRasterizerState().setCullMode('none');
|
|
922
|
+
}
|
|
923
|
+
if (!SkyRenderer._renderStatesSkyNoDepthTest) {
|
|
924
|
+
SkyRenderer._renderStatesSkyNoDepthTest = device.createRenderStateSet();
|
|
925
|
+
SkyRenderer._renderStatesSkyNoDepthTest.useDepthState().enableTest(false).enableWrite(false);
|
|
926
|
+
SkyRenderer._renderStatesSkyNoDepthTest.useRasterizerState().setCullMode('none');
|
|
927
|
+
}
|
|
928
|
+
if (!SkyRenderer._renderStatesFog) {
|
|
929
|
+
SkyRenderer._renderStatesFog = device.createRenderStateSet();
|
|
930
|
+
SkyRenderer._renderStatesFog.useRasterizerState().setCullMode('none');
|
|
931
|
+
SkyRenderer._renderStatesFog.useBlendingState().enable(true).setBlendFunc('one', 'src-alpha');
|
|
932
|
+
SkyRenderer._renderStatesFog.useDepthState().enableTest(false).enableWrite(false);
|
|
933
|
+
}
|
|
934
|
+
if (!SkyRenderer._renderStatesFogScatter) {
|
|
935
|
+
SkyRenderer._renderStatesFogScatter = device.createRenderStateSet();
|
|
936
|
+
SkyRenderer._renderStatesFogScatter.useRasterizerState().setCullMode('none');
|
|
937
|
+
SkyRenderer._renderStatesFogScatter.useBlendingState().enable(true).setBlendFunc('one', 'src-alpha');
|
|
938
|
+
SkyRenderer._renderStatesFogScatter.useDepthState().enableTest(true).enableWrite(false).setCompareFunc('gt');
|
|
939
|
+
}
|
|
940
|
+
if (!SkyRenderer._renderStatesDistantLight) {
|
|
941
|
+
SkyRenderer._renderStatesDistantLight = device.createRenderStateSet();
|
|
942
|
+
SkyRenderer._renderStatesDistantLight.useDepthState().enableTest(false).enableWrite(false);
|
|
943
|
+
SkyRenderer._renderStatesDistantLight.useBlendingState().enable(true).setBlendEquation('add', 'add').setBlendFuncRGB('one', 'one').setBlendFuncAlpha('zero', 'one');
|
|
944
|
+
SkyRenderer._renderStatesDistantLight.useRasterizerState().setCullMode('none');
|
|
945
|
+
}
|
|
946
|
+
if (!SkyRenderer._vertexLayout) {
|
|
947
|
+
SkyRenderer._vertexLayout = device.createVertexLayout({
|
|
948
|
+
vertexBuffers: [
|
|
949
|
+
{
|
|
950
|
+
buffer: device.createVertexBuffer('position_f32x2', new Float32Array([
|
|
951
|
+
-1,
|
|
952
|
+
-1,
|
|
953
|
+
1,
|
|
954
|
+
-1,
|
|
955
|
+
-1,
|
|
956
|
+
1,
|
|
957
|
+
1,
|
|
958
|
+
1
|
|
959
|
+
]))
|
|
960
|
+
}
|
|
961
|
+
]
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
if (!SkyRenderer._primitiveSky) {
|
|
965
|
+
SkyRenderer._primitiveSky = new BoxShape({
|
|
966
|
+
size: 8
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
if (!SkyRenderer._primitiveDistantLight) {
|
|
970
|
+
const data = new Float32Array(uniformSphereSamples.length * 3);
|
|
971
|
+
let i = 0;
|
|
972
|
+
for (const v of uniformSphereSamples){
|
|
973
|
+
data[i++] = v.x;
|
|
974
|
+
data[i++] = v.y;
|
|
975
|
+
data[i++] = v.z;
|
|
976
|
+
}
|
|
977
|
+
SkyRenderer._primitiveDistantLight = new Primitive();
|
|
978
|
+
SkyRenderer._primitiveDistantLight.createAndSetVertexBuffer('position_f32x3', data);
|
|
979
|
+
SkyRenderer._primitiveDistantLight.indexCount = uniformSphereSamples.length;
|
|
980
|
+
SkyRenderer._primitiveDistantLight.indexStart = 0;
|
|
981
|
+
SkyRenderer._primitiveDistantLight.primitiveType = 'point-list';
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
/** @internal */ static _getSunDir(sunLight) {
|
|
985
|
+
// TODO: reduce GC
|
|
986
|
+
return sunLight?.directionAndCutoff.xyz().scaleBy(-1) ?? ShaderHelper.defaultSunDir;
|
|
987
|
+
}
|
|
988
|
+
/** @internal */ static _getSunColor(sunLight) {
|
|
989
|
+
// TODO: reduce GC
|
|
990
|
+
return sunLight?.diffuseAndIntensity ?? new Vector4(1, 1, 1, 10);
|
|
991
|
+
}
|
|
992
|
+
static _createAtmosphereLUTPrograms(device) {
|
|
993
|
+
if (!this.transmittanceLutProgram) {
|
|
994
|
+
this.transmittanceLutProgram = createTransmittanceLutProgram(device);
|
|
995
|
+
}
|
|
996
|
+
if (!this.multiScatteringLutProgram) {
|
|
997
|
+
this.multiScatteringLutProgram = createMultiScatteringLutProgram(device);
|
|
998
|
+
}
|
|
999
|
+
if (!this.skyViewLutProgram) {
|
|
1000
|
+
this.skyViewLutProgram = createSkyViewLutProgram(device);
|
|
1001
|
+
}
|
|
1002
|
+
if (!this.APLutProgram) {
|
|
1003
|
+
this.APLutProgram = createAPLutProgram(device);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
static _createScatterProgram(device, cloud) {
|
|
1007
|
+
return device.buildRenderProgram({
|
|
1008
|
+
vertex (pb) {
|
|
1009
|
+
this.$inputs.pos = pb.vec3().attrib('position');
|
|
1010
|
+
this.worldMatrix = pb.mat4().uniform(0);
|
|
1011
|
+
this.viewProjMatrix = pb.mat4().uniform(0);
|
|
1012
|
+
this.cameraPos = pb.vec3().uniform(0);
|
|
1013
|
+
this.flip = pb.vec4().uniform(0);
|
|
1014
|
+
pb.main(function() {
|
|
1015
|
+
this.$outputs.worldDirection = pb.mul(this.worldMatrix, pb.vec4(this.$inputs.pos, 0)).xyz;
|
|
1016
|
+
this.$builtins.position = pb.mul(this.viewProjMatrix, pb.vec4(pb.add(this.$outputs.worldDirection, this.cameraPos), 1), this.flip);
|
|
1017
|
+
this.$builtins.position.z = this.$builtins.position.w;
|
|
1018
|
+
});
|
|
1019
|
+
},
|
|
1020
|
+
fragment (pb) {
|
|
1021
|
+
this.$outputs.outColor = pb.vec4();
|
|
1022
|
+
this.tLut = pb.tex2D().uniform(0);
|
|
1023
|
+
this.skyLut = pb.tex2D().uniform(0);
|
|
1024
|
+
this.params = getAtmosphereParamsStruct(pb)().uniform(0);
|
|
1025
|
+
if (cloud) {
|
|
1026
|
+
this.cloudy = pb.float().uniform(0);
|
|
1027
|
+
this.cloudIntensity = pb.float().uniform(0);
|
|
1028
|
+
this.time = pb.float().uniform(0);
|
|
1029
|
+
this.velocity = pb.vec2().uniform(0);
|
|
1030
|
+
}
|
|
1031
|
+
this.srgbOut = pb.int().uniform(0);
|
|
1032
|
+
pb.func('noise', [
|
|
1033
|
+
pb.vec3('p'),
|
|
1034
|
+
pb.float('t')
|
|
1035
|
+
], function() {
|
|
1036
|
+
this.p2 = pb.mul(this.p, 0.25);
|
|
1037
|
+
this.f = pb.mul(smoothNoise3D(this, this.p2), 0.5);
|
|
1038
|
+
this.p2 = pb.mul(this.p2, 3.02);
|
|
1039
|
+
this.p2.y = pb.sub(this.p2.y, pb.mul(this.t, 0.02));
|
|
1040
|
+
this.f = pb.add(this.f, pb.mul(smoothNoise3D(this, this.p2), 0.25));
|
|
1041
|
+
this.p2 = pb.mul(this.p2, 3.03);
|
|
1042
|
+
this.p2.y = pb.add(this.p2.y, pb.mul(this.t, 0.01));
|
|
1043
|
+
this.f = pb.add(this.f, pb.mul(smoothNoise3D(this, this.p2), 0.125));
|
|
1044
|
+
this.p2 = pb.mul(this.p2, 3.02);
|
|
1045
|
+
this.f = pb.add(this.f, pb.mul(smoothNoise3D(this, this.p2), 0.0625));
|
|
1046
|
+
this.p2 = pb.mul(this.p2, 3.01);
|
|
1047
|
+
this.f = pb.add(this.f, pb.mul(smoothNoise3D(this, this.p2), 0.03125));
|
|
1048
|
+
this.p2 = pb.mul(this.p2, 3.01);
|
|
1049
|
+
this.f = pb.add(this.f, pb.mul(smoothNoise3D(this, this.p2), 0.015625));
|
|
1050
|
+
this.$return(this.f);
|
|
1051
|
+
});
|
|
1052
|
+
pb.main(function() {
|
|
1053
|
+
// Calculate sky color
|
|
1054
|
+
this.$l.sunColor = pb.vec4();
|
|
1055
|
+
this.$l.skyColor = skyBox(this, this.params, this.sunColor, this.$inputs.worldDirection, pb.float(0.01), this.tLut, this.skyLut).rgb;
|
|
1056
|
+
this.$l.rayDir = pb.normalize(this.$inputs.worldDirection);
|
|
1057
|
+
this.$l.sunDir = this.params.lightDir;
|
|
1058
|
+
// ad-hoc
|
|
1059
|
+
this.$l.sunIntensity = pb.sqrt(pb.max(0, pb.mul(this.sunDir.y, this.rayDir.y)));
|
|
1060
|
+
// compute cloud
|
|
1061
|
+
if (cloud) {
|
|
1062
|
+
this.$l.noiseValue = pb.float();
|
|
1063
|
+
this.$if(pb.lessThanEqual(this.rayDir.y, 0), function() {
|
|
1064
|
+
this.noiseValue = 0;
|
|
1065
|
+
}).$else(function() {
|
|
1066
|
+
this.$l.tMin = pb.div(3000, this.rayDir.y);
|
|
1067
|
+
this.$l.cloudPoint = pb.mul(this.rayDir, this.tMin);
|
|
1068
|
+
this.speed = pb.mul(pb.vec3(this.velocity.x, 0, this.velocity.y), this.time);
|
|
1069
|
+
this.$l.noiseScale = pb.float(4e-4);
|
|
1070
|
+
this.noiseValue = this.noise(pb.mul(pb.add(this.cloudPoint, this.speed), this.noiseScale), this.time);
|
|
1071
|
+
this.noiseValue = pb.add(this.noiseValue, this.cloudy);
|
|
1072
|
+
this.noiseValue = pb.smoothStep(1, pb.add(1, this.cloudy), this.noiseValue);
|
|
1073
|
+
});
|
|
1074
|
+
// use sun color as cloud color
|
|
1075
|
+
/*
|
|
1076
|
+
this.$l.sunColor = pb.mul(
|
|
1077
|
+
pb.textureSampleLevel(this.skyLut, viewDirToUV(this, this.sunDir), 0),
|
|
1078
|
+
this.sunIntensity
|
|
1079
|
+
);
|
|
1080
|
+
*/ this.$l.cloudColor = pb.mul(this.sunColor.rgb, this.sunIntensity, pb.mul(this.noiseValue, this.cloudIntensity));
|
|
1081
|
+
}
|
|
1082
|
+
// Compute sky color
|
|
1083
|
+
if (cloud) {
|
|
1084
|
+
// blend
|
|
1085
|
+
this.$l.vfactor = pb.clamp(pb.div(pb.sub(this.rayDir.y, 0.01), pb.sub(0.03, 0.01)), 0, 1);
|
|
1086
|
+
this.$l.factor = pb.clamp(pb.mul(this.noiseValue, this.vfactor), 0, 1);
|
|
1087
|
+
this.$l.color = pb.mix(this.skyColor, this.cloudColor, this.factor);
|
|
1088
|
+
} else {
|
|
1089
|
+
this.$l.color = this.skyColor;
|
|
1090
|
+
}
|
|
1091
|
+
this.$if(pb.equal(this.srgbOut, 0), function() {
|
|
1092
|
+
this.$outputs.outColor = pb.vec4(this.color, 1);
|
|
1093
|
+
}).$else(function() {
|
|
1094
|
+
this.$outputs.outColor = pb.vec4(linearToGamma(this, this.color), 1);
|
|
1095
|
+
});
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
export { SkyRenderer };
|
|
1103
|
+
//# sourceMappingURL=sky.js.map
|