CGI/exercise1/glsl/shader.frag

41 lines
721 B
GLSL
Raw Permalink Normal View History

2018-10-17 08:22:24 +00:00
// This source code is property of the Computer Graphics and Visualization
2018-09-06 12:35:43 +00:00
// chair of the TU Dresden. Do not distribute!
// Copyright (C) CGV TU Dresden - All Rights Reserved
#version 130
in vec4 fragment_color;
2018-10-17 11:14:24 +00:00
in vec2 vertex_pos;
2018-10-21 14:18:27 +00:00
in vec2 julia_position;
2018-09-06 12:35:43 +00:00
out vec4 color;
2018-10-17 14:39:10 +00:00
uniform float m;
uniform vec2 c;
2018-10-17 11:14:24 +00:00
const int i_max = 200;
2018-10-17 08:22:24 +00:00
void main()
2018-09-06 12:35:43 +00:00
{
2018-10-21 14:18:27 +00:00
vec2 z = julia_position * m;
2018-10-17 14:39:10 +00:00
int i;
2018-10-17 11:14:24 +00:00
2018-10-17 14:39:10 +00:00
for(i = 0; i < i_max; i++) {
2018-10-17 11:14:24 +00:00
float x = (z.x * z.x - z.y * z.y) + c.x;
2018-10-17 14:39:10 +00:00
float y = (z.y * z.x + z.x * z.y) + c.y;
2018-10-17 11:14:24 +00:00
2018-10-17 14:39:10 +00:00
if ((x*x + y*y) > 4.0) {
2018-10-17 11:14:24 +00:00
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;
2018-09-06 12:35:43 +00:00
}