cdmWaveVertex.glsl
1 uniform float uTime;
2 uniform float uSpeed;
3 uniform float uAmplitude;
4 uniform float uWaveCountX;
5 uniform float uWaveCountY;
6 uniform float uPeriod;
7 uniform float uNoiseStrength;
8
9 attribute vec4 tangent;
10
11 varying vec2 vUv;
12
13 float remap(float value, float oldMin, float oldMax, float newMin, float newMax) {
14 return newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin);
15 }
16
17 float random (in vec2 st) {
18 return fract(sin(dot(st.xy, vec2(12.9898,78.233))) * 43758.5453123);
19 }
20
21 float getBaseWave(vec2 uv) {
22 float remapAngleX = uv.x * uWaveCountX * PI;
23 float remapAngleY = uv.y * uWaveCountY * PI;
24 float xWave = sin(remapAngleX) * uAmplitude;
25 float yWave = sin(remapAngleY) * uAmplitude;
26 float zWave = xWave * yWave;
27 return zWave;
28 }
29
30 vec3 loopWave(vec3 position ,vec2 uv) {
31 float maxVal = pow(uAmplitude, 2.0);
32 float minVal = - maxVal;
33
34 for (int i = 0; i < 10; i++) {
35 float remapZAngle = remap(position.x, 0.0, 1.0, 0.0, PI/2.0);
36 float remapZ = sin(remapZAngle);
37 position.z += remapZ /3.0;
38 }
39
40 return position;
41 }
42
43 void main() {
44 vec3 biTangent = cross(normal, tangent.xyz);
45 float shift = 0.01;
46 vec3 positionA = csm_Position + tangent.xyz * shift;
47 vec3 positionB = csm_Position + biTangent * shift;
48
49 vUv = uv;
50 float zWave = getBaseWave(vUv);
51 csm_Position.z += zWave;
52 positionA.z += zWave;
53 positionB.z += zWave;
54
55 csm_Position = loopWave(csm_Position,vUv);
56 positionA = loopWave(positionA,vUv);
57 positionB = loopWave(positionB,vUv);
58
59 csm_Position.z *= sin(uTime * uSpeed + (vUv.x + vUv.y ) * uPeriod );
60 positionA.z *= sin(uTime * uSpeed + (vUv.x + vUv.y ) * uPeriod );
61 positionB.z *= sin(uTime * uSpeed + (vUv.x + vUv.y ) * uPeriod );
62
63 csm_Position.z += random(vUv) * uNoiseStrength;
64 positionA.z += random(vUv) * uNoiseStrength;
65 positionB.z += random(vUv) * uNoiseStrength;
66
67 vec3 toA = normalize(positionA - csm_Position);
68 vec3 toB = normalize(positionB - csm_Position);
69 csm_Normal = cross(toA, toB);
70
71 }
csmWaveFragment.glsl
1 varying vec2 vUv;
2
3 void main() {
4 csm_DiffuseColor = vec4(vUv,1.0,1.0);
5 }