1 | R""( |
2 |
|
3 | #version 460 core |
4 |
|
5 | layout (local_size_x = 32, local_size_y = 32, local_size_z = 1) in; |
6 |
|
7 |
|
8 | layout(rgba32f, binding = 0) uniform image2D texture0; |
9 | uniform ivec2 screensize; |
10 | uniform dvec2 offset; |
11 | uniform double zoom; |
12 | uniform float z; |
13 | uniform float discard_threshold; |
14 | uniform int current_iteration; |
15 | uniform int it_steps; |
16 | uniform bool enable_interlacing; |
17 | uniform int interlace_layer; |
18 |
|
19 |
|
20 | const int ADAM7_MATRIX[8][8] = { |
21 | {1, 6, 4, 6, 2, 6, 4, 6}, |
22 | {7, 7, 7, 7, 7, 7, 7, 7}, |
23 | {5, 6, 5, 6, 5, 6, 5, 6}, |
24 | {7, 7, 7, 7, 7, 7, 7, 7}, |
25 | {3, 6, 4, 6, 3, 6, 4, 6}, |
26 | {7, 7, 7, 7, 7, 7, 7, 7}, |
27 | {5, 6, 5, 6, 5, 6, 5, 6}, |
28 | {7, 7, 7, 7, 7, 7, 7, 7}, |
29 | }; |
30 |
|
31 |
|
32 | dvec2 screenSpaceToGraphSpace(dvec2 coord) |
33 | { |
34 | dvec2 dscreensize = dvec2(screensize); |
35 | double aspectratio = dscreensize.x/dscreensize.y; |
36 | return (((coord - dscreensize/2) / dscreensize * zoom) - (offset / dscreensize))*dvec2(aspectratio, 1.0); |
37 | } |
38 |
|
39 | void main() |
40 | { |
41 | ivec2 texelCoord = ivec2(gl_GlobalInvocationID.xy); |
42 |
|
43 | vec4 currentValue; |
44 |
|
45 | dvec2 c = screenSpaceToGraphSpace(vec2(texelCoord)); |
46 | c.y = -c.y; |
47 | if (current_iteration == 0 && interlace_layer == 1) |
48 | { |
49 | currentValue = vec4(0.5, c.x, c.y, 1.0); |
50 | } |
51 | else |
52 | { |
53 | currentValue = imageLoad(texture0, texelCoord); |
54 | } |
55 |
|
56 |
|
57 | bool do_compute = true; |
58 | if (enable_interlacing) |
59 | { |
60 | do_compute = ADAM7_MATRIX[gl_LocalInvocationID.y % 8][gl_LocalInvocationID.x % 8] == interlace_layer; |
61 | } |
62 | if (do_compute) |
63 | { |
64 | if (abs(currentValue.x) < 0.6) |
65 | { |
66 | double x = c.x;//abs(c.x); |
67 | double y = c.y;//abs(c.y); |
68 | double x2 = x*x; |
69 | double y2 = y*y; |
70 |
|
71 | for (int i = 1; i < it_steps; i++) |
72 | { |
73 | y = 2.*x*y + c.y; |
74 | //y = 2.*abs(x*y+z) + c.y - 2.*abs(z); |
75 | x = x2 - y2 + c.x; |
76 | x2 = x*x; |
77 | y2 = y*y; |
78 | if ((x2 + y2) > discard_threshold) |
79 | { |
80 | currentValue.x = current_iteration + i; |
81 | break; |
82 | } |
83 | } |
84 | currentValue.yz = vec2(float(x), float(y)); |
85 | } |
86 | } |
87 |
|
88 | imageStore(texture0, texelCoord, currentValue); |
89 | // memoryBarrier(); |
90 | } |
91 |
|
92 |
|
93 | )"" |
94 |
|