webgl-shader/fragshader.glsl
Christian Lawson-Perfect 61faec2e92 WebGL 2 shader
2025-05-16 06:32:13 +00:00

42 lines
No EOL
1 KiB
GLSL

#version 300 es
#define PI 3.1415926538
#define maxIterations 100
precision mediump float;
uniform float t;
uniform vec2 screen_size;
in vec4 v_pos;
out vec4 fragColor;
vec2 squareImaginary(vec2 number){
return vec2(
pow(number.x,2.)-pow(number.y,2.),
2.*number.x*number.y
);
}
float iterateMandelbrot(vec2 coord) {
vec2 z = vec2(0.,0.);
for(int i=0; i<maxIterations; i++) {
float l = length(z);
z = squareImaginary(z) + coord;
if(l > 2.) {
return float(i)/float(maxIterations);
}
}
return 1.;
}
void main(void) {
float aspect = screen_size.x / screen_size.y;
mat2 squash = mat2(aspect, 0., 0., 1.);
vec2 pos = squash * v_pos.xy;
float r = length(pos.xy);
vec2 centre = vec2(0.367,0.6955);
float bounce = 1.;//(cos(t*0.1) + 1.)/2.;
float zoom = 0.5 / (1. + 200.*(1.-bounce));
//float zoom = 1.;
float m = iterateMandelbrot(pos * zoom + centre);
float c = m==1. ? 1. : m*0.8;
vec4 color = vec4(c, c, c, 1.0);
fragColor = color;
}