aboutsummaryrefslogtreecommitdiff
path: root/shader
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-05-20 07:41:03 +0200
committerCharles <sircharlesaze@gmail.com>2020-05-20 07:41:03 +0200
commit09a819b2ef927adf5239a73f91cdfcefd6774688 (patch)
tree8602814faa153aae01acc95a557d45b24c028f3b /shader
parent70bf7ac330545f14ab9babddfdf0cb5df9e9ee69 (diff)
downloadmandelbrot-09a819b2ef927adf5239a73f91cdfcefd6774688.tar.gz
mandelbrot-09a819b2ef927adf5239a73f91cdfcefd6774688.tar.bz2
mandelbrot-09a819b2ef927adf5239a73f91cdfcefd6774688.zip
Added colors with 1D texture
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));
}