-
-
Notifications
You must be signed in to change notification settings - Fork 107
/
water.vert
57 lines (45 loc) · 1.43 KB
/
water.vert
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
uniform vec3 offset;
uniform mat4 viewProjection;
uniform float time;
uniform vec4 waveParameters[4];
uniform vec2 directions[4];
const int noWaves = 4;
const float pi = 3.14159;
in vec3 position;
out vec2 uvs;
out vec3 nor;
out vec3 pos;
out vec4 col;
void main()
{
pos = position + offset;
nor = vec3(0., 1., 0.);
// Offset position
for (int i = 0; i < noWaves; ++i)
{
vec4 parameters = waveParameters[i];
float wavelength = parameters.x;
float amplitude = parameters.y;
if(wavelength > 0.001 && amplitude > 0.001) {
vec2 dir = directions[i];
float steepness = parameters.z;
float speed = parameters.w;
float frequency = 2.0 * pi / wavelength;//sqrt(g * wavelength / (2.0 * pi)) * tanh(2.0 * pi * waterDepth / wavelength);
float theta = dot(dir, pos.xz);
float a = theta * frequency + time * speed;
float sin_a = sin(a);
float cos_a = cos(a);
vec2 b = amplitude * cos_a * dir;
float c = amplitude * sin_a;
pos.y += c;
pos.x += steepness * b.x;
pos.z += steepness * b.y;
nor.y -= steepness * frequency * c;
nor.x -= frequency * b.x;
nor.z -= frequency * b.y;
}
}
gl_Position = viewProjection * vec4(pos, 1.);
uvs = pos.xz;
col = vec4(1.0);
}