Skip to content

Instantly share code, notes, and snippets.

@grazer
Last active December 24, 2015 09:09
Show Gist options
  • Save grazer/6774862 to your computer and use it in GitHub Desktop.
Save grazer/6774862 to your computer and use it in GitHub Desktop.
Mandelbrot Fractal GLSL
vec2 center = vec2(0.8,0);
float blue = 0.3;
void main() {
vec2 z, c;
float scale = 20.0/iGlobalTime; // zoom in
vec2 uv = gl_FragCoord.xy / iResolution.xy;
c.x = 1.3333 * (uv.x - 0.5) * scale - center.x;
c.y = (uv.y - 0.5) * scale - center.y;
z = c;
vec4 col = vec4(0,0,0,0);
for(int i=0; i<100; 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;
blue += 0.028;
if((x * x + y * y) > 4.0) {
col = vec4(0,0,blue,0);
break;
}
z.x = x;
z.y = y;
}
gl_FragColor = col;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment