Space Sim
Toggle main menu visibility
Loading...
Searching...
No Matches
src
FFT
fft.comp
Go to the documentation of this file.
1
#version 440
2
layout
(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
3
layout
(rgba32f, binding = 0) readonly uniform image2D inputTex;
4
layout
(rgba32f, binding = 1) writeonly uniform image2D outputTex;
5
11
12
#define N 128
13
14
uniform
int
stage
;
15
uniform
int
direction
;
16
uniform
int
final_stage
;
17
18
vec4
cmul2
(
vec4
a,
vec2
w) {
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
28
void
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
N
#define N
Definition
bit_reversal.comp:13
layout
layout(local_size_x=16, local_size_y=16, local_size_z=1) in
direction
uniform int direction
Definition
fft.comp:15
cmul2
vec4 cmul2(vec4 a, vec2 w)
Definition
fft.comp:18
final_stage
uniform int final_stage
Definition
fft.comp:16
stage
uniform int stage
Definition
fft.comp:14
main
int main(int argc, char *argv[])
Definition
main.c:1726
vec2::x
float x
Definition
types.h:45
vec4::w
float w
Definition
types.h:47
vec4::z
float z
Definition
types.h:47
vec4::x
float x
Definition
types.h:47
vec2::y
float y
Definition
types.h:45
vec4::y
float y
Definition
types.h:47
vec2
Definition
types.h:45
vec4
Definition
types.h:47
t
uniform float t
Definition
water.comp:23
Generated by
1.18.0