Index

zydeco / fractal

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
1008 Dec 2023 15:215a717feFractal renderer update for articleJosh Stockin145G

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

text/plain2365 bytesdownload raw
1R""(
2
3#version 460 core
4
5
6in vec4 gl_FragCoord;
7layout(rgba32f, binding = 0) uniform image2D texture0;
8uniform int it_count;
9uniform ivec2 screensize;
10uniform float brightness;
11uniform bool enable_interlacing;
12uniform int interlace_layer;
13uniform bool first_interlace;
14out vec4 fragColor;
15
16const float INTERLACE_COLOR_MULTIPLIERS[7] = {3., 3., 2., 2., 2., 1., 1.};
17
18void main()
19{
20 ivec2 texcoord = ivec2(gl_FragCoord.xy);
21 bool point_contains_data = imageLoad(texture0, texcoord).r >= 0.9;
22 if (enable_interlacing && first_interlace && !point_contains_data)
23 {
24 int nearest_x = 8;
25 int nearest_y = 8;
26 int offset_x = 0;
27 int offset_y = 0;
28 switch (interlace_layer)
29 {
30 case 1:
31 nearest_x = 8;
32 nearest_y = 8;
33 int offset_x = 8;
34 int offset_y = 8;
35 break;
36 case 2:
37 nearest_x = 8;
38 nearest_y = 8;
39 offset_x = 4;
40 break;
41 case 3:
42 nearest_x = 4;
43 nearest_y = 8;
44 offset_y = 4;
45 break;
46 case 4:
47 nearest_x = 4;
48 nearest_y = 4;
49 offset_x = 2;
50 break;
51 case 5:
52 nearest_x = 2;
53 nearest_y = 4;
54 offset_y = 2;
55 break;
56 case 6:
57 nearest_x = 2;
58 nearest_y = 2;
59 offset_x = 1;
60 break;
61 case 7:
62 nearest_x = 1;
63 nearest_y = 2;
64 offset_y = 1;
65 break;
66 }
67
68 int xpos = (int(gl_FragCoord.x) - (int(gl_FragCoord.x) % nearest_x)) + offset_x;
69 int ypos = (int(gl_FragCoord.y) - (int(gl_FragCoord.y) % nearest_y)) + offset_y;
70
71 texcoord = ivec2(xpos, ypos).xy;
72 }
73
74 float iterations = imageLoad(texture0, texcoord).r;
75 float col = iterations;
76 if (enable_interlacing && first_interlace) { col *= INTERLACE_COLOR_MULTIPLIERS[interlace_layer - 1]; }
77
78 if (iterations <= 0.6)
79 {
80 fragColor = vec4(0.0, 0.0, 0.0, 0.0);
81 }
82 else
83 {
84 col = clamp(col/it_count*brightness, 0.0, 1.0);
85 fragColor = vec4(col*0.65, col*0.35, col*0.7, 0.0);
86 }
87}
88
89)""
90