Index

zydeco / a4d3636

Experiment in graphics programming, C++, OpenGL, simulation techniques.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
916 Nov 2023 11:11a4d3636Fractal ViewerJosh Stockin1930G

Blob @ zydeco / include / render / shaders / fractal.cs.glsl

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