Skip to content

Instantly share code, notes, and snippets.

@electronicwhisper
Created November 19, 2012 23:52
Show Gist options
  • Save electronicwhisper/4114971 to your computer and use it in GitHub Desktop.
Save electronicwhisper/4114971 to your computer and use it in GitHub Desktop.
Mandelbrot shader
precision mediump float;
varying vec2 position;
void main() {
vec2 c = position;
vec2 z = c;
float escape = 0.;
const float iter = 50.;
for(float i = 0.; i<iter; i++) {
escape = 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) > 800.0) break;
z.x = x;
z.y = y;
}
float b = escape/iter;
vec3 col = vec3(0.5,0.8,1.0);
gl_FragColor = vec4(col*b,1.);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment