-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.glsl
51 lines (41 loc) · 1.19 KB
/
index.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
const float TWOPI = 6.283185307179586;
vec4 fft (
sampler2D src,
vec2 resolution,
float subtransformSize,
bool horizontal,
bool forward,
float normalization
) {
vec2 evenPos, oddPos, twiddle, outputA, outputB;
vec4 even, odd;
float index, evenIndex, twiddleArgument;
index = (horizontal ? gl_FragCoord.x : gl_FragCoord.y) - 0.5;
evenIndex = floor(index / subtransformSize) *
(subtransformSize * 0.5) +
mod(index, subtransformSize * 0.5) +
0.5;
if (horizontal) {
evenPos = vec2(evenIndex, gl_FragCoord.y);
oddPos = vec2(evenIndex, gl_FragCoord.y);
} else {
evenPos = vec2(gl_FragCoord.x, evenIndex);
oddPos = vec2(gl_FragCoord.x, evenIndex);
}
evenPos *= resolution;
oddPos *= resolution;
if (horizontal) {
oddPos.x += 0.5;
} else {
oddPos.y += 0.5;
}
even = texture2D(src, evenPos);
odd = texture2D(src, oddPos);
twiddleArgument = (forward ? TWOPI : -TWOPI) * (index / subtransformSize);
twiddle = vec2(cos(twiddleArgument), sin(twiddleArgument));
return (even.rgba + vec4(
twiddle.x * odd.xz - twiddle.y * odd.yw,
twiddle.y * odd.xz + twiddle.x * odd.yw
).xzyw) * normalization;
}
#pragma glslify: export(fft)