@zephyr3d/scene 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation/animation.js +173 -0
- package/dist/animation/animation.js.map +1 -0
- package/dist/animation/animationset.js +95 -0
- package/dist/animation/animationset.js.map +1 -0
- package/dist/animation/animationtrack.js +38 -0
- package/dist/animation/animationtrack.js.map +1 -0
- package/dist/animation/eulerrotationtrack.js +33 -0
- package/dist/animation/eulerrotationtrack.js.map +1 -0
- package/dist/animation/rotationtrack.js +37 -0
- package/dist/animation/rotationtrack.js.map +1 -0
- package/dist/animation/scaletrack.js +36 -0
- package/dist/animation/scaletrack.js.map +1 -0
- package/dist/animation/skeleton.js +97 -0
- package/dist/animation/skeleton.js.map +1 -0
- package/dist/animation/translationtrack.js +36 -0
- package/dist/animation/translationtrack.js.map +1 -0
- package/dist/animation/usertrack.js +47 -0
- package/dist/animation/usertrack.js.map +1 -0
- package/dist/app.js +173 -0
- package/dist/app.js.map +1 -0
- package/dist/asset/assetmanager.js +476 -0
- package/dist/asset/assetmanager.js.map +1 -0
- package/dist/asset/builtin.js +373 -0
- package/dist/asset/builtin.js.map +1 -0
- package/dist/asset/loaders/dds/dds.js +472 -0
- package/dist/asset/loaders/dds/dds.js.map +1 -0
- package/dist/asset/loaders/dds/dds_loader.js +38 -0
- package/dist/asset/loaders/dds/dds_loader.js.map +1 -0
- package/dist/asset/loaders/gltf/gltf_loader.js +981 -0
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -0
- package/dist/asset/loaders/gltf/helpers.js +314 -0
- package/dist/asset/loaders/gltf/helpers.js.map +1 -0
- package/dist/asset/loaders/hdr/hdr.js +175 -0
- package/dist/asset/loaders/hdr/hdr.js.map +1 -0
- package/dist/asset/loaders/image/tga_Loader.js +117 -0
- package/dist/asset/loaders/image/tga_Loader.js.map +1 -0
- package/dist/asset/loaders/image/webimage_loader.js +50 -0
- package/dist/asset/loaders/image/webimage_loader.js.map +1 -0
- package/dist/asset/loaders/loader.js +45 -0
- package/dist/asset/loaders/loader.js.map +1 -0
- package/dist/asset/model.js +264 -0
- package/dist/asset/model.js.map +1 -0
- package/dist/blitter/blitter.js +389 -0
- package/dist/blitter/blitter.js.map +1 -0
- package/dist/blitter/box.js +118 -0
- package/dist/blitter/box.js.map +1 -0
- package/dist/blitter/copy.js +22 -0
- package/dist/blitter/copy.js.map +1 -0
- package/dist/blitter/depthlimitedgaussion.js +166 -0
- package/dist/blitter/depthlimitedgaussion.js.map +1 -0
- package/dist/blitter/gaussianblur.js +229 -0
- package/dist/blitter/gaussianblur.js.map +1 -0
- package/dist/camera/base.js +90 -0
- package/dist/camera/base.js.map +1 -0
- package/dist/camera/camera.js +358 -0
- package/dist/camera/camera.js.map +1 -0
- package/dist/camera/fps.js +246 -0
- package/dist/camera/fps.js.map +1 -0
- package/dist/camera/orbit.js +157 -0
- package/dist/camera/orbit.js.map +1 -0
- package/dist/camera/orthocamera.js +126 -0
- package/dist/camera/orthocamera.js.map +1 -0
- package/dist/camera/perspectivecamera.js +133 -0
- package/dist/camera/perspectivecamera.js.map +1 -0
- package/dist/index.d.ts +8402 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/input/inputmgr.js +242 -0
- package/dist/input/inputmgr.js.map +1 -0
- package/dist/material/blinn.js +75 -0
- package/dist/material/blinn.js.map +1 -0
- package/dist/material/grassmaterial.js +221 -0
- package/dist/material/grassmaterial.js.map +1 -0
- package/dist/material/lambert.js +52 -0
- package/dist/material/lambert.js.map +1 -0
- package/dist/material/lightmodel.js +2074 -0
- package/dist/material/lightmodel.js.map +1 -0
- package/dist/material/lit.js +578 -0
- package/dist/material/lit.js.map +1 -0
- package/dist/material/material.js +458 -0
- package/dist/material/material.js.map +1 -0
- package/dist/material/meshmaterial.js +311 -0
- package/dist/material/meshmaterial.js.map +1 -0
- package/dist/material/mixins/albedocolor.js +130 -0
- package/dist/material/mixins/albedocolor.js.map +1 -0
- package/dist/material/mixins/texture.js +110 -0
- package/dist/material/mixins/texture.js.map +1 -0
- package/dist/material/mixins/vertexcolor.js +45 -0
- package/dist/material/mixins/vertexcolor.js.map +1 -0
- package/dist/material/pbr.js +27 -0
- package/dist/material/pbr.js.map +1 -0
- package/dist/material/standard.js +282 -0
- package/dist/material/standard.js.map +1 -0
- package/dist/material/terrainlightmodel.js +259 -0
- package/dist/material/terrainlightmodel.js.map +1 -0
- package/dist/material/terrainmaterial.js +139 -0
- package/dist/material/terrainmaterial.js.map +1 -0
- package/dist/material/unlit.js +29 -0
- package/dist/material/unlit.js.map +1 -0
- package/dist/posteffect/bloom.js +398 -0
- package/dist/posteffect/bloom.js.map +1 -0
- package/dist/posteffect/compositor.js +264 -0
- package/dist/posteffect/compositor.js.map +1 -0
- package/dist/posteffect/fxaa.js +291 -0
- package/dist/posteffect/fxaa.js.map +1 -0
- package/dist/posteffect/grayscale.js +87 -0
- package/dist/posteffect/grayscale.js.map +1 -0
- package/dist/posteffect/posteffect.js +165 -0
- package/dist/posteffect/posteffect.js.map +1 -0
- package/dist/posteffect/sao.js +327 -0
- package/dist/posteffect/sao.js.map +1 -0
- package/dist/posteffect/tonemap.js +112 -0
- package/dist/posteffect/tonemap.js.map +1 -0
- package/dist/posteffect/water.js +535 -0
- package/dist/posteffect/water.js.map +1 -0
- package/dist/render/clipmap.js +462 -0
- package/dist/render/clipmap.js.map +1 -0
- package/dist/render/cluster_light.js +329 -0
- package/dist/render/cluster_light.js.map +1 -0
- package/dist/render/cull_visitor.js +124 -0
- package/dist/render/cull_visitor.js.map +1 -0
- package/dist/render/depth_pass.js +47 -0
- package/dist/render/depth_pass.js.map +1 -0
- package/dist/render/envlight.js +282 -0
- package/dist/render/envlight.js.map +1 -0
- package/dist/render/forward.js +186 -0
- package/dist/render/forward.js.map +1 -0
- package/dist/render/forward_pass.js +137 -0
- package/dist/render/forward_pass.js.map +1 -0
- package/dist/render/helper.js +38 -0
- package/dist/render/helper.js.map +1 -0
- package/dist/render/primitive.js +246 -0
- package/dist/render/primitive.js.map +1 -0
- package/dist/render/render_queue.js +163 -0
- package/dist/render/render_queue.js.map +1 -0
- package/dist/render/renderpass.js +151 -0
- package/dist/render/renderpass.js.map +1 -0
- package/dist/render/renderscheme.js +61 -0
- package/dist/render/renderscheme.js.map +1 -0
- package/dist/render/scatteringlut.js +634 -0
- package/dist/render/scatteringlut.js.map +1 -0
- package/dist/render/shadowmap_pass.js +70 -0
- package/dist/render/shadowmap_pass.js.map +1 -0
- package/dist/render/sky.js +881 -0
- package/dist/render/sky.js.map +1 -0
- package/dist/render/temporalcache.js +222 -0
- package/dist/render/temporalcache.js.map +1 -0
- package/dist/render/watermesh.js +835 -0
- package/dist/render/watermesh.js.map +1 -0
- package/dist/scene/environment.js +146 -0
- package/dist/scene/environment.js.map +1 -0
- package/dist/scene/graph_node.js +69 -0
- package/dist/scene/graph_node.js.map +1 -0
- package/dist/scene/light.js +436 -0
- package/dist/scene/light.js.map +1 -0
- package/dist/scene/mesh.js +215 -0
- package/dist/scene/mesh.js.map +1 -0
- package/dist/scene/model.js +111 -0
- package/dist/scene/model.js.map +1 -0
- package/dist/scene/octree.js +651 -0
- package/dist/scene/octree.js.map +1 -0
- package/dist/scene/octree_update_visitor.js +16 -0
- package/dist/scene/octree_update_visitor.js.map +1 -0
- package/dist/scene/raycast_visitor.js +72 -0
- package/dist/scene/raycast_visitor.js.map +1 -0
- package/dist/scene/scene.js +225 -0
- package/dist/scene/scene.js.map +1 -0
- package/dist/scene/scene_node.js +299 -0
- package/dist/scene/scene_node.js.map +1 -0
- package/dist/scene/terrain/grass.js +277 -0
- package/dist/scene/terrain/grass.js.map +1 -0
- package/dist/scene/terrain/heightfield.js +391 -0
- package/dist/scene/terrain/heightfield.js.map +1 -0
- package/dist/scene/terrain/patch.js +530 -0
- package/dist/scene/terrain/patch.js.map +1 -0
- package/dist/scene/terrain/quadtree.js +430 -0
- package/dist/scene/terrain/quadtree.js.map +1 -0
- package/dist/scene/terrain/terrain.js +258 -0
- package/dist/scene/terrain/terrain.js.map +1 -0
- package/dist/scene/xform.js +224 -0
- package/dist/scene/xform.js.map +1 -0
- package/dist/shaders/builtins.js +110 -0
- package/dist/shaders/builtins.js.map +1 -0
- package/dist/shaders/framework.js +709 -0
- package/dist/shaders/framework.js.map +1 -0
- package/dist/shaders/lighting.js +335 -0
- package/dist/shaders/lighting.js.map +1 -0
- package/dist/shaders/misc.js +405 -0
- package/dist/shaders/misc.js.map +1 -0
- package/dist/shaders/noise.js +157 -0
- package/dist/shaders/noise.js.map +1 -0
- package/dist/shaders/pbr.js +132 -0
- package/dist/shaders/pbr.js.map +1 -0
- package/dist/shaders/shadow.js +642 -0
- package/dist/shaders/shadow.js.map +1 -0
- package/dist/shaders/water.js +630 -0
- package/dist/shaders/water.js.map +1 -0
- package/dist/shadow/esm.js +235 -0
- package/dist/shadow/esm.js.map +1 -0
- package/dist/shadow/pcf_opt.js +182 -0
- package/dist/shadow/pcf_opt.js.map +1 -0
- package/dist/shadow/pcf_pd.js +190 -0
- package/dist/shadow/pcf_pd.js.map +1 -0
- package/dist/shadow/shadow_impl.js +15 -0
- package/dist/shadow/shadow_impl.js.map +1 -0
- package/dist/shadow/shadowmapper.js +709 -0
- package/dist/shadow/shadowmapper.js.map +1 -0
- package/dist/shadow/ssm.js +194 -0
- package/dist/shadow/ssm.js.map +1 -0
- package/dist/shadow/vsm.js +298 -0
- package/dist/shadow/vsm.js.map +1 -0
- package/dist/shapes/box.js +313 -0
- package/dist/shapes/box.js.map +1 -0
- package/dist/shapes/cylinder.js +74 -0
- package/dist/shapes/cylinder.js.map +1 -0
- package/dist/shapes/plane.js +48 -0
- package/dist/shapes/plane.js.map +1 -0
- package/dist/shapes/shape.js +33 -0
- package/dist/shapes/shape.js.map +1 -0
- package/dist/shapes/sphere.js +91 -0
- package/dist/shapes/sphere.js.map +1 -0
- package/dist/shapes/torus.js +100 -0
- package/dist/shapes/torus.js.map +1 -0
- package/dist/utility/aabbtree.js +390 -0
- package/dist/utility/aabbtree.js.map +1 -0
- package/dist/utility/bounding_volume.js +78 -0
- package/dist/utility/bounding_volume.js.map +1 -0
- package/dist/utility/panorama.js +163 -0
- package/dist/utility/panorama.js.map +1 -0
- package/dist/utility/pmrem.js +345 -0
- package/dist/utility/pmrem.js.map +1 -0
- package/dist/utility/shprojection.js +448 -0
- package/dist/utility/shprojection.js.map +1 -0
- package/dist/values.js +48 -0
- package/dist/values.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
import { Application } from '../app.js';
|
|
2
|
+
|
|
3
|
+
// copy from: https://github.com/codeagent/webgl-ocean/
|
|
4
|
+
/** @internal */ function createProgramOcean(impl) {
|
|
5
|
+
return Application.instance.device.buildRenderProgram({
|
|
6
|
+
vertex (pb) {
|
|
7
|
+
this.$inputs.position = pb.vec3().attrib('position');
|
|
8
|
+
this.$outputs.outPos = pb.vec3();
|
|
9
|
+
this.$outputs.outXZ = pb.vec2();
|
|
10
|
+
this.$outputs.uv0 = pb.vec2();
|
|
11
|
+
this.$outputs.uv1 = pb.vec2();
|
|
12
|
+
this.$outputs.uv2 = pb.vec2();
|
|
13
|
+
this.flip = pb.int().uniform(0);
|
|
14
|
+
this.viewProjMatrix = pb.mat4().uniform(0);
|
|
15
|
+
this.modelMatrix = pb.mat4().uniform(0);
|
|
16
|
+
this.gridScale = pb.float().uniform(0);
|
|
17
|
+
this.level = pb.float().uniform(0);
|
|
18
|
+
this.sizes = pb.vec4().uniform(0);
|
|
19
|
+
this.croppinesses = pb.vec4().uniform(0);
|
|
20
|
+
this.offset = pb.vec2().uniform(0);
|
|
21
|
+
this.scale = pb.float().uniform(0);
|
|
22
|
+
this.dx_hy_dz_dxdz0 = pb.tex2D().uniform(0);
|
|
23
|
+
this.sx_sz_dxdx_dzdz0 = pb.tex2D().uniform(0);
|
|
24
|
+
this.dx_hy_dz_dxdz1 = pb.tex2D().uniform(0);
|
|
25
|
+
this.sx_sz_dxdx_dzdz1 = pb.tex2D().uniform(0);
|
|
26
|
+
this.dx_hy_dz_dxdz2 = pb.tex2D().uniform(0);
|
|
27
|
+
this.sx_sz_dxdx_dzdz2 = pb.tex2D().uniform(0);
|
|
28
|
+
impl?.setupUniforms(this);
|
|
29
|
+
pb.main(function() {
|
|
30
|
+
this.$l.xz = pb.mul(pb.add(this.offset, pb.mul(pb.mul(this.modelMatrix, pb.vec4(this.$inputs.position, 1)).xy, this.scale)), this.gridScale);
|
|
31
|
+
this.$outputs.uv0 = pb.div(this.xz, this.sizes.x);
|
|
32
|
+
this.$outputs.uv1 = pb.div(this.xz, this.sizes.y);
|
|
33
|
+
this.$outputs.uv2 = pb.div(this.xz, this.sizes.z);
|
|
34
|
+
if (pb.getDevice().type === 'webgl') {
|
|
35
|
+
this.$l.a = pb.mul(pb.textureSample(this.dx_hy_dz_dxdz0, this.$outputs.uv0).rgb, pb.vec3(this.croppinesses.x, 1, this.croppinesses.x));
|
|
36
|
+
this.$l.b = pb.mul(pb.textureSample(this.dx_hy_dz_dxdz1, this.$outputs.uv1).rgb, pb.vec3(this.croppinesses.y, 1, this.croppinesses.y));
|
|
37
|
+
this.$l.c = pb.mul(pb.textureSample(this.dx_hy_dz_dxdz2, this.$outputs.uv2).rgb, pb.vec3(this.croppinesses.z, 1, this.croppinesses.z));
|
|
38
|
+
} else {
|
|
39
|
+
this.$l.a = pb.mul(pb.textureSampleLevel(this.dx_hy_dz_dxdz0, this.$outputs.uv0, 0).rgb, pb.vec3(this.croppinesses.x, 1, this.croppinesses.x));
|
|
40
|
+
this.$l.b = pb.mul(pb.textureSampleLevel(this.dx_hy_dz_dxdz1, this.$outputs.uv1, 0).rgb, pb.vec3(this.croppinesses.y, 1, this.croppinesses.y));
|
|
41
|
+
this.$l.c = pb.mul(pb.textureSampleLevel(this.dx_hy_dz_dxdz2, this.$outputs.uv2, 0).rgb, pb.vec3(this.croppinesses.z, 1, this.croppinesses.z));
|
|
42
|
+
}
|
|
43
|
+
this.$l.displacement = pb.add(this.a, this.b, this.c);
|
|
44
|
+
this.$outputs.outPos = pb.add(pb.vec3(this.xz.x, this.level, this.xz.y), this.displacement);
|
|
45
|
+
this.$outputs.outXZ = this.xz;
|
|
46
|
+
this.$builtins.position = pb.mul(this.viewProjMatrix, pb.vec4(this.$outputs.outPos, 1));
|
|
47
|
+
this.$if(pb.notEqual(this.flip, 0), function() {
|
|
48
|
+
this.$builtins.position.y = pb.neg(this.$builtins.position.y);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
fragment (pb) {
|
|
53
|
+
this.$outputs.outColor = pb.vec4();
|
|
54
|
+
this.pos = pb.vec3().uniform(0);
|
|
55
|
+
this.regionMin = pb.vec2().uniform(0);
|
|
56
|
+
this.regionMax = pb.vec2().uniform(0);
|
|
57
|
+
this.foamParams = pb.vec2().uniform(0);
|
|
58
|
+
this.sizes = pb.vec4().uniform(0);
|
|
59
|
+
this.croppinesses = pb.vec4().uniform(0);
|
|
60
|
+
this.dx_hy_dz_dxdz0 = pb.tex2D().uniform(0);
|
|
61
|
+
this.sx_sz_dxdx_dzdz0 = pb.tex2D().uniform(0);
|
|
62
|
+
this.dx_hy_dz_dxdz1 = pb.tex2D().uniform(0);
|
|
63
|
+
this.sx_sz_dxdx_dzdz1 = pb.tex2D().uniform(0);
|
|
64
|
+
this.dx_hy_dz_dxdz2 = pb.tex2D().uniform(0);
|
|
65
|
+
this.sx_sz_dxdx_dzdz2 = pb.tex2D().uniform(0);
|
|
66
|
+
impl?.setupUniforms(this);
|
|
67
|
+
pb.func('jacobian', [
|
|
68
|
+
pb.float('dxdx'),
|
|
69
|
+
pb.float('dxdz'),
|
|
70
|
+
pb.float('dzdz')
|
|
71
|
+
], function() {
|
|
72
|
+
this.$l.Jxx = pb.add(this.dxdx, 1);
|
|
73
|
+
this.$l.Jxz = this.dxdz;
|
|
74
|
+
this.$l.Jzz = pb.add(this.dzdz, 1);
|
|
75
|
+
this.$return(pb.vec4(this.Jxx, this.Jxz, this.Jxz, this.Jzz));
|
|
76
|
+
});
|
|
77
|
+
pb.func('det', [
|
|
78
|
+
pb.vec4('jacobian')
|
|
79
|
+
], function() {
|
|
80
|
+
this.$return(pb.sub(pb.mul(this.jacobian.x, this.jacobian.w), pb.mul(this.jacobian.y, this.jacobian.z)));
|
|
81
|
+
});
|
|
82
|
+
pb.func('getNormalAndFoam', [
|
|
83
|
+
pb.vec2('xz')
|
|
84
|
+
], function() {
|
|
85
|
+
this.$l.uv0 = pb.div(this.xz, this.sizes.x);
|
|
86
|
+
this.$l.uv1 = pb.div(this.xz, this.sizes.y);
|
|
87
|
+
this.$l.uv2 = pb.div(this.xz, this.sizes.z);
|
|
88
|
+
this.$l._sx_sz_dxdx_dzdz0 = pb.textureSampleLevel(this.sx_sz_dxdx_dzdz0, this.uv0, 0);
|
|
89
|
+
this.$l._sx_sz_dxdx_dzdz1 = pb.textureSampleLevel(this.sx_sz_dxdx_dzdz1, this.uv1, 0);
|
|
90
|
+
this.$l._sx_sz_dxdx_dzdz2 = pb.textureSampleLevel(this.sx_sz_dxdx_dzdz2, this.uv2, 0);
|
|
91
|
+
this.$l.sx = pb.add(this._sx_sz_dxdx_dzdz0.x, this._sx_sz_dxdx_dzdz1.x, this._sx_sz_dxdx_dzdz2.x);
|
|
92
|
+
this.$l.sz = pb.add(this._sx_sz_dxdx_dzdz0.y, this._sx_sz_dxdx_dzdz1.y, this._sx_sz_dxdx_dzdz2.y);
|
|
93
|
+
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));
|
|
94
|
+
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)));
|
|
95
|
+
this.$l.normal = pb.normalize(pb.vec3(pb.neg(this.slope.x), 1.0, pb.neg(this.slope.y)));
|
|
96
|
+
// foam
|
|
97
|
+
this.$l.dxdx_dzdz0 = this._sx_sz_dxdx_dzdz0.zw;
|
|
98
|
+
this.$l.dxdx_dzdz1 = this._sx_sz_dxdx_dzdz1.zw;
|
|
99
|
+
this.$l.dxdx_dzdz2 = this._sx_sz_dxdx_dzdz2.zw;
|
|
100
|
+
this.$l.dxdz0 = pb.textureSampleLevel(this.dx_hy_dz_dxdz0, this.uv0, 0).w;
|
|
101
|
+
this.$l.dxdz1 = pb.textureSampleLevel(this.dx_hy_dz_dxdz1, this.uv1, 0).w;
|
|
102
|
+
this.$l.dxdz2 = pb.textureSampleLevel(this.dx_hy_dz_dxdz2, this.uv2, 0).w;
|
|
103
|
+
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));
|
|
104
|
+
this.$l.val = this.det(this.jacobian(this.dxdx_dzdz.x, this.dxdz, this.dxdx_dzdz.y));
|
|
105
|
+
this.$l.foam = pb.abs(pb.pow(pb.neg(pb.min(0, pb.sub(this.val, this.foamParams.x))), this.foamParams.y));
|
|
106
|
+
this.$return(pb.vec4(this.normal, this.foam));
|
|
107
|
+
});
|
|
108
|
+
pb.main(function() {
|
|
109
|
+
this.$if(pb.or(pb.any(pb.lessThan(this.$inputs.outXZ, this.regionMin)), pb.any(pb.greaterThan(this.$inputs.outXZ, this.regionMax))), function() {
|
|
110
|
+
pb.discard();
|
|
111
|
+
});
|
|
112
|
+
this.$l.n = this.getNormalAndFoam(this.$inputs.outXZ);
|
|
113
|
+
this.$outputs.outColor = impl?.shading(this, this.$inputs.outPos, this.n.xyz, this.n.w) ?? pb.vec4(pb.add(pb.mul(this.n.xyz, 0.5), pb.vec3(0.5)), 1);
|
|
114
|
+
//this.$outputs.outColor = pb.vec4(pb.fract(this.$inputs.uv0), 0, 1);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/** @internal */ function createProgramPostFFT2(limit) {
|
|
120
|
+
return Application.instance.device.buildRenderProgram({
|
|
121
|
+
vertex (pb) {
|
|
122
|
+
this.$inputs.position = pb.vec3().attrib('position');
|
|
123
|
+
pb.main(function() {
|
|
124
|
+
this.$builtins.position = pb.vec4(this.$inputs.position, 1);
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
fragment (pb) {
|
|
128
|
+
if (!limit || limit === 4) {
|
|
129
|
+
this.$outputs.dx_hy_dz_dxdz0 = pb.vec4();
|
|
130
|
+
this.$outputs.sx_sz_dxdx_dzdz0 = pb.vec4();
|
|
131
|
+
this.$outputs.dx_hy_dz_dxdz1 = pb.vec4();
|
|
132
|
+
this.$outputs.sx_sz_dxdx_dzdz1 = pb.vec4();
|
|
133
|
+
}
|
|
134
|
+
if (!limit || limit === 2) {
|
|
135
|
+
this.$outputs.dx_hy_dz_dxdz2 = pb.vec4();
|
|
136
|
+
this.$outputs.sx_sz_dxdx_dzdz2 = pb.vec4();
|
|
137
|
+
}
|
|
138
|
+
this.N2 = pb.float().uniform(0);
|
|
139
|
+
if (!limit || limit === 4) {
|
|
140
|
+
this.ifft0 = pb.tex2D().uniform(0);
|
|
141
|
+
this.ifft1 = pb.tex2D().uniform(0);
|
|
142
|
+
this.ifft2 = pb.tex2D().uniform(0);
|
|
143
|
+
this.ifft3 = pb.tex2D().uniform(0);
|
|
144
|
+
}
|
|
145
|
+
if (!limit || limit === 2) {
|
|
146
|
+
this.ifft4 = pb.tex2D().uniform(0);
|
|
147
|
+
this.ifft5 = pb.tex2D().uniform(0);
|
|
148
|
+
}
|
|
149
|
+
if (pb.getDevice().type === 'webgl') {
|
|
150
|
+
this.ifftTexSize = pb.vec2().uniform(0);
|
|
151
|
+
}
|
|
152
|
+
pb.main(function() {
|
|
153
|
+
this.$l.p = pb.float(pb.add(this.$builtins.fragCoord.x, this.$builtins.fragCoord.y));
|
|
154
|
+
this.$l.s = pb.sub(pb.mul(pb.sub(1, pb.mod(this.p, 2)), 2), 1);
|
|
155
|
+
this.$l.m = pb.mul(this.s, this.N2);
|
|
156
|
+
if (pb.getDevice().type === 'webgl') {
|
|
157
|
+
this.$l.uv = pb.div(pb.vec2(this.$builtins.fragCoord.xy), this.ifftTexSize);
|
|
158
|
+
if (!limit || limit === 4) {
|
|
159
|
+
this.$outputs.dx_hy_dz_dxdz0 = pb.mul(pb.textureSampleLevel(this.ifft0, this.uv, 0), this.m);
|
|
160
|
+
this.$outputs.sx_sz_dxdx_dzdz0 = pb.mul(pb.textureSampleLevel(this.ifft1, this.uv, 0), this.m);
|
|
161
|
+
this.$outputs.dx_hy_dz_dxdz1 = pb.mul(pb.textureSampleLevel(this.ifft2, this.uv, 0), this.m);
|
|
162
|
+
this.$outputs.sx_sz_dxdx_dzdz1 = pb.mul(pb.textureSampleLevel(this.ifft3, this.uv, 0), this.m);
|
|
163
|
+
}
|
|
164
|
+
if (!limit || limit === 2) {
|
|
165
|
+
this.$outputs.dx_hy_dz_dxdz2 = pb.mul(pb.textureSampleLevel(this.ifft4, this.uv, 0), this.m);
|
|
166
|
+
this.$outputs.sx_sz_dxdx_dzdz2 = pb.mul(pb.textureSampleLevel(this.ifft5, this.uv, 0), this.m);
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
this.$l.uv = pb.ivec2(this.$builtins.fragCoord.xy);
|
|
170
|
+
if (!limit || limit === 4) {
|
|
171
|
+
this.$outputs.dx_hy_dz_dxdz0 = pb.mul(pb.textureLoad(this.ifft0, this.uv, 0), this.m);
|
|
172
|
+
this.$outputs.sx_sz_dxdx_dzdz0 = pb.mul(pb.textureLoad(this.ifft1, this.uv, 0), this.m);
|
|
173
|
+
this.$outputs.dx_hy_dz_dxdz1 = pb.mul(pb.textureLoad(this.ifft2, this.uv, 0), this.m);
|
|
174
|
+
this.$outputs.sx_sz_dxdx_dzdz1 = pb.mul(pb.textureLoad(this.ifft3, this.uv, 0), this.m);
|
|
175
|
+
}
|
|
176
|
+
if (!limit || limit === 2) {
|
|
177
|
+
this.$outputs.dx_hy_dz_dxdz2 = pb.mul(pb.textureLoad(this.ifft4, this.uv, 0), this.m);
|
|
178
|
+
this.$outputs.sx_sz_dxdx_dzdz2 = pb.mul(pb.textureLoad(this.ifft5, this.uv, 0), this.m);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/** @internal */ function createProgramHk(limit) {
|
|
186
|
+
return Application.instance.device.buildRenderProgram({
|
|
187
|
+
vertex (pb) {
|
|
188
|
+
this.$inputs.position = pb.vec3().attrib('position');
|
|
189
|
+
pb.main(function() {
|
|
190
|
+
this.$builtins.position = pb.vec4(this.$inputs.position, 1);
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
fragment (pb) {
|
|
194
|
+
if (!limit || limit === 4) {
|
|
195
|
+
this.$outputs.spectrum0 = pb.vec4();
|
|
196
|
+
this.$outputs.spectrum1 = pb.vec4();
|
|
197
|
+
this.$outputs.spectrum2 = pb.vec4();
|
|
198
|
+
this.$outputs.spectrum3 = pb.vec4();
|
|
199
|
+
}
|
|
200
|
+
if (!limit || limit === 2) {
|
|
201
|
+
this.$outputs.spectrum4 = pb.vec4();
|
|
202
|
+
this.$outputs.spectrum5 = pb.vec4();
|
|
203
|
+
}
|
|
204
|
+
this.resolution = pb.int().uniform(0);
|
|
205
|
+
this.sizes = pb.vec4().uniform(0);
|
|
206
|
+
this.t = pb.float().uniform(0);
|
|
207
|
+
if (!limit || limit === 4) {
|
|
208
|
+
this.h0Texture0 = pb.tex2D().uniform(0);
|
|
209
|
+
this.h0Texture1 = pb.tex2D().uniform(0);
|
|
210
|
+
}
|
|
211
|
+
if (!limit || limit === 2) {
|
|
212
|
+
this.h0Texture2 = pb.tex2D().uniform(0);
|
|
213
|
+
}
|
|
214
|
+
if (pb.getDevice().type === 'webgl') {
|
|
215
|
+
this.h0TexSize = pb.vec2().uniform(0);
|
|
216
|
+
}
|
|
217
|
+
this.RATIO = pb.float(0.618033989036);
|
|
218
|
+
this.g = pb.float(9.81);
|
|
219
|
+
const Complex = pb.defineStruct([
|
|
220
|
+
pb.float('re'),
|
|
221
|
+
pb.float('im')
|
|
222
|
+
], 'Complex');
|
|
223
|
+
const Spectrum = pb.defineStruct([
|
|
224
|
+
Complex('dx'),
|
|
225
|
+
Complex('hy'),
|
|
226
|
+
Complex('dz'),
|
|
227
|
+
Complex('sx'),
|
|
228
|
+
Complex('sz'),
|
|
229
|
+
Complex('dxdx'),
|
|
230
|
+
Complex('dxdz'),
|
|
231
|
+
Complex('dzdz')
|
|
232
|
+
], 'Spectrum');
|
|
233
|
+
pb.func('add', [
|
|
234
|
+
Complex('a'),
|
|
235
|
+
Complex('b')
|
|
236
|
+
], function() {
|
|
237
|
+
this.$return(Complex(pb.add(this.a.re, this.b.re), pb.add(this.a.im, this.b.im)));
|
|
238
|
+
});
|
|
239
|
+
pb.func('mul', [
|
|
240
|
+
Complex('a'),
|
|
241
|
+
Complex('b')
|
|
242
|
+
], function() {
|
|
243
|
+
this.$return(Complex(pb.sub(pb.mul(this.a.re, this.b.re), pb.mul(this.a.im, this.b.im)), pb.add(pb.mul(this.a.re, this.b.im), pb.mul(this.a.im, this.b.re))));
|
|
244
|
+
});
|
|
245
|
+
pb.func('eix', [
|
|
246
|
+
pb.float('x')
|
|
247
|
+
], function() {
|
|
248
|
+
this.$return(Complex(pb.cos(this.x), pb.sin(this.x)));
|
|
249
|
+
});
|
|
250
|
+
pb.func('conj', [
|
|
251
|
+
Complex('a')
|
|
252
|
+
], function() {
|
|
253
|
+
this.$return(Complex(this.a.re, pb.neg(this.a.im)));
|
|
254
|
+
});
|
|
255
|
+
pb.func('scale', [
|
|
256
|
+
Complex('a'),
|
|
257
|
+
pb.float('v')
|
|
258
|
+
], function() {
|
|
259
|
+
this.$return(Complex(pb.mul(this.a.re, this.v), pb.mul(this.a.im, this.v)));
|
|
260
|
+
});
|
|
261
|
+
pb.func('negate', [
|
|
262
|
+
Complex('a')
|
|
263
|
+
], function() {
|
|
264
|
+
this.$return(Complex(pb.neg(this.a.re), pb.neg(this.a.im)));
|
|
265
|
+
});
|
|
266
|
+
for(let x = 0; x <= 2; x++){
|
|
267
|
+
if (x < 2 && limit === 2) {
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
if (x === 2 && limit === 4) {
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
pb.func(`getSpectrum${x}`, [
|
|
274
|
+
pb.vec2('x'),
|
|
275
|
+
pb.float('size'),
|
|
276
|
+
pb.ivec2('fragCoord')
|
|
277
|
+
], function() {
|
|
278
|
+
this.$l.hy = Complex(0, 0);
|
|
279
|
+
this.$l.sx = Complex(0, 0);
|
|
280
|
+
this.$l.sz = Complex(0, 0);
|
|
281
|
+
this.$l.dx = Complex(0, 0);
|
|
282
|
+
this.$l.dz = Complex(0, 0);
|
|
283
|
+
this.$l.dxdx = Complex(0, 0);
|
|
284
|
+
this.$l.dxdz = Complex(0, 0);
|
|
285
|
+
this.$l.dzdz = Complex(0, 0);
|
|
286
|
+
this.$if(pb.lessThanEqual(this.size, 1e-3), function() {
|
|
287
|
+
this.$return(Spectrum(this.dx, this.hy, this.dz, this.sx, this.sz, this.dxdx, this.dxdz, this.dzdz));
|
|
288
|
+
});
|
|
289
|
+
this.$l.k = pb.mul(this.x, pb.div(Math.PI * 2, this.size));
|
|
290
|
+
this.$l.kLen = pb.length(this.k);
|
|
291
|
+
this.$if(pb.greaterThan(this.kLen, 1e-6), function() {
|
|
292
|
+
this.$l.w = pb.sqrt(pb.mul(this.kLen, this.g));
|
|
293
|
+
if (pb.getDevice().type === 'webgl') {
|
|
294
|
+
this.$l.h0Texel = pb.textureSampleLevel(this[`h0Texture${x}`], pb.div(pb.vec2(this.fragCoord), this.h0TexSize), 0);
|
|
295
|
+
} else {
|
|
296
|
+
this.$l.h0Texel = pb.textureLoad(this[`h0Texture${x}`], this.fragCoord, 0);
|
|
297
|
+
}
|
|
298
|
+
this.$l.e = this.eix(pb.mul(this.w, this.t));
|
|
299
|
+
this.$l.h0 = Complex(this.h0Texel.x, this.h0Texel.y);
|
|
300
|
+
this.$l.h0MinConj = Complex(this.h0Texel.z, this.h0Texel.w);
|
|
301
|
+
this.hy = this.add(this.mul(this.h0, this.e), this.mul(this.h0MinConj, this.conj(this.e)));
|
|
302
|
+
this.$if(pb.notEqual(this.fragCoord.x, 0), function() {
|
|
303
|
+
this.sx = this.mul(Complex(0, this.k.x), this.hy);
|
|
304
|
+
this.dx = this.mul(Complex(0, pb.div(pb.neg(this.k.x), this.kLen)), this.hy);
|
|
305
|
+
this.dxdx = this.scale(this.hy, pb.div(pb.mul(this.k.x, this.k.x), this.kLen));
|
|
306
|
+
});
|
|
307
|
+
this.$if(pb.notEqual(this.fragCoord.y, 0), function() {
|
|
308
|
+
this.sz = this.mul(Complex(0, this.k.y), this.hy);
|
|
309
|
+
this.dz = this.mul(Complex(0, pb.div(pb.neg(this.k.y), this.kLen)), this.hy);
|
|
310
|
+
this.dzdz = this.scale(this.hy, pb.div(pb.mul(this.k.y, this.k.y), this.kLen));
|
|
311
|
+
this.$if(pb.notEqual(this.fragCoord.x, 0), function() {
|
|
312
|
+
this.dxdz = this.scale(this.hy, pb.div(pb.mul(this.k.x, this.k.y), this.kLen));
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
this.$return(Spectrum(this.dx, this.hy, this.dz, this.sx, this.sz, this.dxdx, this.dxdz, this.dzdz));
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
pb.func('compressSpectrum', [
|
|
320
|
+
Spectrum('spec'),
|
|
321
|
+
pb.vec4('part0').out(),
|
|
322
|
+
pb.vec4('part1').out()
|
|
323
|
+
], function() {
|
|
324
|
+
this.$l.i = Complex(0, 1);
|
|
325
|
+
this.$l.dx_hy = this.add(this.spec.dx, this.mul(this.i, this.spec.hy));
|
|
326
|
+
this.$l.dz_dxdz = this.add(this.spec.dz, this.mul(this.i, this.spec.dxdz));
|
|
327
|
+
this.$l.sx_sz = this.add(this.spec.sx, this.mul(this.i, this.spec.sz));
|
|
328
|
+
this.$l.dxdx_dzdz = this.add(this.spec.dxdx, this.mul(this.i, this.spec.dzdz));
|
|
329
|
+
this.part0 = pb.vec4(this.dx_hy.re, this.dx_hy.im, this.dz_dxdz.re, this.dz_dxdz.im);
|
|
330
|
+
this.part1 = pb.vec4(this.sx_sz.re, this.sx_sz.im, this.dxdx_dzdz.re, this.dxdx_dzdz.im);
|
|
331
|
+
});
|
|
332
|
+
pb.main(function() {
|
|
333
|
+
this.fragXY = pb.ivec2(this.$builtins.fragCoord.xy);
|
|
334
|
+
this.$l.x = pb.vec2(pb.sub(this.fragXY, pb.ivec2(pb.div(this.resolution, 2))));
|
|
335
|
+
if (!limit || limit === 4) {
|
|
336
|
+
this.$l.spectrum0 = pb.vec4();
|
|
337
|
+
this.$l.spectrum1 = pb.vec4();
|
|
338
|
+
this.$l.spectrum2 = pb.vec4();
|
|
339
|
+
this.$l.spectrum3 = pb.vec4();
|
|
340
|
+
this.$l.spec0 = this.getSpectrum0(this.x, this.sizes.x, this.fragXY);
|
|
341
|
+
this.$l.spec1 = this.getSpectrum1(this.x, this.sizes.y, this.fragXY);
|
|
342
|
+
this.compressSpectrum(this.spec0, this.spectrum0, this.spectrum1);
|
|
343
|
+
this.compressSpectrum(this.spec1, this.spectrum2, this.spectrum3);
|
|
344
|
+
this.$outputs.spectrum0 = this.spectrum0;
|
|
345
|
+
this.$outputs.spectrum1 = this.spectrum1;
|
|
346
|
+
this.$outputs.spectrum2 = this.spectrum2;
|
|
347
|
+
this.$outputs.spectrum3 = this.spectrum3;
|
|
348
|
+
}
|
|
349
|
+
if (!limit || limit === 2) {
|
|
350
|
+
this.$l.spectrum4 = pb.vec4();
|
|
351
|
+
this.$l.spectrum5 = pb.vec4();
|
|
352
|
+
this.$l.spec2 = this.getSpectrum2(this.x, this.sizes.z, this.fragXY);
|
|
353
|
+
this.compressSpectrum(this.spec2, this.spectrum4, this.spectrum5);
|
|
354
|
+
this.$outputs.spectrum4 = this.spectrum4;
|
|
355
|
+
this.$outputs.spectrum5 = this.spectrum5;
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
/** @internal */ function createProgramH0() {
|
|
362
|
+
return Application.instance.device.buildRenderProgram({
|
|
363
|
+
vertex (pb) {
|
|
364
|
+
this.$inputs.position = pb.vec3().attrib('position');
|
|
365
|
+
pb.main(function() {
|
|
366
|
+
this.$builtins.position = pb.vec4(this.$inputs.position, 1);
|
|
367
|
+
});
|
|
368
|
+
},
|
|
369
|
+
fragment (pb) {
|
|
370
|
+
this.$outputs.spectrum0 = pb.vec4();
|
|
371
|
+
this.$outputs.spectrum1 = pb.vec4();
|
|
372
|
+
this.$outputs.spectrum2 = pb.vec4();
|
|
373
|
+
this.noise = pb.tex2D().uniform(0);
|
|
374
|
+
this.resolution = pb.int().uniform(0);
|
|
375
|
+
this.wind = pb.vec2().uniform(0);
|
|
376
|
+
this.alignment = pb.float().uniform(0);
|
|
377
|
+
this.g = pb.float(9.81);
|
|
378
|
+
this.cascade0 = pb.vec4().uniform(0);
|
|
379
|
+
this.cascade1 = pb.vec4().uniform(0);
|
|
380
|
+
this.cascade2 = pb.vec4().uniform(0);
|
|
381
|
+
pb.func('gauss', [
|
|
382
|
+
pb.ivec2('fragCoord')
|
|
383
|
+
], function() {
|
|
384
|
+
this.$l.uv = pb.div(pb.vec2(this.fragCoord), pb.float(this.resolution));
|
|
385
|
+
this.$l.noise0 = pb.textureSampleLevel(this.noise, this.uv, 0).rg;
|
|
386
|
+
this.$l.noise1 = pb.textureSampleLevel(this.noise, pb.neg(this.uv), 0).rg;
|
|
387
|
+
this.$l.u0 = pb.mul(this.noise0.x, Math.PI * 2);
|
|
388
|
+
this.$l.v0 = pb.sqrt(pb.mul(pb.log(this.noise0.y), -2));
|
|
389
|
+
this.$l.u1 = pb.mul(this.noise1.x, Math.PI * 2);
|
|
390
|
+
this.$l.v1 = pb.sqrt(pb.mul(pb.log(this.noise1.y), -2));
|
|
391
|
+
this.$return(pb.vec4(pb.mul(this.v0, pb.cos(this.u0)), pb.mul(this.v0, pb.sin(this.u0)), pb.mul(this.v1, pb.cos(this.u1)), pb.mul(pb.neg(this.v1), pb.sin(this.u1))));
|
|
392
|
+
});
|
|
393
|
+
pb.func('phillips', [
|
|
394
|
+
pb.vec2('k'),
|
|
395
|
+
pb.float('A'),
|
|
396
|
+
pb.float('minK'),
|
|
397
|
+
pb.float('maxK')
|
|
398
|
+
], function() {
|
|
399
|
+
this.$l.k2 = pb.dot(this.k, this.k);
|
|
400
|
+
this.$if(pb.or(pb.lessThanEqual(this.k2, pb.mul(this.minK, this.minK)), pb.greaterThanEqual(this.k2, pb.mul(this.maxK, this.maxK))), function() {
|
|
401
|
+
this.$return(pb.vec4(0));
|
|
402
|
+
});
|
|
403
|
+
this.$l.L = pb.div(pb.dot(this.wind, this.wind), this.g);
|
|
404
|
+
this.$l.L2 = pb.mul(this.L, this.L);
|
|
405
|
+
this.$l.h0k = pb.mul(pb.div(pb.div(this.A, this.k2), this.k2), pb.exp(pb.div(-1, pb.mul(this.k2, this.L2))), 0.5);
|
|
406
|
+
this.$l.h0mk = this.h0k;
|
|
407
|
+
this.$if(pb.greaterThan(this.alignment, 0), function() {
|
|
408
|
+
this.h0k = pb.mul(this.h0k, pb.pow(pb.max(0, pb.dot(pb.normalize(this.wind), pb.normalize(this.k))), this.alignment));
|
|
409
|
+
this.h0mk = pb.mul(this.h0mk, pb.pow(pb.max(0, pb.dot(pb.normalize(this.wind), pb.normalize(pb.neg(this.k)))), this.alignment));
|
|
410
|
+
});
|
|
411
|
+
this.$return(pb.sqrt(pb.vec4(this.h0k, this.h0k, this.h0mk, this.h0mk)));
|
|
412
|
+
});
|
|
413
|
+
pb.main(function() {
|
|
414
|
+
this.$l.x = pb.vec2(pb.sub(pb.ivec2(this.$builtins.fragCoord.xy), pb.ivec2(pb.div(this.resolution, 2))));
|
|
415
|
+
this.$l.k = pb.mul(pb.vec2(Math.PI * 2), this.x);
|
|
416
|
+
this.$l.rnd = this.gauss(pb.ivec2(this.$builtins.fragCoord.xy));
|
|
417
|
+
this.$outputs.spectrum0 = pb.mul(this.phillips(pb.div(this.k, this.cascade0.x), this.cascade0.y, this.cascade0.z, this.cascade0.w), this.rnd);
|
|
418
|
+
this.$outputs.spectrum1 = pb.mul(this.phillips(pb.div(this.k, this.cascade1.x), this.cascade1.y, this.cascade1.z, this.cascade1.w), this.rnd);
|
|
419
|
+
this.$outputs.spectrum2 = pb.mul(this.phillips(pb.div(this.k, this.cascade2.x), this.cascade2.y, this.cascade2.z, this.cascade2.w), this.rnd);
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
/** @internal */ function createProgramFFT2V(limit) {
|
|
425
|
+
return Application.instance.device.buildRenderProgram({
|
|
426
|
+
vertex (pb) {
|
|
427
|
+
this.$inputs.position = pb.vec3().attrib('position');
|
|
428
|
+
pb.main(function() {
|
|
429
|
+
this.$builtins.position = pb.vec4(this.$inputs.position, 1);
|
|
430
|
+
});
|
|
431
|
+
},
|
|
432
|
+
fragment (pb) {
|
|
433
|
+
if (!limit || limit === 4) {
|
|
434
|
+
this.$outputs.ifft0 = pb.vec4();
|
|
435
|
+
this.$outputs.ifft1 = pb.vec4();
|
|
436
|
+
this.$outputs.ifft2 = pb.vec4();
|
|
437
|
+
this.$outputs.ifft3 = pb.vec4();
|
|
438
|
+
this.spectrum0 = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
439
|
+
this.spectrum1 = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
440
|
+
this.spectrum2 = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
441
|
+
this.spectrum3 = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
442
|
+
}
|
|
443
|
+
if (!limit || limit === 2) {
|
|
444
|
+
this.$outputs.ifft4 = pb.vec4();
|
|
445
|
+
this.$outputs.ifft5 = pb.vec4();
|
|
446
|
+
this.spectrum4 = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
447
|
+
this.spectrum5 = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
448
|
+
}
|
|
449
|
+
this.butterfly = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
450
|
+
if (pb.getDevice().type === 'webgl') {
|
|
451
|
+
this.texSize = pb.vec4().uniform(0);
|
|
452
|
+
}
|
|
453
|
+
this.phase = pb.int().uniform(0);
|
|
454
|
+
const Complex = pb.defineStruct([
|
|
455
|
+
pb.float('re'),
|
|
456
|
+
pb.float('im')
|
|
457
|
+
], 'Complex');
|
|
458
|
+
pb.func('add', [
|
|
459
|
+
Complex('a'),
|
|
460
|
+
Complex('b')
|
|
461
|
+
], function() {
|
|
462
|
+
this.$return(Complex(pb.add(this.a.re, this.b.re), pb.add(this.a.im, this.b.im)));
|
|
463
|
+
});
|
|
464
|
+
pb.func('mul', [
|
|
465
|
+
Complex('a'),
|
|
466
|
+
Complex('b')
|
|
467
|
+
], function() {
|
|
468
|
+
this.$return(Complex(pb.sub(pb.mul(this.a.re, this.b.re), pb.mul(this.a.im, this.b.im)), pb.add(pb.mul(this.a.re, this.b.im), pb.mul(this.a.im, this.b.re))));
|
|
469
|
+
});
|
|
470
|
+
pb.func('scale', [
|
|
471
|
+
Complex('a'),
|
|
472
|
+
pb.float('v')
|
|
473
|
+
], function() {
|
|
474
|
+
this.$return(Complex(pb.mul(this.a.re, this.v), pb.mul(this.a.im, this.v)));
|
|
475
|
+
});
|
|
476
|
+
for(let x = 0; x <= 5; x++){
|
|
477
|
+
if (x < 4 && limit === 2) {
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
if (x > 3 && limit === 4) {
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
pb.func(`twiddle${x}`, [
|
|
484
|
+
pb.vec4('texelButt'),
|
|
485
|
+
pb.int('x')
|
|
486
|
+
], function() {
|
|
487
|
+
if (pb.getDevice().type === 'webgl') {
|
|
488
|
+
this.$l.texelA = pb.textureSampleLevel(this[`spectrum${x}`], pb.div(pb.vec2(pb.float(this.x), this.texelButt.b), this.texSize.xy), 0);
|
|
489
|
+
this.$l.texelB = pb.textureSampleLevel(this[`spectrum${x}`], pb.div(pb.vec2(pb.float(this.x), this.texelButt.a), this.texSize.xy), 0);
|
|
490
|
+
} else {
|
|
491
|
+
this.$l.texelA = pb.textureLoad(this[`spectrum${x}`], pb.ivec2(this.x, pb.int(this.texelButt.b)), 0);
|
|
492
|
+
this.$l.texelB = pb.textureLoad(this[`spectrum${x}`], pb.ivec2(this.x, pb.int(this.texelButt.a)), 0);
|
|
493
|
+
}
|
|
494
|
+
this.$l.w = Complex(this.texelButt.r, this.texelButt.g);
|
|
495
|
+
this.$l.a1 = Complex(this.texelA.x, this.texelA.y);
|
|
496
|
+
this.$l.b1 = Complex(this.texelB.x, this.texelB.y);
|
|
497
|
+
this.$l.r1 = this.scale(this.add(this.a1, this.mul(this.b1, this.w)), 0.5);
|
|
498
|
+
this.$l.a2 = Complex(this.texelA.z, this.texelA.w);
|
|
499
|
+
this.$l.b2 = Complex(this.texelB.z, this.texelB.w);
|
|
500
|
+
this.$l.r2 = this.scale(this.add(this.a2, this.mul(this.b2, this.w)), 0.5);
|
|
501
|
+
this.$return(pb.vec4(this.r1.re, this.r1.im, this.r2.re, this.r2.im));
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
pb.main(function() {
|
|
505
|
+
this.$l.x = pb.int(this.$builtins.fragCoord.x);
|
|
506
|
+
this.$l.y = pb.int(this.$builtins.fragCoord.y);
|
|
507
|
+
if (pb.getDevice().type === 'webgl') {
|
|
508
|
+
this.$l.texelButt = pb.textureSampleLevel(this.butterfly, pb.div(pb.vec2(pb.float(this.phase), pb.float(this.y)), this.texSize.zw), 0);
|
|
509
|
+
} else {
|
|
510
|
+
this.$l.texelButt = pb.textureLoad(this.butterfly, pb.ivec2(this.phase, this.y), 0);
|
|
511
|
+
}
|
|
512
|
+
if (!limit || limit === 4) {
|
|
513
|
+
this.$outputs.ifft0 = this.twiddle0(this.texelButt, this.x);
|
|
514
|
+
this.$outputs.ifft1 = this.twiddle1(this.texelButt, this.x);
|
|
515
|
+
this.$outputs.ifft2 = this.twiddle2(this.texelButt, this.x);
|
|
516
|
+
this.$outputs.ifft3 = this.twiddle3(this.texelButt, this.x);
|
|
517
|
+
}
|
|
518
|
+
if (!limit || limit === 2) {
|
|
519
|
+
this.$outputs.ifft4 = this.twiddle4(this.texelButt, this.x);
|
|
520
|
+
this.$outputs.ifft5 = this.twiddle5(this.texelButt, this.x);
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
/** @internal */ function createProgramFFT2H(limit) {
|
|
527
|
+
return Application.instance.device.buildRenderProgram({
|
|
528
|
+
vertex (pb) {
|
|
529
|
+
this.$inputs.position = pb.vec3().attrib('position');
|
|
530
|
+
pb.main(function() {
|
|
531
|
+
this.$builtins.position = pb.vec4(this.$inputs.position, 1);
|
|
532
|
+
});
|
|
533
|
+
},
|
|
534
|
+
fragment (pb) {
|
|
535
|
+
if (!limit || limit === 4) {
|
|
536
|
+
this.$outputs.ifft0 = pb.vec4();
|
|
537
|
+
this.$outputs.ifft1 = pb.vec4();
|
|
538
|
+
this.$outputs.ifft2 = pb.vec4();
|
|
539
|
+
this.$outputs.ifft3 = pb.vec4();
|
|
540
|
+
this.spectrum0 = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
541
|
+
this.spectrum1 = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
542
|
+
this.spectrum2 = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
543
|
+
this.spectrum3 = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
544
|
+
}
|
|
545
|
+
if (!limit || limit === 2) {
|
|
546
|
+
this.$outputs.ifft4 = pb.vec4();
|
|
547
|
+
this.$outputs.ifft5 = pb.vec4();
|
|
548
|
+
this.spectrum4 = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
549
|
+
this.spectrum5 = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
550
|
+
}
|
|
551
|
+
this.butterfly = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
552
|
+
this.phase = pb.int().uniform(0);
|
|
553
|
+
if (pb.getDevice().type === 'webgl') {
|
|
554
|
+
this.texSize = pb.vec4().uniform(0);
|
|
555
|
+
}
|
|
556
|
+
const Complex = pb.defineStruct([
|
|
557
|
+
pb.float('re'),
|
|
558
|
+
pb.float('im')
|
|
559
|
+
], 'Complex');
|
|
560
|
+
pb.func('add', [
|
|
561
|
+
Complex('a'),
|
|
562
|
+
Complex('b')
|
|
563
|
+
], function() {
|
|
564
|
+
this.$return(Complex(pb.add(this.a.re, this.b.re), pb.add(this.a.im, this.b.im)));
|
|
565
|
+
});
|
|
566
|
+
pb.func('mul', [
|
|
567
|
+
Complex('a'),
|
|
568
|
+
Complex('b')
|
|
569
|
+
], function() {
|
|
570
|
+
this.$return(Complex(pb.sub(pb.mul(this.a.re, this.b.re), pb.mul(this.a.im, this.b.im)), pb.add(pb.mul(this.a.re, this.b.im), pb.mul(this.a.im, this.b.re))));
|
|
571
|
+
});
|
|
572
|
+
pb.func('scale', [
|
|
573
|
+
Complex('a'),
|
|
574
|
+
pb.float('v')
|
|
575
|
+
], function() {
|
|
576
|
+
this.$return(Complex(pb.mul(this.a.re, this.v), pb.mul(this.a.im, this.v)));
|
|
577
|
+
});
|
|
578
|
+
for(let x = 0; x <= 5; x++){
|
|
579
|
+
if (x < 4 && limit === 2) {
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
if (x > 3 && limit === 4) {
|
|
583
|
+
continue;
|
|
584
|
+
}
|
|
585
|
+
pb.func(`twiddle${x}`, [
|
|
586
|
+
pb.vec4('texelButt'),
|
|
587
|
+
pb.int('y')
|
|
588
|
+
], function() {
|
|
589
|
+
if (pb.getDevice().type === 'webgl') {
|
|
590
|
+
this.$l.texelA = pb.textureSampleLevel(this[`spectrum${x}`], pb.div(pb.vec2(this.texelButt.b, pb.float(this.y)), this.texSize.xy), 0);
|
|
591
|
+
this.$l.texelB = pb.textureSampleLevel(this[`spectrum${x}`], pb.div(pb.vec2(this.texelButt.a, pb.float(this.y)), this.texSize.xy), 0);
|
|
592
|
+
} else {
|
|
593
|
+
this.$l.texelA = pb.textureLoad(this[`spectrum${x}`], pb.ivec2(pb.int(this.texelButt.b), this.y), 0);
|
|
594
|
+
this.$l.texelB = pb.textureLoad(this[`spectrum${x}`], pb.ivec2(pb.int(this.texelButt.a), this.y), 0);
|
|
595
|
+
}
|
|
596
|
+
this.$l.w = Complex(this.texelButt.r, this.texelButt.g);
|
|
597
|
+
this.$l.a1 = Complex(this.texelA.x, this.texelA.y);
|
|
598
|
+
this.$l.b1 = Complex(this.texelB.x, this.texelB.y);
|
|
599
|
+
this.$l.r1 = this.scale(this.add(this.a1, this.mul(this.b1, this.w)), 0.5);
|
|
600
|
+
this.$l.a2 = Complex(this.texelA.z, this.texelA.w);
|
|
601
|
+
this.$l.b2 = Complex(this.texelB.z, this.texelB.w);
|
|
602
|
+
this.$l.r2 = this.scale(this.add(this.a2, this.mul(this.b2, this.w)), 0.5);
|
|
603
|
+
this.$return(pb.vec4(this.r1.re, this.r1.im, this.r2.re, this.r2.im));
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
pb.main(function() {
|
|
607
|
+
this.$l.x = pb.int(this.$builtins.fragCoord.x);
|
|
608
|
+
this.$l.y = pb.int(this.$builtins.fragCoord.y);
|
|
609
|
+
if (pb.getDevice().type === 'webgl') {
|
|
610
|
+
this.$l.texelButt = pb.textureSampleLevel(this.butterfly, pb.div(pb.vec2(pb.float(this.phase), pb.float(this.x)), this.texSize.zw), 0);
|
|
611
|
+
} else {
|
|
612
|
+
this.$l.texelButt = pb.textureLoad(this.butterfly, pb.ivec2(this.phase, this.x), 0);
|
|
613
|
+
}
|
|
614
|
+
if (!limit || limit === 4) {
|
|
615
|
+
this.$outputs.ifft0 = this.twiddle0(this.texelButt, this.y);
|
|
616
|
+
this.$outputs.ifft1 = this.twiddle1(this.texelButt, this.y);
|
|
617
|
+
this.$outputs.ifft2 = this.twiddle2(this.texelButt, this.y);
|
|
618
|
+
this.$outputs.ifft3 = this.twiddle3(this.texelButt, this.y);
|
|
619
|
+
}
|
|
620
|
+
if (!limit || limit === 2) {
|
|
621
|
+
this.$outputs.ifft4 = this.twiddle4(this.texelButt, this.y);
|
|
622
|
+
this.$outputs.ifft5 = this.twiddle5(this.texelButt, this.y);
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
export { createProgramFFT2H, createProgramFFT2V, createProgramH0, createProgramHk, createProgramOcean, createProgramPostFFT2 };
|
|
630
|
+
//# sourceMappingURL=water.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"water.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|