parent
0548e61f8a
commit
9f7f9e4124
8 changed files with 106 additions and 30 deletions
@ -1,6 +1,31 @@ |
||||
#version 330 core |
||||
out vec4 pixColor; |
||||
|
||||
uniform int iterationCount; |
||||
uniform float divergeThreshold; |
||||
|
||||
in vec2 complexPos; |
||||
|
||||
vec2 mul(in vec2 a, in vec2 b) { |
||||
return vec2(a.x * b.x - a.y * b.y, a.y * b.x + a.x * b.y); |
||||
} |
||||
|
||||
vec3 getColor(in float value){ |
||||
vec3 red = vec3(0.5, 0, 0); |
||||
vec3 blue = vec3(0, 0, 0.5); |
||||
return value * red + (1 - value) * blue; |
||||
} |
||||
|
||||
void main(){ |
||||
pixColor = vec4(1., 0., 0., 1); |
||||
|
||||
vec2 z; |
||||
float stepsNeeded = 0; |
||||
while (stepsNeeded < iterationCount && length(z) < divergeThreshold){ |
||||
z = mul(z, z) + complexPos; |
||||
++stepsNeeded; |
||||
} |
||||
|
||||
float value = stepsNeeded / iterationCount; |
||||
pixColor = vec4(getColor(value), 1); |
||||
} |
||||
|
||||
|
@ -1,6 +1,14 @@ |
||||
#version 330 core |
||||
layout (location = 0) in vec2 position; |
||||
layout (location = 0) in vec2 pos; |
||||
|
||||
uniform vec2 origin; |
||||
uniform vec2 size; |
||||
|
||||
out vec2 complexPos; |
||||
|
||||
void main(){ |
||||
gl_Position = vec4(position.x, position.y, 0.0, 1.); |
||||
vec2 offset = (pos + 1) / 2 * size; |
||||
offset.y *= -1; |
||||
complexPos = origin + offset; |
||||
gl_Position = vec4(pos.xy, 0.0, 1.); |
||||
} |
Loading…
Reference in new issue