three-base 2.0.142 → 2.0.145
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/DirectionalLight.d.ts +6 -6
- package/DirectionalLight.js +68 -68
- package/EventMap.d.ts +103 -103
- package/EventMap.js +17 -17
- package/EventMesh.d.ts +18 -18
- package/EventMesh.js +59 -59
- package/ExtrudeMesh.d.ts +112 -112
- package/ExtrudeMesh.js +342 -342
- package/FPScontrol.d.ts +511 -511
- package/FPScontrol.js +1799 -1799
- package/FPScontrol.ts +1855 -1855
- package/Fire/Fire.d.ts +28 -28
- package/Fire/Fire.js +80 -80
- package/Fire/FireGeometry.d.ts +9 -9
- package/Fire/FireGeometry.js +40 -40
- package/Fire/FireMaterial.d.ts +28 -28
- package/Fire/FireMaterial.js +32 -32
- package/Fire/index.d.ts +2 -2
- package/Fire/index.js +2 -2
- package/GLTFDracoLoader.d.ts +71 -71
- package/GLTFDracoLoader.js +266 -266
- package/GLTFDracoLoader.ts +1 -1
- package/Grass/Grass.d.ts +8 -8
- package/Grass/Grass.js +38 -38
- package/Grass/index.d.ts +2 -2
- package/Grass/index.js +2 -2
- package/Ground1/Ground1.d.ts +10 -10
- package/Ground1/Ground1.js +71 -71
- package/Ground1/index.d.ts +1 -1
- package/Ground1/index.js +1 -1
- package/MeshBase.d.ts +36 -36
- package/MeshBase.js +247 -247
- package/Mirror.d.ts +25 -25
- package/Mirror.js +143 -143
- package/MktMesh/MktMesh.d.ts +301 -291
- package/MktMesh/MktMesh.js +1064 -1045
- package/MktMesh/MktMesh.ts +32 -11
- package/MktMesh/assetUrl.d.ts +59 -35
- package/MktMesh/assetUrl.js +154 -69
- package/MktMesh/assetUrl.ts +155 -69
- package/MktMesh/mktMappingShader.d.ts +12 -12
- package/MktMesh/mktMappingShader.js +138 -138
- package/MktMesh/mktMappingShader.ts +139 -139
- package/MktMesh/mktShader.d.ts +263 -263
- package/MktMesh/mktShader.js +1236 -1236
- package/MktMesh/mktShader.ts +1344 -1344
- package/MktMesh/panoBitmapTexture.d.ts +25 -25
- package/MktMesh/panoBitmapTexture.js +52 -52
- package/MktMesh/panoBitmapTexture.ts +54 -54
- package/MktMesh/panoSlotBind.d.ts +29 -29
- package/MktMesh/panoSlotBind.js +106 -106
- package/MktMesh/panoSlotBind.ts +153 -153
- package/MktMesh/panoSlotRoster.d.ts +22 -22
- package/MktMesh/panoSlotRoster.js +169 -169
- package/MktMesh/panoSlotRoster.ts +168 -168
- package/MktMesh/panoTileStitcher.d.ts +119 -119
- package/MktMesh/panoTileStitcher.js +529 -529
- package/MktMesh/panoTileStitcher.ts +616 -616
- package/MktMesh/types.d.ts +75 -75
- package/MktMesh/types.js +1 -1
- package/MktMesh/wallCapTessellate.d.ts +33 -33
- package/MktMesh/wallCapTessellate.js +97 -97
- package/MktMesh/wallCapTessellate.ts +68 -68
- package/PipeMesh/PathGeometry.d.ts +44 -44
- package/PipeMesh/PathGeometry.js +307 -307
- package/PipeMesh/PathPoint.d.ts +17 -17
- package/PipeMesh/PathPoint.js +31 -31
- package/PipeMesh/PathPointList.d.ts +31 -31
- package/PipeMesh/PathPointList.js +209 -209
- package/PipeMesh/PathTubeGeometry.d.ts +25 -25
- package/PipeMesh/PathTubeGeometry.js +130 -130
- package/PipeMesh/PipeMesh.d.ts +25 -25
- package/PipeMesh/PipeMesh.js +63 -63
- package/PipeMesh/index.d.ts +1 -1
- package/PipeMesh/index.js +1 -1
- package/PlaneModal1/PlaneModal1.d.ts +34 -34
- package/PlaneModal1/PlaneModal1.js +109 -109
- package/PlaneModal1/index.d.ts +1 -1
- package/PlaneModal1/index.js +1 -1
- package/PlaneText.d.ts +27 -27
- package/PlaneText.js +35 -35
- package/PlaneWithHtml.d.ts +13 -13
- package/PlaneWithHtml.js +64 -64
- package/PointLight/PointLight.d.ts +13 -13
- package/PointLight/PointLight.js +64 -64
- package/PointLight/index.d.ts +1 -1
- package/PointLight/index.js +1 -1
- package/Sky/Sky.d.ts +9 -9
- package/Sky/Sky.js +22 -22
- package/Sky/index.d.ts +1 -1
- package/Sky/index.js +1 -1
- package/SpotLight.d.ts +6 -6
- package/SpotLight.js +72 -72
- package/SpriteModal1/SpriteModal1.d.ts +33 -33
- package/SpriteModal1/SpriteModal1.js +116 -116
- package/SpriteModal1/index.d.ts +1 -1
- package/SpriteModal1/index.js +1 -1
- package/SpriteText.d.ts +46 -46
- package/SpriteText.js +176 -176
- package/SpriteText2.d.ts +48 -48
- package/SpriteText2.js +223 -223
- package/SpriteText3.d.ts +86 -86
- package/SpriteText3.js +517 -517
- package/SpriteText3.ts +599 -599
- package/SpriteWithHtml.d.ts +9 -9
- package/SpriteWithHtml.js +44 -44
- package/Text3D/Text3D.d.ts +20 -20
- package/Text3D/Text3D.js +58 -58
- package/Text3D/fontController.d.ts +60 -60
- package/Text3D/fontController.js +166 -166
- package/Text3D/index.d.ts +1 -1
- package/Text3D/index.js +1 -1
- package/ThreeBase.d.ts +248 -248
- package/ThreeBase.js +1202 -1202
- package/ThreeBase.ts +1314 -1314
- package/ThreeMouse.d.ts +53 -54
- package/ThreeMouse.js +453 -453
- package/Transition.d.ts +45 -45
- package/Transition.js +209 -209
- package/Water/Water.d.ts +5 -5
- package/Water/Water.js +44 -44
- package/Water/index.d.ts +2 -2
- package/Water/index.js +2 -2
- package/WaterFlow/FloatingDuck.d.ts +88 -88
- package/WaterFlow/FloatingDuck.js +307 -307
- package/WaterFlow/FloatingDuck.ts +445 -445
- package/WaterFlow/GPUFluidSimulation.d.ts +56 -56
- package/WaterFlow/GPUFluidSimulation.js +781 -781
- package/WaterFlow/GPUFluidSimulation.ts +827 -827
- package/WaterFlow/ReservoirSystem.d.ts +106 -106
- package/WaterFlow/ReservoirSystem.js +611 -611
- package/WaterFlow/ReservoirSystem.ts +754 -754
- package/WaterFlow/SPHField.d.ts +35 -35
- package/WaterFlow/SPHField.js +203 -203
- package/WaterFlow/SPHField.ts +228 -228
- package/WaterFlow/ScreenSpaceFluidPass.d.ts +69 -69
- package/WaterFlow/ScreenSpaceFluidPass.js +728 -728
- package/WaterFlow/ScreenSpaceFluidPass.ts +789 -789
- package/WaterFlow/ShallowWaterSurface.d.ts +45 -45
- package/WaterFlow/ShallowWaterSurface.js +438 -438
- package/WaterFlow/ShallowWaterSurface.ts +510 -510
- package/WaterFlow/WaterFlow.d.ts +87 -87
- package/WaterFlow/WaterFlow.js +171 -171
- package/WaterFlow/WaterFlow.ts +219 -219
- package/WaterFlow/types.d.ts +161 -161
- package/WaterFlow/types.js +1 -1
- package/WaterFlow/types.ts +189 -189
- package/WaterFlow/waterFlowPass.d.ts +3 -3
- package/WaterFlow/waterFlowPass.js +20 -20
- package/WaterFlow/waterFlowPass.ts +40 -40
- package/collisionOBB.d.ts +42 -42
- package/collisionOBB.js +112 -112
- package/collisionOBB.ts +108 -108
- package/declare.d.ts +25 -25
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/instanced/InstancedBatch.d.ts +57 -57
- package/instanced/InstancedBatch.js +348 -348
- package/instanced/InstancedBatch.ts +406 -406
- package/instanced/InstancedChild.d.ts +174 -174
- package/instanced/InstancedChild.js +264 -264
- package/instanced/InstancedChild.ts +327 -327
- package/instanced/InstancedGroup.d.ts +43 -43
- package/instanced/InstancedGroup.js +126 -126
- package/instanced/InstancedGroup.ts +137 -137
- package/instanced/InstancedMeshBase.d.ts +38 -38
- package/instanced/InstancedMeshBase.js +282 -282
- package/instanced/InstancedTemplate.d.ts +46 -46
- package/instanced/InstancedTemplate.js +125 -125
- package/keyControls.d.ts +29 -30
- package/keyControls.js +101 -101
- package/lensflare/LensFlare.d.ts +39 -39
- package/lensflare/LensFlare.js +284 -284
- package/package.json +6 -1
- package/pass/bloom_pass.d.ts +2 -2
- package/pass/bloom_pass.js +174 -174
- package/pass/cover_pass.d.ts +2 -2
- package/pass/cover_pass.js +108 -108
- package/pass/debugDepthState.d.ts +20 -20
- package/pass/debugDepthState.js +9 -9
- package/pass/debugDepthState.ts +22 -22
- package/pass/depthTestBias.d.ts +12 -12
- package/pass/depthTestBias.js +12 -12
- package/pass/depthTestBias.ts +12 -12
- package/pass/effectUserData.d.ts +27 -27
- package/pass/effectUserData.js +1 -1
- package/pass/effectUserData.ts +46 -46
- package/pass/frosted_glass_pass.d.ts +2 -2
- package/pass/frosted_glass_pass.js +150 -150
- package/pass/fsQuad.d.ts +9 -9
- package/pass/fsQuad.js +28 -28
- package/pass/glow_pass.d.ts +2 -2
- package/pass/glow_pass.js +350 -350
- package/pass/screen_bloom_pass.d.ts +11 -11
- package/pass/screen_bloom_pass.js +136 -136
- package/pass/ssao_pass.d.ts +88 -88
- package/pass/ssao_pass.js +799 -799
- package/pass/ssao_pass.ts +918 -918
- package/pass/stroke_pass.d.ts +2 -2
- package/pass/stroke_pass.js +267 -267
- package/shaders/FXAAShaderMaterial.d.ts +3 -3
- package/shaders/FXAAShaderMaterial.js +20 -20
- package/shaders/baseDepthVisShader.d.ts +11 -11
- package/shaders/baseDepthVisShader.js +36 -36
- package/shaders/baseDepthVisShader.ts +36 -36
- package/shaders/baseTextureToRenderShader.d.ts +2 -2
- package/shaders/baseTextureToRenderShader.js +19 -19
- package/shaders/copyShader.d.ts +3 -3
- package/shaders/copyShader.js +13 -13
- package/shaders/debugDepthCompareShader.d.ts +14 -14
- package/shaders/debugDepthCompareShader.js +49 -49
- package/shaders/debugDepthCompareShader.ts +50 -50
- package/shaders/debugDepthJudgeShader.d.ts +18 -18
- package/shaders/debugDepthJudgeShader.js +52 -52
- package/shaders/debugDepthJudgeShader.ts +54 -54
- package/shaders/debugExcludedShader.d.ts +13 -13
- package/shaders/debugExcludedShader.js +46 -46
- package/shaders/debugExcludedShader.ts +48 -48
- package/spriteTextBg.d.ts +1 -1
- package/spriteTextBg.js +20 -20
- package/spriteTextBg.ts +20 -20
- package/threeLoader.d.ts +35 -35
- package/threeLoader.js +518 -518
- package/threeUtils.d.ts +53 -53
- package/threeUtils.js +329 -329
- package/types.d.ts +2 -2
- package/types.js +6 -6
|
@@ -1,441 +1,441 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
const quadVertex = /* glsl */ `
|
|
3
|
-
out vec2 vUv;
|
|
4
|
-
void main() {
|
|
5
|
-
vUv = uv;
|
|
6
|
-
gl_Position = vec4(position, 1.0);
|
|
7
|
-
}
|
|
8
|
-
`;
|
|
9
|
-
function createWaveTarget(width, height) {
|
|
10
|
-
return new THREE.WebGLRenderTarget(width, height, {
|
|
11
|
-
format: THREE.RGBAFormat,
|
|
12
|
-
type: THREE.HalfFloatType,
|
|
13
|
-
minFilter: THREE.LinearFilter,
|
|
14
|
-
magFilter: THREE.LinearFilter,
|
|
15
|
-
wrapS: THREE.ClampToEdgeWrapping,
|
|
16
|
-
wrapT: THREE.ClampToEdgeWrapping,
|
|
17
|
-
depthBuffer: false,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
function ambientSurfaceHeight(u, v, time) {
|
|
21
|
-
const sourceX = 0.56 + Math.sin(time * 0.17) * 0.13;
|
|
22
|
-
const sourceZ = 0.48 + Math.cos(time * 0.14) * 0.11;
|
|
23
|
-
const radialX = (u - sourceX) * 1.65;
|
|
24
|
-
const radialZ = v - sourceZ;
|
|
25
|
-
const radialDistance = Math.hypot(radialX, radialZ);
|
|
26
|
-
const swellA = Math.sin(u * 11.0 + v * 7.0 + time * 1.15) * 0.008;
|
|
27
|
-
const swellB = Math.sin(-u * 8.0 + v * 13.0 - time * 0.88 + 0.9) * 0.0055;
|
|
28
|
-
const radial = Math.sin(radialDistance * 29.0 - time * 2.05)
|
|
29
|
-
* Math.exp(-radialDistance * 2.0) * 0.0065;
|
|
30
|
-
return swellA + swellB + radial;
|
|
31
|
-
}
|
|
32
|
-
function sloshSurfaceHeight(u, v, slosh) {
|
|
33
|
-
return (u - 0.5) * 2 * slosh.x + (v - 0.5) * 2 * slosh.y;
|
|
34
|
-
}
|
|
35
|
-
export class ShallowWaterSurface {
|
|
36
|
-
renderer;
|
|
37
|
-
width;
|
|
38
|
-
height;
|
|
39
|
-
basinMinX;
|
|
40
|
-
basinMaxX;
|
|
41
|
-
basinHalfZ;
|
|
42
|
-
basinCenterZ;
|
|
43
|
-
waterY;
|
|
44
|
-
cpuSampling;
|
|
45
|
-
cpuWidth;
|
|
46
|
-
cpuHeight;
|
|
47
|
-
cpuCurrent;
|
|
48
|
-
cpuPrevious;
|
|
49
|
-
cpuNext;
|
|
50
|
-
cpuLastDelta;
|
|
51
|
-
cpuImpactX;
|
|
52
|
-
cpuImpactZ;
|
|
53
|
-
cpuImpactEnergy;
|
|
54
|
-
cpuEmitting;
|
|
55
|
-
elapsed;
|
|
56
|
-
slosh;
|
|
57
|
-
previousSlosh;
|
|
58
|
-
motionImpulse;
|
|
59
|
-
/** 高度场乒乓 RT:每帧交换,故非 readonly。 */
|
|
60
|
-
read;
|
|
61
|
-
write;
|
|
62
|
-
computeScene;
|
|
63
|
-
computeCamera;
|
|
64
|
-
computeMaterial;
|
|
65
|
-
computeQuad;
|
|
66
|
-
material;
|
|
67
|
-
/** 对外可见的水面网格(ReservoirSystem 会改 renderOrder / visible)。 */
|
|
68
|
-
mesh;
|
|
69
|
-
constructor(renderer, { width = 256, height = 128, basinMinX = 0.25, basinMaxX = 3.85, basinHalfZ = 0.82, basinCenterZ = 0, waterY = 0.2, cpuSampling = false, } = {}) {
|
|
70
|
-
this.renderer = renderer;
|
|
71
|
-
this.width = width;
|
|
72
|
-
this.height = height;
|
|
73
|
-
this.basinMinX = basinMinX;
|
|
74
|
-
this.basinMaxX = basinMaxX;
|
|
75
|
-
this.basinHalfZ = basinHalfZ;
|
|
76
|
-
this.basinCenterZ = basinCenterZ;
|
|
77
|
-
this.waterY = waterY;
|
|
78
|
-
this.cpuSampling = cpuSampling;
|
|
79
|
-
this.cpuWidth = cpuSampling ? 48 : 0;
|
|
80
|
-
this.cpuHeight = cpuSampling ? 24 : 0;
|
|
81
|
-
this.cpuCurrent = cpuSampling ? new Float32Array(this.cpuWidth * this.cpuHeight) : null;
|
|
82
|
-
this.cpuPrevious = cpuSampling ? new Float32Array(this.cpuWidth * this.cpuHeight) : null;
|
|
83
|
-
this.cpuNext = cpuSampling ? new Float32Array(this.cpuWidth * this.cpuHeight) : null;
|
|
84
|
-
this.cpuLastDelta = 1 / 60;
|
|
85
|
-
this.cpuImpactX = (basinMinX + basinMaxX) * 0.5;
|
|
86
|
-
this.cpuImpactZ = basinCenterZ;
|
|
87
|
-
this.cpuImpactEnergy = 0;
|
|
88
|
-
this.cpuEmitting = false;
|
|
89
|
-
this.elapsed = 0;
|
|
90
|
-
this.slosh = new THREE.Vector2();
|
|
91
|
-
this.previousSlosh = new THREE.Vector2();
|
|
92
|
-
this.motionImpulse = new THREE.Vector2();
|
|
93
|
-
this.read = createWaveTarget(width, height);
|
|
94
|
-
this.write = createWaveTarget(width, height);
|
|
95
|
-
this.computeScene = new THREE.Scene();
|
|
96
|
-
this.computeCamera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
|
97
|
-
this.computeMaterial = new THREE.ShaderMaterial({
|
|
98
|
-
glslVersion: THREE.GLSL3,
|
|
99
|
-
uniforms: {
|
|
100
|
-
uState: { value: this.read.texture },
|
|
101
|
-
uTexel: { value: new THREE.Vector2(1 / width, 1 / height) },
|
|
102
|
-
uImpactUv: { value: new THREE.Vector2(0.35, 0.5) },
|
|
103
|
-
uImpulse: { value: 0 },
|
|
104
|
-
uTime: { value: 0 },
|
|
105
|
-
uMotionImpulse: { value: new THREE.Vector2() },
|
|
106
|
-
},
|
|
107
|
-
vertexShader: quadVertex,
|
|
108
|
-
fragmentShader: /* glsl */ `
|
|
109
|
-
precision highp float;
|
|
110
|
-
uniform sampler2D uState;
|
|
111
|
-
uniform vec2 uTexel;
|
|
112
|
-
uniform vec2 uImpactUv;
|
|
113
|
-
uniform float uImpulse;
|
|
114
|
-
uniform float uTime;
|
|
115
|
-
uniform vec2 uMotionImpulse;
|
|
116
|
-
in vec2 vUv;
|
|
117
|
-
out vec4 outColor;
|
|
118
|
-
|
|
119
|
-
void main() {
|
|
120
|
-
vec2 state = texture(uState, vUv).rg;
|
|
121
|
-
float current = state.r;
|
|
122
|
-
float previous = state.g;
|
|
123
|
-
float left = texture(uState, vUv - vec2(uTexel.x, 0.0)).r;
|
|
124
|
-
float right = texture(uState, vUv + vec2(uTexel.x, 0.0)).r;
|
|
125
|
-
float down = texture(uState, vUv - vec2(0.0, uTexel.y)).r;
|
|
126
|
-
float up = texture(uState, vUv + vec2(0.0, uTexel.y)).r;
|
|
127
|
-
float laplacian = left + right + down + up - 4.0 * current;
|
|
128
|
-
float nextHeight = (2.0 * current - previous) + laplacian * 0.235;
|
|
129
|
-
nextHeight *= 0.9925;
|
|
130
|
-
|
|
131
|
-
vec2 aspectUv = (vUv - uImpactUv) * vec2(2.2, 1.0);
|
|
132
|
-
float impact = exp(-dot(aspectUv, aspectUv) * 420.0);
|
|
133
|
-
float microPulse = 0.72 + 0.28 * sin(uTime * 19.0);
|
|
134
|
-
nextHeight += impact * uImpulse * microPulse;
|
|
135
|
-
|
|
136
|
-
vec2 sourceA = vec2(0.22 + sin(uTime * 0.19) * 0.08, 0.31 + cos(uTime * 0.16) * 0.09);
|
|
137
|
-
vec2 sourceB = vec2(0.72 + cos(uTime * 0.13) * 0.09, 0.68 + sin(uTime * 0.17) * 0.08);
|
|
138
|
-
vec2 deltaA = (vUv - sourceA) * vec2(1.75, 1.0);
|
|
139
|
-
vec2 deltaB = (vUv - sourceB) * vec2(1.55, 1.0);
|
|
140
|
-
float distanceA = length(deltaA);
|
|
141
|
-
float distanceB = length(deltaB);
|
|
142
|
-
float ambientWaves = sin(distanceA * 47.0 - uTime * 2.15) * exp(-distanceA * 3.8)
|
|
143
|
-
+ sin(distanceB * 39.0 - uTime * 1.72 + 1.4) * exp(-distanceB * 3.5);
|
|
144
|
-
nextHeight += ambientWaves * 0.000028;
|
|
145
|
-
|
|
146
|
-
vec2 centered = vUv - 0.5;
|
|
147
|
-
float wallResponse = 0.34
|
|
148
|
-
+ 0.66 * pow(max(abs(centered.x), abs(centered.y)) * 2.0, 2.0);
|
|
149
|
-
nextHeight += dot(centered, uMotionImpulse) * wallResponse;
|
|
150
|
-
|
|
151
|
-
float edge = smoothstep(0.0, 0.025, vUv.x) * smoothstep(1.0, 0.975, vUv.x)
|
|
152
|
-
* smoothstep(0.0, 0.045, vUv.y) * smoothstep(1.0, 0.955, vUv.y);
|
|
153
|
-
nextHeight *= mix(0.86, 1.0, edge);
|
|
154
|
-
outColor = vec4(nextHeight, current, 0.0, 1.0);
|
|
155
|
-
}
|
|
156
|
-
`,
|
|
157
|
-
depthTest: false,
|
|
158
|
-
depthWrite: false,
|
|
159
|
-
toneMapped: false,
|
|
160
|
-
});
|
|
161
|
-
this.computeQuad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2), this.computeMaterial);
|
|
162
|
-
this.computeQuad.frustumCulled = false;
|
|
163
|
-
this.computeScene.add(this.computeQuad);
|
|
164
|
-
this.material = new THREE.ShaderMaterial({
|
|
165
|
-
glslVersion: THREE.GLSL3,
|
|
166
|
-
uniforms: {
|
|
167
|
-
uHeightMap: { value: this.read.texture },
|
|
168
|
-
uTexel: { value: new THREE.Vector2(1 / width, 1 / height) },
|
|
169
|
-
uTime: { value: 0 },
|
|
170
|
-
uSlosh: { value: this.slosh },
|
|
171
|
-
uLightPosition: { value: new THREE.Vector3(-1, 5, 4) },
|
|
172
|
-
},
|
|
173
|
-
vertexShader: /* glsl */ `
|
|
174
|
-
precision highp float;
|
|
175
|
-
uniform sampler2D uHeightMap;
|
|
176
|
-
uniform vec2 uTexel;
|
|
177
|
-
uniform float uTime;
|
|
178
|
-
uniform vec2 uSlosh;
|
|
179
|
-
out vec2 vUv;
|
|
180
|
-
out vec3 vWorldPosition;
|
|
181
|
-
out vec3 vWorldNormal;
|
|
182
|
-
|
|
183
|
-
float ambientHeight(vec2 sampleUv) {
|
|
184
|
-
vec2 source = vec2(
|
|
185
|
-
0.56 + sin(uTime * 0.17) * 0.13,
|
|
186
|
-
0.48 + cos(uTime * 0.14) * 0.11
|
|
187
|
-
);
|
|
188
|
-
vec2 radialDelta = (sampleUv - source) * vec2(1.65, 1.0);
|
|
189
|
-
float radialDistance = length(radialDelta);
|
|
190
|
-
float swellA = sin(sampleUv.x * 11.0 + sampleUv.y * 7.0 + uTime * 1.15) * 0.008;
|
|
191
|
-
float swellB = sin(-sampleUv.x * 8.0 + sampleUv.y * 13.0 - uTime * 0.88 + 0.9) * 0.0055;
|
|
192
|
-
float radial = sin(radialDistance * 29.0 - uTime * 2.05)
|
|
193
|
-
* exp(-radialDistance * 2.0) * 0.0065;
|
|
194
|
-
return swellA + swellB + radial;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
float surfaceHeight(vec2 sampleUv) {
|
|
198
|
-
float sloshHeight = dot((sampleUv - 0.5) * 2.0, uSlosh);
|
|
199
|
-
return texture(uHeightMap, sampleUv).r * 0.52 + ambientHeight(sampleUv) + sloshHeight;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
void main() {
|
|
203
|
-
vUv = uv;
|
|
204
|
-
float h = surfaceHeight(uv);
|
|
205
|
-
float hL = surfaceHeight(uv - vec2(uTexel.x, 0.0));
|
|
206
|
-
float hR = surfaceHeight(uv + vec2(uTexel.x, 0.0));
|
|
207
|
-
float hD = surfaceHeight(uv - vec2(0.0, uTexel.y));
|
|
208
|
-
float hU = surfaceHeight(uv + vec2(0.0, uTexel.y));
|
|
209
|
-
vec3 displaced = position;
|
|
210
|
-
displaced.z += h;
|
|
211
|
-
vec3 localNormal = normalize(vec3((hL - hR) * 46.0, (hD - hU) * 46.0, 1.0));
|
|
212
|
-
vec4 world = modelMatrix * vec4(displaced, 1.0);
|
|
213
|
-
vWorldPosition = world.xyz;
|
|
214
|
-
vWorldNormal = normalize(mat3(modelMatrix) * localNormal);
|
|
215
|
-
gl_Position = projectionMatrix * viewMatrix * world;
|
|
216
|
-
}
|
|
217
|
-
`,
|
|
218
|
-
fragmentShader: /* glsl */ `
|
|
219
|
-
precision highp float;
|
|
220
|
-
uniform sampler2D uHeightMap;
|
|
221
|
-
uniform vec2 uTexel;
|
|
222
|
-
uniform float uTime;
|
|
223
|
-
uniform vec3 uLightPosition;
|
|
224
|
-
in vec2 vUv;
|
|
225
|
-
in vec3 vWorldPosition;
|
|
226
|
-
in vec3 vWorldNormal;
|
|
227
|
-
out vec4 outColor;
|
|
228
|
-
|
|
229
|
-
void main() {
|
|
230
|
-
vec2 microRipple = vec2(
|
|
231
|
-
sin(vUv.x * 54.0 + vUv.y * 19.0 + uTime * 1.35)
|
|
232
|
-
+ sin(vUv.y * 37.0 - uTime * 0.94),
|
|
233
|
-
cos(vUv.y * 49.0 - vUv.x * 17.0 + uTime * 1.12)
|
|
234
|
-
+ cos(vUv.x * 31.0 + uTime * 0.78)
|
|
235
|
-
) * 0.014;
|
|
236
|
-
vec3 normal = normalize(vWorldNormal + vec3(microRipple.x, 0.0, microRipple.y));
|
|
237
|
-
vec3 viewDir = normalize(cameraPosition - vWorldPosition);
|
|
238
|
-
vec3 lightDir = normalize(uLightPosition - vWorldPosition);
|
|
239
|
-
vec3 halfDir = normalize(viewDir + lightDir);
|
|
240
|
-
float fresnel = 0.02 + 0.98 * pow(1.0 - max(dot(viewDir, normal), 0.0), 5.0);
|
|
241
|
-
float specular = pow(max(dot(normal, halfDir), 0.0), 118.0);
|
|
242
|
-
float height = texture(uHeightMap, vUv).r;
|
|
243
|
-
float slope = abs(texture(uHeightMap, vUv + vec2(uTexel.x, 0.0)).r - texture(uHeightMap, vUv - vec2(uTexel.x, 0.0)).r)
|
|
244
|
-
+ abs(texture(uHeightMap, vUv + vec2(0.0, uTexel.y)).r - texture(uHeightMap, vUv - vec2(0.0, uTexel.y)).r);
|
|
245
|
-
float foam = smoothstep(0.018, 0.07, slope + abs(height) * 0.16);
|
|
246
|
-
vec3 deep = vec3(0.018, 0.16, 0.2);
|
|
247
|
-
vec3 reflection = mix(vec3(0.06, 0.2, 0.24), vec3(0.5, 0.86, 0.9), fresnel);
|
|
248
|
-
vec3 color = mix(deep, reflection, 0.32 + fresnel * 0.68);
|
|
249
|
-
color += vec3(0.75, 0.98, 1.0) * specular * 1.4;
|
|
250
|
-
color = mix(color, vec3(0.72, 0.94, 0.96), foam * 0.36);
|
|
251
|
-
outColor = vec4(color, 0.66 + fresnel * 0.22);
|
|
252
|
-
}
|
|
253
|
-
`,
|
|
254
|
-
transparent: true,
|
|
255
|
-
depthWrite: false,
|
|
256
|
-
side: THREE.DoubleSide,
|
|
257
|
-
});
|
|
258
|
-
const segmentsX = width >= 200 ? 128 : 64;
|
|
259
|
-
const segmentsY = width >= 200 ? 64 : 32;
|
|
260
|
-
this.mesh = new THREE.Mesh(new THREE.PlaneGeometry(basinMaxX - basinMinX - 0.12, basinHalfZ * 2 - 0.12, segmentsX, segmentsY), this.material);
|
|
261
|
-
this.mesh.rotation.x = -Math.PI / 2;
|
|
262
|
-
this.mesh.position.set((basinMinX + basinMaxX) * 0.5, waterY, basinCenterZ);
|
|
263
|
-
this.mesh.renderOrder = 2;
|
|
264
|
-
this.clear();
|
|
265
|
-
}
|
|
266
|
-
clear() {
|
|
267
|
-
this.cpuCurrent?.fill(0);
|
|
268
|
-
this.cpuPrevious?.fill(0);
|
|
269
|
-
this.cpuNext?.fill(0);
|
|
270
|
-
const previousTarget = this.renderer.getRenderTarget();
|
|
271
|
-
const previousColor = this.renderer.getClearColor(new THREE.Color());
|
|
272
|
-
const previousAlpha = this.renderer.getClearAlpha();
|
|
273
|
-
this.renderer.setClearColor(0x000000, 0);
|
|
274
|
-
this.renderer.setRenderTarget(this.read);
|
|
275
|
-
this.renderer.clear();
|
|
276
|
-
this.renderer.setRenderTarget(this.write);
|
|
277
|
-
this.renderer.clear();
|
|
278
|
-
this.renderer.setRenderTarget(previousTarget);
|
|
279
|
-
this.renderer.setClearColor(previousColor, previousAlpha);
|
|
280
|
-
}
|
|
281
|
-
setBounds({ basinMinX, basinMaxX, basinHalfZ, basinCenterZ = 0, waterY }) {
|
|
282
|
-
this.basinMinX = basinMinX;
|
|
283
|
-
this.basinMaxX = basinMaxX;
|
|
284
|
-
this.basinHalfZ = basinHalfZ;
|
|
285
|
-
this.basinCenterZ = basinCenterZ;
|
|
286
|
-
this.waterY = waterY;
|
|
287
|
-
this.mesh.position.set((basinMinX + basinMaxX) * 0.5, waterY, basinCenterZ);
|
|
288
|
-
}
|
|
289
|
-
setContainerMotion(sloshX = 0, sloshZ = 0, impulseX = 0, impulseZ = 0) {
|
|
290
|
-
this.previousSlosh.copy(this.slosh);
|
|
291
|
-
this.slosh.set(sloshX, sloshZ);
|
|
292
|
-
this.motionImpulse.set(impulseX, impulseZ);
|
|
293
|
-
this.computeMaterial.uniforms.uMotionImpulse.value.copy(this.motionImpulse);
|
|
294
|
-
}
|
|
295
|
-
update(delta, elapsed, impactWorldX, energy, emitting, impactWorldZ = 0) {
|
|
296
|
-
this.elapsed = elapsed;
|
|
297
|
-
const impactUvX = THREE.MathUtils.clamp((impactWorldX - this.basinMinX) / (this.basinMaxX - this.basinMinX), 0.03, 0.97);
|
|
298
|
-
const impactUvZ = THREE.MathUtils.clamp((impactWorldZ - (this.basinCenterZ - this.basinHalfZ)) / (this.basinHalfZ * 2), 0.03, 0.97);
|
|
299
|
-
const impulse = emitting ? Math.min(energy * delta * 0.00135, 0.0035) : 0;
|
|
300
|
-
this.computeMaterial.uniforms.uState.value = this.read.texture;
|
|
301
|
-
this.computeMaterial.uniforms.uImpactUv.value.set(impactUvX, impactUvZ);
|
|
302
|
-
this.computeMaterial.uniforms.uImpulse.value = impulse;
|
|
303
|
-
this.computeMaterial.uniforms.uTime.value = elapsed;
|
|
304
|
-
if (this.cpuSampling) {
|
|
305
|
-
this.stepCpuSampler(delta, elapsed, impactUvX, impactUvZ, impactWorldX, impactWorldZ, energy, emitting, impulse);
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
const quadVertex = /* glsl */ `
|
|
3
|
+
out vec2 vUv;
|
|
4
|
+
void main() {
|
|
5
|
+
vUv = uv;
|
|
6
|
+
gl_Position = vec4(position, 1.0);
|
|
7
|
+
}
|
|
8
|
+
`;
|
|
9
|
+
function createWaveTarget(width, height) {
|
|
10
|
+
return new THREE.WebGLRenderTarget(width, height, {
|
|
11
|
+
format: THREE.RGBAFormat,
|
|
12
|
+
type: THREE.HalfFloatType,
|
|
13
|
+
minFilter: THREE.LinearFilter,
|
|
14
|
+
magFilter: THREE.LinearFilter,
|
|
15
|
+
wrapS: THREE.ClampToEdgeWrapping,
|
|
16
|
+
wrapT: THREE.ClampToEdgeWrapping,
|
|
17
|
+
depthBuffer: false,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function ambientSurfaceHeight(u, v, time) {
|
|
21
|
+
const sourceX = 0.56 + Math.sin(time * 0.17) * 0.13;
|
|
22
|
+
const sourceZ = 0.48 + Math.cos(time * 0.14) * 0.11;
|
|
23
|
+
const radialX = (u - sourceX) * 1.65;
|
|
24
|
+
const radialZ = v - sourceZ;
|
|
25
|
+
const radialDistance = Math.hypot(radialX, radialZ);
|
|
26
|
+
const swellA = Math.sin(u * 11.0 + v * 7.0 + time * 1.15) * 0.008;
|
|
27
|
+
const swellB = Math.sin(-u * 8.0 + v * 13.0 - time * 0.88 + 0.9) * 0.0055;
|
|
28
|
+
const radial = Math.sin(radialDistance * 29.0 - time * 2.05)
|
|
29
|
+
* Math.exp(-radialDistance * 2.0) * 0.0065;
|
|
30
|
+
return swellA + swellB + radial;
|
|
31
|
+
}
|
|
32
|
+
function sloshSurfaceHeight(u, v, slosh) {
|
|
33
|
+
return (u - 0.5) * 2 * slosh.x + (v - 0.5) * 2 * slosh.y;
|
|
34
|
+
}
|
|
35
|
+
export class ShallowWaterSurface {
|
|
36
|
+
renderer;
|
|
37
|
+
width;
|
|
38
|
+
height;
|
|
39
|
+
basinMinX;
|
|
40
|
+
basinMaxX;
|
|
41
|
+
basinHalfZ;
|
|
42
|
+
basinCenterZ;
|
|
43
|
+
waterY;
|
|
44
|
+
cpuSampling;
|
|
45
|
+
cpuWidth;
|
|
46
|
+
cpuHeight;
|
|
47
|
+
cpuCurrent;
|
|
48
|
+
cpuPrevious;
|
|
49
|
+
cpuNext;
|
|
50
|
+
cpuLastDelta;
|
|
51
|
+
cpuImpactX;
|
|
52
|
+
cpuImpactZ;
|
|
53
|
+
cpuImpactEnergy;
|
|
54
|
+
cpuEmitting;
|
|
55
|
+
elapsed;
|
|
56
|
+
slosh;
|
|
57
|
+
previousSlosh;
|
|
58
|
+
motionImpulse;
|
|
59
|
+
/** 高度场乒乓 RT:每帧交换,故非 readonly。 */
|
|
60
|
+
read;
|
|
61
|
+
write;
|
|
62
|
+
computeScene;
|
|
63
|
+
computeCamera;
|
|
64
|
+
computeMaterial;
|
|
65
|
+
computeQuad;
|
|
66
|
+
material;
|
|
67
|
+
/** 对外可见的水面网格(ReservoirSystem 会改 renderOrder / visible)。 */
|
|
68
|
+
mesh;
|
|
69
|
+
constructor(renderer, { width = 256, height = 128, basinMinX = 0.25, basinMaxX = 3.85, basinHalfZ = 0.82, basinCenterZ = 0, waterY = 0.2, cpuSampling = false, } = {}) {
|
|
70
|
+
this.renderer = renderer;
|
|
71
|
+
this.width = width;
|
|
72
|
+
this.height = height;
|
|
73
|
+
this.basinMinX = basinMinX;
|
|
74
|
+
this.basinMaxX = basinMaxX;
|
|
75
|
+
this.basinHalfZ = basinHalfZ;
|
|
76
|
+
this.basinCenterZ = basinCenterZ;
|
|
77
|
+
this.waterY = waterY;
|
|
78
|
+
this.cpuSampling = cpuSampling;
|
|
79
|
+
this.cpuWidth = cpuSampling ? 48 : 0;
|
|
80
|
+
this.cpuHeight = cpuSampling ? 24 : 0;
|
|
81
|
+
this.cpuCurrent = cpuSampling ? new Float32Array(this.cpuWidth * this.cpuHeight) : null;
|
|
82
|
+
this.cpuPrevious = cpuSampling ? new Float32Array(this.cpuWidth * this.cpuHeight) : null;
|
|
83
|
+
this.cpuNext = cpuSampling ? new Float32Array(this.cpuWidth * this.cpuHeight) : null;
|
|
84
|
+
this.cpuLastDelta = 1 / 60;
|
|
85
|
+
this.cpuImpactX = (basinMinX + basinMaxX) * 0.5;
|
|
86
|
+
this.cpuImpactZ = basinCenterZ;
|
|
87
|
+
this.cpuImpactEnergy = 0;
|
|
88
|
+
this.cpuEmitting = false;
|
|
89
|
+
this.elapsed = 0;
|
|
90
|
+
this.slosh = new THREE.Vector2();
|
|
91
|
+
this.previousSlosh = new THREE.Vector2();
|
|
92
|
+
this.motionImpulse = new THREE.Vector2();
|
|
93
|
+
this.read = createWaveTarget(width, height);
|
|
94
|
+
this.write = createWaveTarget(width, height);
|
|
95
|
+
this.computeScene = new THREE.Scene();
|
|
96
|
+
this.computeCamera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
|
97
|
+
this.computeMaterial = new THREE.ShaderMaterial({
|
|
98
|
+
glslVersion: THREE.GLSL3,
|
|
99
|
+
uniforms: {
|
|
100
|
+
uState: { value: this.read.texture },
|
|
101
|
+
uTexel: { value: new THREE.Vector2(1 / width, 1 / height) },
|
|
102
|
+
uImpactUv: { value: new THREE.Vector2(0.35, 0.5) },
|
|
103
|
+
uImpulse: { value: 0 },
|
|
104
|
+
uTime: { value: 0 },
|
|
105
|
+
uMotionImpulse: { value: new THREE.Vector2() },
|
|
106
|
+
},
|
|
107
|
+
vertexShader: quadVertex,
|
|
108
|
+
fragmentShader: /* glsl */ `
|
|
109
|
+
precision highp float;
|
|
110
|
+
uniform sampler2D uState;
|
|
111
|
+
uniform vec2 uTexel;
|
|
112
|
+
uniform vec2 uImpactUv;
|
|
113
|
+
uniform float uImpulse;
|
|
114
|
+
uniform float uTime;
|
|
115
|
+
uniform vec2 uMotionImpulse;
|
|
116
|
+
in vec2 vUv;
|
|
117
|
+
out vec4 outColor;
|
|
118
|
+
|
|
119
|
+
void main() {
|
|
120
|
+
vec2 state = texture(uState, vUv).rg;
|
|
121
|
+
float current = state.r;
|
|
122
|
+
float previous = state.g;
|
|
123
|
+
float left = texture(uState, vUv - vec2(uTexel.x, 0.0)).r;
|
|
124
|
+
float right = texture(uState, vUv + vec2(uTexel.x, 0.0)).r;
|
|
125
|
+
float down = texture(uState, vUv - vec2(0.0, uTexel.y)).r;
|
|
126
|
+
float up = texture(uState, vUv + vec2(0.0, uTexel.y)).r;
|
|
127
|
+
float laplacian = left + right + down + up - 4.0 * current;
|
|
128
|
+
float nextHeight = (2.0 * current - previous) + laplacian * 0.235;
|
|
129
|
+
nextHeight *= 0.9925;
|
|
130
|
+
|
|
131
|
+
vec2 aspectUv = (vUv - uImpactUv) * vec2(2.2, 1.0);
|
|
132
|
+
float impact = exp(-dot(aspectUv, aspectUv) * 420.0);
|
|
133
|
+
float microPulse = 0.72 + 0.28 * sin(uTime * 19.0);
|
|
134
|
+
nextHeight += impact * uImpulse * microPulse;
|
|
135
|
+
|
|
136
|
+
vec2 sourceA = vec2(0.22 + sin(uTime * 0.19) * 0.08, 0.31 + cos(uTime * 0.16) * 0.09);
|
|
137
|
+
vec2 sourceB = vec2(0.72 + cos(uTime * 0.13) * 0.09, 0.68 + sin(uTime * 0.17) * 0.08);
|
|
138
|
+
vec2 deltaA = (vUv - sourceA) * vec2(1.75, 1.0);
|
|
139
|
+
vec2 deltaB = (vUv - sourceB) * vec2(1.55, 1.0);
|
|
140
|
+
float distanceA = length(deltaA);
|
|
141
|
+
float distanceB = length(deltaB);
|
|
142
|
+
float ambientWaves = sin(distanceA * 47.0 - uTime * 2.15) * exp(-distanceA * 3.8)
|
|
143
|
+
+ sin(distanceB * 39.0 - uTime * 1.72 + 1.4) * exp(-distanceB * 3.5);
|
|
144
|
+
nextHeight += ambientWaves * 0.000028;
|
|
145
|
+
|
|
146
|
+
vec2 centered = vUv - 0.5;
|
|
147
|
+
float wallResponse = 0.34
|
|
148
|
+
+ 0.66 * pow(max(abs(centered.x), abs(centered.y)) * 2.0, 2.0);
|
|
149
|
+
nextHeight += dot(centered, uMotionImpulse) * wallResponse;
|
|
150
|
+
|
|
151
|
+
float edge = smoothstep(0.0, 0.025, vUv.x) * smoothstep(1.0, 0.975, vUv.x)
|
|
152
|
+
* smoothstep(0.0, 0.045, vUv.y) * smoothstep(1.0, 0.955, vUv.y);
|
|
153
|
+
nextHeight *= mix(0.86, 1.0, edge);
|
|
154
|
+
outColor = vec4(nextHeight, current, 0.0, 1.0);
|
|
306
155
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
this.
|
|
313
|
-
this.
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
const distanceA = Math.hypot(ambientAX, ambientAZ);
|
|
347
|
-
const distanceB = Math.hypot(ambientBX, ambientBZ);
|
|
348
|
-
const ambientWaves = Math.sin(distanceA * 47 - elapsed * 2.15) * Math.exp(-distanceA * 3.8)
|
|
349
|
-
+ Math.sin(distanceB * 39 - elapsed * 1.72 + 1.4) * Math.exp(-distanceB * 3.5);
|
|
350
|
-
nextHeight += ambientWaves * 0.000028;
|
|
351
|
-
const centeredX = uvX - 0.5;
|
|
352
|
-
const centeredZ = uvZ - 0.5;
|
|
353
|
-
const wallResponse = 0.34 + 0.66 * Math.pow(Math.max(Math.abs(centeredX), Math.abs(centeredZ)) * 2, 2);
|
|
354
|
-
nextHeight += (centeredX * this.motionImpulse.x + centeredZ * this.motionImpulse.y) * wallResponse;
|
|
355
|
-
const xEdge = Math.min(1, uvX / 0.035, (1 - uvX) / 0.035);
|
|
356
|
-
nextHeight *= THREE.MathUtils.lerp(0.86, 1, Math.max(0, Math.min(xEdge, zEdge)));
|
|
357
|
-
next[index] = nextHeight;
|
|
358
|
-
}
|
|
156
|
+
`,
|
|
157
|
+
depthTest: false,
|
|
158
|
+
depthWrite: false,
|
|
159
|
+
toneMapped: false,
|
|
160
|
+
});
|
|
161
|
+
this.computeQuad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2), this.computeMaterial);
|
|
162
|
+
this.computeQuad.frustumCulled = false;
|
|
163
|
+
this.computeScene.add(this.computeQuad);
|
|
164
|
+
this.material = new THREE.ShaderMaterial({
|
|
165
|
+
glslVersion: THREE.GLSL3,
|
|
166
|
+
uniforms: {
|
|
167
|
+
uHeightMap: { value: this.read.texture },
|
|
168
|
+
uTexel: { value: new THREE.Vector2(1 / width, 1 / height) },
|
|
169
|
+
uTime: { value: 0 },
|
|
170
|
+
uSlosh: { value: this.slosh },
|
|
171
|
+
uLightPosition: { value: new THREE.Vector3(-1, 5, 4) },
|
|
172
|
+
},
|
|
173
|
+
vertexShader: /* glsl */ `
|
|
174
|
+
precision highp float;
|
|
175
|
+
uniform sampler2D uHeightMap;
|
|
176
|
+
uniform vec2 uTexel;
|
|
177
|
+
uniform float uTime;
|
|
178
|
+
uniform vec2 uSlosh;
|
|
179
|
+
out vec2 vUv;
|
|
180
|
+
out vec3 vWorldPosition;
|
|
181
|
+
out vec3 vWorldNormal;
|
|
182
|
+
|
|
183
|
+
float ambientHeight(vec2 sampleUv) {
|
|
184
|
+
vec2 source = vec2(
|
|
185
|
+
0.56 + sin(uTime * 0.17) * 0.13,
|
|
186
|
+
0.48 + cos(uTime * 0.14) * 0.11
|
|
187
|
+
);
|
|
188
|
+
vec2 radialDelta = (sampleUv - source) * vec2(1.65, 1.0);
|
|
189
|
+
float radialDistance = length(radialDelta);
|
|
190
|
+
float swellA = sin(sampleUv.x * 11.0 + sampleUv.y * 7.0 + uTime * 1.15) * 0.008;
|
|
191
|
+
float swellB = sin(-sampleUv.x * 8.0 + sampleUv.y * 13.0 - uTime * 0.88 + 0.9) * 0.0055;
|
|
192
|
+
float radial = sin(radialDistance * 29.0 - uTime * 2.05)
|
|
193
|
+
* exp(-radialDistance * 2.0) * 0.0065;
|
|
194
|
+
return swellA + swellB + radial;
|
|
359
195
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
this.cpuImpactX = impactWorldX;
|
|
365
|
-
this.cpuImpactZ = impactWorldZ;
|
|
366
|
-
this.cpuImpactEnergy = energy;
|
|
367
|
-
this.cpuEmitting = emitting;
|
|
368
|
-
}
|
|
369
|
-
sampleSurface(worldX, worldZ, target = {}) {
|
|
370
|
-
target.height = 0;
|
|
371
|
-
target.velocityY = 0;
|
|
372
|
-
target.slopeX = 0;
|
|
373
|
-
target.slopeZ = 0;
|
|
374
|
-
target.flowX = 0;
|
|
375
|
-
target.flowZ = 0;
|
|
376
|
-
target.impact = 0;
|
|
377
|
-
if (!this.cpuSampling || !this.cpuCurrent)
|
|
378
|
-
return target;
|
|
379
|
-
const sample = (field, u, v) => {
|
|
380
|
-
const x = THREE.MathUtils.clamp(u, 0, 1) * (this.cpuWidth - 1);
|
|
381
|
-
const z = THREE.MathUtils.clamp(v, 0, 1) * (this.cpuHeight - 1);
|
|
382
|
-
const x0 = Math.floor(x);
|
|
383
|
-
const z0 = Math.floor(z);
|
|
384
|
-
const x1 = Math.min(this.cpuWidth - 1, x0 + 1);
|
|
385
|
-
const z1 = Math.min(this.cpuHeight - 1, z0 + 1);
|
|
386
|
-
const tx = x - x0;
|
|
387
|
-
const tz = z - z0;
|
|
388
|
-
const a = THREE.MathUtils.lerp(field[z0 * this.cpuWidth + x0], field[z0 * this.cpuWidth + x1], tx);
|
|
389
|
-
const b = THREE.MathUtils.lerp(field[z1 * this.cpuWidth + x0], field[z1 * this.cpuWidth + x1], tx);
|
|
390
|
-
return THREE.MathUtils.lerp(a, b, tz);
|
|
391
|
-
};
|
|
392
|
-
const u = (worldX - this.basinMinX) / Math.max(this.basinMaxX - this.basinMinX, 0.001);
|
|
393
|
-
const v = (worldZ - (this.basinCenterZ - this.basinHalfZ)) / Math.max(this.basinHalfZ * 2, 0.001);
|
|
394
|
-
const du = 1 / Math.max(this.cpuWidth - 1, 1);
|
|
395
|
-
const dv = 1 / Math.max(this.cpuHeight - 1, 1);
|
|
396
|
-
const center = sample(this.cpuCurrent, u, v);
|
|
397
|
-
const previous = sample(this.cpuPrevious, u, v);
|
|
398
|
-
const left = sample(this.cpuCurrent, u - du, v);
|
|
399
|
-
const right = sample(this.cpuCurrent, u + du, v);
|
|
400
|
-
const down = sample(this.cpuCurrent, u, v - dv);
|
|
401
|
-
const up = sample(this.cpuCurrent, u, v + dv);
|
|
402
|
-
const cellX = (this.basinMaxX - this.basinMinX) * du;
|
|
403
|
-
const cellZ = this.basinHalfZ * 2 * dv;
|
|
404
|
-
const displacementScale = 0.52;
|
|
405
|
-
const ambientCenter = ambientSurfaceHeight(u, v, this.elapsed) + sloshSurfaceHeight(u, v, this.slosh);
|
|
406
|
-
const ambientPrevious = ambientSurfaceHeight(u, v, this.elapsed - this.cpuLastDelta)
|
|
407
|
-
+ sloshSurfaceHeight(u, v, this.previousSlosh);
|
|
408
|
-
const ambientLeft = ambientSurfaceHeight(u - du, v, this.elapsed) + sloshSurfaceHeight(u - du, v, this.slosh);
|
|
409
|
-
const ambientRight = ambientSurfaceHeight(u + du, v, this.elapsed) + sloshSurfaceHeight(u + du, v, this.slosh);
|
|
410
|
-
const ambientDown = ambientSurfaceHeight(u, v - dv, this.elapsed) + sloshSurfaceHeight(u, v - dv, this.slosh);
|
|
411
|
-
const ambientUp = ambientSurfaceHeight(u, v + dv, this.elapsed) + sloshSurfaceHeight(u, v + dv, this.slosh);
|
|
412
|
-
target.height = center * displacementScale + ambientCenter;
|
|
413
|
-
target.velocityY = ((center - previous) * displacementScale + ambientCenter - ambientPrevious)
|
|
414
|
-
/ this.cpuLastDelta;
|
|
415
|
-
target.slopeX = ((right - left) * displacementScale + ambientRight - ambientLeft)
|
|
416
|
-
/ Math.max(cellX * 2, 0.001);
|
|
417
|
-
target.slopeZ = ((up - down) * displacementScale + ambientUp - ambientDown)
|
|
418
|
-
/ Math.max(cellZ * 2, 0.001);
|
|
419
|
-
target.flowX = -target.slopeX * 1.35;
|
|
420
|
-
target.flowZ = -target.slopeZ * 1.35;
|
|
421
|
-
if (this.cpuEmitting) {
|
|
422
|
-
const dx = worldX - this.cpuImpactX;
|
|
423
|
-
const dz = worldZ - this.cpuImpactZ;
|
|
424
|
-
const distanceSq = dx * dx + dz * dz;
|
|
425
|
-
const inverseDistance = 1 / Math.max(Math.sqrt(distanceSq), 0.06);
|
|
426
|
-
const sourceStrength = Math.min(this.cpuImpactEnergy * 0.075, 1.15) * Math.exp(-distanceSq / 0.48);
|
|
427
|
-
target.flowX += sourceStrength * (0.42 + dx * inverseDistance * 0.68);
|
|
428
|
-
target.flowZ += sourceStrength * dz * inverseDistance * 0.92;
|
|
429
|
-
target.impact = sourceStrength * Math.exp(-distanceSq / 0.095);
|
|
196
|
+
|
|
197
|
+
float surfaceHeight(vec2 sampleUv) {
|
|
198
|
+
float sloshHeight = dot((sampleUv - 0.5) * 2.0, uSlosh);
|
|
199
|
+
return texture(uHeightMap, sampleUv).r * 0.52 + ambientHeight(sampleUv) + sloshHeight;
|
|
430
200
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
201
|
+
|
|
202
|
+
void main() {
|
|
203
|
+
vUv = uv;
|
|
204
|
+
float h = surfaceHeight(uv);
|
|
205
|
+
float hL = surfaceHeight(uv - vec2(uTexel.x, 0.0));
|
|
206
|
+
float hR = surfaceHeight(uv + vec2(uTexel.x, 0.0));
|
|
207
|
+
float hD = surfaceHeight(uv - vec2(0.0, uTexel.y));
|
|
208
|
+
float hU = surfaceHeight(uv + vec2(0.0, uTexel.y));
|
|
209
|
+
vec3 displaced = position;
|
|
210
|
+
displaced.z += h;
|
|
211
|
+
vec3 localNormal = normalize(vec3((hL - hR) * 46.0, (hD - hU) * 46.0, 1.0));
|
|
212
|
+
vec4 world = modelMatrix * vec4(displaced, 1.0);
|
|
213
|
+
vWorldPosition = world.xyz;
|
|
214
|
+
vWorldNormal = normalize(mat3(modelMatrix) * localNormal);
|
|
215
|
+
gl_Position = projectionMatrix * viewMatrix * world;
|
|
216
|
+
}
|
|
217
|
+
`,
|
|
218
|
+
fragmentShader: /* glsl */ `
|
|
219
|
+
precision highp float;
|
|
220
|
+
uniform sampler2D uHeightMap;
|
|
221
|
+
uniform vec2 uTexel;
|
|
222
|
+
uniform float uTime;
|
|
223
|
+
uniform vec3 uLightPosition;
|
|
224
|
+
in vec2 vUv;
|
|
225
|
+
in vec3 vWorldPosition;
|
|
226
|
+
in vec3 vWorldNormal;
|
|
227
|
+
out vec4 outColor;
|
|
228
|
+
|
|
229
|
+
void main() {
|
|
230
|
+
vec2 microRipple = vec2(
|
|
231
|
+
sin(vUv.x * 54.0 + vUv.y * 19.0 + uTime * 1.35)
|
|
232
|
+
+ sin(vUv.y * 37.0 - uTime * 0.94),
|
|
233
|
+
cos(vUv.y * 49.0 - vUv.x * 17.0 + uTime * 1.12)
|
|
234
|
+
+ cos(vUv.x * 31.0 + uTime * 0.78)
|
|
235
|
+
) * 0.014;
|
|
236
|
+
vec3 normal = normalize(vWorldNormal + vec3(microRipple.x, 0.0, microRipple.y));
|
|
237
|
+
vec3 viewDir = normalize(cameraPosition - vWorldPosition);
|
|
238
|
+
vec3 lightDir = normalize(uLightPosition - vWorldPosition);
|
|
239
|
+
vec3 halfDir = normalize(viewDir + lightDir);
|
|
240
|
+
float fresnel = 0.02 + 0.98 * pow(1.0 - max(dot(viewDir, normal), 0.0), 5.0);
|
|
241
|
+
float specular = pow(max(dot(normal, halfDir), 0.0), 118.0);
|
|
242
|
+
float height = texture(uHeightMap, vUv).r;
|
|
243
|
+
float slope = abs(texture(uHeightMap, vUv + vec2(uTexel.x, 0.0)).r - texture(uHeightMap, vUv - vec2(uTexel.x, 0.0)).r)
|
|
244
|
+
+ abs(texture(uHeightMap, vUv + vec2(0.0, uTexel.y)).r - texture(uHeightMap, vUv - vec2(0.0, uTexel.y)).r);
|
|
245
|
+
float foam = smoothstep(0.018, 0.07, slope + abs(height) * 0.16);
|
|
246
|
+
vec3 deep = vec3(0.018, 0.16, 0.2);
|
|
247
|
+
vec3 reflection = mix(vec3(0.06, 0.2, 0.24), vec3(0.5, 0.86, 0.9), fresnel);
|
|
248
|
+
vec3 color = mix(deep, reflection, 0.32 + fresnel * 0.68);
|
|
249
|
+
color += vec3(0.75, 0.98, 1.0) * specular * 1.4;
|
|
250
|
+
color = mix(color, vec3(0.72, 0.94, 0.96), foam * 0.36);
|
|
251
|
+
outColor = vec4(color, 0.66 + fresnel * 0.22);
|
|
252
|
+
}
|
|
253
|
+
`,
|
|
254
|
+
transparent: true,
|
|
255
|
+
depthWrite: false,
|
|
256
|
+
side: THREE.DoubleSide,
|
|
257
|
+
});
|
|
258
|
+
const segmentsX = width >= 200 ? 128 : 64;
|
|
259
|
+
const segmentsY = width >= 200 ? 64 : 32;
|
|
260
|
+
this.mesh = new THREE.Mesh(new THREE.PlaneGeometry(basinMaxX - basinMinX - 0.12, basinHalfZ * 2 - 0.12, segmentsX, segmentsY), this.material);
|
|
261
|
+
this.mesh.rotation.x = -Math.PI / 2;
|
|
262
|
+
this.mesh.position.set((basinMinX + basinMaxX) * 0.5, waterY, basinCenterZ);
|
|
263
|
+
this.mesh.renderOrder = 2;
|
|
264
|
+
this.clear();
|
|
265
|
+
}
|
|
266
|
+
clear() {
|
|
267
|
+
this.cpuCurrent?.fill(0);
|
|
268
|
+
this.cpuPrevious?.fill(0);
|
|
269
|
+
this.cpuNext?.fill(0);
|
|
270
|
+
const previousTarget = this.renderer.getRenderTarget();
|
|
271
|
+
const previousColor = this.renderer.getClearColor(new THREE.Color());
|
|
272
|
+
const previousAlpha = this.renderer.getClearAlpha();
|
|
273
|
+
this.renderer.setClearColor(0x000000, 0);
|
|
274
|
+
this.renderer.setRenderTarget(this.read);
|
|
275
|
+
this.renderer.clear();
|
|
276
|
+
this.renderer.setRenderTarget(this.write);
|
|
277
|
+
this.renderer.clear();
|
|
278
|
+
this.renderer.setRenderTarget(previousTarget);
|
|
279
|
+
this.renderer.setClearColor(previousColor, previousAlpha);
|
|
280
|
+
}
|
|
281
|
+
setBounds({ basinMinX, basinMaxX, basinHalfZ, basinCenterZ = 0, waterY }) {
|
|
282
|
+
this.basinMinX = basinMinX;
|
|
283
|
+
this.basinMaxX = basinMaxX;
|
|
284
|
+
this.basinHalfZ = basinHalfZ;
|
|
285
|
+
this.basinCenterZ = basinCenterZ;
|
|
286
|
+
this.waterY = waterY;
|
|
287
|
+
this.mesh.position.set((basinMinX + basinMaxX) * 0.5, waterY, basinCenterZ);
|
|
288
|
+
}
|
|
289
|
+
setContainerMotion(sloshX = 0, sloshZ = 0, impulseX = 0, impulseZ = 0) {
|
|
290
|
+
this.previousSlosh.copy(this.slosh);
|
|
291
|
+
this.slosh.set(sloshX, sloshZ);
|
|
292
|
+
this.motionImpulse.set(impulseX, impulseZ);
|
|
293
|
+
this.computeMaterial.uniforms.uMotionImpulse.value.copy(this.motionImpulse);
|
|
294
|
+
}
|
|
295
|
+
update(delta, elapsed, impactWorldX, energy, emitting, impactWorldZ = 0) {
|
|
296
|
+
this.elapsed = elapsed;
|
|
297
|
+
const impactUvX = THREE.MathUtils.clamp((impactWorldX - this.basinMinX) / (this.basinMaxX - this.basinMinX), 0.03, 0.97);
|
|
298
|
+
const impactUvZ = THREE.MathUtils.clamp((impactWorldZ - (this.basinCenterZ - this.basinHalfZ)) / (this.basinHalfZ * 2), 0.03, 0.97);
|
|
299
|
+
const impulse = emitting ? Math.min(energy * delta * 0.00135, 0.0035) : 0;
|
|
300
|
+
this.computeMaterial.uniforms.uState.value = this.read.texture;
|
|
301
|
+
this.computeMaterial.uniforms.uImpactUv.value.set(impactUvX, impactUvZ);
|
|
302
|
+
this.computeMaterial.uniforms.uImpulse.value = impulse;
|
|
303
|
+
this.computeMaterial.uniforms.uTime.value = elapsed;
|
|
304
|
+
if (this.cpuSampling) {
|
|
305
|
+
this.stepCpuSampler(delta, elapsed, impactUvX, impactUvZ, impactWorldX, impactWorldZ, energy, emitting, impulse);
|
|
306
|
+
}
|
|
307
|
+
const previousTarget = this.renderer.getRenderTarget();
|
|
308
|
+
this.renderer.setRenderTarget(this.write);
|
|
309
|
+
this.renderer.render(this.computeScene, this.computeCamera);
|
|
310
|
+
this.renderer.setRenderTarget(previousTarget);
|
|
311
|
+
[this.read, this.write] = [this.write, this.read];
|
|
312
|
+
this.material.uniforms.uHeightMap.value = this.read.texture;
|
|
313
|
+
this.material.uniforms.uTime.value = elapsed;
|
|
314
|
+
}
|
|
315
|
+
stepCpuSampler(delta, elapsed, impactUvX, impactUvZ, impactWorldX, impactWorldZ, energy, emitting, impulse) {
|
|
316
|
+
const width = this.cpuWidth;
|
|
317
|
+
const height = this.cpuHeight;
|
|
318
|
+
const current = this.cpuCurrent;
|
|
319
|
+
const previous = this.cpuPrevious;
|
|
320
|
+
const next = this.cpuNext;
|
|
321
|
+
const microPulse = 0.72 + 0.28 * Math.sin(elapsed * 19);
|
|
322
|
+
const sourceAX = 0.22 + Math.sin(elapsed * 0.19) * 0.08;
|
|
323
|
+
const sourceAZ = 0.31 + Math.cos(elapsed * 0.16) * 0.09;
|
|
324
|
+
const sourceBX = 0.72 + Math.cos(elapsed * 0.13) * 0.09;
|
|
325
|
+
const sourceBZ = 0.68 + Math.sin(elapsed * 0.17) * 0.08;
|
|
326
|
+
for (let z = 0; z < height; z++) {
|
|
327
|
+
const uvZ = (z + 0.5) / height;
|
|
328
|
+
const zEdge = Math.min(1, uvZ / 0.055, (1 - uvZ) / 0.055);
|
|
329
|
+
for (let x = 0; x < width; x++) {
|
|
330
|
+
const index = z * width + x;
|
|
331
|
+
const uvX = (x + 0.5) / width;
|
|
332
|
+
const left = current[z * width + Math.max(0, x - 1)];
|
|
333
|
+
const right = current[z * width + Math.min(width - 1, x + 1)];
|
|
334
|
+
const down = current[Math.max(0, z - 1) * width + x];
|
|
335
|
+
const up = current[Math.min(height - 1, z + 1) * width + x];
|
|
336
|
+
const laplacian = left + right + down + up - 4 * current[index];
|
|
337
|
+
let nextHeight = (2 * current[index] - previous[index]) + laplacian * 0.235;
|
|
338
|
+
nextHeight *= 0.9925;
|
|
339
|
+
const dx = (uvX - impactUvX) * 2.2;
|
|
340
|
+
const dz = uvZ - impactUvZ;
|
|
341
|
+
nextHeight += Math.exp(-(dx * dx + dz * dz) * 420) * impulse * microPulse;
|
|
342
|
+
const ambientAX = (uvX - sourceAX) * 1.75;
|
|
343
|
+
const ambientAZ = uvZ - sourceAZ;
|
|
344
|
+
const ambientBX = (uvX - sourceBX) * 1.55;
|
|
345
|
+
const ambientBZ = uvZ - sourceBZ;
|
|
346
|
+
const distanceA = Math.hypot(ambientAX, ambientAZ);
|
|
347
|
+
const distanceB = Math.hypot(ambientBX, ambientBZ);
|
|
348
|
+
const ambientWaves = Math.sin(distanceA * 47 - elapsed * 2.15) * Math.exp(-distanceA * 3.8)
|
|
349
|
+
+ Math.sin(distanceB * 39 - elapsed * 1.72 + 1.4) * Math.exp(-distanceB * 3.5);
|
|
350
|
+
nextHeight += ambientWaves * 0.000028;
|
|
351
|
+
const centeredX = uvX - 0.5;
|
|
352
|
+
const centeredZ = uvZ - 0.5;
|
|
353
|
+
const wallResponse = 0.34 + 0.66 * Math.pow(Math.max(Math.abs(centeredX), Math.abs(centeredZ)) * 2, 2);
|
|
354
|
+
nextHeight += (centeredX * this.motionImpulse.x + centeredZ * this.motionImpulse.y) * wallResponse;
|
|
355
|
+
const xEdge = Math.min(1, uvX / 0.035, (1 - uvX) / 0.035);
|
|
356
|
+
nextHeight *= THREE.MathUtils.lerp(0.86, 1, Math.max(0, Math.min(xEdge, zEdge)));
|
|
357
|
+
next[index] = nextHeight;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
this.cpuPrevious = current;
|
|
361
|
+
this.cpuCurrent = next;
|
|
362
|
+
this.cpuNext = previous;
|
|
363
|
+
this.cpuLastDelta = Math.max(delta, 1 / 120);
|
|
364
|
+
this.cpuImpactX = impactWorldX;
|
|
365
|
+
this.cpuImpactZ = impactWorldZ;
|
|
366
|
+
this.cpuImpactEnergy = energy;
|
|
367
|
+
this.cpuEmitting = emitting;
|
|
368
|
+
}
|
|
369
|
+
sampleSurface(worldX, worldZ, target = {}) {
|
|
370
|
+
target.height = 0;
|
|
371
|
+
target.velocityY = 0;
|
|
372
|
+
target.slopeX = 0;
|
|
373
|
+
target.slopeZ = 0;
|
|
374
|
+
target.flowX = 0;
|
|
375
|
+
target.flowZ = 0;
|
|
376
|
+
target.impact = 0;
|
|
377
|
+
if (!this.cpuSampling || !this.cpuCurrent)
|
|
378
|
+
return target;
|
|
379
|
+
const sample = (field, u, v) => {
|
|
380
|
+
const x = THREE.MathUtils.clamp(u, 0, 1) * (this.cpuWidth - 1);
|
|
381
|
+
const z = THREE.MathUtils.clamp(v, 0, 1) * (this.cpuHeight - 1);
|
|
382
|
+
const x0 = Math.floor(x);
|
|
383
|
+
const z0 = Math.floor(z);
|
|
384
|
+
const x1 = Math.min(this.cpuWidth - 1, x0 + 1);
|
|
385
|
+
const z1 = Math.min(this.cpuHeight - 1, z0 + 1);
|
|
386
|
+
const tx = x - x0;
|
|
387
|
+
const tz = z - z0;
|
|
388
|
+
const a = THREE.MathUtils.lerp(field[z0 * this.cpuWidth + x0], field[z0 * this.cpuWidth + x1], tx);
|
|
389
|
+
const b = THREE.MathUtils.lerp(field[z1 * this.cpuWidth + x0], field[z1 * this.cpuWidth + x1], tx);
|
|
390
|
+
return THREE.MathUtils.lerp(a, b, tz);
|
|
391
|
+
};
|
|
392
|
+
const u = (worldX - this.basinMinX) / Math.max(this.basinMaxX - this.basinMinX, 0.001);
|
|
393
|
+
const v = (worldZ - (this.basinCenterZ - this.basinHalfZ)) / Math.max(this.basinHalfZ * 2, 0.001);
|
|
394
|
+
const du = 1 / Math.max(this.cpuWidth - 1, 1);
|
|
395
|
+
const dv = 1 / Math.max(this.cpuHeight - 1, 1);
|
|
396
|
+
const center = sample(this.cpuCurrent, u, v);
|
|
397
|
+
const previous = sample(this.cpuPrevious, u, v);
|
|
398
|
+
const left = sample(this.cpuCurrent, u - du, v);
|
|
399
|
+
const right = sample(this.cpuCurrent, u + du, v);
|
|
400
|
+
const down = sample(this.cpuCurrent, u, v - dv);
|
|
401
|
+
const up = sample(this.cpuCurrent, u, v + dv);
|
|
402
|
+
const cellX = (this.basinMaxX - this.basinMinX) * du;
|
|
403
|
+
const cellZ = this.basinHalfZ * 2 * dv;
|
|
404
|
+
const displacementScale = 0.52;
|
|
405
|
+
const ambientCenter = ambientSurfaceHeight(u, v, this.elapsed) + sloshSurfaceHeight(u, v, this.slosh);
|
|
406
|
+
const ambientPrevious = ambientSurfaceHeight(u, v, this.elapsed - this.cpuLastDelta)
|
|
407
|
+
+ sloshSurfaceHeight(u, v, this.previousSlosh);
|
|
408
|
+
const ambientLeft = ambientSurfaceHeight(u - du, v, this.elapsed) + sloshSurfaceHeight(u - du, v, this.slosh);
|
|
409
|
+
const ambientRight = ambientSurfaceHeight(u + du, v, this.elapsed) + sloshSurfaceHeight(u + du, v, this.slosh);
|
|
410
|
+
const ambientDown = ambientSurfaceHeight(u, v - dv, this.elapsed) + sloshSurfaceHeight(u, v - dv, this.slosh);
|
|
411
|
+
const ambientUp = ambientSurfaceHeight(u, v + dv, this.elapsed) + sloshSurfaceHeight(u, v + dv, this.slosh);
|
|
412
|
+
target.height = center * displacementScale + ambientCenter;
|
|
413
|
+
target.velocityY = ((center - previous) * displacementScale + ambientCenter - ambientPrevious)
|
|
414
|
+
/ this.cpuLastDelta;
|
|
415
|
+
target.slopeX = ((right - left) * displacementScale + ambientRight - ambientLeft)
|
|
416
|
+
/ Math.max(cellX * 2, 0.001);
|
|
417
|
+
target.slopeZ = ((up - down) * displacementScale + ambientUp - ambientDown)
|
|
418
|
+
/ Math.max(cellZ * 2, 0.001);
|
|
419
|
+
target.flowX = -target.slopeX * 1.35;
|
|
420
|
+
target.flowZ = -target.slopeZ * 1.35;
|
|
421
|
+
if (this.cpuEmitting) {
|
|
422
|
+
const dx = worldX - this.cpuImpactX;
|
|
423
|
+
const dz = worldZ - this.cpuImpactZ;
|
|
424
|
+
const distanceSq = dx * dx + dz * dz;
|
|
425
|
+
const inverseDistance = 1 / Math.max(Math.sqrt(distanceSq), 0.06);
|
|
426
|
+
const sourceStrength = Math.min(this.cpuImpactEnergy * 0.075, 1.15) * Math.exp(-distanceSq / 0.48);
|
|
427
|
+
target.flowX += sourceStrength * (0.42 + dx * inverseDistance * 0.68);
|
|
428
|
+
target.flowZ += sourceStrength * dz * inverseDistance * 0.92;
|
|
429
|
+
target.impact = sourceStrength * Math.exp(-distanceSq / 0.095);
|
|
430
|
+
}
|
|
431
|
+
return target;
|
|
432
|
+
}
|
|
433
|
+
dispose() {
|
|
434
|
+
this.read.dispose();
|
|
435
|
+
this.write.dispose();
|
|
436
|
+
this.computeMaterial.dispose();
|
|
437
|
+
this.computeQuad.geometry.dispose();
|
|
438
|
+
this.material.dispose();
|
|
439
|
+
this.mesh.geometry.dispose();
|
|
440
|
+
}
|
|
441
|
+
}
|