forked from jdupuy/whitecaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fftx.glsl
72 lines (56 loc) · 1.74 KB
/
fftx.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifdef _VERTEX_
varying vec2 uvIn;
void main() {
uvIn = gl_Vertex.zw;
gl_Position = vec4(gl_Vertex.xy, 0.0, 1.0);
}
#endif
#ifdef _GEOMETRY_
//#version 120
#extension GL_EXT_gpu_shader4 : enable
#extension GL_EXT_geometry_shader4 : enable
uniform int nLayers;
uniform int sLayer;
varying in vec2 uvIn[];
varying vec2 uv;
void main() {
for (int i = sLayer; i < nLayers + sLayer; ++i) {
gl_Layer = i;
gl_PrimitiveID = i;
gl_Position = gl_PositionIn[0];
uv = uvIn[0];
EmitVertex();
gl_Position = gl_PositionIn[1];
uv = uvIn[1];
EmitVertex();
gl_Position = gl_PositionIn[2];
uv = uvIn[2];
EmitVertex();
EndPrimitive();
}
}
#endif
#ifdef _FRAGMENT_
#extension GL_EXT_gpu_shader4 : enable
uniform sampler2D butterflySampler;
uniform sampler2DArray imgSampler; // 2 complex inputs (= 4 values) per layer
uniform float pass;
varying vec2 uv;
// performs two FFTs on two inputs packed in a single texture
// returns two results packed in a single vec4
vec4 fft2(int layer, vec2 i, vec2 w) {
vec4 input1 = texture2DArrayLod(imgSampler, vec3(i.x, uv.y, layer), 0.0);
vec4 input2 = texture2DArrayLod(imgSampler, vec3(i.y, uv.y, layer), 0.0);
float res1x = w.x * input2.x - w.y * input2.y;
float res1y = w.y * input2.x + w.x * input2.y;
float res2x = w.x * input2.z - w.y * input2.w;
float res2y = w.y * input2.z + w.x * input2.w;
return input1 + vec4(res1x, res1y, res2x, res2y);
}
void main() {
vec4 data = texture2DLod(butterflySampler, vec2(uv.x, pass), 0.0);
vec2 i = data.xy;
vec2 w = data.zw;
gl_FragColor = fft2(gl_PrimitiveID, i, w);
}
#endif