Skip to content

Instantly share code, notes, and snippets.

@creaktive
Created March 25, 2021 15:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creaktive/131472f92ed80c71593c737e423cf649 to your computer and use it in GitHub Desktop.
Save creaktive/131472f92ed80c71593c737e423cf649 to your computer and use it in GitHub Desktop.
Mandelbrot set plot, implemented as GLSL fragment shader
// shamelessly stolen from https://p5js.org/reference/#/p5/loadShader
// ported to work with https://thebookofshaders.com/edit.php
precision highp float;
const int I = 500;
void main() {
vec2 vPos = gl_FragCoord.xy;
vec2 p = vec2(-0.74364388703, 0.13182590421);
float r = .00001;
vec2 c = p + vPos * r, z = c;
float n = 0.0;
for (int i = I; i > 0; i --) {
if(z.x*z.x+z.y*z.y > 4.0) {
n = float(i)/float(I);
break;
}
z = vec2(z.x*z.x-z.y*z.y, 2.0*z.x*z.y) + c;
}
gl_FragColor = vec4(0.5-cos(n*17.0)/2.0,0.5-cos(n*13.0)/2.0,0.5-cos(n*23.0)/2.0,1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment