Space Sim
Loading...
Searching...
No Matches
fft.comp
Go to the documentation of this file.
1#version 440
2layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
3layout(rgba32f, binding = 0) readonly uniform image2D inputTex;
4layout(rgba32f, binding = 1) writeonly uniform image2D outputTex;
5
11
12#define N 128
13
14uniform int stage;
15uniform int direction;
16uniform int final_stage;
17
19 return vec4(
20 a.x * w.x - a.y * w.y,
21 a.x * w.y + a.y * w.x,
22
23 a.z * w.x - a.w * w.y,
24 a.z * w.y + a.w * w.x
25 );
26}
27
28void main()
29{
30
31 ivec2 id = ivec2(gl_GlobalInvocationID.xy);
32 if (id.x >= N || id.y >= N) return;
33
34 int i = (direction == 0) ? id.x : id.y;
35 int j = (direction == 0) ? id.y : id.x;
36
37 int halfSize = 1 << stage;
38 int step = halfSize << 1;
39
40
41 if ((i % step) >= halfSize) return;
42
43 int k = (i / step) * step;
44 int offset = i % halfSize;
45
46 int i0 = k + offset;
47 int i1 = i0 + halfSize;
48
49 ivec2 coord0 = (direction == 0) ? ivec2(i0, j) : ivec2(j, i0);
50 ivec2 coord1 = (direction == 0) ? ivec2(i1, j) : ivec2(j, i1);
51
52 vec4 a = imageLoad(inputTex, coord0);
53 vec4 b = imageLoad(inputTex, coord1);
54
55 float angle = 0;
56 if (direction == 0)
57 {
58
59 angle = -2.0 * 3.14159265 * float(offset) / float(step);
60 }
61 else
62 {
63 angle = 2.0 * 3.14159265 * float(offset) / float(step);
64 }
65 vec2 twiddle = vec2(cos(angle), sin(angle));
66
67 vec4 t = cmul2(b, twiddle);
68
69 vec4 out0 = a + t;
70 vec4 out1 = a - t;
71
72 if (final_stage == 1)
73 {
74 out0 /= (N * N);
75 out1 /= (N * N);
76 }
77
78 imageStore(outputTex, coord0, out0);
79 imageStore(outputTex, coord1, out1);
80
81}
82
#define N
layout(local_size_x=16, local_size_y=16, local_size_z=1) in
uniform int direction
Definition fft.comp:15
vec4 cmul2(vec4 a, vec2 w)
Definition fft.comp:18
uniform int final_stage
Definition fft.comp:16
uniform int stage
Definition fft.comp:14
int main(int argc, char *argv[])
Definition main.c:1726
float x
Definition types.h:45
float w
Definition types.h:47
float z
Definition types.h:47
float x
Definition types.h:47
float y
Definition types.h:45
float y
Definition types.h:47
Definition types.h:45
Definition types.h:47
uniform float t
Definition water.comp:23