From 09a819b2ef927adf5239a73f91cdfcefd6774688 Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 20 May 2020 07:41:03 +0200 Subject: Added colors with 1D texture --- shader/fragment.glsl | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'shader') 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)); } -- cgit