forked from jdupuy/whitecaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
whitecap_precompute.glsl
49 lines (35 loc) · 1.35 KB
/
whitecap_precompute.glsl
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
#extension GL_EXT_gpu_shader4 : enable
varying vec2 uv; // texcoords
#ifdef _VERTEX_
void main() {
uv = gl_Vertex.zw;
gl_Position = vec4(gl_Vertex.xy, 0.0, 1.0);
}
#endif
#ifdef _FRAGMENT_
#define LAYER_JACOBIAN_XX 5.0
#define LAYER_JACOBIAN_YY 6.0
#define LAYER_JACOBIAN_XY 7.0
uniform sampler2DArray fftWavesSampler;
uniform vec4 choppy;
void main() {
// fftWavesSampler has 4 height values
// heights.r : Lx, Lz = x0
// heights.g : Lx, Lz = x1
// heights.b : Lx, Lz = x2
// heights.a : Lx, Lz = x3
// with x0 < x1 < x2 < x3
vec4 heights = texture2DArray(fftWavesSampler, vec3(uv, 0.0));
gl_FragData[0] = vec4(heights.x, heights.x * heights.x, heights.y, heights.y * heights.y);
gl_FragData[1] = vec4(heights.z, heights.z * heights.z, heights.w, heights.w * heights.w);
// store Jacobian coeff value and variance
vec4 Jxx = choppy*texture2DArray(fftWavesSampler, vec3(uv, LAYER_JACOBIAN_XX));
vec4 Jyy = choppy*texture2DArray(fftWavesSampler, vec3(uv, LAYER_JACOBIAN_YY));
vec4 Jxy = choppy*choppy*texture2DArray(fftWavesSampler, vec3(uv, LAYER_JACOBIAN_XY));
// Store partial jacobians
vec4 res = 0.25 + Jxx + Jyy + choppy*Jxx*Jyy - Jxy*Jxy;
vec4 res2 = res*res;
gl_FragData[2] = vec4(res.x, res2.x, res.y, res2.y);
gl_FragData[3] = vec4(res.z, res2.z, res.w, res2.w);
}
#endif