@zephyr3d/scene 0.9.5 → 0.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation/joint_dynamics/controller.js +92 -32
- package/dist/animation/joint_dynamics/controller.js.map +1 -1
- package/dist/animation/joint_dynamics/convex_collider.js +320 -0
- package/dist/animation/joint_dynamics/convex_collider.js.map +1 -0
- package/dist/animation/joint_dynamics/joint_dynamics_system.js +57 -19
- package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
- package/dist/animation/joint_dynamics/solver.js +71 -27
- package/dist/animation/joint_dynamics/solver.js.map +1 -1
- package/dist/animation/joint_dynamics_modifier.js +21 -20
- package/dist/animation/joint_dynamics_modifier.js.map +1 -1
- package/dist/animation/skeleton.js +7 -10
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/app/engine.js +134 -140
- package/dist/app/engine.js.map +1 -1
- package/dist/app/scriptregistry.js +47 -16
- package/dist/app/scriptregistry.js.map +1 -1
- package/dist/asset/assetmanager.js +3 -1
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/model.js +346 -7
- package/dist/asset/model.js.map +1 -1
- package/dist/avatar/wardrobe.js +20 -16
- package/dist/avatar/wardrobe.js.map +1 -1
- package/dist/camera/camera.js +416 -210
- package/dist/camera/camera.js.map +1 -1
- package/dist/index.d.ts +1350 -621
- package/dist/index.js +6 -11
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +1 -1
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/lambert.js +1 -1
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/material.js +23 -1
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +178 -23
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/albedocolor.js +4 -4
- package/dist/material/mixins/albedocolor.js.map +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js +2 -1
- package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
- package/dist/material/mixins/lightmodel/lambert.js +2 -1
- package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +63 -16
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +105 -32
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +16 -6
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
- package/dist/material/mixins/lit.js +1 -1
- package/dist/material/mixins/lit.js.map +1 -1
- package/dist/material/mixins/pbr/common.js +276 -65
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/mixins/texture.js +3 -3
- package/dist/material/mixins/texture.js.map +1 -1
- package/dist/material/mixins/vertexcolor.js +2 -2
- package/dist/material/mixins/vertexcolor.js.map +1 -1
- package/dist/material/msdf_text.js +3 -3
- package/dist/material/msdf_text.js.map +1 -1
- package/dist/material/mtoon.js +574 -0
- package/dist/material/mtoon.js.map +1 -0
- package/dist/material/pbrblueprint.js +499 -336
- package/dist/material/pbrblueprint.js.map +1 -1
- package/dist/material/pbrmr.js +118 -100
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/pbrsg.js +1 -1
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/shader/helper.js +324 -294
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/subsurfaceprofile.js +812 -0
- package/dist/material/subsurfaceprofile.js.map +1 -0
- package/dist/material/unlit.js +1 -1
- package/dist/material/unlit.js.map +1 -1
- package/dist/posteffect/compositor.js +46 -11
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/ssr.js +422 -96
- package/dist/posteffect/ssr.js.map +1 -1
- package/dist/posteffect/sss.js +1053 -0
- package/dist/posteffect/sss.js.map +1 -0
- package/dist/posteffect/taa.js +61 -60
- package/dist/posteffect/taa.js.map +1 -1
- package/dist/render/abuffer_oit.js +63 -12
- package/dist/render/abuffer_oit.js.map +1 -1
- package/dist/render/cluster_light.js +6 -5
- package/dist/render/cluster_light.js.map +1 -1
- package/dist/render/drawable.js +1 -5
- package/dist/render/drawable.js.map +1 -1
- package/dist/render/drawable_mixin.js +2 -1
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/fbm_wavegenerator.js +2 -1
- package/dist/render/fbm_wavegenerator.js.map +1 -1
- package/dist/render/gerstner_wavegenerator.js +2 -1
- package/dist/render/gerstner_wavegenerator.js.map +1 -1
- package/dist/render/globalbindgroup_allocator.js +2 -1
- package/dist/render/globalbindgroup_allocator.js.map +1 -1
- package/dist/render/lightpass.js +110 -23
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/render_queue.js +51 -8
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +80 -66
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/rendergraph/device_pool_allocator.js +8 -0
- package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
- package/dist/render/rendergraph/forward_plus_builder.js +481 -95
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/render/rendergraph/history_resource_manager.js +55 -0
- package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
- package/dist/render/rendergraph/history_resources.js +3 -1
- package/dist/render/rendergraph/history_resources.js.map +1 -1
- package/dist/render/rendergraph/types.js.map +1 -1
- package/dist/render/renderpass.js +10 -4
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/sky.js +31 -1
- package/dist/render/sky.js.map +1 -1
- package/dist/render/weightedblended_oit.js +23 -5
- package/dist/render/weightedblended_oit.js.map +1 -1
- package/dist/scene/basesprite.js +4 -2
- package/dist/scene/basesprite.js.map +1 -1
- package/dist/scene/batchgroup.js +3 -1
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +11 -1
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/light.js +21 -3
- package/dist/scene/light.js.map +1 -1
- package/dist/scene/mesh.js +29 -14
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/meshdrawable.js +6 -0
- package/dist/scene/meshdrawable.js.map +1 -1
- package/dist/scene/msdftext.js +5 -2
- package/dist/scene/msdftext.js.map +1 -1
- package/dist/scene/msdftextsprite.js +5 -3
- package/dist/scene/msdftextsprite.js.map +1 -1
- package/dist/scene/particlesys.js +3 -1
- package/dist/scene/particlesys.js.map +1 -1
- package/dist/scene/scene.js +6 -5
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/terrain-cm/grass.js +4 -2
- package/dist/scene/terrain-cm/grass.js.map +1 -1
- package/dist/scene/terrain-cm/grassmaterial.js +2 -1
- package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
- package/dist/scene/terrain-cm/terrain-cm.js +4 -2
- package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
- package/dist/scene/water.js +4 -2
- package/dist/scene/water.js.map +1 -1
- package/dist/shaders/shadow.js +26 -393
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shadow/esm.js +112 -12
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/pcf_opt.js +2 -2
- package/dist/shadow/pcf_opt.js.map +1 -1
- package/dist/shadow/pcf_pd.js +19 -10
- package/dist/shadow/pcf_pd.js.map +1 -1
- package/dist/shadow/shader.js +58 -7
- package/dist/shadow/shader.js.map +1 -1
- package/dist/shadow/shadow_impl.js +6 -0
- package/dist/shadow/shadow_impl.js.map +1 -1
- package/dist/shadow/shadow_region.js +229 -0
- package/dist/shadow/shadow_region.js.map +1 -0
- package/dist/shadow/shadowmapper.js +67 -59
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/vsm.js +45 -19
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/text/font/cff_font.js +890 -0
- package/dist/text/font/cff_font.js.map +1 -0
- package/dist/text/font/font_asset.js +17 -3
- package/dist/text/font/font_asset.js.map +1 -1
- package/dist/utility/blueprint/common/constants.js +8 -8
- package/dist/utility/blueprint/common/constants.js.map +1 -1
- package/dist/utility/blueprint/material/pbr.js +31 -4
- package/dist/utility/blueprint/material/pbr.js.map +1 -1
- package/dist/utility/blueprint/material/texture.js +1 -17
- package/dist/utility/blueprint/material/texture.js.map +1 -1
- package/dist/utility/serialization/manager.js +327 -359
- package/dist/utility/serialization/manager.js.map +1 -1
- package/dist/utility/serialization/scene/animation.js +5 -2
- package/dist/utility/serialization/scene/animation.js.map +1 -1
- package/dist/utility/serialization/scene/batch.js +4 -1
- package/dist/utility/serialization/scene/batch.js.map +1 -1
- package/dist/utility/serialization/scene/camera.js +249 -54
- package/dist/utility/serialization/scene/camera.js.map +1 -1
- package/dist/utility/serialization/scene/common.js +37 -1
- package/dist/utility/serialization/scene/common.js.map +1 -1
- package/dist/utility/serialization/scene/light.js +42 -3
- package/dist/utility/serialization/scene/light.js.map +1 -1
- package/dist/utility/serialization/scene/material.js +1112 -646
- package/dist/utility/serialization/scene/material.js.map +1 -1
- package/dist/utility/serialization/scene/mesh.js +7 -4
- package/dist/utility/serialization/scene/mesh.js.map +1 -1
- package/dist/utility/serialization/scene/node.js +31 -12
- package/dist/utility/serialization/scene/node.js.map +1 -1
- package/dist/utility/serialization/scene/particle.js +4 -1
- package/dist/utility/serialization/scene/particle.js.map +1 -1
- package/dist/utility/serialization/scene/primitive.js +3 -1
- package/dist/utility/serialization/scene/primitive.js.map +1 -1
- package/dist/utility/serialization/scene/scene.js +18 -0
- package/dist/utility/serialization/scene/scene.js.map +1 -1
- package/dist/utility/serialization/scene/sprite.js +6 -3
- package/dist/utility/serialization/scene/sprite.js.map +1 -1
- package/dist/utility/serialization/scene/terrain.js +5 -2
- package/dist/utility/serialization/scene/terrain.js.map +1 -1
- package/dist/utility/serialization/scene/text.js +3 -1
- package/dist/utility/serialization/scene/text.js.map +1 -1
- package/dist/utility/serialization/scene/water.js +4 -1
- package/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/utility/textures/ltcdata.js +6 -0
- package/dist/utility/textures/ltcdata.js.map +1 -0
- package/dist/utility/textures/ltclut.js +61 -0
- package/dist/utility/textures/ltclut.js.map +1 -0
- package/dist/values.js +9 -1
- package/dist/values.js.map +1 -1
- package/package.json +3 -3
- package/dist/animation/ik/ik_chain_builder.js +0 -68
- package/dist/animation/ik/ik_chain_builder.js.map +0 -1
- package/dist/animation/ik/ik_pole_constraint.js +0 -123
- package/dist/animation/ik/ik_pole_constraint.js.map +0 -1
- package/dist/animation/ik/ik_track.js +0 -96
- package/dist/animation/ik/ik_track.js.map +0 -1
- package/dist/animation/ik_postprocessor.js +0 -71
- package/dist/animation/ik_postprocessor.js.map +0 -1
- package/dist/animation/joint_dynamics/math.js +0 -16
- package/dist/animation/joint_dynamics/math.js.map +0 -1
- package/dist/animation/manual_transform_processor.js +0 -156
- package/dist/animation/manual_transform_processor.js.map +0 -1
- package/dist/animation/skeleton_postprocessor.js +0 -50
- package/dist/animation/skeleton_postprocessor.js.map +0 -1
- package/dist/animation/spring2/collision.js +0 -469
- package/dist/animation/spring2/collision.js.map +0 -1
- package/dist/animation/spring2/constraints.js +0 -329
- package/dist/animation/spring2/constraints.js.map +0 -1
- package/dist/animation/spring2/controller.js +0 -434
- package/dist/animation/spring2/controller.js.map +0 -1
- package/dist/animation/spring2/math.js +0 -16
- package/dist/animation/spring2/math.js.map +0 -1
- package/dist/animation/spring2/solver.js +0 -624
- package/dist/animation/spring2/solver.js.map +0 -1
- package/dist/animation/spring2/spring_system.js +0 -118
- package/dist/animation/spring2/spring_system.js.map +0 -1
- package/dist/animation/spring2/types.js +0 -19
- package/dist/animation/spring2/types.js.map +0 -1
- package/dist/animation/spring_postprocessor.js +0 -54
- package/dist/animation/spring_postprocessor.js.map +0 -1
- package/dist/asset/loaders/gltf/gltf_loader.js +0 -1276
- package/dist/asset/loaders/gltf/gltf_loader.js.map +0 -1
- package/dist/asset/loaders/gltf/helpers.js +0 -331
- package/dist/asset/loaders/gltf/helpers.js.map +0 -1
- package/dist/material/sprite3d.js +0 -301
- package/dist/material/sprite3d.js.map +0 -1
- package/dist/material/sprite3d_std.js +0 -116
- package/dist/material/sprite3d_std.js.map +0 -1
- package/dist/material/sprite3dblueprint.js +0 -235
- package/dist/material/sprite3dblueprint.js.map +0 -1
- package/dist/material/sprite_sdf.js +0 -106
- package/dist/material/sprite_sdf.js.map +0 -1
- package/dist/material/terrainmaterial.js +0 -368
- package/dist/material/terrainmaterial.js.map +0 -1
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js +0 -38
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js.map +0 -1
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js +0 -10
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js.map +0 -1
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js +0 -127
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js.map +0 -1
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js +0 -263
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js.map +0 -1
- package/dist/render/deferredlightpass.js +0 -510
- package/dist/render/deferredlightpass.js.map +0 -1
- package/dist/render/deferredshadowlightpass.js +0 -428
- package/dist/render/deferredshadowlightpass.js.map +0 -1
- package/dist/render/gbufferpass.js +0 -50
- package/dist/render/gbufferpass.js.map +0 -1
- package/dist/scene/sdftextsprite.js +0 -322
- package/dist/scene/sdftextsprite.js.map +0 -1
- package/dist/scene/sprite3d.js +0 -18
- package/dist/scene/sprite3d.js.map +0 -1
- package/dist/scene/terrain/grass.js +0 -280
- package/dist/scene/terrain/grass.js.map +0 -1
- package/dist/scene/terrain/heightfield.js +0 -475
- package/dist/scene/terrain/heightfield.js.map +0 -1
- package/dist/scene/terrain/patch.js +0 -532
- package/dist/scene/terrain/patch.js.map +0 -1
- package/dist/scene/terrain/quadtree.js +0 -461
- package/dist/scene/terrain/quadtree.js.map +0 -1
- package/dist/scene/terrain/terrain.js +0 -231
- package/dist/scene/terrain/terrain.js.map +0 -1
- package/dist/src/animation/animation.js +0 -127
- package/dist/src/animation/animation.js.map +0 -1
- package/dist/src/animation/animationset.js +0 -255
- package/dist/src/animation/animationset.js.map +0 -1
- package/dist/src/animation/animationtrack.js +0 -34
- package/dist/src/animation/animationtrack.js.map +0 -1
- package/dist/src/animation/eulerrotationtrack.js +0 -52
- package/dist/src/animation/eulerrotationtrack.js.map +0 -1
- package/dist/src/animation/morphtarget.js +0 -93
- package/dist/src/animation/morphtarget.js.map +0 -1
- package/dist/src/animation/morphtrack.js +0 -70
- package/dist/src/animation/morphtrack.js.map +0 -1
- package/dist/src/animation/proptrack.js +0 -161
- package/dist/src/animation/proptrack.js.map +0 -1
- package/dist/src/animation/rotationtrack.js +0 -51
- package/dist/src/animation/rotationtrack.js.map +0 -1
- package/dist/src/animation/scaletrack.js +0 -50
- package/dist/src/animation/scaletrack.js.map +0 -1
- package/dist/src/animation/skeleton.js +0 -204
- package/dist/src/animation/skeleton.js.map +0 -1
- package/dist/src/animation/translationtrack.js +0 -50
- package/dist/src/animation/translationtrack.js.map +0 -1
- package/dist/src/app/app.js +0 -129
- package/dist/src/app/app.js.map +0 -1
- package/dist/src/app/inputmgr.js +0 -267
- package/dist/src/app/inputmgr.js.map +0 -1
- package/dist/src/asset/assetmanager.js +0 -404
- package/dist/src/asset/assetmanager.js.map +0 -1
- package/dist/src/asset/builtin.js +0 -337
- package/dist/src/asset/builtin.js.map +0 -1
- package/dist/src/asset/loaders/dds/dds.js +0 -470
- package/dist/src/asset/loaders/dds/dds.js.map +0 -1
- package/dist/src/asset/loaders/dds/dds_loader.js +0 -28
- package/dist/src/asset/loaders/dds/dds_loader.js.map +0 -1
- package/dist/src/asset/loaders/gltf/gltf_loader.js +0 -1265
- package/dist/src/asset/loaders/gltf/gltf_loader.js.map +0 -1
- package/dist/src/asset/loaders/gltf/helpers.js +0 -327
- package/dist/src/asset/loaders/gltf/helpers.js.map +0 -1
- package/dist/src/asset/loaders/hdr/hdr.js +0 -180
- package/dist/src/asset/loaders/hdr/hdr.js.map +0 -1
- package/dist/src/asset/loaders/image/tga_Loader.js +0 -116
- package/dist/src/asset/loaders/image/tga_Loader.js.map +0 -1
- package/dist/src/asset/loaders/image/webimage_loader.js +0 -63
- package/dist/src/asset/loaders/image/webimage_loader.js.map +0 -1
- package/dist/src/asset/loaders/loader.js +0 -45
- package/dist/src/asset/loaders/loader.js.map +0 -1
- package/dist/src/asset/model.js +0 -414
- package/dist/src/asset/model.js.map +0 -1
- package/dist/src/blitter/bilateralblur.js +0 -221
- package/dist/src/blitter/bilateralblur.js.map +0 -1
- package/dist/src/blitter/blitter.js +0 -390
- package/dist/src/blitter/blitter.js.map +0 -1
- package/dist/src/blitter/box.js +0 -118
- package/dist/src/blitter/box.js.map +0 -1
- package/dist/src/blitter/copy.js +0 -22
- package/dist/src/blitter/copy.js.map +0 -1
- package/dist/src/blitter/gaussianblur.js +0 -228
- package/dist/src/blitter/gaussianblur.js.map +0 -1
- package/dist/src/camera/base.js +0 -92
- package/dist/src/camera/base.js.map +0 -1
- package/dist/src/camera/camera.js +0 -1005
- package/dist/src/camera/camera.js.map +0 -1
- package/dist/src/camera/fps.js +0 -238
- package/dist/src/camera/fps.js.map +0 -1
- package/dist/src/camera/orbit.js +0 -245
- package/dist/src/camera/orbit.js.map +0 -1
- package/dist/src/camera/orthocamera.js +0 -167
- package/dist/src/camera/orthocamera.js.map +0 -1
- package/dist/src/camera/perspectivecamera.js +0 -141
- package/dist/src/camera/perspectivecamera.js.map +0 -1
- package/dist/src/index.js +0 -120
- package/dist/src/index.js.map +0 -1
- package/dist/src/material/blinn.js +0 -81
- package/dist/src/material/blinn.js.map +0 -1
- package/dist/src/material/grassmaterial.js +0 -113
- package/dist/src/material/grassmaterial.js.map +0 -1
- package/dist/src/material/lambert.js +0 -92
- package/dist/src/material/lambert.js.map +0 -1
- package/dist/src/material/material.js +0 -301
- package/dist/src/material/material.js.map +0 -1
- package/dist/src/material/meshmaterial.js +0 -704
- package/dist/src/material/meshmaterial.js.map +0 -1
- package/dist/src/material/mixins/albedocolor.js +0 -76
- package/dist/src/material/mixins/albedocolor.js.map +0 -1
- package/dist/src/material/mixins/foliage.js +0 -47
- package/dist/src/material/mixins/foliage.js.map +0 -1
- package/dist/src/material/mixins/lightmodel/blinnphong.js +0 -112
- package/dist/src/material/mixins/lightmodel/blinnphong.js.map +0 -1
- package/dist/src/material/mixins/lightmodel/lambert.js +0 -58
- package/dist/src/material/mixins/lightmodel/lambert.js.map +0 -1
- package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js +0 -178
- package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js.map +0 -1
- package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js +0 -139
- package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js.map +0 -1
- package/dist/src/material/mixins/lit.js +0 -476
- package/dist/src/material/mixins/lit.js.map +0 -1
- package/dist/src/material/mixins/pbr/common.js +0 -918
- package/dist/src/material/mixins/pbr/common.js.map +0 -1
- package/dist/src/material/mixins/texture.js +0 -172
- package/dist/src/material/mixins/texture.js.map +0 -1
- package/dist/src/material/mixins/vertexcolor.js +0 -56
- package/dist/src/material/mixins/vertexcolor.js.map +0 -1
- package/dist/src/material/particle.js +0 -178
- package/dist/src/material/particle.js.map +0 -1
- package/dist/src/material/pbrmr.js +0 -97
- package/dist/src/material/pbrmr.js.map +0 -1
- package/dist/src/material/pbrsg.js +0 -97
- package/dist/src/material/pbrsg.js.map +0 -1
- package/dist/src/material/shader/helper.js +0 -1209
- package/dist/src/material/shader/helper.js.map +0 -1
- package/dist/src/material/terrain-cm.js +0 -606
- package/dist/src/material/terrain-cm.js.map +0 -1
- package/dist/src/material/terrainmaterial.js +0 -375
- package/dist/src/material/terrainmaterial.js.map +0 -1
- package/dist/src/material/unlit.js +0 -41
- package/dist/src/material/unlit.js.map +0 -1
- package/dist/src/material/water.js +0 -417
- package/dist/src/material/water.js.map +0 -1
- package/dist/src/posteffect/bloom.js +0 -361
- package/dist/src/posteffect/bloom.js.map +0 -1
- package/dist/src/posteffect/compositor.js +0 -226
- package/dist/src/posteffect/compositor.js.map +0 -1
- package/dist/src/posteffect/fxaa.js +0 -273
- package/dist/src/posteffect/fxaa.js.map +0 -1
- package/dist/src/posteffect/grayscale.js +0 -69
- package/dist/src/posteffect/grayscale.js.map +0 -1
- package/dist/src/posteffect/motionblur.js +0 -96
- package/dist/src/posteffect/motionblur.js.map +0 -1
- package/dist/src/posteffect/posteffect.js +0 -126
- package/dist/src/posteffect/posteffect.js.map +0 -1
- package/dist/src/posteffect/sao.js +0 -324
- package/dist/src/posteffect/sao.js.map +0 -1
- package/dist/src/posteffect/ssr.js +0 -489
- package/dist/src/posteffect/ssr.js.map +0 -1
- package/dist/src/posteffect/taa.js +0 -172
- package/dist/src/posteffect/taa.js.map +0 -1
- package/dist/src/posteffect/tonemap.js +0 -94
- package/dist/src/posteffect/tonemap.js.map +0 -1
- package/dist/src/render/abuffer_oit.js +0 -361
- package/dist/src/render/abuffer_oit.js.map +0 -1
- package/dist/src/render/clipmap.js +0 -851
- package/dist/src/render/clipmap.js.map +0 -1
- package/dist/src/render/cluster_light.js +0 -333
- package/dist/src/render/cluster_light.js.map +0 -1
- package/dist/src/render/cull_visitor.js +0 -187
- package/dist/src/render/cull_visitor.js.map +0 -1
- package/dist/src/render/depthpass.js +0 -68
- package/dist/src/render/depthpass.js.map +0 -1
- package/dist/src/render/drawable_mixin.js +0 -227
- package/dist/src/render/drawable_mixin.js.map +0 -1
- package/dist/src/render/envlight.js +0 -463
- package/dist/src/render/envlight.js.map +0 -1
- package/dist/src/render/fbm_wavegenerator.js +0 -251
- package/dist/src/render/fbm_wavegenerator.js.map +0 -1
- package/dist/src/render/fft_wavegenerator.js +0 -1006
- package/dist/src/render/fft_wavegenerator.js.map +0 -1
- package/dist/src/render/fullscreenquad.js +0 -38
- package/dist/src/render/fullscreenquad.js.map +0 -1
- package/dist/src/render/gerstner_wavegenerator.js +0 -314
- package/dist/src/render/gerstner_wavegenerator.js.map +0 -1
- package/dist/src/render/globalbindgroup_allocator.js +0 -60
- package/dist/src/render/globalbindgroup_allocator.js.map +0 -1
- package/dist/src/render/hzb.js +0 -273
- package/dist/src/render/hzb.js.map +0 -1
- package/dist/src/render/lightpass.js +0 -172
- package/dist/src/render/lightpass.js.map +0 -1
- package/dist/src/render/objectcolorpass.js +0 -51
- package/dist/src/render/objectcolorpass.js.map +0 -1
- package/dist/src/render/primitive.js +0 -364
- package/dist/src/render/primitive.js.map +0 -1
- package/dist/src/render/render_queue.js +0 -467
- package/dist/src/render/render_queue.js.map +0 -1
- package/dist/src/render/renderbundle_wrapper.js +0 -152
- package/dist/src/render/renderbundle_wrapper.js.map +0 -1
- package/dist/src/render/renderer.js +0 -455
- package/dist/src/render/renderer.js.map +0 -1
- package/dist/src/render/renderpass.js +0 -200
- package/dist/src/render/renderpass.js.map +0 -1
- package/dist/src/render/shadowmap_pass.js +0 -56
- package/dist/src/render/shadowmap_pass.js.map +0 -1
- package/dist/src/render/sky.js +0 -1103
- package/dist/src/render/sky.js.map +0 -1
- package/dist/src/render/weightedblended_oit.js +0 -168
- package/dist/src/render/weightedblended_oit.js.map +0 -1
- package/dist/src/scene/batchgroup.js +0 -162
- package/dist/src/scene/batchgroup.js.map +0 -1
- package/dist/src/scene/environment.js +0 -209
- package/dist/src/scene/environment.js.map +0 -1
- package/dist/src/scene/graph_node.js +0 -72
- package/dist/src/scene/graph_node.js.map +0 -1
- package/dist/src/scene/light.js +0 -416
- package/dist/src/scene/light.js.map +0 -1
- package/dist/src/scene/mesh.js +0 -341
- package/dist/src/scene/mesh.js.map +0 -1
- package/dist/src/scene/octree.js +0 -649
- package/dist/src/scene/octree.js.map +0 -1
- package/dist/src/scene/particlesys.js +0 -738
- package/dist/src/scene/particlesys.js.map +0 -1
- package/dist/src/scene/raycast_visitor.js +0 -103
- package/dist/src/scene/raycast_visitor.js.map +0 -1
- package/dist/src/scene/scene.js +0 -284
- package/dist/src/scene/scene.js.map +0 -1
- package/dist/src/scene/scene_node.js +0 -732
- package/dist/src/scene/scene_node.js.map +0 -1
- package/dist/src/scene/terrain/grass.js +0 -278
- package/dist/src/scene/terrain/grass.js.map +0 -1
- package/dist/src/scene/terrain/heightfield.js +0 -475
- package/dist/src/scene/terrain/heightfield.js.map +0 -1
- package/dist/src/scene/terrain/patch.js +0 -530
- package/dist/src/scene/terrain/patch.js.map +0 -1
- package/dist/src/scene/terrain/quadtree.js +0 -461
- package/dist/src/scene/terrain/quadtree.js.map +0 -1
- package/dist/src/scene/terrain/terrain.js +0 -246
- package/dist/src/scene/terrain/terrain.js.map +0 -1
- package/dist/src/scene/terrain-cm/grass.js +0 -594
- package/dist/src/scene/terrain-cm/grass.js.map +0 -1
- package/dist/src/scene/terrain-cm/grassmaterial.js +0 -159
- package/dist/src/scene/terrain-cm/grassmaterial.js.map +0 -1
- package/dist/src/scene/terrain-cm/terrain-cm.js +0 -538
- package/dist/src/scene/terrain-cm/terrain-cm.js.map +0 -1
- package/dist/src/scene/water.js +0 -374
- package/dist/src/scene/water.js.map +0 -1
- package/dist/src/shaders/atmosphere.js +0 -957
- package/dist/src/shaders/atmosphere.js.map +0 -1
- package/dist/src/shaders/fog.js +0 -112
- package/dist/src/shaders/fog.js.map +0 -1
- package/dist/src/shaders/misc.js +0 -266
- package/dist/src/shaders/misc.js.map +0 -1
- package/dist/src/shaders/noise.js +0 -222
- package/dist/src/shaders/noise.js.map +0 -1
- package/dist/src/shaders/pbr.js +0 -51
- package/dist/src/shaders/pbr.js.map +0 -1
- package/dist/src/shaders/shadow.js +0 -636
- package/dist/src/shaders/shadow.js.map +0 -1
- package/dist/src/shaders/ssr.js +0 -490
- package/dist/src/shaders/ssr.js.map +0 -1
- package/dist/src/shaders/temporal.js +0 -215
- package/dist/src/shaders/temporal.js.map +0 -1
- package/dist/src/shaders/water.js +0 -756
- package/dist/src/shaders/water.js.map +0 -1
- package/dist/src/shadow/esm.js +0 -237
- package/dist/src/shadow/esm.js.map +0 -1
- package/dist/src/shadow/pcf_opt.js +0 -181
- package/dist/src/shadow/pcf_opt.js.map +0 -1
- package/dist/src/shadow/pcf_pd.js +0 -189
- package/dist/src/shadow/pcf_pd.js.map +0 -1
- package/dist/src/shadow/shader.js +0 -37
- package/dist/src/shadow/shader.js.map +0 -1
- package/dist/src/shadow/shadow_impl.js +0 -15
- package/dist/src/shadow/shadow_impl.js.map +0 -1
- package/dist/src/shadow/shadowmapper.js +0 -790
- package/dist/src/shadow/shadowmapper.js.map +0 -1
- package/dist/src/shadow/ssm.js +0 -159
- package/dist/src/shadow/ssm.js.map +0 -1
- package/dist/src/shadow/vsm.js +0 -297
- package/dist/src/shadow/vsm.js.map +0 -1
- package/dist/src/shapes/box.js +0 -386
- package/dist/src/shapes/box.js.map +0 -1
- package/dist/src/shapes/cylinder.js +0 -125
- package/dist/src/shapes/cylinder.js.map +0 -1
- package/dist/src/shapes/plane.js +0 -88
- package/dist/src/shapes/plane.js.map +0 -1
- package/dist/src/shapes/shape.js +0 -87
- package/dist/src/shapes/shape.js.map +0 -1
- package/dist/src/shapes/sphere.js +0 -114
- package/dist/src/shapes/sphere.js.map +0 -1
- package/dist/src/shapes/tetrahedron.js +0 -188
- package/dist/src/shapes/tetrahedron.js.map +0 -1
- package/dist/src/shapes/torus.js +0 -111
- package/dist/src/shapes/torus.js.map +0 -1
- package/dist/src/utility/aabbtree.js +0 -400
- package/dist/src/utility/aabbtree.js.map +0 -1
- package/dist/src/utility/bounding_volume.js +0 -29
- package/dist/src/utility/bounding_volume.js.map +0 -1
- package/dist/src/utility/debug.js +0 -28
- package/dist/src/utility/debug.js.map +0 -1
- package/dist/src/utility/draco/decoder.js +0 -116
- package/dist/src/utility/draco/decoder.js.map +0 -1
- package/dist/src/utility/misc.js +0 -105
- package/dist/src/utility/misc.js.map +0 -1
- package/dist/src/utility/panorama.js +0 -163
- package/dist/src/utility/panorama.js.map +0 -1
- package/dist/src/utility/pmrem.js +0 -354
- package/dist/src/utility/pmrem.js.map +0 -1
- package/dist/src/utility/rendermipmap.js +0 -115
- package/dist/src/utility/rendermipmap.js.map +0 -1
- package/dist/src/utility/serialization/json.js +0 -402
- package/dist/src/utility/serialization/json.js.map +0 -1
- package/dist/src/utility/serialization/manager.js +0 -623
- package/dist/src/utility/serialization/manager.js.map +0 -1
- package/dist/src/utility/serialization/scene/animation.js +0 -248
- package/dist/src/utility/serialization/scene/animation.js.map +0 -1
- package/dist/src/utility/serialization/scene/batch.js +0 -59
- package/dist/src/utility/serialization/scene/batch.js.map +0 -1
- package/dist/src/utility/serialization/scene/camera.js +0 -790
- package/dist/src/utility/serialization/scene/camera.js.map +0 -1
- package/dist/src/utility/serialization/scene/common.js +0 -222
- package/dist/src/utility/serialization/scene/common.js.map +0 -1
- package/dist/src/utility/serialization/scene/light.js +0 -575
- package/dist/src/utility/serialization/scene/light.js.map +0 -1
- package/dist/src/utility/serialization/scene/material.js +0 -1111
- package/dist/src/utility/serialization/scene/material.js.map +0 -1
- package/dist/src/utility/serialization/scene/mesh.js +0 -148
- package/dist/src/utility/serialization/scene/mesh.js.map +0 -1
- package/dist/src/utility/serialization/scene/misc.js +0 -39
- package/dist/src/utility/serialization/scene/misc.js.map +0 -1
- package/dist/src/utility/serialization/scene/node.js +0 -451
- package/dist/src/utility/serialization/scene/node.js.map +0 -1
- package/dist/src/utility/serialization/scene/particle.js +0 -425
- package/dist/src/utility/serialization/scene/particle.js.map +0 -1
- package/dist/src/utility/serialization/scene/primitive.js +0 -692
- package/dist/src/utility/serialization/scene/primitive.js.map +0 -1
- package/dist/src/utility/serialization/scene/scene.js +0 -704
- package/dist/src/utility/serialization/scene/scene.js.map +0 -1
- package/dist/src/utility/serialization/scene/terrain.js +0 -488
- package/dist/src/utility/serialization/scene/terrain.js.map +0 -1
- package/dist/src/utility/serialization/scene/water.js +0 -465
- package/dist/src/utility/serialization/scene/water.js.map +0 -1
- package/dist/src/utility/shprojector.js +0 -297
- package/dist/src/utility/shprojector.js.map +0 -1
- package/dist/src/utility/textures/ggxlut.js +0 -213
- package/dist/src/utility/textures/ggxlut.js.map +0 -1
- package/dist/src/utility/textures/gradientnoise.js +0 -62
- package/dist/src/utility/textures/gradientnoise.js.map +0 -1
- package/dist/src/utility/textures/randomnoise.js +0 -41
- package/dist/src/utility/textures/randomnoise.js.map +0 -1
- package/dist/src/values.js +0 -162
- package/dist/src/values.js.map +0 -1
- package/dist/utility/blueprint/material/common.js +0 -7
- package/dist/utility/blueprint/material/common.js.map +0 -1
- package/dist/utility/serialization/blueprint/constants.js +0 -255
- package/dist/utility/serialization/blueprint/constants.js.map +0 -1
- package/dist/utility/serialization/blueprint/material/constants.js +0 -203
- package/dist/utility/serialization/blueprint/material/constants.js.map +0 -1
- package/dist/utility/serialization/blueprint/material/texture.js +0 -165
- package/dist/utility/serialization/blueprint/material/texture.js.map +0 -1
- package/dist/utility/serialization/scene/cloth_script.js +0 -834
- package/dist/utility/serialization/scene/cloth_script.js.map +0 -1
- package/dist/utility/serialization/scene/spring_script.js +0 -596
- package/dist/utility/serialization/scene/spring_script.js.map +0 -1
|
@@ -1,1006 +0,0 @@
|
|
|
1
|
-
import { Disposable, Vector4, PRNG, Vector2 } from '@zephyr3d/base';
|
|
2
|
-
import { Primitive } from './primitive.js';
|
|
3
|
-
import { Application } from '../app/app.js';
|
|
4
|
-
import '@zephyr3d/device';
|
|
5
|
-
import { createProgramH0, createProgramHk, createProgramFFT2H, createProgramFFT2V, createProgramPostFFT2 } from '../shaders/water.js';
|
|
6
|
-
import '../shaders/atmosphere.js';
|
|
7
|
-
import { fetchSampler } from '../utility/misc.js';
|
|
8
|
-
|
|
9
|
-
function getDefaultBuildParams() {
|
|
10
|
-
return {
|
|
11
|
-
cascades: [
|
|
12
|
-
{
|
|
13
|
-
size: 400.0,
|
|
14
|
-
strength: 0.4,
|
|
15
|
-
croppiness: -1.5,
|
|
16
|
-
minWave: 0,
|
|
17
|
-
maxWave: 100
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
size: 100.0,
|
|
21
|
-
strength: 0.4,
|
|
22
|
-
croppiness: -1.2,
|
|
23
|
-
minWave: 0,
|
|
24
|
-
maxWave: 100
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
size: 15,
|
|
28
|
-
strength: 0.2,
|
|
29
|
-
croppiness: -0.5,
|
|
30
|
-
minWave: 0,
|
|
31
|
-
maxWave: 7
|
|
32
|
-
}
|
|
33
|
-
],
|
|
34
|
-
resolution: 256,
|
|
35
|
-
wind: new Vector2(2, 2),
|
|
36
|
-
alignment: 1,
|
|
37
|
-
foamParams: new Vector2(1.2, 7.2),
|
|
38
|
-
randomSeed: 0
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
const RENDER_NONE = 0;
|
|
42
|
-
const RENDER_NORMAL = 1;
|
|
43
|
-
const RENDER_TWO_PASS = 2;
|
|
44
|
-
const THREAD_GROUP_SIZE = 16;
|
|
45
|
-
/**
|
|
46
|
-
* This class generates a 2D ocean field using the Fast Fourier Transform (FFT) algorithm.
|
|
47
|
-
* @public
|
|
48
|
-
*/ class FFTWaveGenerator extends Disposable {
|
|
49
|
-
static _globals = null;
|
|
50
|
-
_useComputeShader;
|
|
51
|
-
_h0BindGroup;
|
|
52
|
-
_hkBindGroup;
|
|
53
|
-
_hkBindGroup2;
|
|
54
|
-
_hkBindGroup4;
|
|
55
|
-
_fft2hBindGroup;
|
|
56
|
-
_fft2vBindGroup;
|
|
57
|
-
_fft2hBindGroup2Used;
|
|
58
|
-
_fft2hBindGroup2Free;
|
|
59
|
-
_fft2hBindGroup4Used;
|
|
60
|
-
_fft2hBindGroup4Free;
|
|
61
|
-
_fft2vBindGroup2Used;
|
|
62
|
-
_fft2vBindGroup2Free;
|
|
63
|
-
_fft2vBindGroup4Used;
|
|
64
|
-
_fft2vBindGroup4Free;
|
|
65
|
-
_postfft2BindGroup;
|
|
66
|
-
_postfft2BindGroup2;
|
|
67
|
-
_postfft2BindGroup4;
|
|
68
|
-
_updateRenderStates;
|
|
69
|
-
_sizes;
|
|
70
|
-
_croppinesses;
|
|
71
|
-
_params;
|
|
72
|
-
_instanceData;
|
|
73
|
-
_ifftTextures;
|
|
74
|
-
_cascades;
|
|
75
|
-
_paramsChanged;
|
|
76
|
-
_version;
|
|
77
|
-
_resolutionChanged;
|
|
78
|
-
_textureFormat;
|
|
79
|
-
_h0TextureFormat;
|
|
80
|
-
_dataTextureFormat;
|
|
81
|
-
_renderMode;
|
|
82
|
-
/**
|
|
83
|
-
* Create a new instance of the FFTWaveGenerator class.
|
|
84
|
-
* @param params - Ocean field build parameters. If not provided, default parameters will be used.
|
|
85
|
-
*/ constructor(params){
|
|
86
|
-
super();
|
|
87
|
-
const device = Application.instance.device;
|
|
88
|
-
const renderTargetFloat16 = device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer;
|
|
89
|
-
const maxDrawBuffers = /*device.type !== 'webgl' && */ renderTargetFloat16 ? device.getDeviceCaps().framebufferCaps.maxDrawBuffers : 0;
|
|
90
|
-
this._textureFormat = 'rgba16f';
|
|
91
|
-
this._h0TextureFormat = 'rgba16f';
|
|
92
|
-
this._dataTextureFormat = 'rgba16f';
|
|
93
|
-
this._useComputeShader = device.type === 'webgpu';
|
|
94
|
-
const maxSampleBytes = device.getDeviceCaps().framebufferCaps.maxColorAttachmentBytesPerSample;
|
|
95
|
-
if (maxDrawBuffers === 0) {
|
|
96
|
-
this._renderMode = RENDER_NONE;
|
|
97
|
-
} else if (this._useComputeShader || maxSampleBytes >= 48) {
|
|
98
|
-
this._renderMode = RENDER_NORMAL;
|
|
99
|
-
} else {
|
|
100
|
-
this._renderMode = RENDER_TWO_PASS;
|
|
101
|
-
}
|
|
102
|
-
if (this._renderMode !== RENDER_NONE) {
|
|
103
|
-
FFTWaveGenerator._globals = FFTWaveGenerator._globals ?? {
|
|
104
|
-
programs: {
|
|
105
|
-
h0Program: createProgramH0(this._useComputeShader, THREAD_GROUP_SIZE, this._h0TextureFormat),
|
|
106
|
-
hkProgram: this._renderMode === RENDER_NORMAL ? createProgramHk(this._useComputeShader, THREAD_GROUP_SIZE, this._dataTextureFormat) : null,
|
|
107
|
-
hkProgram2: this._renderMode === RENDER_TWO_PASS ? createProgramHk(false, 0, null, 2) : null,
|
|
108
|
-
hkProgram4: this._renderMode === RENDER_TWO_PASS ? createProgramHk(false, 0, null, 4) : null,
|
|
109
|
-
fft2hProgram: this._renderMode === RENDER_NORMAL ? createProgramFFT2H(this._useComputeShader, THREAD_GROUP_SIZE, this._dataTextureFormat) : null,
|
|
110
|
-
fft2hProgram2: this._renderMode === RENDER_TWO_PASS ? createProgramFFT2H(false, 0, null, 2) : null,
|
|
111
|
-
fft2hProgram4: this._renderMode === RENDER_TWO_PASS ? createProgramFFT2H(false, 0, null, 4) : null,
|
|
112
|
-
fft2vProgram: this._renderMode === RENDER_NORMAL ? createProgramFFT2V(this._useComputeShader, THREAD_GROUP_SIZE, this._dataTextureFormat) : null,
|
|
113
|
-
fft2vProgram2: this._renderMode === RENDER_TWO_PASS ? createProgramFFT2V(false, 0, null, 2) : null,
|
|
114
|
-
fft2vProgram4: this._renderMode === RENDER_TWO_PASS ? createProgramFFT2V(false, 0, null, 4) : null,
|
|
115
|
-
postfft2Program: this._renderMode === RENDER_NORMAL ? createProgramPostFFT2(this._useComputeShader, THREAD_GROUP_SIZE, this._dataTextureFormat) : null,
|
|
116
|
-
postfft2Program2: this._renderMode === RENDER_TWO_PASS ? createProgramPostFFT2(false, 0, null, 2) : null,
|
|
117
|
-
postfft2Program4: this._renderMode === RENDER_TWO_PASS ? createProgramPostFFT2(false, 0, null, 4) : null
|
|
118
|
-
},
|
|
119
|
-
quad: FFTWaveGenerator.createQuad(),
|
|
120
|
-
noiseTextures: new Map(),
|
|
121
|
-
butterflyTextures: new Map()
|
|
122
|
-
};
|
|
123
|
-
this._params = params ?? getDefaultBuildParams();
|
|
124
|
-
const programs = FFTWaveGenerator._globals.programs;
|
|
125
|
-
this._h0BindGroup = device.createBindGroup(programs.h0Program.bindGroupLayouts[0]);
|
|
126
|
-
this._hkBindGroup = programs.hkProgram ? device.createBindGroup(FFTWaveGenerator._globals.programs.hkProgram.bindGroupLayouts[0]) : null;
|
|
127
|
-
this._hkBindGroup2 = programs.hkProgram2 ? device.createBindGroup(FFTWaveGenerator._globals.programs.hkProgram2.bindGroupLayouts[0]) : null;
|
|
128
|
-
this._hkBindGroup4 = programs.hkProgram4 ? device.createBindGroup(FFTWaveGenerator._globals.programs.hkProgram4.bindGroupLayouts[0]) : null;
|
|
129
|
-
this._fft2hBindGroup = programs.fft2hProgram ? device.createBindGroup(FFTWaveGenerator._globals.programs.fft2hProgram.bindGroupLayouts[0]) : null;
|
|
130
|
-
this._fft2vBindGroup = programs.fft2vProgram ? device.createBindGroup(FFTWaveGenerator._globals.programs.fft2vProgram.bindGroupLayouts[0]) : null;
|
|
131
|
-
this._fft2hBindGroup2Used = [
|
|
132
|
-
[],
|
|
133
|
-
[]
|
|
134
|
-
];
|
|
135
|
-
this._fft2hBindGroup2Free = [
|
|
136
|
-
[],
|
|
137
|
-
[]
|
|
138
|
-
];
|
|
139
|
-
this._fft2hBindGroup4Used = [
|
|
140
|
-
[],
|
|
141
|
-
[]
|
|
142
|
-
];
|
|
143
|
-
this._fft2hBindGroup4Free = [
|
|
144
|
-
[],
|
|
145
|
-
[]
|
|
146
|
-
];
|
|
147
|
-
this._fft2vBindGroup2Used = [
|
|
148
|
-
[],
|
|
149
|
-
[]
|
|
150
|
-
];
|
|
151
|
-
this._fft2vBindGroup2Free = [
|
|
152
|
-
[],
|
|
153
|
-
[]
|
|
154
|
-
];
|
|
155
|
-
this._fft2vBindGroup4Used = [
|
|
156
|
-
[],
|
|
157
|
-
[]
|
|
158
|
-
];
|
|
159
|
-
this._fft2vBindGroup4Free = [
|
|
160
|
-
[],
|
|
161
|
-
[]
|
|
162
|
-
];
|
|
163
|
-
this._postfft2BindGroup = programs.postfft2Program ? device.createBindGroup(FFTWaveGenerator._globals.programs.postfft2Program.bindGroupLayouts[0]) : null;
|
|
164
|
-
this._postfft2BindGroup2 = programs.postfft2Program2 ? device.createBindGroup(FFTWaveGenerator._globals.programs.postfft2Program2.bindGroupLayouts[0]) : null;
|
|
165
|
-
this._postfft2BindGroup4 = programs.postfft2Program4 ? device.createBindGroup(FFTWaveGenerator._globals.programs.postfft2Program4.bindGroupLayouts[0]) : null;
|
|
166
|
-
this._instanceData = null;
|
|
167
|
-
this._ifftTextures = null;
|
|
168
|
-
this._sizes = new Vector4();
|
|
169
|
-
this._croppinesses = new Vector4();
|
|
170
|
-
this._cascades = [
|
|
171
|
-
new Vector4(),
|
|
172
|
-
new Vector4(),
|
|
173
|
-
new Vector4(),
|
|
174
|
-
new Vector4()
|
|
175
|
-
];
|
|
176
|
-
this._updateRenderStates = Application.instance.device.createRenderStateSet();
|
|
177
|
-
this._updateRenderStates.useRasterizerState().setCullMode('none');
|
|
178
|
-
this._updateRenderStates.useDepthState().enableTest(false).enableWrite(false);
|
|
179
|
-
this._version = 0;
|
|
180
|
-
this.paramsChanged();
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
get version() {
|
|
184
|
-
return this._version;
|
|
185
|
-
}
|
|
186
|
-
clone() {
|
|
187
|
-
return new FFTWaveGenerator(this._params);
|
|
188
|
-
}
|
|
189
|
-
/*
|
|
190
|
-
get params() {
|
|
191
|
-
return this._params;
|
|
192
|
-
}
|
|
193
|
-
set params(val: OceanFieldBuildParams) {
|
|
194
|
-
if (val && val !== this._params) {
|
|
195
|
-
this._params = val;
|
|
196
|
-
this.paramsChanged();
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
*/ paramsChanged() {
|
|
200
|
-
this._paramsChanged = true;
|
|
201
|
-
this._version++;
|
|
202
|
-
}
|
|
203
|
-
/** Gets the wave alighment */ get alignment() {
|
|
204
|
-
return this._params.alignment;
|
|
205
|
-
}
|
|
206
|
-
set alignment(val) {
|
|
207
|
-
if (this._params.alignment !== val) {
|
|
208
|
-
this._params.alignment = val;
|
|
209
|
-
this.paramsChanged();
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
/** Gets the wind vector */ get wind() {
|
|
213
|
-
return this._params.wind;
|
|
214
|
-
}
|
|
215
|
-
set wind(val) {
|
|
216
|
-
if (val !== this._params.wind && (val.x !== this._params.wind.x || val.y !== this._params.wind.y)) {
|
|
217
|
-
this._params.wind.x = val.x;
|
|
218
|
-
this._params.wind.y = val.y;
|
|
219
|
-
this.paramsChanged();
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
/** Gets the foam width */ get foamWidth() {
|
|
223
|
-
return this._params.foamParams.x;
|
|
224
|
-
}
|
|
225
|
-
set foamWidth(val) {
|
|
226
|
-
if (val !== this._params.foamParams.x) {
|
|
227
|
-
this._params.foamParams.x = val;
|
|
228
|
-
this.paramsChanged();
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
/** Gets the foam contrast */ get foamContrast() {
|
|
232
|
-
return this._params.foamParams.y;
|
|
233
|
-
}
|
|
234
|
-
set foamContrast(val) {
|
|
235
|
-
if (val !== this._params.foamParams.y) {
|
|
236
|
-
this._params.foamParams.y = val;
|
|
237
|
-
this.paramsChanged();
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
/** Gets the wave length for the specified cascade */ getWaveLength(cascade) {
|
|
241
|
-
return this._params.cascades[cascade].size;
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Sets the wave length for the specified cascade
|
|
245
|
-
* @param cascade - The cascade index
|
|
246
|
-
* @param length - The new wave length for the specified cascade
|
|
247
|
-
*/ setWaveLength(cascade, length) {
|
|
248
|
-
if (this._params.cascades[cascade].size !== length) {
|
|
249
|
-
this._params.cascades[cascade].size = length;
|
|
250
|
-
this.paramsChanged();
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
/** Gets the wave strength for the specified cascade */ getWaveStrength(cascade) {
|
|
254
|
-
return this._params.cascades[cascade].strength;
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Sets the wave strength for the specified cascade
|
|
258
|
-
* @param cascade - The cascade index
|
|
259
|
-
* @param strength - The new wave strength for the specified cascade
|
|
260
|
-
*/ setWaveStrength(cascade, strength) {
|
|
261
|
-
if (this._params.cascades[cascade].strength !== strength) {
|
|
262
|
-
this._params.cascades[cascade].strength = strength;
|
|
263
|
-
this.paramsChanged();
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
/** Gets the wave croppiness for the specified cascade */ getWaveCroppiness(cascade) {
|
|
267
|
-
return this._params.cascades[cascade].croppiness;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Sets the wave croppiness for the specified cascade
|
|
271
|
-
* @param cascade - The cascade index
|
|
272
|
-
* @param croppiness - The new wave croppiness for the specified cascade
|
|
273
|
-
*/ setWaveCroppiness(cascade, croppiness) {
|
|
274
|
-
if (this._params.cascades[cascade].croppiness !== croppiness) {
|
|
275
|
-
this._params.cascades[cascade].croppiness = croppiness;
|
|
276
|
-
this.paramsChanged();
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
/** @internal */ static createQuad() {
|
|
280
|
-
const vertexData = new Float32Array([
|
|
281
|
-
-1,
|
|
282
|
-
-1,
|
|
283
|
-
0,
|
|
284
|
-
0.0,
|
|
285
|
-
0.0,
|
|
286
|
-
1,
|
|
287
|
-
-1,
|
|
288
|
-
0,
|
|
289
|
-
1.0,
|
|
290
|
-
0.0,
|
|
291
|
-
1,
|
|
292
|
-
1,
|
|
293
|
-
0,
|
|
294
|
-
1.0,
|
|
295
|
-
1.0,
|
|
296
|
-
-1,
|
|
297
|
-
1,
|
|
298
|
-
0,
|
|
299
|
-
0.0,
|
|
300
|
-
1.0
|
|
301
|
-
]);
|
|
302
|
-
const indexData = new Uint32Array([
|
|
303
|
-
0,
|
|
304
|
-
1,
|
|
305
|
-
2,
|
|
306
|
-
0,
|
|
307
|
-
2,
|
|
308
|
-
3
|
|
309
|
-
]);
|
|
310
|
-
const prim = new Primitive();
|
|
311
|
-
prim.createAndSetVertexBuffer([
|
|
312
|
-
'position_f32x3',
|
|
313
|
-
'tex0_f32x2'
|
|
314
|
-
], vertexData);
|
|
315
|
-
prim.createAndSetIndexBuffer(indexData);
|
|
316
|
-
prim.primitiveType = 'triangle-list';
|
|
317
|
-
prim.indexStart = 0;
|
|
318
|
-
prim.indexCount = indexData.length;
|
|
319
|
-
return prim;
|
|
320
|
-
}
|
|
321
|
-
/** @internal */ getButterflyTexture(size) {
|
|
322
|
-
const device = Application.instance.device;
|
|
323
|
-
let tex = FFTWaveGenerator._globals.butterflyTextures.get(size);
|
|
324
|
-
if (!tex) {
|
|
325
|
-
tex = device.createTexture2D('rgba32f', Math.log2(size), size, {
|
|
326
|
-
samplerOptions: {
|
|
327
|
-
mipFilter: 'none'
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
tex.name = `butterfly${size}`;
|
|
331
|
-
tex.update(this.createButterflyTexture(size), 0, 0, tex.width, tex.height);
|
|
332
|
-
FFTWaveGenerator._globals.butterflyTextures.set(size, tex);
|
|
333
|
-
}
|
|
334
|
-
return tex;
|
|
335
|
-
}
|
|
336
|
-
/** @internal */ generateInitialSpectrum() {
|
|
337
|
-
const device = Application.instance.device;
|
|
338
|
-
const instanceData = this.getInstanceData();
|
|
339
|
-
device.setProgram(FFTWaveGenerator._globals.programs.h0Program);
|
|
340
|
-
device.setBindGroup(0, this._h0BindGroup);
|
|
341
|
-
this._h0BindGroup.setTexture('noise', this.getNoiseTexture(this._params.resolution, this._params.randomSeed), fetchSampler('repeat_nearest_nomip'));
|
|
342
|
-
this._h0BindGroup.setValue('resolution', this._params.resolution);
|
|
343
|
-
this._h0BindGroup.setValue('wind', this._params.wind);
|
|
344
|
-
this._h0BindGroup.setValue('alignment', this._params.alignment);
|
|
345
|
-
for(let i = 0; i < this._params.cascades.length; i++){
|
|
346
|
-
this._cascades[i].x = this._params.cascades[i].size;
|
|
347
|
-
this._cascades[i].y = this._params.cascades[i].strength * 0.081 / (this._params.cascades[i].size * this._params.cascades[i].size);
|
|
348
|
-
this._cascades[i].z = 2 * Math.PI / this._params.cascades[i].maxWave;
|
|
349
|
-
this._cascades[i].w = 2 * Math.PI / this._params.cascades[i].minWave;
|
|
350
|
-
}
|
|
351
|
-
this._h0BindGroup.setValue('cascade0', this._cascades[0]);
|
|
352
|
-
this._h0BindGroup.setValue('cascade1', this._cascades[1]);
|
|
353
|
-
this._h0BindGroup.setValue('cascade2', this._cascades[2]);
|
|
354
|
-
if (device.type === 'webgpu') {
|
|
355
|
-
this._h0BindGroup.setTexture('spectrum', instanceData.h0Textures);
|
|
356
|
-
device.compute(this._params.resolution / THREAD_GROUP_SIZE, this._params.resolution / THREAD_GROUP_SIZE, 1);
|
|
357
|
-
} else {
|
|
358
|
-
device.setFramebuffer(instanceData.h0Framebuffer);
|
|
359
|
-
device.clearFrameBuffer(Vector4.zero(), null, null);
|
|
360
|
-
FFTWaveGenerator._globals.quad.draw();
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
/** @internal */ getNoiseTexture(size, randomSeed) {
|
|
364
|
-
const device = Application.instance.device;
|
|
365
|
-
let tex = FFTWaveGenerator._globals.noiseTextures.get(size);
|
|
366
|
-
if (!tex) {
|
|
367
|
-
tex = device.createTexture2D(device.type === 'webgl' ? 'rgba32f' : 'rg32f', size, size, {
|
|
368
|
-
samplerOptions: {
|
|
369
|
-
mipFilter: 'none'
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
tex.name = `noiseTex${size}`;
|
|
373
|
-
tex.update(this.getNoise2d(size, randomSeed, device.type === 'webgl'), 0, 0, size, size);
|
|
374
|
-
FFTWaveGenerator._globals.noiseTextures.set(size, tex);
|
|
375
|
-
}
|
|
376
|
-
return tex;
|
|
377
|
-
}
|
|
378
|
-
/** @internal */ getNoise2d(size, randomSeed, rgba) {
|
|
379
|
-
const rand = new PRNG(randomSeed);
|
|
380
|
-
if (rgba) {
|
|
381
|
-
const array = new Float32Array(size * size * 4);
|
|
382
|
-
for(let i = 0; i < size * size; i++){
|
|
383
|
-
array[i * 4 + 0] = rand.get();
|
|
384
|
-
array[i * 4 + 1] = rand.get();
|
|
385
|
-
}
|
|
386
|
-
return array;
|
|
387
|
-
} else {
|
|
388
|
-
return Float32Array.from([
|
|
389
|
-
...Array(size * size * 2)
|
|
390
|
-
].map(()=>rand.get()));
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
/** @internal */ reverseBits(v, width) {
|
|
394
|
-
return parseInt(v.toString(2).padStart(width, '0').split('').reverse().join(''), 2);
|
|
395
|
-
}
|
|
396
|
-
/** @internal */ createButterflyTexture(size) {
|
|
397
|
-
const width = Math.log2(size);
|
|
398
|
-
const height = size;
|
|
399
|
-
const texture = new Float32Array(width * height * 4);
|
|
400
|
-
const w = 2.0 * Math.PI / size;
|
|
401
|
-
const bitReversed = [
|
|
402
|
-
...Array(size).keys()
|
|
403
|
-
].map((v)=>this.reverseBits(v, width));
|
|
404
|
-
for(let j = 0; j < width; j++){
|
|
405
|
-
for(let i = 0; i < height; i++){
|
|
406
|
-
const k = i * (size >> j + 1);
|
|
407
|
-
const c = Math.cos(k * w);
|
|
408
|
-
const s = Math.sin(k * w);
|
|
409
|
-
const span = 2 ** j;
|
|
410
|
-
const wing = i % 2 ** (j + 1) < span ? 0 : 1; // 0 - top wing, 1 - bottom wing
|
|
411
|
-
const texel = new Vector4();
|
|
412
|
-
if (j === 0) {
|
|
413
|
-
if (wing === 0) {
|
|
414
|
-
texel.setXYZW(c, s, bitReversed[i], bitReversed[i + 1]);
|
|
415
|
-
} else {
|
|
416
|
-
texel.setXYZW(c, s, bitReversed[i - 1], bitReversed[i]);
|
|
417
|
-
}
|
|
418
|
-
} else {
|
|
419
|
-
if (wing === 0) {
|
|
420
|
-
texel.setXYZW(c, s, i, i + span);
|
|
421
|
-
} else {
|
|
422
|
-
texel.setXYZW(c, s, i - span, i);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
texture[(width * i + j) * 4] = texel[0];
|
|
426
|
-
texture[(width * i + j) * 4 + 1] = texel[1];
|
|
427
|
-
texture[(width * i + j) * 4 + 2] = texel[2];
|
|
428
|
-
texture[(width * i + j) * 4 + 3] = texel[3];
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
return texture;
|
|
432
|
-
}
|
|
433
|
-
/** @internal */ getInstanceData() {
|
|
434
|
-
if (!this._instanceData) {
|
|
435
|
-
const device = Application.instance.device;
|
|
436
|
-
const h0Textures = this.createNTextures(device, this._h0TextureFormat, this._params.resolution, 3, 'Water-h0', false);
|
|
437
|
-
const dataTextures = this.createNTextures(device, this._dataTextureFormat, this._params.resolution, 6, 'Water-data', true);
|
|
438
|
-
const spectrumTextures = this.createNTextures(device, this._textureFormat, this._params.resolution, 6, 'Water-spectrum', true);
|
|
439
|
-
const pingpongTextures = this.createNTextures(device, this._textureFormat, this._params.resolution, 6, 'Water-pingpong', false);
|
|
440
|
-
this._instanceData = {
|
|
441
|
-
dataTextures,
|
|
442
|
-
h0Textures: h0Textures,
|
|
443
|
-
pingpongTextures: pingpongTextures,
|
|
444
|
-
spectrumTextures: spectrumTextures,
|
|
445
|
-
h0Framebuffer: this._useComputeShader ? null : device.createFrameBuffer(h0Textures, null),
|
|
446
|
-
spectrumFramebuffer: !this._useComputeShader && this._renderMode === RENDER_NORMAL ? device.createFrameBuffer(spectrumTextures, null) : null,
|
|
447
|
-
spectrumFramebuffer2: this._renderMode === RENDER_TWO_PASS ? device.createFrameBuffer(spectrumTextures.slice(4, 6), null) : null,
|
|
448
|
-
spectrumFramebuffer4: this._renderMode === RENDER_TWO_PASS ? device.createFrameBuffer(spectrumTextures.slice(0, 4), null) : null,
|
|
449
|
-
pingpongFramebuffer: !this._useComputeShader && this._renderMode === RENDER_NORMAL ? device.createFrameBuffer(pingpongTextures, null) : null,
|
|
450
|
-
pingpongFramebuffer2: this._renderMode === RENDER_TWO_PASS ? device.createFrameBuffer(pingpongTextures.slice(4, 6), null) : null,
|
|
451
|
-
pingpongFramebuffer4: this._renderMode === RENDER_TWO_PASS ? device.createFrameBuffer(pingpongTextures.slice(0, 4), null) : null,
|
|
452
|
-
postIfft2Framebuffer: !this._useComputeShader && this._renderMode === RENDER_NORMAL ? device.createFrameBuffer(dataTextures, null) : null,
|
|
453
|
-
postIfft2Framebuffer2: this._renderMode === RENDER_TWO_PASS ? device.createFrameBuffer(dataTextures.slice(4, 6), null) : null,
|
|
454
|
-
postIfft2Framebuffer4: this._renderMode === RENDER_TWO_PASS ? device.createFrameBuffer(dataTextures.slice(0, 4), null) : null
|
|
455
|
-
};
|
|
456
|
-
}
|
|
457
|
-
return this._instanceData;
|
|
458
|
-
}
|
|
459
|
-
/** @internal */ createNTextures(device, format, size, num, name, linear) {
|
|
460
|
-
const options = {
|
|
461
|
-
samplerOptions: {
|
|
462
|
-
minFilter: linear ? 'linear' : 'nearest',
|
|
463
|
-
magFilter: linear ? 'linear' : 'nearest',
|
|
464
|
-
mipFilter: 'none',
|
|
465
|
-
addressU: 'repeat',
|
|
466
|
-
addressV: 'repeat'
|
|
467
|
-
},
|
|
468
|
-
writable: !!this._useComputeShader
|
|
469
|
-
};
|
|
470
|
-
if (this._useComputeShader) {
|
|
471
|
-
const tex = device.createTexture2DArray(format, size, size, num, options);
|
|
472
|
-
tex.name = name;
|
|
473
|
-
return tex;
|
|
474
|
-
} else {
|
|
475
|
-
return Array.from({
|
|
476
|
-
length: num
|
|
477
|
-
}).map((val, index)=>{
|
|
478
|
-
const tex = device.createTexture2D(format, size, size, options);
|
|
479
|
-
tex.name = `${name}-${index}`;
|
|
480
|
-
return tex;
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
/** {@inheritDoc WaveGenerator.update} */ update(time) {
|
|
485
|
-
const device = Application.instance.device;
|
|
486
|
-
device.pushDeviceStates();
|
|
487
|
-
device.setRenderStates(this._updateRenderStates);
|
|
488
|
-
if (this._resolutionChanged) {
|
|
489
|
-
this.disposeInstanceData();
|
|
490
|
-
}
|
|
491
|
-
if (this._paramsChanged) {
|
|
492
|
-
this.generateInitialSpectrum();
|
|
493
|
-
}
|
|
494
|
-
this._resolutionChanged = false;
|
|
495
|
-
this._paramsChanged = false;
|
|
496
|
-
for(let i = 0; i < 3; i++){
|
|
497
|
-
this._sizes[i] = this._params.cascades[i].size;
|
|
498
|
-
this._croppinesses[i] = this._params.cascades[i].croppiness;
|
|
499
|
-
}
|
|
500
|
-
if (this._renderMode === RENDER_NORMAL) {
|
|
501
|
-
this.generateSpectrum(time);
|
|
502
|
-
this.ifft2();
|
|
503
|
-
this.postIfft2();
|
|
504
|
-
} else {
|
|
505
|
-
this.generateSpectrumTwoPass(time);
|
|
506
|
-
this.ifft2TwoPass();
|
|
507
|
-
this.postIfft2TwoPass();
|
|
508
|
-
}
|
|
509
|
-
device.popDeviceStates();
|
|
510
|
-
}
|
|
511
|
-
/** {@inheritDoc WaveGenerator.needUpdate} */ needUpdate() {
|
|
512
|
-
return true;
|
|
513
|
-
}
|
|
514
|
-
/** @internal */ disposeNTextures(texture) {
|
|
515
|
-
if (Array.isArray(texture)) {
|
|
516
|
-
texture.forEach((tex)=>tex.dispose());
|
|
517
|
-
} else if (texture) {
|
|
518
|
-
texture.dispose();
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
/** @internal */ disposeInstanceData() {
|
|
522
|
-
if (this._instanceData) {
|
|
523
|
-
this.disposeNTextures(this._instanceData.dataTextures);
|
|
524
|
-
this._instanceData.dataTextures = null;
|
|
525
|
-
this.disposeNTextures(this._instanceData.h0Textures);
|
|
526
|
-
this._instanceData.h0Textures = null;
|
|
527
|
-
this.disposeNTextures(this._instanceData.pingpongTextures);
|
|
528
|
-
this._instanceData.pingpongTextures = null;
|
|
529
|
-
this.disposeNTextures(this._instanceData.spectrumTextures);
|
|
530
|
-
this._instanceData.spectrumTextures = null;
|
|
531
|
-
this._instanceData.h0Framebuffer?.dispose();
|
|
532
|
-
this._instanceData.pingpongFramebuffer?.dispose();
|
|
533
|
-
this._instanceData.pingpongFramebuffer2?.dispose();
|
|
534
|
-
this._instanceData.pingpongFramebuffer4?.dispose();
|
|
535
|
-
this._instanceData.spectrumFramebuffer?.dispose();
|
|
536
|
-
this._instanceData.spectrumFramebuffer2?.dispose();
|
|
537
|
-
this._instanceData.spectrumFramebuffer4?.dispose();
|
|
538
|
-
this._instanceData.postIfft2Framebuffer?.dispose();
|
|
539
|
-
this._instanceData.postIfft2Framebuffer2?.dispose();
|
|
540
|
-
this._instanceData.postIfft2Framebuffer4?.dispose();
|
|
541
|
-
this._instanceData = null;
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
/** @internal */ generateSpectrum(time) {
|
|
545
|
-
const device = Application.instance.device;
|
|
546
|
-
const instanceData = this.getInstanceData();
|
|
547
|
-
const nearestRepeatSampler = fetchSampler('repeat_nearest_nomip');
|
|
548
|
-
device.setProgram(FFTWaveGenerator._globals.programs.hkProgram);
|
|
549
|
-
device.setBindGroup(0, this._hkBindGroup);
|
|
550
|
-
this._hkBindGroup.setValue('t', time);
|
|
551
|
-
this._hkBindGroup.setValue('resolution', this._params.resolution);
|
|
552
|
-
this._hkBindGroup.setValue('sizes', this._sizes);
|
|
553
|
-
if (this._useComputeShader) {
|
|
554
|
-
this._hkBindGroup.setTexture('h0Texture', instanceData.h0Textures);
|
|
555
|
-
this._hkBindGroup.setTexture('spectrum', instanceData.spectrumTextures);
|
|
556
|
-
device.compute(this._params.resolution / THREAD_GROUP_SIZE, this._params.resolution / THREAD_GROUP_SIZE, 1);
|
|
557
|
-
} else {
|
|
558
|
-
this._hkBindGroup.setTexture('h0Texture0', instanceData.h0Textures[0], nearestRepeatSampler);
|
|
559
|
-
this._hkBindGroup.setTexture('h0Texture1', instanceData.h0Textures[1], nearestRepeatSampler);
|
|
560
|
-
this._hkBindGroup.setTexture('h0Texture2', instanceData.h0Textures[2], nearestRepeatSampler);
|
|
561
|
-
if (device.type === 'webgl') {
|
|
562
|
-
this._hkBindGroup.setValue('h0TexSize', new Vector2(instanceData.h0Textures[0].width, instanceData.h0Textures[0].height));
|
|
563
|
-
}
|
|
564
|
-
device.setFramebuffer(instanceData.spectrumFramebuffer);
|
|
565
|
-
FFTWaveGenerator._globals.quad.draw();
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
/** @internal */ generateSpectrumTwoPass(time) {
|
|
569
|
-
const device = Application.instance.device;
|
|
570
|
-
const instanceData = this.getInstanceData();
|
|
571
|
-
const nearestRepeatSampler = fetchSampler('repeat_nearest_nomip');
|
|
572
|
-
device.setProgram(FFTWaveGenerator._globals.programs.hkProgram4);
|
|
573
|
-
device.setBindGroup(0, this._hkBindGroup4);
|
|
574
|
-
this._hkBindGroup4.setValue('resolution', this._params.resolution);
|
|
575
|
-
this._hkBindGroup4.setValue('sizes', this._sizes);
|
|
576
|
-
this._hkBindGroup4.setTexture('h0Texture0', instanceData.h0Textures[0], nearestRepeatSampler);
|
|
577
|
-
this._hkBindGroup4.setTexture('h0Texture1', instanceData.h0Textures[1], nearestRepeatSampler);
|
|
578
|
-
this._hkBindGroup4.setValue('t', time);
|
|
579
|
-
if (device.type === 'webgl') {
|
|
580
|
-
this._hkBindGroup4.setValue('h0TexSize', new Vector2(instanceData.h0Textures[0].width, instanceData.h0Textures[0].height));
|
|
581
|
-
}
|
|
582
|
-
device.setFramebuffer(instanceData.spectrumFramebuffer4);
|
|
583
|
-
FFTWaveGenerator._globals.quad.draw();
|
|
584
|
-
device.setProgram(FFTWaveGenerator._globals.programs.hkProgram2);
|
|
585
|
-
device.setBindGroup(0, this._hkBindGroup2);
|
|
586
|
-
this._hkBindGroup2.setValue('resolution', this._params.resolution);
|
|
587
|
-
this._hkBindGroup2.setValue('sizes', this._sizes);
|
|
588
|
-
this._hkBindGroup2.setTexture('h0Texture2', instanceData.h0Textures[2], nearestRepeatSampler);
|
|
589
|
-
this._hkBindGroup2.setValue('t', time);
|
|
590
|
-
if (device.type === 'webgl') {
|
|
591
|
-
this._hkBindGroup2.setValue('h0TexSize', new Vector2(instanceData.h0Textures[0].width, instanceData.h0Textures[0].height));
|
|
592
|
-
}
|
|
593
|
-
device.setFramebuffer(instanceData.spectrumFramebuffer2);
|
|
594
|
-
FFTWaveGenerator._globals.quad.draw();
|
|
595
|
-
}
|
|
596
|
-
/** @internal */ ifft2() {
|
|
597
|
-
const device = Application.instance.device;
|
|
598
|
-
const instanceData = this.getInstanceData();
|
|
599
|
-
const nearestRepeatSampler = fetchSampler('repeat_nearest_nomip');
|
|
600
|
-
const phases = Math.log2(this._params.resolution);
|
|
601
|
-
const pingPongTextures = [
|
|
602
|
-
instanceData.spectrumTextures,
|
|
603
|
-
instanceData.pingpongTextures
|
|
604
|
-
];
|
|
605
|
-
const pingPongFramebuffers = this._useComputeShader ? [
|
|
606
|
-
instanceData.pingpongTextures,
|
|
607
|
-
instanceData.spectrumTextures
|
|
608
|
-
] : [
|
|
609
|
-
instanceData.pingpongFramebuffer,
|
|
610
|
-
instanceData.spectrumFramebuffer
|
|
611
|
-
];
|
|
612
|
-
const butterflyTex = this.getButterflyTexture(this._params.resolution);
|
|
613
|
-
let pingPong = 0;
|
|
614
|
-
// horizontal ifft
|
|
615
|
-
device.setProgram(FFTWaveGenerator._globals.programs.fft2hProgram);
|
|
616
|
-
device.setBindGroup(0, this._fft2hBindGroup);
|
|
617
|
-
this._fft2hBindGroup.setTexture('butterfly', butterflyTex, nearestRepeatSampler);
|
|
618
|
-
for(let phase = 0; phase < phases; phase++){
|
|
619
|
-
this._fft2hBindGroup.setValue('phase', phase);
|
|
620
|
-
if (this._useComputeShader) {
|
|
621
|
-
this._fft2hBindGroup.setTexture('spectrum', pingPongTextures[pingPong], nearestRepeatSampler);
|
|
622
|
-
this._fft2hBindGroup.setTexture('ifft', pingPongFramebuffers[pingPong]);
|
|
623
|
-
device.compute(this._params.resolution / THREAD_GROUP_SIZE, this._params.resolution / THREAD_GROUP_SIZE, 1);
|
|
624
|
-
} else {
|
|
625
|
-
device.setFramebuffer(pingPongFramebuffers[pingPong]);
|
|
626
|
-
this._fft2hBindGroup.setTexture('spectrum0', pingPongTextures[pingPong][0], nearestRepeatSampler);
|
|
627
|
-
this._fft2hBindGroup.setTexture('spectrum1', pingPongTextures[pingPong][1], nearestRepeatSampler);
|
|
628
|
-
this._fft2hBindGroup.setTexture('spectrum2', pingPongTextures[pingPong][2], nearestRepeatSampler);
|
|
629
|
-
this._fft2hBindGroup.setTexture('spectrum3', pingPongTextures[pingPong][3], nearestRepeatSampler);
|
|
630
|
-
this._fft2hBindGroup.setTexture('spectrum4', pingPongTextures[pingPong][4], nearestRepeatSampler);
|
|
631
|
-
this._fft2hBindGroup.setTexture('spectrum5', pingPongTextures[pingPong][5], nearestRepeatSampler);
|
|
632
|
-
if (device.type === 'webgl') {
|
|
633
|
-
this._fft2hBindGroup.setValue('texSize', new Vector4(pingPongTextures[pingPong][0].width, pingPongTextures[pingPong][0].height, butterflyTex.width, butterflyTex.height));
|
|
634
|
-
}
|
|
635
|
-
FFTWaveGenerator._globals.quad.draw();
|
|
636
|
-
}
|
|
637
|
-
pingPong = 1 - pingPong; //(pingPong + 1) % 2;
|
|
638
|
-
}
|
|
639
|
-
// vertical ifft
|
|
640
|
-
device.setProgram(FFTWaveGenerator._globals.programs.fft2vProgram);
|
|
641
|
-
device.setBindGroup(0, this._fft2vBindGroup);
|
|
642
|
-
this._fft2vBindGroup.setTexture('butterfly', butterflyTex, nearestRepeatSampler);
|
|
643
|
-
for(let phase = 0; phase < phases; phase++){
|
|
644
|
-
this._fft2vBindGroup.setValue('phase', phase);
|
|
645
|
-
if (this._useComputeShader) {
|
|
646
|
-
this._fft2vBindGroup.setTexture('spectrum', pingPongTextures[pingPong], nearestRepeatSampler);
|
|
647
|
-
this._fft2vBindGroup.setTexture('ifft', pingPongFramebuffers[pingPong]);
|
|
648
|
-
device.compute(this._params.resolution / THREAD_GROUP_SIZE, this._params.resolution / THREAD_GROUP_SIZE, 1);
|
|
649
|
-
} else {
|
|
650
|
-
device.setFramebuffer(pingPongFramebuffers[pingPong]);
|
|
651
|
-
this._fft2vBindGroup.setTexture('spectrum0', pingPongTextures[pingPong][0], nearestRepeatSampler);
|
|
652
|
-
this._fft2vBindGroup.setTexture('spectrum1', pingPongTextures[pingPong][1], nearestRepeatSampler);
|
|
653
|
-
this._fft2vBindGroup.setTexture('spectrum2', pingPongTextures[pingPong][2], nearestRepeatSampler);
|
|
654
|
-
this._fft2vBindGroup.setTexture('spectrum3', pingPongTextures[pingPong][3], nearestRepeatSampler);
|
|
655
|
-
this._fft2vBindGroup.setTexture('spectrum4', pingPongTextures[pingPong][4], nearestRepeatSampler);
|
|
656
|
-
this._fft2vBindGroup.setTexture('spectrum5', pingPongTextures[pingPong][5], nearestRepeatSampler);
|
|
657
|
-
if (device.type === 'webgl') {
|
|
658
|
-
this._fft2vBindGroup.setValue('texSize', new Vector4(pingPongTextures[pingPong][0].width, pingPongTextures[pingPong][0].height, butterflyTex.width, butterflyTex.height));
|
|
659
|
-
}
|
|
660
|
-
FFTWaveGenerator._globals.quad.draw();
|
|
661
|
-
}
|
|
662
|
-
pingPong = 1 - pingPong;
|
|
663
|
-
}
|
|
664
|
-
this._ifftTextures = pingPongTextures[pingPong];
|
|
665
|
-
}
|
|
666
|
-
/** @internal */ getFFT2hBindGroup2(device, pingpong) {
|
|
667
|
-
let bindGroup = this._fft2hBindGroup2Used[pingpong].pop();
|
|
668
|
-
if (!bindGroup) {
|
|
669
|
-
bindGroup = device.createBindGroup(FFTWaveGenerator._globals.programs.fft2hProgram2.bindGroupLayouts[0]);
|
|
670
|
-
}
|
|
671
|
-
this._fft2hBindGroup2Free[pingpong].push(bindGroup);
|
|
672
|
-
return bindGroup;
|
|
673
|
-
}
|
|
674
|
-
/** @internal */ getFFT2hBindGroup4(device, pingpong) {
|
|
675
|
-
let bindGroup = this._fft2hBindGroup4Used[pingpong].pop();
|
|
676
|
-
if (!bindGroup) {
|
|
677
|
-
bindGroup = device.createBindGroup(FFTWaveGenerator._globals.programs.fft2hProgram4.bindGroupLayouts[0]);
|
|
678
|
-
}
|
|
679
|
-
this._fft2hBindGroup4Free[pingpong].push(bindGroup);
|
|
680
|
-
return bindGroup;
|
|
681
|
-
}
|
|
682
|
-
/** @internal */ getFFT2vBindGroup2(device, pingpong) {
|
|
683
|
-
let bindGroup = this._fft2vBindGroup2Used[pingpong].pop();
|
|
684
|
-
if (!bindGroup) {
|
|
685
|
-
bindGroup = device.createBindGroup(FFTWaveGenerator._globals.programs.fft2vProgram2.bindGroupLayouts[0]);
|
|
686
|
-
}
|
|
687
|
-
this._fft2vBindGroup2Free[pingpong].push(bindGroup);
|
|
688
|
-
return bindGroup;
|
|
689
|
-
}
|
|
690
|
-
/** @internal */ getFFT2vBindGroup4(device, pingpong) {
|
|
691
|
-
let bindGroup = this._fft2vBindGroup4Used[pingpong].pop();
|
|
692
|
-
if (!bindGroup) {
|
|
693
|
-
bindGroup = device.createBindGroup(FFTWaveGenerator._globals.programs.fft2vProgram4.bindGroupLayouts[0]);
|
|
694
|
-
}
|
|
695
|
-
this._fft2vBindGroup4Free[pingpong].push(bindGroup);
|
|
696
|
-
return bindGroup;
|
|
697
|
-
}
|
|
698
|
-
/** @internal */ ifft2TwoPass() {
|
|
699
|
-
const device = Application.instance.device;
|
|
700
|
-
const instanceData = this.getInstanceData();
|
|
701
|
-
const nearestRepeatSampler = fetchSampler('repeat_nearest_nomip');
|
|
702
|
-
const phases = Math.log2(this._params.resolution);
|
|
703
|
-
const pingPongTextures = [
|
|
704
|
-
instanceData.spectrumTextures,
|
|
705
|
-
instanceData.pingpongTextures
|
|
706
|
-
];
|
|
707
|
-
const pingPongFramebuffers4 = [
|
|
708
|
-
instanceData.pingpongFramebuffer4,
|
|
709
|
-
instanceData.spectrumFramebuffer4
|
|
710
|
-
];
|
|
711
|
-
const pingPongFramebuffers2 = [
|
|
712
|
-
instanceData.pingpongFramebuffer2,
|
|
713
|
-
instanceData.spectrumFramebuffer2
|
|
714
|
-
];
|
|
715
|
-
const butterflyTex = this.getButterflyTexture(this._params.resolution);
|
|
716
|
-
// horizontal ifft
|
|
717
|
-
let pingPong = 0;
|
|
718
|
-
for(let phase = 0; phase < phases; phase++){
|
|
719
|
-
device.setFramebuffer(pingPongFramebuffers4[pingPong]);
|
|
720
|
-
device.setProgram(FFTWaveGenerator._globals.programs.fft2hProgram4);
|
|
721
|
-
const fft2hBindGroup4 = this.getFFT2hBindGroup4(device, pingPong);
|
|
722
|
-
device.setBindGroup(0, fft2hBindGroup4);
|
|
723
|
-
fft2hBindGroup4.setTexture('butterfly', butterflyTex, nearestRepeatSampler);
|
|
724
|
-
fft2hBindGroup4.setValue('phase', phase);
|
|
725
|
-
fft2hBindGroup4.setTexture('spectrum0', pingPongTextures[pingPong][0], nearestRepeatSampler);
|
|
726
|
-
fft2hBindGroup4.setTexture('spectrum1', pingPongTextures[pingPong][1], nearestRepeatSampler);
|
|
727
|
-
fft2hBindGroup4.setTexture('spectrum2', pingPongTextures[pingPong][2], nearestRepeatSampler);
|
|
728
|
-
fft2hBindGroup4.setTexture('spectrum3', pingPongTextures[pingPong][3], nearestRepeatSampler);
|
|
729
|
-
if (device.type === 'webgl') {
|
|
730
|
-
fft2hBindGroup4.setValue('texSize', new Vector4(pingPongTextures[pingPong][0].width, pingPongTextures[pingPong][0].height, butterflyTex.width, butterflyTex.height));
|
|
731
|
-
}
|
|
732
|
-
FFTWaveGenerator._globals.quad.draw();
|
|
733
|
-
device.setFramebuffer(pingPongFramebuffers2[pingPong]);
|
|
734
|
-
device.setProgram(FFTWaveGenerator._globals.programs.fft2hProgram2);
|
|
735
|
-
const fft2hBindGroup2 = this.getFFT2hBindGroup2(device, pingPong);
|
|
736
|
-
device.setBindGroup(0, fft2hBindGroup2);
|
|
737
|
-
fft2hBindGroup2.setTexture('butterfly', butterflyTex, nearestRepeatSampler);
|
|
738
|
-
fft2hBindGroup2.setValue('phase', phase);
|
|
739
|
-
fft2hBindGroup2.setTexture('spectrum4', pingPongTextures[pingPong][4], nearestRepeatSampler);
|
|
740
|
-
fft2hBindGroup2.setTexture('spectrum5', pingPongTextures[pingPong][5], nearestRepeatSampler);
|
|
741
|
-
if (device.type === 'webgl') {
|
|
742
|
-
fft2hBindGroup2.setValue('texSize', new Vector4(pingPongTextures[pingPong][0].width, pingPongTextures[pingPong][0].height, butterflyTex.width, butterflyTex.height));
|
|
743
|
-
}
|
|
744
|
-
FFTWaveGenerator._globals.quad.draw();
|
|
745
|
-
pingPong = (pingPong + 1) % 2;
|
|
746
|
-
}
|
|
747
|
-
// vertical ifft
|
|
748
|
-
for(let phase = 0; phase < phases; phase++){
|
|
749
|
-
device.setFramebuffer(pingPongFramebuffers4[pingPong]);
|
|
750
|
-
device.setProgram(FFTWaveGenerator._globals.programs.fft2vProgram4);
|
|
751
|
-
const fft2vBindGroup4 = this.getFFT2vBindGroup4(device, pingPong);
|
|
752
|
-
device.setBindGroup(0, fft2vBindGroup4);
|
|
753
|
-
fft2vBindGroup4.setTexture('butterfly', butterflyTex, nearestRepeatSampler);
|
|
754
|
-
fft2vBindGroup4.setValue('phase', phase);
|
|
755
|
-
fft2vBindGroup4.setTexture('spectrum0', pingPongTextures[pingPong][0], nearestRepeatSampler);
|
|
756
|
-
fft2vBindGroup4.setTexture('spectrum1', pingPongTextures[pingPong][1], nearestRepeatSampler);
|
|
757
|
-
fft2vBindGroup4.setTexture('spectrum2', pingPongTextures[pingPong][2], nearestRepeatSampler);
|
|
758
|
-
fft2vBindGroup4.setTexture('spectrum3', pingPongTextures[pingPong][3], nearestRepeatSampler);
|
|
759
|
-
if (device.type === 'webgl') {
|
|
760
|
-
fft2vBindGroup4.setValue('texSize', new Vector4(pingPongTextures[pingPong][0].width, pingPongTextures[pingPong][0].height, butterflyTex.width, butterflyTex.height));
|
|
761
|
-
}
|
|
762
|
-
FFTWaveGenerator._globals.quad.draw();
|
|
763
|
-
device.setFramebuffer(pingPongFramebuffers2[pingPong]);
|
|
764
|
-
device.setProgram(FFTWaveGenerator._globals.programs.fft2vProgram2);
|
|
765
|
-
const fft2vBindGroup2 = this.getFFT2vBindGroup2(device, pingPong);
|
|
766
|
-
device.setBindGroup(0, fft2vBindGroup2);
|
|
767
|
-
fft2vBindGroup2.setTexture('butterfly', butterflyTex, nearestRepeatSampler);
|
|
768
|
-
fft2vBindGroup2.setValue('phase', phase);
|
|
769
|
-
fft2vBindGroup2.setTexture('spectrum4', pingPongTextures[pingPong][4], nearestRepeatSampler);
|
|
770
|
-
fft2vBindGroup2.setTexture('spectrum5', pingPongTextures[pingPong][5], nearestRepeatSampler);
|
|
771
|
-
if (device.type === 'webgl') {
|
|
772
|
-
fft2vBindGroup2.setValue('texSize', new Vector4(pingPongTextures[pingPong][0].width, pingPongTextures[pingPong][0].height, butterflyTex.width, butterflyTex.height));
|
|
773
|
-
}
|
|
774
|
-
FFTWaveGenerator._globals.quad.draw();
|
|
775
|
-
pingPong = (pingPong + 1) % 2;
|
|
776
|
-
}
|
|
777
|
-
this._ifftTextures = pingPongTextures[pingPong];
|
|
778
|
-
for(let i = 0; i < 2; i++){
|
|
779
|
-
this._fft2hBindGroup2Used[i].push(...this._fft2hBindGroup2Free[i]);
|
|
780
|
-
this._fft2hBindGroup2Free[i].length = 0;
|
|
781
|
-
this._fft2hBindGroup4Used[i].push(...this._fft2hBindGroup4Free[i]);
|
|
782
|
-
this._fft2hBindGroup4Free[i].length = 0;
|
|
783
|
-
this._fft2vBindGroup2Used[i].push(...this._fft2vBindGroup2Free[i]);
|
|
784
|
-
this._fft2vBindGroup2Free[i].length = 0;
|
|
785
|
-
this._fft2vBindGroup4Used[i].push(...this._fft2vBindGroup4Free[i]);
|
|
786
|
-
this._fft2vBindGroup4Free[i].length = 0;
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
/** @internal */ postIfft2() {
|
|
790
|
-
const device = Application.instance.device;
|
|
791
|
-
const instanceData = this.getInstanceData();
|
|
792
|
-
const nearestRepeatSampler = fetchSampler('repeat_nearest_nomip');
|
|
793
|
-
device.setProgram(FFTWaveGenerator._globals.programs.postfft2Program);
|
|
794
|
-
device.setBindGroup(0, this._postfft2BindGroup);
|
|
795
|
-
this._postfft2BindGroup.setValue('N2', this._params.resolution * this._params.resolution);
|
|
796
|
-
if (this._useComputeShader) {
|
|
797
|
-
this._postfft2BindGroup.setTexture('output', instanceData.dataTextures);
|
|
798
|
-
this._postfft2BindGroup.setTexture('ifft', this._ifftTextures, nearestRepeatSampler);
|
|
799
|
-
device.compute(this._params.resolution / THREAD_GROUP_SIZE, this._params.resolution / THREAD_GROUP_SIZE, 1);
|
|
800
|
-
} else {
|
|
801
|
-
device.setFramebuffer(instanceData.postIfft2Framebuffer);
|
|
802
|
-
this._postfft2BindGroup.setTexture('ifft0', this._ifftTextures[0], nearestRepeatSampler);
|
|
803
|
-
this._postfft2BindGroup.setTexture('ifft1', this._ifftTextures[1], nearestRepeatSampler);
|
|
804
|
-
this._postfft2BindGroup.setTexture('ifft2', this._ifftTextures[2], nearestRepeatSampler);
|
|
805
|
-
this._postfft2BindGroup.setTexture('ifft3', this._ifftTextures[3], nearestRepeatSampler);
|
|
806
|
-
this._postfft2BindGroup.setTexture('ifft4', this._ifftTextures[4], nearestRepeatSampler);
|
|
807
|
-
this._postfft2BindGroup.setTexture('ifft5', this._ifftTextures[5], nearestRepeatSampler);
|
|
808
|
-
if (device.type === 'webgl') {
|
|
809
|
-
this._postfft2BindGroup.setValue('ifftTexSize', new Vector2(this._ifftTextures[0].width, this._ifftTextures[0].height));
|
|
810
|
-
}
|
|
811
|
-
FFTWaveGenerator._globals.quad.draw();
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
/** @internal */ postIfft2TwoPass() {
|
|
815
|
-
const device = Application.instance.device;
|
|
816
|
-
const instanceData = this.getInstanceData();
|
|
817
|
-
const nearestRepeatSampler = fetchSampler('repeat_nearest_nomip');
|
|
818
|
-
device.setFramebuffer(instanceData.postIfft2Framebuffer4);
|
|
819
|
-
device.setProgram(FFTWaveGenerator._globals.programs.postfft2Program4);
|
|
820
|
-
device.setBindGroup(0, this._postfft2BindGroup4);
|
|
821
|
-
this._postfft2BindGroup4.setValue('N2', this._params.resolution * this._params.resolution);
|
|
822
|
-
this._postfft2BindGroup4.setTexture('ifft0', this._ifftTextures[0], nearestRepeatSampler);
|
|
823
|
-
this._postfft2BindGroup4.setTexture('ifft1', this._ifftTextures[1], nearestRepeatSampler);
|
|
824
|
-
this._postfft2BindGroup4.setTexture('ifft2', this._ifftTextures[2], nearestRepeatSampler);
|
|
825
|
-
this._postfft2BindGroup4.setTexture('ifft3', this._ifftTextures[3], nearestRepeatSampler);
|
|
826
|
-
if (device.type === 'webgl') {
|
|
827
|
-
this._postfft2BindGroup4.setValue('ifftTexSize', new Vector2(this._ifftTextures[0].width, this._ifftTextures[0].height));
|
|
828
|
-
}
|
|
829
|
-
FFTWaveGenerator._globals.quad.draw();
|
|
830
|
-
device.setFramebuffer(instanceData.postIfft2Framebuffer2);
|
|
831
|
-
device.setProgram(FFTWaveGenerator._globals.programs.postfft2Program2);
|
|
832
|
-
device.setBindGroup(0, this._postfft2BindGroup2);
|
|
833
|
-
this._postfft2BindGroup2.setValue('N2', this._params.resolution * this._params.resolution);
|
|
834
|
-
this._postfft2BindGroup2.setTexture('ifft4', this._ifftTextures[4], nearestRepeatSampler);
|
|
835
|
-
this._postfft2BindGroup2.setTexture('ifft5', this._ifftTextures[5], nearestRepeatSampler);
|
|
836
|
-
if (device.type === 'webgl') {
|
|
837
|
-
this._postfft2BindGroup2.setValue('ifftTexSize', new Vector2(this._ifftTextures[0].width, this._ifftTextures[0].height));
|
|
838
|
-
}
|
|
839
|
-
FFTWaveGenerator._globals.quad.draw();
|
|
840
|
-
}
|
|
841
|
-
/** {@inheritDoc WaveGenerator.setupUniforms} */ setupUniforms(scope, uniformGroup) {
|
|
842
|
-
const pb = scope.$builder;
|
|
843
|
-
scope.sizes = pb.vec4().uniform(uniformGroup);
|
|
844
|
-
scope.croppinesses = pb.vec4().uniform(uniformGroup);
|
|
845
|
-
if (this._useComputeShader) {
|
|
846
|
-
scope.dataTexture = pb.tex2DArray().uniform(uniformGroup);
|
|
847
|
-
} else {
|
|
848
|
-
scope.dx_hy_dz_dxdz0 = pb.tex2D().uniform(uniformGroup);
|
|
849
|
-
scope.sx_sz_dxdx_dzdz0 = pb.tex2D().uniform(uniformGroup);
|
|
850
|
-
scope.dx_hy_dz_dxdz1 = pb.tex2D().uniform(uniformGroup);
|
|
851
|
-
scope.sx_sz_dxdx_dzdz1 = pb.tex2D().uniform(uniformGroup);
|
|
852
|
-
scope.dx_hy_dz_dxdz2 = pb.tex2D().uniform(uniformGroup);
|
|
853
|
-
scope.sx_sz_dxdx_dzdz2 = pb.tex2D().uniform(uniformGroup);
|
|
854
|
-
}
|
|
855
|
-
if (pb.shaderKind === 'fragment') {
|
|
856
|
-
scope.foamParams = pb.vec2().uniform(uniformGroup);
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
/** {@inheritDoc WaveGenerator.calcVertexPositionAndNormal} */ calcVertexPositionAndNormal(scope, inPos, outPos, outNormal) {
|
|
860
|
-
const pb = scope.$builder;
|
|
861
|
-
const that = this;
|
|
862
|
-
pb.func('calcPositionAndNormal', [
|
|
863
|
-
pb.vec3('inPos'),
|
|
864
|
-
pb.vec3('outPos').out(),
|
|
865
|
-
pb.vec3('outNormal').out()
|
|
866
|
-
], function() {
|
|
867
|
-
this.$l.xz = this.inPos.xz;
|
|
868
|
-
this.$l.uv0 = pb.div(this.xz, this.sizes.x);
|
|
869
|
-
this.$l.uv1 = pb.div(this.xz, this.sizes.y);
|
|
870
|
-
this.$l.uv2 = pb.div(this.xz, this.sizes.z);
|
|
871
|
-
if (that._useComputeShader) {
|
|
872
|
-
this.$l.a = pb.mul(pb.textureArraySampleLevel(this.dataTexture, this.uv0, 0, 0).rgb, pb.vec3(this.croppinesses.x, 1, this.croppinesses.x));
|
|
873
|
-
this.$l.b = pb.mul(pb.textureArraySampleLevel(this.dataTexture, this.uv1, 2, 0).rgb, pb.vec3(this.croppinesses.y, 1, this.croppinesses.y));
|
|
874
|
-
this.$l.c = pb.mul(pb.textureArraySampleLevel(this.dataTexture, this.uv2, 4, 0).rgb, pb.vec3(this.croppinesses.z, 1, this.croppinesses.z));
|
|
875
|
-
} else {
|
|
876
|
-
this.$l.a = pb.mul(pb.textureSampleLevel(this.dx_hy_dz_dxdz0, this.uv0, 0).rgb, pb.vec3(this.croppinesses.x, 1, this.croppinesses.x));
|
|
877
|
-
this.$l.b = pb.mul(pb.textureSampleLevel(this.dx_hy_dz_dxdz1, this.uv1, 0).rgb, pb.vec3(this.croppinesses.y, 1, this.croppinesses.y));
|
|
878
|
-
this.$l.c = pb.mul(pb.textureSampleLevel(this.dx_hy_dz_dxdz2, this.uv2, 0).rgb, pb.vec3(this.croppinesses.z, 1, this.croppinesses.z));
|
|
879
|
-
}
|
|
880
|
-
this.$l.displacement = pb.add(this.a, this.b, this.c);
|
|
881
|
-
this.outPos = pb.add(this.inPos, this.displacement);
|
|
882
|
-
this.outNormal = pb.vec3(0, 1, 0);
|
|
883
|
-
});
|
|
884
|
-
scope.calcPositionAndNormal(inPos, outPos, outNormal);
|
|
885
|
-
}
|
|
886
|
-
/** {@inheritDoc WaveGenerator.calcFragmentNormal} */ calcFragmentNormal(scope, xz, _vertexNormal) {
|
|
887
|
-
const pb = scope.$builder;
|
|
888
|
-
const that = this;
|
|
889
|
-
pb.func('calcFragmentNormal', [
|
|
890
|
-
pb.vec2('xz')
|
|
891
|
-
], function() {
|
|
892
|
-
this.$l.uv0 = pb.div(this.xz, this.sizes.x);
|
|
893
|
-
this.$l.uv1 = pb.div(this.xz, this.sizes.y);
|
|
894
|
-
this.$l.uv2 = pb.div(this.xz, this.sizes.z);
|
|
895
|
-
if (that._useComputeShader) {
|
|
896
|
-
this.$l._sx_sz_dxdx_dzdz0 = pb.textureArraySampleLevel(this.dataTexture, this.uv0, 1, 0);
|
|
897
|
-
this.$l._sx_sz_dxdx_dzdz1 = pb.textureArraySampleLevel(this.dataTexture, this.uv1, 3, 0);
|
|
898
|
-
this.$l._sx_sz_dxdx_dzdz2 = pb.textureArraySampleLevel(this.dataTexture, this.uv2, 5, 0);
|
|
899
|
-
} else {
|
|
900
|
-
this.$l._sx_sz_dxdx_dzdz0 = pb.textureSampleLevel(this.sx_sz_dxdx_dzdz0, this.uv0, 0);
|
|
901
|
-
this.$l._sx_sz_dxdx_dzdz1 = pb.textureSampleLevel(this.sx_sz_dxdx_dzdz1, this.uv1, 0);
|
|
902
|
-
this.$l._sx_sz_dxdx_dzdz2 = pb.textureSampleLevel(this.sx_sz_dxdx_dzdz2, this.uv2, 0);
|
|
903
|
-
}
|
|
904
|
-
this.$l.sx = pb.add(this._sx_sz_dxdx_dzdz0.x, this._sx_sz_dxdx_dzdz1.x, this._sx_sz_dxdx_dzdz2.x);
|
|
905
|
-
this.$l.sz = pb.add(this._sx_sz_dxdx_dzdz0.y, this._sx_sz_dxdx_dzdz1.y, this._sx_sz_dxdx_dzdz2.y);
|
|
906
|
-
this.$l.dxdx_dzdz = pb.add(pb.mul(this._sx_sz_dxdx_dzdz0.zw, this.croppinesses.x), pb.mul(this._sx_sz_dxdx_dzdz1.zw, this.croppinesses.y), pb.mul(this._sx_sz_dxdx_dzdz2.zw, this.croppinesses.z));
|
|
907
|
-
this.$l.slope = pb.vec2(pb.div(this.sx, pb.add(1.0, this.dxdx_dzdz.x)), pb.div(this.sz, pb.add(1.0, this.dxdx_dzdz.y)));
|
|
908
|
-
this.$l.normal = pb.normalize(pb.vec3(pb.neg(this.slope.x), 1.0, pb.neg(this.slope.y)));
|
|
909
|
-
this.$return(this.normal);
|
|
910
|
-
});
|
|
911
|
-
return scope.calcFragmentNormal(xz);
|
|
912
|
-
}
|
|
913
|
-
/** {@inheritDoc WaveGenerator.calcFragmentNormalAndFoam} */ calcFragmentNormalAndFoam(scope, xz) {
|
|
914
|
-
const pb = scope.$builder;
|
|
915
|
-
const that = this;
|
|
916
|
-
pb.func('jacobian', [
|
|
917
|
-
pb.float('dxdx'),
|
|
918
|
-
pb.float('dxdz'),
|
|
919
|
-
pb.float('dzdz')
|
|
920
|
-
], function() {
|
|
921
|
-
this.$l.Jxx = pb.add(this.dxdx, 1);
|
|
922
|
-
this.$l.Jxz = this.dxdz;
|
|
923
|
-
this.$l.Jzz = pb.add(this.dzdz, 1);
|
|
924
|
-
this.$return(pb.vec4(this.Jxx, this.Jxz, this.Jxz, this.Jzz));
|
|
925
|
-
});
|
|
926
|
-
pb.func('det', [
|
|
927
|
-
pb.vec4('jacobian')
|
|
928
|
-
], function() {
|
|
929
|
-
this.$return(pb.sub(pb.mul(this.jacobian.x, this.jacobian.w), pb.mul(this.jacobian.y, this.jacobian.z)));
|
|
930
|
-
});
|
|
931
|
-
pb.func('calcNormalAndFoam', [
|
|
932
|
-
pb.vec2('xz')
|
|
933
|
-
], function() {
|
|
934
|
-
this.$l.uv0 = pb.div(this.xz, this.sizes.x);
|
|
935
|
-
this.$l.uv1 = pb.div(this.xz, this.sizes.y);
|
|
936
|
-
this.$l.uv2 = pb.div(this.xz, this.sizes.z);
|
|
937
|
-
if (that._useComputeShader) {
|
|
938
|
-
this.$l._sx_sz_dxdx_dzdz0 = pb.textureArraySampleLevel(this.dataTexture, this.uv0, 1, 0);
|
|
939
|
-
this.$l._sx_sz_dxdx_dzdz1 = pb.textureArraySampleLevel(this.dataTexture, this.uv1, 3, 0);
|
|
940
|
-
this.$l._sx_sz_dxdx_dzdz2 = pb.textureArraySampleLevel(this.dataTexture, this.uv2, 5, 0);
|
|
941
|
-
} else {
|
|
942
|
-
this.$l._sx_sz_dxdx_dzdz0 = pb.textureSampleLevel(this.sx_sz_dxdx_dzdz0, this.uv0, 0);
|
|
943
|
-
this.$l._sx_sz_dxdx_dzdz1 = pb.textureSampleLevel(this.sx_sz_dxdx_dzdz1, this.uv1, 0);
|
|
944
|
-
this.$l._sx_sz_dxdx_dzdz2 = pb.textureSampleLevel(this.sx_sz_dxdx_dzdz2, this.uv2, 0);
|
|
945
|
-
}
|
|
946
|
-
this.$l.sx = pb.add(this._sx_sz_dxdx_dzdz0.x, this._sx_sz_dxdx_dzdz1.x, this._sx_sz_dxdx_dzdz2.x);
|
|
947
|
-
this.$l.sz = pb.add(this._sx_sz_dxdx_dzdz0.y, this._sx_sz_dxdx_dzdz1.y, this._sx_sz_dxdx_dzdz2.y);
|
|
948
|
-
this.$l.dxdx_dzdz = pb.add(pb.mul(this._sx_sz_dxdx_dzdz0.zw, this.croppinesses.x), pb.mul(this._sx_sz_dxdx_dzdz1.zw, this.croppinesses.y), pb.mul(this._sx_sz_dxdx_dzdz2.zw, this.croppinesses.z));
|
|
949
|
-
this.$l.slope = pb.vec2(pb.div(this.sx, pb.add(1.0, this.dxdx_dzdz.x)), pb.div(this.sz, pb.add(1.0, this.dxdx_dzdz.y)));
|
|
950
|
-
this.$l.normal = pb.normalize(pb.vec3(pb.neg(this.slope.x), 1.0, pb.neg(this.slope.y)));
|
|
951
|
-
// foam
|
|
952
|
-
this.$l.dxdx_dzdz0 = this._sx_sz_dxdx_dzdz0.zw;
|
|
953
|
-
this.$l.dxdx_dzdz1 = this._sx_sz_dxdx_dzdz1.zw;
|
|
954
|
-
this.$l.dxdx_dzdz2 = this._sx_sz_dxdx_dzdz2.zw;
|
|
955
|
-
if (that._useComputeShader) {
|
|
956
|
-
this.$l.dxdz0 = pb.textureArraySampleLevel(this.dataTexture, this.uv0, 0, 0).w;
|
|
957
|
-
this.$l.dxdz1 = pb.textureArraySampleLevel(this.dataTexture, this.uv1, 2, 0).w;
|
|
958
|
-
this.$l.dxdz2 = pb.textureArraySampleLevel(this.dataTexture, this.uv2, 4, 0).w;
|
|
959
|
-
} else {
|
|
960
|
-
this.$l.dxdz0 = pb.textureSampleLevel(this.dx_hy_dz_dxdz0, this.uv0, 0).w;
|
|
961
|
-
this.$l.dxdz1 = pb.textureSampleLevel(this.dx_hy_dz_dxdz1, this.uv1, 0).w;
|
|
962
|
-
this.$l.dxdz2 = pb.textureSampleLevel(this.dx_hy_dz_dxdz2, this.uv2, 0).w;
|
|
963
|
-
}
|
|
964
|
-
this.$l.dxdz = pb.add(pb.mul(this.dxdz0, this.croppinesses.x), pb.mul(this.dxdz1, this.croppinesses.y), pb.mul(this.dxdz2, this.croppinesses.z));
|
|
965
|
-
this.$l.val = this.det(this.jacobian(this.dxdx_dzdz.x, this.dxdz, this.dxdx_dzdz.y));
|
|
966
|
-
this.$l.foam = pb.abs(pb.pow(pb.neg(pb.min(0, pb.sub(this.val, this.foamParams.x))), this.foamParams.y));
|
|
967
|
-
this.$return(pb.vec4(this.normal, this.foam));
|
|
968
|
-
});
|
|
969
|
-
return scope.calcNormalAndFoam(xz);
|
|
970
|
-
}
|
|
971
|
-
/** {@inheritDoc WaveGenerator.isOk} */ isOk() {
|
|
972
|
-
return this._renderMode !== RENDER_NONE;
|
|
973
|
-
}
|
|
974
|
-
/** {@inheritDoc WaveGenerator.applyWaterBindGroup} */ applyWaterBindGroup(bindGroup) {
|
|
975
|
-
const instanceData = this.getInstanceData();
|
|
976
|
-
const linearRepeatSampler = fetchSampler('repeat_linear_nomip');
|
|
977
|
-
if (this._useComputeShader) {
|
|
978
|
-
bindGroup.setTexture('dataTexture', instanceData.dataTextures, linearRepeatSampler);
|
|
979
|
-
} else {
|
|
980
|
-
bindGroup.setTexture('dx_hy_dz_dxdz0', instanceData.dataTextures[0], linearRepeatSampler);
|
|
981
|
-
bindGroup.setTexture('sx_sz_dxdx_dzdz0', instanceData.dataTextures[1], linearRepeatSampler);
|
|
982
|
-
bindGroup.setTexture('dx_hy_dz_dxdz1', instanceData.dataTextures[2], linearRepeatSampler);
|
|
983
|
-
bindGroup.setTexture('sx_sz_dxdx_dzdz1', instanceData.dataTextures[3], linearRepeatSampler);
|
|
984
|
-
bindGroup.setTexture('dx_hy_dz_dxdz2', instanceData.dataTextures[4], linearRepeatSampler);
|
|
985
|
-
bindGroup.setTexture('sx_sz_dxdx_dzdz2', instanceData.dataTextures[5], linearRepeatSampler);
|
|
986
|
-
}
|
|
987
|
-
bindGroup.setValue('foamParams', this._params.foamParams);
|
|
988
|
-
bindGroup.setValue('sizes', this._sizes);
|
|
989
|
-
bindGroup.setValue('croppinesses', this._croppinesses);
|
|
990
|
-
}
|
|
991
|
-
/** {@inheritDoc WaveGenerator.calcClipmapTileAABB} */ calcClipmapTileAABB(minX, maxX, minZ, maxZ, y, outAABB) {
|
|
992
|
-
const disturb = Math.max(Math.abs(this.wind.x), Math.abs(this.wind.y), 2);
|
|
993
|
-
outAABB.minPoint.setXYZ(minX - 8 * disturb, y - 8 * disturb, minZ - 8 * disturb);
|
|
994
|
-
outAABB.maxPoint.setXYZ(maxX + 8 * disturb, y + 8 * disturb, maxZ + 8 * disturb);
|
|
995
|
-
}
|
|
996
|
-
/** {@inheritDoc WaveGenerator.getHash} */ getHash() {
|
|
997
|
-
return 'FFTWaveGenerator';
|
|
998
|
-
}
|
|
999
|
-
onDispose() {
|
|
1000
|
-
super.onDispose();
|
|
1001
|
-
this.disposeInstanceData();
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
export { FFTWaveGenerator };
|
|
1006
|
-
//# sourceMappingURL=fft_wavegenerator.js.map
|