Files
ReShader/shaders/fastmandelbrot.frag.glsl
2025-04-22 01:11:39 -05:00

75 lines
1.7 KiB
GLSL

#version 120
#ifdef GL_ES
precision mediump float;
#endif
#define PI 3.14159265359
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
uniform vec2 u_translation;
uniform float u_zoom;
#define N 48.
#define B 4.
vec3 pal(in float t, in vec3 a, in vec3 b, in vec3 c, in vec3 d) {
return a + b*cos(6.28318*(c*t+d));
}
float iterate(vec2 p) {
vec2 z = vec2(0), c = p;
float i;
for (i=0.; i < N; i++ ) {
z = mat2(z, -z.y, z.x) * z + c;
if (dot(z, z) > B*B) break;
}
//return i;
// Compute the iteration smoothly, instead of in integers.
if (p.y < 0.f) return i;
return i - log(log(dot(z, z)) / log(B)) / log(2.);;
}
void main() {
vec2 R = u_resolution.xy;
vec2 uv = 1.2 * (2. * gl_FragCoord.xy - R - 1.) / R.y - vec2(.4, 0.);
//vec2 z = vec2(0), c = uv;
//float i;
//for (i = 0.; i < N; i++) {
// z = mat2(z, -z.y, z.x) * z + c;
// if (dot(z, z) > B*B) break;
//}
float n = iterate(uv) / N;
vec3 col = pal(fract(n + 0.5), vec3(.5), vec3(.5), vec3(1), vec3(.0, .1, .2));
//if (n == 1.) {n = 0; }
gl_FragColor = vec4(n == 1. ? vec3(0) : col, 1.);
//vec2 st = gl_FragCoord.xy/u_resolution.xy;
//vec3 color = vec3(0.0);
//vec3 pct = vec3(st.x);
// pct.r = smoothstep(0.0,1.0, st.x);
// pct.g = sin(st.x*PI);
// pct.b = pow(st.x,0.5);
//color = mix(colorA, colorB, pct);
// Plot transition lines for each channel
// color = mix(color,vec3(1.0,0.0,0.0),plot(st,pct.r));
// color = mix(color,vec3(0.0,1.0,0.0),plot(st,pct.g));
// color = mix(color,vec3(0.0,0.0,1.0),plot(st,pct.b));
// gl_FragColor = vec4(color,1.0);
}