From 8e8fb66873636ac2dbe10ed4304ab7ae05561892 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Wed, 17 Oct 2018 13:14:24 +0200 Subject: [PATCH] Impl julia fractal --- exercise1/glsl/shader.frag | 30 +++++++++++++++++++++++++++++- exercise1/glsl/shader.vert | 2 ++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/exercise1/glsl/shader.frag b/exercise1/glsl/shader.frag index f62db14..5f7d2b9 100644 --- a/exercise1/glsl/shader.frag +++ b/exercise1/glsl/shader.frag @@ -4,12 +4,40 @@ #version 130 in vec4 fragment_color; +in vec2 vertex_pos; out vec4 color; +const int i_max = 200; + void main() { - color = fragment_color; + float m = 0.3; + vec2 c = vec2(0.5, 1.5); + + vec2 z = vertex_pos * m; + + int i = 0; + + for(; i < i_max; i++) { + float x = (z.x * z.x - z.y * z.y) + c.x; + float y = (z.y * z.x - z.x * z.y) + c.y; + + if (x*x + y*y > 4.0) { + break; + } + + z.x = x; + z.y = y; + } + + float alpha = 0.0; + + if (i < i_max) { + alpha = float(i) / float(i_max); + } + + color = vec4(alpha, alpha, alpha, alpha) * 10.0 * fragment_color; /**** Begin of tasks *** - 1.2.5 diff --git a/exercise1/glsl/shader.vert b/exercise1/glsl/shader.vert index 9cad82e..e07b317 100644 --- a/exercise1/glsl/shader.vert +++ b/exercise1/glsl/shader.vert @@ -10,9 +10,11 @@ uniform mat4 view; uniform mat4 proj; out vec4 fragment_color; +out vec2 vertex_pos; void main() { + vertex_pos = in_position.xy; gl_Position = proj * view * in_position; fragment_color = in_color;