@zephyr3d/scene 0.9.26 → 0.9.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation/animationset.js +92 -30
- package/dist/animation/animationset.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/skeleton.js +21 -1
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/asset/model.js +6 -2
- package/dist/asset/model.js.map +1 -1
- package/dist/camera/camera.js +75 -23
- package/dist/camera/camera.js.map +1 -1
- package/dist/index.d.ts +4764 -3600
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/material/hairstrand.js +235 -235
- package/dist/material/hairstrand.js.map +1 -1
- package/dist/material/material.js +296 -296
- package/dist/material/material.js.map +1 -1
- package/dist/material/mixins/lit.js +33 -1
- package/dist/material/mixins/lit.js.map +1 -1
- package/dist/material/shader/helper.js +404 -3
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/water.js +2057 -72
- package/dist/material/water.js.map +1 -1
- package/dist/posteffect/motionblur.js +663 -58
- package/dist/posteffect/motionblur.js.map +1 -1
- package/dist/posteffect/posteffect.js +12 -1
- package/dist/posteffect/posteffect.js.map +1 -1
- package/dist/posteffect/sao.js +46 -44
- package/dist/posteffect/sao.js.map +1 -1
- package/dist/posteffect/sss.js +30 -2
- package/dist/posteffect/sss.js.map +1 -1
- package/dist/render/abuffer_oit.js +37 -37
- package/dist/render/abuffer_oit.js.map +1 -1
- package/dist/render/clipmap.js +156 -5
- package/dist/render/clipmap.js.map +1 -1
- package/dist/render/cull_visitor.js +1 -0
- package/dist/render/cull_visitor.js.map +1 -1
- package/dist/render/dualdepthpeeling_oit.js +49 -49
- package/dist/render/dualdepthpeeling_oit.js.map +1 -1
- package/dist/render/fbm_wavegenerator.js +3 -3
- package/dist/render/fbm_wavegenerator.js.map +1 -1
- package/dist/render/fft_wavegenerator.js +57 -15
- package/dist/render/fft_wavegenerator.js.map +1 -1
- package/dist/render/gerstner_wavegenerator.js +127 -20
- package/dist/render/gerstner_wavegenerator.js.map +1 -1
- package/dist/render/hzb.js +80 -22
- package/dist/render/hzb.js.map +1 -1
- package/dist/render/lightpass.js +6 -3
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/oit.js +11 -11
- package/dist/render/oit.js.map +1 -1
- package/dist/render/render_queue.js +36 -0
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +4 -0
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/rendergraph/blackboard.js +1 -0
- package/dist/render/rendergraph/blackboard.js.map +1 -1
- package/dist/render/rendergraph/forward_plus_builder.js +318 -9
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/render/rendergraph/frame_resource_requirements.js +1 -0
- package/dist/render/rendergraph/frame_resource_requirements.js.map +1 -1
- package/dist/render/rendergraph/history_resources.js +8 -1
- package/dist/render/rendergraph/history_resources.js.map +1 -1
- package/dist/render/underwater.js +624 -0
- package/dist/render/underwater.js.map +1 -0
- package/dist/render/water_caustics.js +1380 -0
- package/dist/render/water_caustics.js.map +1 -0
- package/dist/render/weightedblended_oit.js +33 -33
- package/dist/render/weightedblended_oit.js.map +1 -1
- package/dist/scene/water.js +540 -4
- package/dist/scene/water.js.map +1 -1
- package/dist/shaders/water.js +22 -19
- package/dist/shaders/water.js.map +1 -1
- package/dist/shaders/water_medium.js +56 -0
- package/dist/shaders/water_medium.js.map +1 -0
- package/dist/shadow/shadow_region.js +49 -49
- package/dist/shadow/shadow_region.js.map +1 -1
- package/dist/utility/serialization/manager.js +3 -1
- package/dist/utility/serialization/manager.js.map +1 -1
- package/dist/utility/serialization/scene/animation.js +31 -2
- package/dist/utility/serialization/scene/animation.js.map +1 -1
- package/dist/utility/serialization/scene/camera.js +53 -25
- package/dist/utility/serialization/scene/camera.js.map +1 -1
- package/dist/utility/serialization/scene/light.js.map +1 -1
- package/dist/utility/serialization/scene/water.js +1101 -21
- package/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/utility/shprojector.js +87 -87
- package/dist/utility/shprojector.js.map +1 -1
- package/package.json +1 -1
- package/dist/render/rendergraph/frame_graph_context.js +0 -41
- package/dist/render/rendergraph/frame_graph_context.js.map +0 -1
- package/dist/shaders/ssgi.js +0 -63
- package/dist/shaders/ssgi.js.map +0 -1
- package/dist/shaders/ssgi_reprojection.js +0 -118
- package/dist/shaders/ssgi_reprojection.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Disposable } from '@zephyr3d/base';
|
|
1
|
+
import { Disposable, PRNG } from '@zephyr3d/base';
|
|
2
2
|
import { ShaderHelper } from '../material/shader/helper.js';
|
|
3
3
|
import '../material/lambert.js';
|
|
4
4
|
import '../material/blinn.js';
|
|
@@ -29,26 +29,35 @@ import '../utility/blueprint/material/texture.js';
|
|
|
29
29
|
_version;
|
|
30
30
|
_waveParams;
|
|
31
31
|
_numWaves;
|
|
32
|
+
_rand;
|
|
33
|
+
_foamParams;
|
|
32
34
|
/**
|
|
33
35
|
* Creates a new Gerstner wave generator.
|
|
34
|
-
*/ constructor(){
|
|
36
|
+
*/ constructor(randomSeed = 0){
|
|
35
37
|
super();
|
|
36
38
|
this._waveParams = new Float32Array(8 * MAX_GERSTNER_WAVE_COUNT);
|
|
39
|
+
this._rand = new PRNG(randomSeed);
|
|
37
40
|
this.randomWave(0);
|
|
38
41
|
this.randomWave(1);
|
|
39
42
|
this.randomWave(2);
|
|
40
43
|
this.randomWave(3);
|
|
41
44
|
this._numWaves = 4;
|
|
42
45
|
this._version = 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
// Same defaults as the FFT generator, so switching between the two does not
|
|
47
|
+
// change the foam response out of the box.
|
|
48
|
+
this._foamParams = new Float32Array([
|
|
49
|
+
1.2,
|
|
50
|
+
7.2
|
|
51
|
+
]);
|
|
52
|
+
}
|
|
53
|
+
/** @internal */ static randomWaveData(rand, array, offset) {
|
|
54
|
+
array[offset + 0] = rand.get() * Math.PI * 2;
|
|
55
|
+
array[offset + 1] = rand.get() * 0.5 + 0.5;
|
|
56
|
+
array[offset + 2] = rand.get() * 0.1;
|
|
57
|
+
array[offset + 3] = rand.get() * 10;
|
|
58
|
+
array[offset + 4] = rand.get() * 100 - 50;
|
|
50
59
|
array[offset + 5] = 0;
|
|
51
|
-
array[offset + 6] =
|
|
60
|
+
array[offset + 6] = rand.get() * 100 - 50;
|
|
52
61
|
array[offset + 7] = 0;
|
|
53
62
|
}
|
|
54
63
|
/** @internal */ setRaw(data, index) {
|
|
@@ -58,8 +67,12 @@ import '../utility/blueprint/material/texture.js';
|
|
|
58
67
|
const other = new GerstnerWaveGenerator();
|
|
59
68
|
other.numWaves = this.numWaves;
|
|
60
69
|
other._waveParams.set(this._waveParams);
|
|
70
|
+
other._foamParams.set(this._foamParams);
|
|
61
71
|
return other;
|
|
62
72
|
}
|
|
73
|
+
get rand() {
|
|
74
|
+
return this._rand;
|
|
75
|
+
}
|
|
63
76
|
get version() {
|
|
64
77
|
return this._version;
|
|
65
78
|
}
|
|
@@ -80,20 +93,37 @@ import '../utility/blueprint/material/texture.js';
|
|
|
80
93
|
}
|
|
81
94
|
}
|
|
82
95
|
/** Delete wave at index */ deleteWave(index) {
|
|
96
|
+
if (index < 0 || index >= this._numWaves) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
83
99
|
for(let i = index; i < this._numWaves - 1; i++){
|
|
84
100
|
for(let j = 0; j < 8; j++){
|
|
85
101
|
this._waveParams[i * 8 + j] = this._waveParams[(i + 1) * 8 + j];
|
|
86
102
|
}
|
|
87
103
|
}
|
|
88
104
|
this._numWaves--;
|
|
105
|
+
this._version++;
|
|
89
106
|
}
|
|
90
|
-
/**
|
|
91
|
-
|
|
107
|
+
/** Insert a wave slot at index, shifting the subsequent waves up */ insertWave(index) {
|
|
108
|
+
// Bounded by the parameter buffer; the shader reads this many slots.
|
|
109
|
+
if (this._numWaves >= MAX_GERSTNER_WAVE_COUNT) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
// Shift from the tail backwards so the gap opens at `index` without
|
|
113
|
+
// overwriting the slot that is about to move. Copying forward here would
|
|
114
|
+
// duplicate `waveParams[index]` into every later slot instead of moving
|
|
115
|
+
// them up. The new slot is filled with a random wave rather than left at
|
|
116
|
+
// zero: a zero wavelength makes `w = 2*PI / length` infinite and drives the
|
|
117
|
+
// vertex shader into NaN, which collapses the whole surface, so the slot
|
|
118
|
+
// has to be a valid wave even before the caller writes its parameters.
|
|
119
|
+
for(let i = this._numWaves - 1; i >= index; i--){
|
|
92
120
|
for(let j = 0; j < 8; j++){
|
|
93
121
|
this._waveParams[(i + 1) * 8 + j] = this._waveParams[i * 8 + j];
|
|
94
122
|
}
|
|
95
123
|
}
|
|
124
|
+
this.randomWave(index);
|
|
96
125
|
this._numWaves++;
|
|
126
|
+
this._version++;
|
|
97
127
|
}
|
|
98
128
|
/**
|
|
99
129
|
* Sets the angle of the wave direction in radians.
|
|
@@ -180,6 +210,24 @@ import '../utility/blueprint/material/texture.js';
|
|
|
180
210
|
this._version++;
|
|
181
211
|
}
|
|
182
212
|
}
|
|
213
|
+
/** Gets the foam width. */ get foamWidth() {
|
|
214
|
+
return this._foamParams[0];
|
|
215
|
+
}
|
|
216
|
+
set foamWidth(val) {
|
|
217
|
+
if (val !== this._foamParams[0]) {
|
|
218
|
+
this._foamParams[0] = val;
|
|
219
|
+
this._version++;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/** Gets the foam contrast. */ get foamContrast() {
|
|
223
|
+
return this._foamParams[1];
|
|
224
|
+
}
|
|
225
|
+
set foamContrast(val) {
|
|
226
|
+
if (val !== this._foamParams[1]) {
|
|
227
|
+
this._foamParams[1] = val;
|
|
228
|
+
this._version++;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
183
231
|
/**
|
|
184
232
|
* Gets the X coordinate of the wave origin if it is an omni-directional wave.
|
|
185
233
|
* @param waveIndex - index of the wave to set.
|
|
@@ -207,7 +255,7 @@ import '../utility/blueprint/material/texture.js';
|
|
|
207
255
|
}
|
|
208
256
|
}
|
|
209
257
|
/** @internal */ randomWave(i) {
|
|
210
|
-
GerstnerWaveGenerator.randomWaveData(this._waveParams, i * 8);
|
|
258
|
+
GerstnerWaveGenerator.randomWaveData(this._rand, this._waveParams, i * 8);
|
|
211
259
|
}
|
|
212
260
|
/** {@inheritDoc WaveGenerator.update} */ update() {}
|
|
213
261
|
/** {@inheritDoc WaveGenerator.needUpdate} */ needUpdate() {
|
|
@@ -224,7 +272,7 @@ import '../utility/blueprint/material/texture.js';
|
|
|
224
272
|
outAABB.minPoint.setXYZ(minX, y, minZ);
|
|
225
273
|
outAABB.maxPoint.setXYZ(maxX, y + maxHeight, maxZ);
|
|
226
274
|
}
|
|
227
|
-
/** {@inheritDoc WaveGenerator.calcFragmentNormal} */ calcFragmentNormal(scope, xz) {
|
|
275
|
+
/** {@inheritDoc WaveGenerator.calcFragmentNormal} */ calcFragmentNormal(scope, xz, _vertexNormal) {
|
|
228
276
|
const pb = scope.$builder;
|
|
229
277
|
const that = this;
|
|
230
278
|
pb.func('calcFragmentNormal', [
|
|
@@ -238,21 +286,64 @@ import '../utility/blueprint/material/texture.js';
|
|
|
238
286
|
});
|
|
239
287
|
return scope.calcFragmentNormal(xz);
|
|
240
288
|
}
|
|
241
|
-
/** {@inheritDoc WaveGenerator.calcFragmentNormalAndFoam} */ calcFragmentNormalAndFoam(scope, xz) {
|
|
242
|
-
|
|
289
|
+
/** {@inheritDoc WaveGenerator.calcFragmentNormalAndFoam} */ calcFragmentNormalAndFoam(scope, xz, _vertexNormal) {
|
|
290
|
+
const pb = scope.$builder;
|
|
291
|
+
const that = this;
|
|
292
|
+
pb.func('calcNormalAndFoam', [
|
|
293
|
+
pb.vec2('xz')
|
|
294
|
+
], function() {
|
|
295
|
+
this.$l.inPos = pb.vec3(this.xz.x, 0, this.xz.y);
|
|
296
|
+
this.$l.outPos = pb.vec3();
|
|
297
|
+
this.$l.outNormal = pb.vec3(0);
|
|
298
|
+
// Horizontal-gradient terms accumulated over the waves. The displacement
|
|
299
|
+
// derivative terms come out of gerstnerWave; summed, they feed det(I + J),
|
|
300
|
+
// the fold signal the foam is derived from - the same Jacobian the FFT
|
|
301
|
+
// generator uses, so both generators key foam off the same physics.
|
|
302
|
+
this.$l.dxdx = pb.float(0);
|
|
303
|
+
this.$l.dzdz = pb.float(0);
|
|
304
|
+
this.$l.dxdz = pb.float(0);
|
|
305
|
+
this.$for(pb.float('i'), 0, pb.getDevice().type === 'webgl' ? MAX_GERSTNER_WAVE_COUNT : this.numWaves, function() {
|
|
306
|
+
if (pb.getDevice().type === 'webgl') {
|
|
307
|
+
this.$if(pb.greaterThanEqual(this.i, this.numWaves), function() {
|
|
308
|
+
this.$break();
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
this.$l.waveNormal = pb.vec3();
|
|
312
|
+
this.$l.waveDxdx = pb.float();
|
|
313
|
+
this.$l.waveDzdz = pb.float();
|
|
314
|
+
this.$l.waveDxdz = pb.float();
|
|
315
|
+
this.$l.wavePos = that.gerstnerWave(this, this.waveParams.at(pb.mul(this.i, 2)), this.waveParams.at(pb.add(pb.mul(this.i, 2), 1)), this.inPos, this.waveNormal, this.waveDxdx, this.waveDzdz, this.waveDxdz);
|
|
316
|
+
this.outPos = pb.add(this.outPos, this.wavePos);
|
|
317
|
+
this.outNormal = pb.add(this.outNormal, this.waveNormal);
|
|
318
|
+
this.dxdx = pb.add(this.dxdx, this.waveDxdx);
|
|
319
|
+
this.dzdz = pb.add(this.dzdz, this.waveDzdz);
|
|
320
|
+
this.dxdz = pb.add(this.dxdz, this.waveDxdz);
|
|
321
|
+
});
|
|
322
|
+
// Jacobian determinant of the horizontal displacement, det(I + J). When the
|
|
323
|
+
// surface folds over the determinant drops below the foamParams.x threshold
|
|
324
|
+
// and the coverage ramps in. Mirrors the FFT generator's foam.
|
|
325
|
+
this.$l.val = pb.sub(pb.mul(pb.add(1, this.dxdx), pb.add(1, this.dzdz)), pb.mul(this.dxdz, this.dxdz));
|
|
326
|
+
this.$l.foam = pb.abs(pb.pow(pb.neg(pb.min(0, pb.sub(this.val, this.foamParams.x))), this.foamParams.y));
|
|
327
|
+
this.$return(pb.vec4(this.outNormal, this.foam));
|
|
328
|
+
});
|
|
329
|
+
return scope.calcNormalAndFoam(xz);
|
|
243
330
|
}
|
|
244
331
|
/** {@inheritDoc WaveGenerator.setupUniforms} */ setupUniforms(scope, uniformGroup) {
|
|
245
332
|
const pb = scope.$builder;
|
|
246
333
|
scope.numWaves = pb.float().uniform(uniformGroup);
|
|
247
334
|
scope.waveParams = pb.vec4[MAX_GERSTNER_WAVE_COUNT * 2]().uniform(uniformGroup);
|
|
335
|
+
scope.foamParams = pb.vec2().uniform(uniformGroup);
|
|
248
336
|
}
|
|
249
|
-
/** @internal */ gerstnerWave(scope, waveParam, omniParam, inPos, outNormal) {
|
|
337
|
+
/** @internal */ gerstnerWave(scope, waveParam, omniParam, inPos, outNormal, outDxdx, outDzdz, outDxdz) {
|
|
250
338
|
const pb = scope.$builder;
|
|
251
339
|
pb.func('gerstnerWave', [
|
|
252
340
|
pb.vec4('waveParam'),
|
|
253
341
|
pb.vec4('omniParam'),
|
|
254
342
|
pb.vec3('inPos'),
|
|
255
|
-
pb.vec3('outNormal').out()
|
|
343
|
+
pb.vec3('outNormal').out(),
|
|
344
|
+
pb.float('outDxdx').out(),
|
|
345
|
+
pb.float('outDzdz').out(),
|
|
346
|
+
pb.float('outDxdz').out()
|
|
256
347
|
], function() {
|
|
257
348
|
this.$l.amplitude = pb.max(this.waveParam.z, 0.01);
|
|
258
349
|
this.$l.wavelength = this.waveParam.w;
|
|
@@ -276,9 +367,21 @@ import '../utility/blueprint/material/texture.js';
|
|
|
276
367
|
this.$l.wa = pb.mul(this.w, this.amplitude);
|
|
277
368
|
this.$l.n = pb.vec3(pb.neg(pb.mul(this.windDir.xy, this.wa, this.cosCalc)), pb.sub(1, pb.mul(this.qi, this.wa, this.sinCalc)));
|
|
278
369
|
this.outNormal = pb.div(this.n.xzy, this.numWaves);
|
|
370
|
+
// Horizontal-gradient of the displacement, per wave. `waveXZ =
|
|
371
|
+
// windDir.xy * qi * amp * cos`, and the derivative of `cos(calc)` w.r.t.
|
|
372
|
+
// xz is `-w * sin(calc)`, so the gradient is the outer product of
|
|
373
|
+
// `windDir.xy` with itself scaled by `-qi * wa * sin`. The sign matters:
|
|
374
|
+
// at a crest (sin positive, cal near PI/2) the surface is compressed
|
|
375
|
+
// horizontally, which is what pushes `det(I + J)` down and fires the
|
|
376
|
+
// fold signal. Summed over waves and run through det(I + J), this is the
|
|
377
|
+
// same Jacobian criterion the FFT generator uses.
|
|
378
|
+
this.$l.jac = pb.neg(pb.mul(this.qi, this.wa, this.sinCalc));
|
|
379
|
+
this.outDxdx = pb.mul(this.jac, this.windDir.x, this.windDir.x);
|
|
380
|
+
this.outDzdz = pb.mul(this.jac, this.windDir.y, this.windDir.y);
|
|
381
|
+
this.outDxdz = pb.mul(this.jac, this.windDir.x, this.windDir.y);
|
|
279
382
|
this.$return(pb.mul(this.wave, pb.clamp(pb.mul(this.amplitude, 10000), 0, 1)));
|
|
280
383
|
});
|
|
281
|
-
return scope.gerstnerWave(waveParam, omniParam, inPos, outNormal);
|
|
384
|
+
return scope.gerstnerWave(waveParam, omniParam, inPos, outNormal, outDxdx, outDzdz, outDxdz);
|
|
282
385
|
}
|
|
283
386
|
/** @internal */ calcNormalAndPos(scope, inPos, outPos, outNormal) {
|
|
284
387
|
const pb = scope.$builder;
|
|
@@ -297,7 +400,10 @@ import '../utility/blueprint/material/texture.js';
|
|
|
297
400
|
});
|
|
298
401
|
}
|
|
299
402
|
this.$l.waveNormal = pb.vec3();
|
|
300
|
-
this.$l.
|
|
403
|
+
this.$l.waveDxdx = pb.float();
|
|
404
|
+
this.$l.waveDzdz = pb.float();
|
|
405
|
+
this.$l.waveDxdz = pb.float();
|
|
406
|
+
this.$l.wavePos = that.gerstnerWave(this, this.waveParams.at(pb.mul(this.i, 2)), this.waveParams.at(pb.add(pb.mul(this.i, 2), 1)), this.inPos, this.waveNormal, this.waveDxdx, this.waveDzdz, this.waveDxdz);
|
|
301
407
|
this.outPos = pb.add(this.outPos, this.wavePos);
|
|
302
408
|
this.outNormal = pb.add(this.outNormal, this.waveNormal);
|
|
303
409
|
});
|
|
@@ -310,6 +416,7 @@ import '../utility/blueprint/material/texture.js';
|
|
|
310
416
|
/** {@inheritDoc WaveGenerator.applyWaterBindGroup} */ applyWaterBindGroup(bindGroup) {
|
|
311
417
|
bindGroup.setValue('numWaves', this._numWaves);
|
|
312
418
|
bindGroup.setValue('waveParams', this._waveParams);
|
|
419
|
+
bindGroup.setValue('foamParams', this._foamParams);
|
|
313
420
|
}
|
|
314
421
|
/** {@inheritDoc WaveGenerator.isOk} */ isOk() {
|
|
315
422
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gerstner_wavegenerator.js","sources":["../../src/render/gerstner_wavegenerator.ts"],"sourcesContent":["import { Disposable, type AABB } from '@zephyr3d/base';\r\nimport type { WaveGenerator } from './wavegenerator';\r\nimport type { BindGroup, PBGlobalScope, PBInsideFunctionScope, PBShaderExp } from '@zephyr3d/device';\r\nimport { ShaderHelper } from '../material';\r\nimport { MAX_GERSTNER_WAVE_COUNT } from '../values';\r\n\r\n/**\r\n * Gerstner wave generator.\r\n * @public\r\n */\r\nexport class GerstnerWaveGenerator extends Disposable implements WaveGenerator {\r\n private _version: number;\r\n private _waveParams: Float32Array<ArrayBuffer>;\r\n private _numWaves: number;\r\n /**\r\n * Creates a new Gerstner wave generator.\r\n */\r\n constructor() {\r\n super();\r\n this._waveParams = new Float32Array(8 * MAX_GERSTNER_WAVE_COUNT);\r\n this.randomWave(0);\r\n this.randomWave(1);\r\n this.randomWave(2);\r\n this.randomWave(3);\r\n this._numWaves = 4;\r\n this._version = 0;\r\n }\r\n /** @internal */\r\n static randomWaveData(array: Float32Array, offset: number) {\r\n array[offset + 0] = Math.random() * Math.PI * 2;\r\n array[offset + 1] = Math.random() * 0.5 + 0.5;\r\n array[offset + 2] = Math.random() * 0.1;\r\n array[offset + 3] = Math.random() * 10;\r\n array[offset + 4] = Math.random() * 100 - 50;\r\n array[offset + 5] = 0;\r\n array[offset + 6] = Math.random() * 100 - 50;\r\n array[offset + 7] = 0;\r\n }\r\n /** @internal */\r\n setRaw(data: Float32Array, index: number) {\r\n this._waveParams.set(data, index * 8);\r\n }\r\n clone() {\r\n const other = new GerstnerWaveGenerator();\r\n other.numWaves = this.numWaves;\r\n other._waveParams.set(this._waveParams);\r\n return other as this;\r\n }\r\n get version() {\r\n return this._version;\r\n }\r\n /** Gets the number of waves. */\r\n get numWaves() {\r\n return this._numWaves;\r\n }\r\n set numWaves(val) {\r\n if (!Number.isInteger(val) || val <= 0 || val > MAX_GERSTNER_WAVE_COUNT) {\r\n console.error(`Invalid wave number: ${val}`);\r\n return;\r\n }\r\n if (val !== this._numWaves) {\r\n for (let i = this._numWaves; i < val; i++) {\r\n this.randomWave(i);\r\n }\r\n this._numWaves = val;\r\n this._version++;\r\n }\r\n }\r\n /** Delete wave at index */\r\n deleteWave(index: number) {\r\n for (let i = index; i < this._numWaves - 1; i++) {\r\n for (let j = 0; j < 8; j++) {\r\n this._waveParams[i * 8 + j] = this._waveParams[(i + 1) * 8 + j];\r\n }\r\n }\r\n this._numWaves--;\r\n }\r\n /** Delete wave at index */\r\n insertWave(index: number) {\r\n for (let i = index; i < this._numWaves - 1; i++) {\r\n for (let j = 0; j < 8; j++) {\r\n this._waveParams[(i + 1) * 8 + j] = this._waveParams[i * 8 + j];\r\n }\r\n }\r\n this._numWaves++;\r\n }\r\n /**\r\n * Sets the angle of the wave direction in radians.\r\n * @param waveIndex - index of the wave to set.\r\n * @param angle - angle of the wave direction in radians.\r\n */\r\n setWaveDirection(waveIndex: number, angle: number) {\r\n if (waveIndex < MAX_GERSTNER_WAVE_COUNT) {\r\n this._waveParams[waveIndex * 8 + 0] = angle;\r\n this._version++;\r\n }\r\n }\r\n /**\r\n * Gets the angle of the wave direction in radians.\r\n * @param waveIndex - index of the wave to get.\r\n * @returns Angle of the wave direction in radians.\r\n */\r\n getWaveDirection(waveIndex: number) {\r\n return waveIndex < MAX_GERSTNER_WAVE_COUNT ? this._waveParams[waveIndex * 8 + 0] : 0;\r\n }\r\n /**\r\n * Sets the steepness of the wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @param steepness - Steepness of the wave.\r\n */\r\n setWaveSteepness(waveIndex: number, steepness: number) {\r\n if (waveIndex < MAX_GERSTNER_WAVE_COUNT) {\r\n this._waveParams[waveIndex * 8 + 1] = steepness;\r\n this._version++;\r\n }\r\n }\r\n /**\r\n * Gets the steepness of the wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @returns Steepness of the wave.\r\n */\r\n getWaveSteepness(waveIndex: number) {\r\n return waveIndex < MAX_GERSTNER_WAVE_COUNT ? this._waveParams[waveIndex * 8 + 1] : 0;\r\n }\r\n /**\r\n * Sets the amplitude of the wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @param val - Amplitude of the wave.\r\n */\r\n setWaveAmplitude(waveIndex: number, val: number) {\r\n if (waveIndex < MAX_GERSTNER_WAVE_COUNT) {\r\n this._waveParams[waveIndex * 8 + 2] = val;\r\n this._version++;\r\n }\r\n }\r\n /**\r\n * Gets the amplitude of the wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @returns Amplitude of the wave.\r\n */\r\n getWaveAmplitude(waveIndex: number) {\r\n return waveIndex < MAX_GERSTNER_WAVE_COUNT ? this._waveParams[waveIndex * 8 + 2] : 0;\r\n }\r\n /**\r\n * Sets the length of the wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @param val - Length of the wave.\r\n */\r\n setWaveLength(waveIndex: number, val: number) {\r\n if (waveIndex < MAX_GERSTNER_WAVE_COUNT) {\r\n this._waveParams[waveIndex * 8 + 3] = val;\r\n this._version++;\r\n }\r\n }\r\n /**\r\n * Gets the length of the wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @returns Length of the wave.\r\n */\r\n getWaveLength(waveIndex: number) {\r\n return waveIndex < MAX_GERSTNER_WAVE_COUNT ? this._waveParams[waveIndex * 8 + 3] : 0;\r\n }\r\n /**\r\n * Query if the wave is an omni-directional wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @returns true if the wave is an omni-directional wave, false otherwise.\r\n */\r\n isOmniWave(waveIndex: number) {\r\n return waveIndex < MAX_GERSTNER_WAVE_COUNT ? this._waveParams[waveIndex * 8 + 7] !== 0 : false;\r\n }\r\n /**\r\n * Sets whether the wave is an omni-directional wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @param isOmni - true if the wave is an omni-directional wave, false otherwise.\r\n */\r\n setOmniWave(waveIndex: number, isOmni: boolean) {\r\n if (waveIndex < MAX_GERSTNER_WAVE_COUNT) {\r\n this._waveParams[waveIndex * 8 + 7] = isOmni ? 1 : 0;\r\n this._version++;\r\n }\r\n }\r\n /**\r\n * Gets the X coordinate of the wave origin if it is an omni-directional wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @returns X coordinate of the wave origin if it is an omni-directional wave, 0 otherwise.\r\n */\r\n getOriginX(waveIndex: number) {\r\n return waveIndex < MAX_GERSTNER_WAVE_COUNT ? this._waveParams[waveIndex * 8 + 4] : 0;\r\n }\r\n /**\r\n * Gets the Z coordinate of the wave origin if it is an omni-directional wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @returns Z coordinate of the wave origin if it is an omni-directional wave, 0 otherwise.\r\n */\r\n getOriginZ(waveIndex: number) {\r\n return waveIndex < MAX_GERSTNER_WAVE_COUNT ? this._waveParams[waveIndex * 8 + 6] : 0;\r\n }\r\n /**\r\n * Sets the X and Z coordinates of the wave origin if it is an omni-directional wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @param x - X coordinate of the wave origin\r\n * @param z - Z coordinate of the wave origin\r\n */\r\n setOrigin(waveIndex: number, x: number, z: number) {\r\n if (waveIndex < MAX_GERSTNER_WAVE_COUNT) {\r\n this._waveParams[waveIndex * 8 + 4] = x;\r\n this._waveParams[waveIndex * 8 + 6] = z;\r\n this._version++;\r\n }\r\n }\r\n /** @internal */\r\n randomWave(i: number) {\r\n GerstnerWaveGenerator.randomWaveData(this._waveParams, i * 8);\r\n }\r\n /** {@inheritDoc WaveGenerator.update} */\r\n update() {}\r\n /** {@inheritDoc WaveGenerator.needUpdate} */\r\n needUpdate() {\r\n return false;\r\n }\r\n /** {@inheritDoc WaveGenerator.calcClipmapTileAABB} */\r\n calcClipmapTileAABB(minX: number, maxX: number, minZ: number, maxZ: number, y: number, outAABB: AABB) {\r\n let maxHeight = 0;\r\n for (let i = 0; i < this._numWaves; i++) {\r\n const h = this._waveParams[i * 8 + 2];\r\n if (h > maxHeight) {\r\n maxHeight = h;\r\n }\r\n }\r\n outAABB.minPoint.setXYZ(minX, y, minZ);\r\n outAABB.maxPoint.setXYZ(maxX, y + maxHeight, maxZ);\r\n }\r\n /** {@inheritDoc WaveGenerator.calcFragmentNormal} */\r\n calcFragmentNormal(scope: PBInsideFunctionScope, xz: PBShaderExp) {\r\n const pb = scope.$builder;\r\n const that = this;\r\n pb.func('calcFragmentNormal', [pb.vec2('xz')], function () {\r\n this.$l.inPos = pb.vec3(this.xz.x, 0, this.xz.y);\r\n this.$l.outPos = pb.vec3();\r\n this.$l.outNormal = pb.vec3();\r\n that.calcNormalAndPos(this, this.inPos, this.outPos, this.outNormal);\r\n this.$return(this.outNormal);\r\n });\r\n return scope.calcFragmentNormal(xz) as PBShaderExp;\r\n }\r\n /** {@inheritDoc WaveGenerator.calcFragmentNormalAndFoam} */\r\n calcFragmentNormalAndFoam(scope: PBInsideFunctionScope, xz: PBShaderExp) {\r\n return scope.$builder.vec4(this.calcFragmentNormal(scope, xz), 0);\r\n }\r\n /** {@inheritDoc WaveGenerator.setupUniforms} */\r\n setupUniforms(scope: PBGlobalScope, uniformGroup: number) {\r\n const pb = scope.$builder;\r\n scope.numWaves = pb.float().uniform(uniformGroup);\r\n scope.waveParams = pb.vec4[MAX_GERSTNER_WAVE_COUNT * 2]().uniform(uniformGroup);\r\n }\r\n /** @internal */\r\n private gerstnerWave(\r\n scope: PBInsideFunctionScope,\r\n waveParam: PBShaderExp,\r\n omniParam: PBShaderExp,\r\n inPos: PBShaderExp,\r\n outNormal: PBShaderExp\r\n ) {\r\n const pb = scope.$builder;\r\n pb.func(\r\n 'gerstnerWave',\r\n [pb.vec4('waveParam'), pb.vec4('omniParam'), pb.vec3('inPos'), pb.vec3('outNormal').out()],\r\n function () {\r\n this.$l.amplitude = pb.max(this.waveParam.z, 0.01);\r\n this.$l.wavelength = this.waveParam.w;\r\n this.$l.omniPos = this.omniParam.xz;\r\n this.$l.omni = this.omniParam.w;\r\n this.$l.direction = pb.vec2(pb.sin(this.waveParam.x), pb.cos(this.waveParam.x));\r\n this.$l.w = pb.max(0.001, pb.div(Math.PI * 2, this.wavelength));\r\n this.$l.wSpeed = pb.sqrt(pb.mul(9.8, this.w));\r\n this.$l.peak = this.waveParam.y;\r\n this.$l.qi = pb.div(this.peak, pb.mul(this.amplitude, this.w, this.numWaves));\r\n this.$l.dirWaveInput = pb.mul(this.direction, pb.sub(1, this.omni));\r\n this.$l.omniWaveInput = pb.mul(pb.sub(this.inPos.xz, this.omniPos), this.omni);\r\n this.$l.windDir = pb.normalize(pb.add(this.dirWaveInput, this.omniWaveInput));\r\n this.$l.dir = pb.dot(this.windDir, pb.sub(this.inPos.xz, pb.mul(this.omniPos, this.omni)));\r\n this.$l.calc = pb.sub(\r\n pb.mul(this.dir, this.w),\r\n pb.mul(this.wSpeed, ShaderHelper.getElapsedTime(this))\r\n );\r\n this.$l.cosCalc = pb.cos(this.calc);\r\n this.$l.sinCalc = pb.sin(this.calc);\r\n this.$l.waveXZ = pb.mul(this.windDir.xy, this.qi, this.amplitude, this.cosCalc);\r\n this.$l.waveY = pb.div(pb.mul(this.sinCalc, this.amplitude), this.numWaves);\r\n this.$l.wave = pb.vec3(this.waveXZ.x, this.waveY, this.waveXZ.y);\r\n this.$l.wa = pb.mul(this.w, this.amplitude);\r\n this.$l.n = pb.vec3(\r\n pb.neg(pb.mul(this.windDir.xy, this.wa, this.cosCalc)),\r\n pb.sub(1, pb.mul(this.qi, this.wa, this.sinCalc))\r\n );\r\n this.outNormal = pb.div(this.n.xzy, this.numWaves);\r\n this.$return(pb.mul(this.wave, pb.clamp(pb.mul(this.amplitude, 10000), 0, 1)));\r\n }\r\n );\r\n return scope.gerstnerWave(waveParam, omniParam, inPos, outNormal) as PBShaderExp;\r\n }\r\n /** @internal */\r\n private calcNormalAndPos(\r\n scope: PBInsideFunctionScope,\r\n inPos: PBShaderExp,\r\n outPos: PBShaderExp,\r\n outNormal: PBShaderExp\r\n ) {\r\n const pb = scope.$builder;\r\n const that = this;\r\n pb.func(\r\n 'calcPositionAndNormal',\r\n [pb.vec3('inPos'), pb.vec3('outPos').out(), pb.vec3('outNormal').out()],\r\n function () {\r\n this.outPos = this.inPos;\r\n this.outNormal = pb.vec3(0);\r\n this.$for(\r\n pb.float('i'),\r\n 0,\r\n pb.getDevice().type === 'webgl' ? MAX_GERSTNER_WAVE_COUNT : this.numWaves,\r\n function () {\r\n if (pb.getDevice().type === 'webgl') {\r\n this.$if(pb.greaterThanEqual(this.i, this.numWaves), function () {\r\n this.$break();\r\n });\r\n }\r\n this.$l.waveNormal = pb.vec3();\r\n this.$l.wavePos = that.gerstnerWave(\r\n this,\r\n this.waveParams.at(pb.mul(this.i, 2)),\r\n this.waveParams.at(pb.add(pb.mul(this.i, 2), 1)),\r\n this.inPos,\r\n this.waveNormal\r\n );\r\n this.outPos = pb.add(this.outPos, this.wavePos);\r\n this.outNormal = pb.add(this.outNormal, this.waveNormal);\r\n }\r\n );\r\n }\r\n );\r\n scope.calcPositionAndNormal(inPos, outPos, outNormal);\r\n }\r\n /** {@inheritDoc WaveGenerator.calcVertexPositionAndNormal} */\r\n calcVertexPositionAndNormal(\r\n scope: PBInsideFunctionScope,\r\n inPos: PBShaderExp,\r\n outPos: PBShaderExp,\r\n outNormal: PBShaderExp\r\n ) {\r\n this.calcNormalAndPos(scope, inPos, outPos, outNormal);\r\n }\r\n /** {@inheritDoc WaveGenerator.applyWaterBindGroup} */\r\n applyWaterBindGroup(bindGroup: BindGroup) {\r\n bindGroup.setValue('numWaves', this._numWaves);\r\n bindGroup.setValue('waveParams', this._waveParams);\r\n }\r\n /** {@inheritDoc WaveGenerator.isOk} */\r\n isOk() {\r\n return true;\r\n }\r\n /** {@inheritDoc WaveGenerator.getHash} */\r\n getHash() {\r\n return 'GerstnerWaveGenerator';\r\n }\r\n}\r\n"],"names":["GerstnerWaveGenerator","Disposable","_version","_waveParams","_numWaves","Float32Array","MAX_GERSTNER_WAVE_COUNT","randomWave","randomWaveData","array","offset","Math","random","PI","setRaw","data","index","set","clone","other","numWaves","version","val","Number","isInteger","console","error","i","deleteWave","j","insertWave","setWaveDirection","waveIndex","angle","getWaveDirection","setWaveSteepness","steepness","getWaveSteepness","setWaveAmplitude","getWaveAmplitude","setWaveLength","getWaveLength","isOmniWave","setOmniWave","isOmni","getOriginX","getOriginZ","setOrigin","x","z","update","needUpdate","calcClipmapTileAABB","minX","maxX","minZ","maxZ","y","outAABB","maxHeight","h","minPoint","setXYZ","maxPoint","calcFragmentNormal","scope","xz","pb","$builder","that","func","vec2","$l","inPos","vec3","outPos","outNormal","calcNormalAndPos","$return","calcFragmentNormalAndFoam","vec4","setupUniforms","uniformGroup","float","uniform","waveParams","gerstnerWave","waveParam","omniParam","out","amplitude","max","wavelength","w","omniPos","omni","direction","sin","cos","div","wSpeed","sqrt","mul","peak","qi","dirWaveInput","sub","omniWaveInput","windDir","normalize","add","dir","dot","calc","ShaderHelper","getElapsedTime","cosCalc","sinCalc","waveXZ","xy","waveY","wave","wa","n","neg","xzy","clamp","$for","getDevice","type","$if","greaterThanEqual","$break","waveNormal","wavePos","at","calcPositionAndNormal","calcVertexPositionAndNormal","applyWaterBindGroup","bindGroup","setValue","isOk","getHash"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAMA;;;IAIO,MAAMA,qBAA8BC,SAAAA,UAAAA,CAAAA;IACjCC,QAAiB;IACjBC,WAAuC;IACvCC,SAAkB;AAC1B;;AAEC,MACD,WAAc,EAAA;QACZ,KAAK,EAAA;AACL,QAAA,IAAI,CAACD,WAAW,GAAG,IAAIE,aAAa,CAAIC,GAAAA,uBAAAA,CAAAA;QACxC,IAAI,CAACC,UAAU,CAAC,CAAA,CAAA;QAChB,IAAI,CAACA,UAAU,CAAC,CAAA,CAAA;QAChB,IAAI,CAACA,UAAU,CAAC,CAAA,CAAA;QAChB,IAAI,CAACA,UAAU,CAAC,CAAA,CAAA;QAChB,IAAI,CAACH,SAAS,GAAG,CAAA;QACjB,IAAI,CAACF,QAAQ,GAAG,CAAA;AAClB;AACA,qBACA,OAAOM,cAAAA,CAAeC,KAAmB,EAAEC,MAAc,EAAE;QACzDD,KAAK,CAACC,SAAS,CAAE,CAAA,GAAGC,KAAKC,MAAM,EAAA,GAAKD,IAAKE,CAAAA,EAAE,GAAG,CAAA;AAC9CJ,QAAAA,KAAK,CAACC,MAAS,GAAA,CAAA,CAAE,GAAGC,IAAKC,CAAAA,MAAM,KAAK,GAAM,GAAA,GAAA;AAC1CH,QAAAA,KAAK,CAACC,MAAS,GAAA,CAAA,CAAE,GAAGC,IAAAA,CAAKC,MAAM,EAAK,GAAA,GAAA;AACpCH,QAAAA,KAAK,CAACC,MAAS,GAAA,CAAA,CAAE,GAAGC,IAAAA,CAAKC,MAAM,EAAK,GAAA,EAAA;AACpCH,QAAAA,KAAK,CAACC,MAAS,GAAA,CAAA,CAAE,GAAGC,IAAKC,CAAAA,MAAM,KAAK,GAAM,GAAA,EAAA;QAC1CH,KAAK,CAACC,MAAS,GAAA,CAAA,CAAE,GAAG,CA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A;AACnD;AACA,4CACA0I,IAAO,GAAA;QACL,OAAO,IAAA;AACT;AACA,+CACAC,OAAU,GAAA;QACR,OAAO,uBAAA;AACT;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"gerstner_wavegenerator.js","sources":["../../src/render/gerstner_wavegenerator.ts"],"sourcesContent":["import { Disposable, PRNG, type AABB } from '@zephyr3d/base';\r\nimport type { WaveGenerator } from './wavegenerator';\r\nimport type { BindGroup, PBGlobalScope, PBInsideFunctionScope, PBShaderExp } from '@zephyr3d/device';\r\nimport { ShaderHelper } from '../material';\r\nimport { MAX_GERSTNER_WAVE_COUNT } from '../values';\r\n\r\n/**\r\n * Gerstner wave generator.\r\n * @public\r\n */\r\nexport class GerstnerWaveGenerator extends Disposable implements WaveGenerator {\r\n private _version: number;\r\n private _waveParams: Float32Array<ArrayBuffer>;\r\n private _numWaves: number;\r\n private _rand: PRNG;\r\n private readonly _foamParams: Float32Array<ArrayBuffer>;\r\n /**\r\n * Creates a new Gerstner wave generator.\r\n */\r\n constructor(randomSeed = 0) {\r\n super();\r\n this._waveParams = new Float32Array(8 * MAX_GERSTNER_WAVE_COUNT);\r\n this._rand = new PRNG(randomSeed);\r\n this.randomWave(0);\r\n this.randomWave(1);\r\n this.randomWave(2);\r\n this.randomWave(3);\r\n this._numWaves = 4;\r\n this._version = 0;\r\n // Same defaults as the FFT generator, so switching between the two does not\r\n // change the foam response out of the box.\r\n this._foamParams = new Float32Array([1.2, 7.2]);\r\n }\r\n /** @internal */\r\n static randomWaveData(rand: PRNG, array: Float32Array, offset: number) {\r\n array[offset + 0] = rand.get() * Math.PI * 2;\r\n array[offset + 1] = rand.get() * 0.5 + 0.5;\r\n array[offset + 2] = rand.get() * 0.1;\r\n array[offset + 3] = rand.get() * 10;\r\n array[offset + 4] = rand.get() * 100 - 50;\r\n array[offset + 5] = 0;\r\n array[offset + 6] = rand.get() * 100 - 50;\r\n array[offset + 7] = 0;\r\n }\r\n /** @internal */\r\n setRaw(data: Float32Array, index: number) {\r\n this._waveParams.set(data, index * 8);\r\n }\r\n clone() {\r\n const other = new GerstnerWaveGenerator();\r\n other.numWaves = this.numWaves;\r\n other._waveParams.set(this._waveParams);\r\n other._foamParams.set(this._foamParams);\r\n return other as this;\r\n }\r\n get rand() {\r\n return this._rand;\r\n }\r\n get version() {\r\n return this._version;\r\n }\r\n /** Gets the number of waves. */\r\n get numWaves() {\r\n return this._numWaves;\r\n }\r\n set numWaves(val) {\r\n if (!Number.isInteger(val) || val <= 0 || val > MAX_GERSTNER_WAVE_COUNT) {\r\n console.error(`Invalid wave number: ${val}`);\r\n return;\r\n }\r\n if (val !== this._numWaves) {\r\n for (let i = this._numWaves; i < val; i++) {\r\n this.randomWave(i);\r\n }\r\n this._numWaves = val;\r\n this._version++;\r\n }\r\n }\r\n /** Delete wave at index */\r\n deleteWave(index: number) {\r\n if (index < 0 || index >= this._numWaves) {\r\n return;\r\n }\r\n for (let i = index; i < this._numWaves - 1; i++) {\r\n for (let j = 0; j < 8; j++) {\r\n this._waveParams[i * 8 + j] = this._waveParams[(i + 1) * 8 + j];\r\n }\r\n }\r\n this._numWaves--;\r\n this._version++;\r\n }\r\n /** Insert a wave slot at index, shifting the subsequent waves up */\r\n insertWave(index: number) {\r\n // Bounded by the parameter buffer; the shader reads this many slots.\r\n if (this._numWaves >= MAX_GERSTNER_WAVE_COUNT) {\r\n return;\r\n }\r\n // Shift from the tail backwards so the gap opens at `index` without\r\n // overwriting the slot that is about to move. Copying forward here would\r\n // duplicate `waveParams[index]` into every later slot instead of moving\r\n // them up. The new slot is filled with a random wave rather than left at\r\n // zero: a zero wavelength makes `w = 2*PI / length` infinite and drives the\r\n // vertex shader into NaN, which collapses the whole surface, so the slot\r\n // has to be a valid wave even before the caller writes its parameters.\r\n for (let i = this._numWaves - 1; i >= index; i--) {\r\n for (let j = 0; j < 8; j++) {\r\n this._waveParams[(i + 1) * 8 + j] = this._waveParams[i * 8 + j];\r\n }\r\n }\r\n this.randomWave(index);\r\n this._numWaves++;\r\n this._version++;\r\n }\r\n /**\r\n * Sets the angle of the wave direction in radians.\r\n * @param waveIndex - index of the wave to set.\r\n * @param angle - angle of the wave direction in radians.\r\n */\r\n setWaveDirection(waveIndex: number, angle: number) {\r\n if (waveIndex < MAX_GERSTNER_WAVE_COUNT) {\r\n this._waveParams[waveIndex * 8 + 0] = angle;\r\n this._version++;\r\n }\r\n }\r\n /**\r\n * Gets the angle of the wave direction in radians.\r\n * @param waveIndex - index of the wave to get.\r\n * @returns Angle of the wave direction in radians.\r\n */\r\n getWaveDirection(waveIndex: number) {\r\n return waveIndex < MAX_GERSTNER_WAVE_COUNT ? this._waveParams[waveIndex * 8 + 0] : 0;\r\n }\r\n /**\r\n * Sets the steepness of the wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @param steepness - Steepness of the wave.\r\n */\r\n setWaveSteepness(waveIndex: number, steepness: number) {\r\n if (waveIndex < MAX_GERSTNER_WAVE_COUNT) {\r\n this._waveParams[waveIndex * 8 + 1] = steepness;\r\n this._version++;\r\n }\r\n }\r\n /**\r\n * Gets the steepness of the wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @returns Steepness of the wave.\r\n */\r\n getWaveSteepness(waveIndex: number) {\r\n return waveIndex < MAX_GERSTNER_WAVE_COUNT ? this._waveParams[waveIndex * 8 + 1] : 0;\r\n }\r\n /**\r\n * Sets the amplitude of the wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @param val - Amplitude of the wave.\r\n */\r\n setWaveAmplitude(waveIndex: number, val: number) {\r\n if (waveIndex < MAX_GERSTNER_WAVE_COUNT) {\r\n this._waveParams[waveIndex * 8 + 2] = val;\r\n this._version++;\r\n }\r\n }\r\n /**\r\n * Gets the amplitude of the wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @returns Amplitude of the wave.\r\n */\r\n getWaveAmplitude(waveIndex: number) {\r\n return waveIndex < MAX_GERSTNER_WAVE_COUNT ? this._waveParams[waveIndex * 8 + 2] : 0;\r\n }\r\n /**\r\n * Sets the length of the wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @param val - Length of the wave.\r\n */\r\n setWaveLength(waveIndex: number, val: number) {\r\n if (waveIndex < MAX_GERSTNER_WAVE_COUNT) {\r\n this._waveParams[waveIndex * 8 + 3] = val;\r\n this._version++;\r\n }\r\n }\r\n /**\r\n * Gets the length of the wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @returns Length of the wave.\r\n */\r\n getWaveLength(waveIndex: number) {\r\n return waveIndex < MAX_GERSTNER_WAVE_COUNT ? this._waveParams[waveIndex * 8 + 3] : 0;\r\n }\r\n /**\r\n * Query if the wave is an omni-directional wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @returns true if the wave is an omni-directional wave, false otherwise.\r\n */\r\n isOmniWave(waveIndex: number) {\r\n return waveIndex < MAX_GERSTNER_WAVE_COUNT ? this._waveParams[waveIndex * 8 + 7] !== 0 : false;\r\n }\r\n /**\r\n * Sets whether the wave is an omni-directional wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @param isOmni - true if the wave is an omni-directional wave, false otherwise.\r\n */\r\n setOmniWave(waveIndex: number, isOmni: boolean) {\r\n if (waveIndex < MAX_GERSTNER_WAVE_COUNT) {\r\n this._waveParams[waveIndex * 8 + 7] = isOmni ? 1 : 0;\r\n this._version++;\r\n }\r\n }\r\n /** Gets the foam width. */\r\n get foamWidth() {\r\n return this._foamParams[0];\r\n }\r\n set foamWidth(val) {\r\n if (val !== this._foamParams[0]) {\r\n this._foamParams[0] = val;\r\n this._version++;\r\n }\r\n }\r\n /** Gets the foam contrast. */\r\n get foamContrast() {\r\n return this._foamParams[1];\r\n }\r\n set foamContrast(val) {\r\n if (val !== this._foamParams[1]) {\r\n this._foamParams[1] = val;\r\n this._version++;\r\n }\r\n }\r\n /**\r\n * Gets the X coordinate of the wave origin if it is an omni-directional wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @returns X coordinate of the wave origin if it is an omni-directional wave, 0 otherwise.\r\n */\r\n getOriginX(waveIndex: number) {\r\n return waveIndex < MAX_GERSTNER_WAVE_COUNT ? this._waveParams[waveIndex * 8 + 4] : 0;\r\n }\r\n /**\r\n * Gets the Z coordinate of the wave origin if it is an omni-directional wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @returns Z coordinate of the wave origin if it is an omni-directional wave, 0 otherwise.\r\n */\r\n getOriginZ(waveIndex: number) {\r\n return waveIndex < MAX_GERSTNER_WAVE_COUNT ? this._waveParams[waveIndex * 8 + 6] : 0;\r\n }\r\n /**\r\n * Sets the X and Z coordinates of the wave origin if it is an omni-directional wave.\r\n * @param waveIndex - index of the wave to set.\r\n * @param x - X coordinate of the wave origin\r\n * @param z - Z coordinate of the wave origin\r\n */\r\n setOrigin(waveIndex: number, x: number, z: number) {\r\n if (waveIndex < MAX_GERSTNER_WAVE_COUNT) {\r\n this._waveParams[waveIndex * 8 + 4] = x;\r\n this._waveParams[waveIndex * 8 + 6] = z;\r\n this._version++;\r\n }\r\n }\r\n /** @internal */\r\n randomWave(i: number) {\r\n GerstnerWaveGenerator.randomWaveData(this._rand, this._waveParams, i * 8);\r\n }\r\n /** {@inheritDoc WaveGenerator.update} */\r\n update() {}\r\n /** {@inheritDoc WaveGenerator.needUpdate} */\r\n needUpdate() {\r\n return false;\r\n }\r\n /** {@inheritDoc WaveGenerator.calcClipmapTileAABB} */\r\n calcClipmapTileAABB(minX: number, maxX: number, minZ: number, maxZ: number, y: number, outAABB: AABB) {\r\n let maxHeight = 0;\r\n for (let i = 0; i < this._numWaves; i++) {\r\n const h = this._waveParams[i * 8 + 2];\r\n if (h > maxHeight) {\r\n maxHeight = h;\r\n }\r\n }\r\n outAABB.minPoint.setXYZ(minX, y, minZ);\r\n outAABB.maxPoint.setXYZ(maxX, y + maxHeight, maxZ);\r\n }\r\n /** {@inheritDoc WaveGenerator.calcFragmentNormal} */\r\n calcFragmentNormal(scope: PBInsideFunctionScope, xz: PBShaderExp, _vertexNormal: PBShaderExp) {\r\n const pb = scope.$builder;\r\n const that = this;\r\n pb.func('calcFragmentNormal', [pb.vec2('xz')], function () {\r\n this.$l.inPos = pb.vec3(this.xz.x, 0, this.xz.y);\r\n this.$l.outPos = pb.vec3();\r\n this.$l.outNormal = pb.vec3();\r\n that.calcNormalAndPos(this, this.inPos, this.outPos, this.outNormal);\r\n this.$return(this.outNormal);\r\n });\r\n return scope.calcFragmentNormal(xz) as PBShaderExp;\r\n }\r\n /** {@inheritDoc WaveGenerator.calcFragmentNormalAndFoam} */\r\n calcFragmentNormalAndFoam(scope: PBInsideFunctionScope, xz: PBShaderExp, _vertexNormal: PBShaderExp) {\r\n const pb = scope.$builder;\r\n const that = this;\r\n pb.func('calcNormalAndFoam', [pb.vec2('xz')], function () {\r\n this.$l.inPos = pb.vec3(this.xz.x, 0, this.xz.y);\r\n this.$l.outPos = pb.vec3();\r\n this.$l.outNormal = pb.vec3(0);\r\n // Horizontal-gradient terms accumulated over the waves. The displacement\r\n // derivative terms come out of gerstnerWave; summed, they feed det(I + J),\r\n // the fold signal the foam is derived from - the same Jacobian the FFT\r\n // generator uses, so both generators key foam off the same physics.\r\n this.$l.dxdx = pb.float(0);\r\n this.$l.dzdz = pb.float(0);\r\n this.$l.dxdz = pb.float(0);\r\n this.$for(\r\n pb.float('i'),\r\n 0,\r\n pb.getDevice().type === 'webgl' ? MAX_GERSTNER_WAVE_COUNT : this.numWaves,\r\n function () {\r\n if (pb.getDevice().type === 'webgl') {\r\n this.$if(pb.greaterThanEqual(this.i, this.numWaves), function () {\r\n this.$break();\r\n });\r\n }\r\n this.$l.waveNormal = pb.vec3();\r\n this.$l.waveDxdx = pb.float();\r\n this.$l.waveDzdz = pb.float();\r\n this.$l.waveDxdz = pb.float();\r\n this.$l.wavePos = that.gerstnerWave(\r\n this,\r\n this.waveParams.at(pb.mul(this.i, 2)),\r\n this.waveParams.at(pb.add(pb.mul(this.i, 2), 1)),\r\n this.inPos,\r\n this.waveNormal,\r\n this.waveDxdx,\r\n this.waveDzdz,\r\n this.waveDxdz\r\n );\r\n this.outPos = pb.add(this.outPos, this.wavePos);\r\n this.outNormal = pb.add(this.outNormal, this.waveNormal);\r\n this.dxdx = pb.add(this.dxdx, this.waveDxdx);\r\n this.dzdz = pb.add(this.dzdz, this.waveDzdz);\r\n this.dxdz = pb.add(this.dxdz, this.waveDxdz);\r\n }\r\n );\r\n // Jacobian determinant of the horizontal displacement, det(I + J). When the\r\n // surface folds over the determinant drops below the foamParams.x threshold\r\n // and the coverage ramps in. Mirrors the FFT generator's foam.\r\n this.$l.val = pb.sub(pb.mul(pb.add(1, this.dxdx), pb.add(1, this.dzdz)), pb.mul(this.dxdz, this.dxdz));\r\n this.$l.foam = pb.abs(\r\n pb.pow(pb.neg(pb.min(0, pb.sub(this.val, this.foamParams.x))), this.foamParams.y)\r\n );\r\n this.$return(pb.vec4(this.outNormal, this.foam));\r\n });\r\n return scope.calcNormalAndFoam(xz) as PBShaderExp;\r\n }\r\n /** {@inheritDoc WaveGenerator.setupUniforms} */\r\n setupUniforms(scope: PBGlobalScope, uniformGroup: number) {\r\n const pb = scope.$builder;\r\n scope.numWaves = pb.float().uniform(uniformGroup);\r\n scope.waveParams = pb.vec4[MAX_GERSTNER_WAVE_COUNT * 2]().uniform(uniformGroup);\r\n scope.foamParams = pb.vec2().uniform(uniformGroup);\r\n }\r\n /** @internal */\r\n private gerstnerWave(\r\n scope: PBInsideFunctionScope,\r\n waveParam: PBShaderExp,\r\n omniParam: PBShaderExp,\r\n inPos: PBShaderExp,\r\n outNormal: PBShaderExp,\r\n outDxdx: PBShaderExp,\r\n outDzdz: PBShaderExp,\r\n outDxdz: PBShaderExp\r\n ) {\r\n const pb = scope.$builder;\r\n pb.func(\r\n 'gerstnerWave',\r\n [\r\n pb.vec4('waveParam'),\r\n pb.vec4('omniParam'),\r\n pb.vec3('inPos'),\r\n pb.vec3('outNormal').out(),\r\n pb.float('outDxdx').out(),\r\n pb.float('outDzdz').out(),\r\n pb.float('outDxdz').out()\r\n ],\r\n function () {\r\n this.$l.amplitude = pb.max(this.waveParam.z, 0.01);\r\n this.$l.wavelength = this.waveParam.w;\r\n this.$l.omniPos = this.omniParam.xz;\r\n this.$l.omni = this.omniParam.w;\r\n this.$l.direction = pb.vec2(pb.sin(this.waveParam.x), pb.cos(this.waveParam.x));\r\n this.$l.w = pb.max(0.001, pb.div(Math.PI * 2, this.wavelength));\r\n this.$l.wSpeed = pb.sqrt(pb.mul(9.8, this.w));\r\n this.$l.peak = this.waveParam.y;\r\n this.$l.qi = pb.div(this.peak, pb.mul(this.amplitude, this.w, this.numWaves));\r\n this.$l.dirWaveInput = pb.mul(this.direction, pb.sub(1, this.omni));\r\n this.$l.omniWaveInput = pb.mul(pb.sub(this.inPos.xz, this.omniPos), this.omni);\r\n this.$l.windDir = pb.normalize(pb.add(this.dirWaveInput, this.omniWaveInput));\r\n this.$l.dir = pb.dot(this.windDir, pb.sub(this.inPos.xz, pb.mul(this.omniPos, this.omni)));\r\n this.$l.calc = pb.sub(\r\n pb.mul(this.dir, this.w),\r\n pb.mul(this.wSpeed, ShaderHelper.getElapsedTime(this))\r\n );\r\n this.$l.cosCalc = pb.cos(this.calc);\r\n this.$l.sinCalc = pb.sin(this.calc);\r\n this.$l.waveXZ = pb.mul(this.windDir.xy, this.qi, this.amplitude, this.cosCalc);\r\n this.$l.waveY = pb.div(pb.mul(this.sinCalc, this.amplitude), this.numWaves);\r\n this.$l.wave = pb.vec3(this.waveXZ.x, this.waveY, this.waveXZ.y);\r\n this.$l.wa = pb.mul(this.w, this.amplitude);\r\n this.$l.n = pb.vec3(\r\n pb.neg(pb.mul(this.windDir.xy, this.wa, this.cosCalc)),\r\n pb.sub(1, pb.mul(this.qi, this.wa, this.sinCalc))\r\n );\r\n this.outNormal = pb.div(this.n.xzy, this.numWaves);\r\n // Horizontal-gradient of the displacement, per wave. `waveXZ =\r\n // windDir.xy * qi * amp * cos`, and the derivative of `cos(calc)` w.r.t.\r\n // xz is `-w * sin(calc)`, so the gradient is the outer product of\r\n // `windDir.xy` with itself scaled by `-qi * wa * sin`. The sign matters:\r\n // at a crest (sin positive, cal near PI/2) the surface is compressed\r\n // horizontally, which is what pushes `det(I + J)` down and fires the\r\n // fold signal. Summed over waves and run through det(I + J), this is the\r\n // same Jacobian criterion the FFT generator uses.\r\n this.$l.jac = pb.neg(pb.mul(this.qi, this.wa, this.sinCalc));\r\n this.outDxdx = pb.mul(this.jac, this.windDir.x, this.windDir.x);\r\n this.outDzdz = pb.mul(this.jac, this.windDir.y, this.windDir.y);\r\n this.outDxdz = pb.mul(this.jac, this.windDir.x, this.windDir.y);\r\n this.$return(pb.mul(this.wave, pb.clamp(pb.mul(this.amplitude, 10000), 0, 1)));\r\n }\r\n );\r\n return scope.gerstnerWave(\r\n waveParam,\r\n omniParam,\r\n inPos,\r\n outNormal,\r\n outDxdx,\r\n outDzdz,\r\n outDxdz\r\n ) as PBShaderExp;\r\n }\r\n /** @internal */\r\n private calcNormalAndPos(\r\n scope: PBInsideFunctionScope,\r\n inPos: PBShaderExp,\r\n outPos: PBShaderExp,\r\n outNormal: PBShaderExp\r\n ) {\r\n const pb = scope.$builder;\r\n const that = this;\r\n pb.func(\r\n 'calcPositionAndNormal',\r\n [pb.vec3('inPos'), pb.vec3('outPos').out(), pb.vec3('outNormal').out()],\r\n function () {\r\n this.outPos = this.inPos;\r\n this.outNormal = pb.vec3(0);\r\n this.$for(\r\n pb.float('i'),\r\n 0,\r\n pb.getDevice().type === 'webgl' ? MAX_GERSTNER_WAVE_COUNT : this.numWaves,\r\n function () {\r\n if (pb.getDevice().type === 'webgl') {\r\n this.$if(pb.greaterThanEqual(this.i, this.numWaves), function () {\r\n this.$break();\r\n });\r\n }\r\n this.$l.waveNormal = pb.vec3();\r\n this.$l.waveDxdx = pb.float();\r\n this.$l.waveDzdz = pb.float();\r\n this.$l.waveDxdz = pb.float();\r\n this.$l.wavePos = that.gerstnerWave(\r\n this,\r\n this.waveParams.at(pb.mul(this.i, 2)),\r\n this.waveParams.at(pb.add(pb.mul(this.i, 2), 1)),\r\n this.inPos,\r\n this.waveNormal,\r\n this.waveDxdx,\r\n this.waveDzdz,\r\n this.waveDxdz\r\n );\r\n this.outPos = pb.add(this.outPos, this.wavePos);\r\n this.outNormal = pb.add(this.outNormal, this.waveNormal);\r\n }\r\n );\r\n }\r\n );\r\n scope.calcPositionAndNormal(inPos, outPos, outNormal);\r\n }\r\n /** {@inheritDoc WaveGenerator.calcVertexPositionAndNormal} */\r\n calcVertexPositionAndNormal(\r\n scope: PBInsideFunctionScope,\r\n inPos: PBShaderExp,\r\n outPos: PBShaderExp,\r\n outNormal: PBShaderExp\r\n ) {\r\n this.calcNormalAndPos(scope, inPos, outPos, outNormal);\r\n }\r\n /** {@inheritDoc WaveGenerator.applyWaterBindGroup} */\r\n applyWaterBindGroup(bindGroup: BindGroup) {\r\n bindGroup.setValue('numWaves', this._numWaves);\r\n bindGroup.setValue('waveParams', this._waveParams);\r\n bindGroup.setValue('foamParams', this._foamParams);\r\n }\r\n /** {@inheritDoc WaveGenerator.isOk} */\r\n isOk() {\r\n return true;\r\n }\r\n /** {@inheritDoc WaveGenerator.getHash} */\r\n getHash() {\r\n return 'GerstnerWaveGenerator';\r\n }\r\n}\r\n"],"names":["GerstnerWaveGenerator","Disposable","_version","_waveParams","_numWaves","_rand","_foamParams","randomSeed","Float32Array","MAX_GERSTNER_WAVE_COUNT","PRNG","randomWave","randomWaveData","rand","array","offset","get","Math","PI","setRaw","data","index","set","clone","other","numWaves","version","val","Number","isInteger","console","error","i","deleteWave","j","insertWave","setWaveDirection","waveIndex","angle","getWaveDirection","setWaveSteepness","steepness","getWaveSteepness","setWaveAmplitude","getWaveAmplitude","setWaveLength","getWaveLength","isOmniWave","setOmniWave","isOmni","foamWidth","foamContrast","getOriginX","getOriginZ","setOrigin","x","z","update","needUpdate","calcClipmapTileAABB","minX","maxX","minZ","maxZ","y","outAABB","maxHeight","h","minPoint","setXYZ","maxPoint","calcFragmentNormal","scope","xz","_vertexNormal","pb","$builder","that","func","vec2","$l","inPos","vec3","outPos","outNormal","calcNormalAndPos","$return","calcFragmentNormalAndFoam","dxdx","float","dzdz","dxdz","$for","getDevice","type","$if","greaterThanEqual","$break","waveNormal","waveDxdx","waveDzdz","waveDxdz","wavePos","gerstnerWave","waveParams","at","mul","add","sub","foam","abs","pow","neg","min","foamParams","vec4","calcNormalAndFoam","setupUniforms","uniformGroup","uniform","waveParam","omniParam","outDxdx","outDzdz","outDxdz","out","amplitude","max","wavelength","w","omniPos","omni","direction","sin","cos","div","wSpeed","sqrt","peak","qi","dirWaveInput","omniWaveInput","windDir","normalize","dir","dot","calc","ShaderHelper","getElapsedTime","cosCalc","sinCalc","waveXZ","xy","waveY","wave","wa","n","xzy","jac","clamp","calcPositionAndNormal","calcVertexPositionAndNormal","applyWaterBindGroup","bindGroup","setValue","isOk","getHash"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAMA;;;IAIO,MAAMA,qBAA8BC,SAAAA,UAAAA,CAAAA;IACjCC,QAAiB;IACjBC,WAAuC;IACvCC,SAAkB;IAClBC,KAAY;IACHC,WAAuC;AACxD;;MAGA,WAAA,CAAYC,UAAa,GAAA,CAAC,CAAE;QAC1B,KAAK,EAAA;AACL,QAAA,IAAI,CAACJ,WAAW,GAAG,IAAIK,aAAa,CAAIC,GAAAA,uBAAAA,CAAAA;AACxC,QAAA,IAAI,CAACJ,KAAK,GAAG,IAAIK,IAAKH,CAAAA,UAAAA,CAAAA;QACtB,IAAI,CAACI,UAAU,CAAC,CAAA,CAAA;QAChB,IAAI,CAACA,UAAU,CAAC,CAAA,CAAA;QAChB,IAAI,CAACA,UAAU,CAAC,CAAA,CAAA;QAChB,IAAI,CAACA,UAAU,CAAC,CAAA,CAAA;QAChB,IAAI,CAACP,SAAS,GAAG,CAAA;QACjB,IAAI,CAACF,QAAQ,GAAG,CAAA;;;AAGhB,QAAA,IAAI,CAACI,WAAW,GAAG,IAAIE,YAAa,CAAA;AAAC,YAAA,GAAA;AAAK,YAAA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AAAA,SAAAA,CAAAA;AAC7C;mEAEA6E,4BACEzF,KAA4B,EAC5BS,KAAkB,EAClBE,MAAmB,EACnBC,SAAsB,EACtB;AACA,QAAA,IAAI,CAACC,gBAAgB,CAACb,KAAAA,EAAOS,OAAOE,MAAQC,EAAAA,SAAAA,CAAAA;AAC9C;2DAEA8E,mBAAoBC,CAAAA,SAAoB,EAAE;AACxCA,QAAAA,SAAAA,CAAUC,QAAQ,CAAC,UAAY,EAAA,IAAI,CAAChK,SAAS,CAAA;AAC7C+J,QAAAA,SAAAA,CAAUC,QAAQ,CAAC,YAAc,EAAA,IAAI,CAACjK,WAAW,CAAA;AACjDgK,QAAAA,SAAAA,CAAUC,QAAQ,CAAC,YAAc,EAAA,IAAI,CAAC9J,WAAW,CAAA;AACnD;AACA,4CACA+J,IAAO,GAAA;QACL,OAAO,IAAA;AACT;AACA,+CACAC,OAAU,GAAA;QACR,OAAO,uBAAA;AACT;AACF;;;;"}
|
package/dist/render/hzb.js
CHANGED
|
@@ -1,19 +1,35 @@
|
|
|
1
1
|
import { drawFullscreenQuad } from './fullscreenquad.js';
|
|
2
|
-
import { DEPTH_FARTHEST, DEPTH_REDUCE_FARTHER } from '@zephyr3d/base';
|
|
2
|
+
import { REVERSE_Z, DEPTH_FARTHEST, DEPTH_REDUCE_FARTHER, DEPTH_REDUCE_CLOSER } from '@zephyr3d/base';
|
|
3
3
|
import './primitive.js';
|
|
4
4
|
import '@zephyr3d/device';
|
|
5
5
|
import { getDevice } from '../app/api.js';
|
|
6
6
|
import { CopyBlitter } from '../blitter/copy.js';
|
|
7
7
|
import { fetchSampler } from '../utility/misc.js';
|
|
8
8
|
|
|
9
|
-
let hzbProgram =
|
|
9
|
+
let hzbProgram = [];
|
|
10
10
|
let hzbBindGroupCache = new WeakMap();
|
|
11
|
-
let blitter =
|
|
11
|
+
let blitter = [];
|
|
12
12
|
const srcSize = new Int32Array(2);
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Seeds mip 0 of the pyramid from the depth prepass.
|
|
15
|
+
*
|
|
16
|
+
* Both channels start from the same device depth: the pyramid only diverges
|
|
17
|
+
* once the reductions run, one keeping the farthest sample of each 2x2 and the
|
|
18
|
+
* other the nearest. `twoChannel` decides whether the nearest channel exists at
|
|
19
|
+
* all - it is a second full mip chain's worth of bandwidth, so a frame that only
|
|
20
|
+
* needs the occlusion pyramid does not carry it.
|
|
21
|
+
*/ class HiZInitBlitter extends CopyBlitter {
|
|
22
|
+
_twoChannel;
|
|
23
|
+
constructor(twoChannel){
|
|
24
|
+
super();
|
|
25
|
+
this._twoChannel = twoChannel;
|
|
26
|
+
}
|
|
14
27
|
/** @override */ filter(scope, type, srcTex, srcUV, srcLayer, sampleType) {
|
|
15
28
|
const depth = super.filter(scope, type, srcTex, srcUV, srcLayer, sampleType);
|
|
16
|
-
return scope.$builder.vec4(depth.x, 0, 0, 1);
|
|
29
|
+
return scope.$builder.vec4(depth.x, this._twoChannel ? depth.x : 0, 0, 1);
|
|
30
|
+
}
|
|
31
|
+
/** @override */ calcHash() {
|
|
32
|
+
return `${super.calcHash()}:${this._twoChannel ? 1 : 0}`;
|
|
17
33
|
}
|
|
18
34
|
}
|
|
19
35
|
/*
|
|
@@ -192,7 +208,26 @@ float3 hi_z_trace(float3 p, float3 v, in uint camera, out uint iterations) {
|
|
|
192
208
|
}
|
|
193
209
|
return ray;
|
|
194
210
|
}
|
|
195
|
-
*/
|
|
211
|
+
*/ /**
|
|
212
|
+
* Texture format for the Hi-Z pyramid.
|
|
213
|
+
*
|
|
214
|
+
* Half float under reverse-Z and full float otherwise, because reverse-Z spends
|
|
215
|
+
* float's relative precision where the depth is: a 16-bit mantissa there is
|
|
216
|
+
* worth a few centimetres at a hundred metres, while a linear-Z half float
|
|
217
|
+
* would quantise the near field into steps.
|
|
218
|
+
*
|
|
219
|
+
* `withNearest` adds the nearest-depth channel. It doubles the pyramid's
|
|
220
|
+
* bandwidth, so it is only requested by a frame that has a consumer for it.
|
|
221
|
+
*/ function getHiZFormat(withNearest) {
|
|
222
|
+
if (withNearest) {
|
|
223
|
+
return REVERSE_Z ? 'rg16f' : 'rg32f';
|
|
224
|
+
}
|
|
225
|
+
return REVERSE_Z ? 'r16f' : 'r32f';
|
|
226
|
+
}
|
|
227
|
+
/** Whether a Hi-Z texture of this format carries the nearest-depth channel. */ function hasNearestChannel(format) {
|
|
228
|
+
return format === 'rg16f' || format === 'rg32f';
|
|
229
|
+
}
|
|
230
|
+
function buildHZBProgram(device, twoChannel) {
|
|
196
231
|
const program = device.buildRenderProgram({
|
|
197
232
|
label: 'HZBBuilder',
|
|
198
233
|
vertex (pb) {
|
|
@@ -221,22 +256,33 @@ float3 hi_z_trace(float3 p, float3 v, in uint camera, out uint iterations) {
|
|
|
221
256
|
this.$l[`d${i}`] = pb.textureLoad(this.srcTex, pb.clamp(pb.add(this.coord, pb.ivec2(i >> 1, i & 1)), this.minCoord, this.maxCoord), device.type === 'webgpu' ? 0 : this.srcMipLevel);
|
|
222
257
|
}
|
|
223
258
|
// Furthest-depth reduction (max under standard Z, min under reverse Z).
|
|
259
|
+
// This is the conservative direction for occlusion: a cell reports the
|
|
260
|
+
// depth nothing behind it can be in front of.
|
|
224
261
|
this.$l.maxDepth = pb[DEPTH_REDUCE_FARTHER](pb[DEPTH_REDUCE_FARTHER](this.d0.r, this.d1.r), pb[DEPTH_REDUCE_FARTHER](this.d2.r, this.d3.r));
|
|
225
|
-
|
|
262
|
+
if (twoChannel) {
|
|
263
|
+
// Nearest-depth reduction, from the green channel. The opposite
|
|
264
|
+
// conservative direction, and the one a proximity query needs: a cell
|
|
265
|
+
// reports the closest surface anywhere inside it, so a query that
|
|
266
|
+
// covers the cell cannot miss geometry that is in there.
|
|
267
|
+
this.$l.minDepth = pb[DEPTH_REDUCE_CLOSER](pb[DEPTH_REDUCE_CLOSER](this.d0.g, this.d1.g), pb[DEPTH_REDUCE_CLOSER](this.d2.g, this.d3.g));
|
|
268
|
+
this.$outputs.color = pb.vec4(this.maxDepth, this.minDepth, 0, 1);
|
|
269
|
+
} else {
|
|
270
|
+
this.$outputs.color = pb.vec4(this.maxDepth, 0, 0, 1);
|
|
271
|
+
}
|
|
226
272
|
});
|
|
227
273
|
}
|
|
228
274
|
});
|
|
229
|
-
program.name =
|
|
275
|
+
program.name = `@HZB_Builder${twoChannel ? '_MinMax' : ''}`;
|
|
230
276
|
return program;
|
|
231
277
|
}
|
|
232
|
-
function getHiZBindGroup(tex, mip) {
|
|
278
|
+
function getHiZBindGroup(tex, mip, program) {
|
|
233
279
|
let info = hzbBindGroupCache.get(tex);
|
|
234
280
|
if (!info) {
|
|
235
281
|
info = [];
|
|
236
282
|
hzbBindGroupCache.set(tex, info);
|
|
237
283
|
}
|
|
238
284
|
if (!info[mip]) {
|
|
239
|
-
info[mip] = tex.device.createBindGroup(
|
|
285
|
+
info[mip] = tex.device.createBindGroup(program.bindGroupLayouts[0]);
|
|
240
286
|
srcSize[0] = Math.max(tex.width >> mip, 1);
|
|
241
287
|
srcSize[1] = Math.max(tex.height >> mip, 1);
|
|
242
288
|
info[mip].setValue('srcSize', srcSize);
|
|
@@ -249,13 +295,13 @@ function getHiZBindGroup(tex, mip) {
|
|
|
249
295
|
}
|
|
250
296
|
return info[mip];
|
|
251
297
|
}
|
|
252
|
-
function buildHiZLevel(device, miplevel, srcTexture, dstTexture) {
|
|
298
|
+
function buildHiZLevel(device, miplevel, srcTexture, dstTexture, program) {
|
|
253
299
|
const framebuffer = device.pool.fetchTemporalFramebuffer(false, 0, 0, [
|
|
254
300
|
dstTexture
|
|
255
301
|
], null, false, 1, true, miplevel + 1);
|
|
256
302
|
framebuffer.setColorAttachmentGenerateMipmaps(0, false);
|
|
257
|
-
device.setProgram(
|
|
258
|
-
device.setBindGroup(0, getHiZBindGroup(srcTexture, miplevel));
|
|
303
|
+
device.setProgram(program);
|
|
304
|
+
device.setBindGroup(0, getHiZBindGroup(srcTexture, miplevel, program));
|
|
259
305
|
device.setFramebuffer(framebuffer);
|
|
260
306
|
drawFullscreenQuad();
|
|
261
307
|
if (srcTexture !== dstTexture) {
|
|
@@ -263,29 +309,41 @@ function buildHiZLevel(device, miplevel, srcTexture, dstTexture) {
|
|
|
263
309
|
}
|
|
264
310
|
device.pool.releaseFrameBuffer(framebuffer);
|
|
265
311
|
}
|
|
266
|
-
|
|
312
|
+
/**
|
|
313
|
+
* Builds the Hi-Z pyramid from the depth prepass.
|
|
314
|
+
*
|
|
315
|
+
* The target's channel count picks the variant: a one-channel target carries
|
|
316
|
+
* only the farthest-depth pyramid the occlusion tests want, a two-channel one
|
|
317
|
+
* adds the nearest-depth pyramid in green for proximity queries. Keyed off the
|
|
318
|
+
* texture rather than a flag so the pyramid and its consumer cannot disagree
|
|
319
|
+
* about what is in green.
|
|
320
|
+
*/ function buildHiZ(sourceTex, HiZFrameBuffer) {
|
|
267
321
|
const device = getDevice();
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
322
|
+
const dstTex = HiZFrameBuffer.getColorAttachments()[0];
|
|
323
|
+
const twoChannel = hasNearestChannel(dstTex.format);
|
|
324
|
+
const variant = twoChannel ? 1 : 0;
|
|
325
|
+
if (!hzbProgram[variant]) {
|
|
326
|
+
hzbProgram[variant] = buildHZBProgram(device, twoChannel);
|
|
327
|
+
blitter[variant] = new HiZInitBlitter(twoChannel);
|
|
271
328
|
}
|
|
272
|
-
|
|
329
|
+
const program = hzbProgram[variant];
|
|
330
|
+
blitter[variant].blit(sourceTex, HiZFrameBuffer, fetchSampler('clamp_nearest'));
|
|
273
331
|
device.pushDeviceStates();
|
|
274
332
|
const srcTex = HiZFrameBuffer.getColorAttachments()[0];
|
|
275
333
|
if (device.type === 'webgpu') {
|
|
276
334
|
for(let i = 0; i < srcTex.mipLevelCount - 1; i++){
|
|
277
|
-
buildHiZLevel(device, i, srcTex, srcTex);
|
|
335
|
+
buildHiZLevel(device, i, srcTex, srcTex, program);
|
|
278
336
|
}
|
|
279
337
|
} else {
|
|
280
338
|
const tmpFramebuffer = device.pool.fetchTemporalFramebuffer(false, HiZFrameBuffer.getWidth(), HiZFrameBuffer.getHeight(), HiZFrameBuffer.getColorAttachments()[0].format, null, true);
|
|
281
|
-
const
|
|
339
|
+
const tmpTex = tmpFramebuffer.getColorAttachments()[0];
|
|
282
340
|
for(let i = 0; i < srcTex.mipLevelCount - 1; i++){
|
|
283
|
-
buildHiZLevel(device, i, srcTex,
|
|
341
|
+
buildHiZLevel(device, i, srcTex, tmpTex, program);
|
|
284
342
|
}
|
|
285
343
|
device.pool.releaseFrameBuffer(tmpFramebuffer);
|
|
286
344
|
}
|
|
287
345
|
device.popDeviceStates();
|
|
288
346
|
}
|
|
289
347
|
|
|
290
|
-
export { buildHiZ };
|
|
348
|
+
export { buildHiZ, getHiZFormat, hasNearestChannel };
|
|
291
349
|
//# sourceMappingURL=hzb.js.map
|