aboutsummaryrefslogtreecommitdiff
path: root/shader
diff options
context:
space:
mode:
Diffstat (limited to 'shader')
-rw-r--r--shader/fragment.glsl35
1 files changed, 19 insertions, 16 deletions
diff --git a/shader/fragment.glsl b/shader/fragment.glsl
index 19b020e..6720236 100644
--- a/shader/fragment.glsl
+++ b/shader/fragment.glsl
@@ -1,16 +1,20 @@
#version 400 core
-out vec4 out_color;
+out vec4 out_color;
-uniform int u_width;
-uniform int u_height;
+uniform int u_width;
+uniform int u_height;
-uniform float u_real_start;
-uniform float u_real_end;
-uniform float u_imag_start;
-uniform float u_imag_end;
+uniform float u_real_start;
+uniform float u_real_end;
+uniform float u_imag_start;
+uniform float u_imag_end;
-uniform int u_iterations;
+uniform int u_iterations;
+
+uniform sampler1D u_texture;
+
+#define ESCAPE_RADIUS 4.0
void main()
{
@@ -18,15 +22,16 @@ void main()
float cb = u_imag_start + float(gl_FragCoord.y) / float(u_height) * (u_imag_end - u_imag_start);
float zr = ca;
float zi = cb;
+
float zr_square;
float zi_square;
- int n;
+ int n;
for (n = 0; n < u_iterations; n++)
{
zi_square = zi * zi;
zr_square = zr * zr;
- if (zr_square + zi_square > 4.0)
+ if (zr_square + zi_square > ESCAPE_RADIUS)
break;
zi = 2.0 * zr * zi;
zr = zr_square - zi_square;
@@ -34,10 +39,8 @@ void main()
zr += ca;
}
- out_color = vec4(
- float(n) / float(u_iterations),
- float(n) / float(u_iterations),
- 0.0,
- 1.0
- );
+ if (n == u_iterations)
+ out_color = vec4(0.0, 0.0, 0.0, 1.0);
+ else
+ out_color = texture1D(u_texture, float(n) / float(u_iterations));
}