STUDIO TAMA


waveVertex.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  float PI = 3.1415926535897932384626433832795;
9
10  varying vec2 vUv;
11
12  float remap(float value, float oldMin, float oldMax, float newMin, float newMax) {
13    return newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin);
14  }
15
16  //noise
17  float random (in vec2 st) {
18    return fract(sin(dot(st.xy, vec2(12.9898,78.233))) * 43758.5453123);
19  }
20
21
22  void main() {
23    vUv = uv;
24
25    vec3 pos = position;
26    float remapAngleX = vUv.x * uWaveCountX * PI;
27    float remapAngleY = vUv.y * uWaveCountY * PI;
28    float xWave = sin(remapAngleX) * uAmplitude;
29    float yWave = sin(remapAngleY) * uAmplitude;
30    float zWave = xWave * yWave;
31    pos.z += zWave;
32    float maxVal = pow(uAmplitude, 2.0);
33    float minVal = - maxVal;
34
35    for (int i = 0; i < 10; i++) {
36      float remapZAngle = remap(pos.x, 0.0, 1.0, 0.0, PI/2.0);
37      float remapZ = sin(remapZAngle);
38      pos.z += remapZ /3.0;
39    }
40
41    pos.z *= sin(uTime * uSpeed + (vUv.x + vUv.y ) * uPeriod );
42    pos.z += random(vUv) * uNoiseStrength;
43
44    if(vUv.x == 0.0 || vUv.x == 1.0 || vUv.y == 0.0 || vUv.y == 1.0) {
45      pos.z = 0.0;
46    }
47
48    gl_Position = projectionMatrix * modelViewMatrix * vec4(pos.x, pos.y,pos.z, 1.0);
49  }

waveFragment.glsl

1  varying vec2 vUv;
2
3  void main() {
4    gl_FragColor = vec4(vUv, 0.8, 1.0);
5  }