cool stuff

This commit is contained in:
2026-01-13 19:47:59 +00:00
parent 687a8ac749
commit 89c0bb5f7f
6 changed files with 448 additions and 56 deletions

View File

@@ -1,31 +1,56 @@
#version 100
precision mediump float;
precision highp float;
uniform float u_time;
uniform vec2 u_resolution;
uniform float u_zoom;
uniform vec2 u_center;
void main() {
vec2 uv = (gl_FragCoord.xy * 2.0 - u_resolution.xy) / u_resolution.y;
// Current pixel coordinate in 0..1
vec2 st = gl_FragCoord.xy / u_resolution.xy;
st.x *= u_resolution.x / u_resolution.y; // Aspect ratio correction
// Auto zoom
float zoom = 1.0 + sin(u_time * 0.1) * 0.5;
zoom = pow(zoom, 4.0);
vec2 c = uv / zoom - vec2(0.74364388703, 0.13182590421); // Zoom into a specific interesting point
// Map to Mandelbrot space using Zoom and Center
// Default (Zoom 1): -2.5 to 1.5 X, -1.5 to 1.5 Y approx?
// Let's say center is 0,0. Range -2..2.
// st is 0..AspectRatio (approx 0..1.7)
// Center the coords:
vec2 c_uv = (gl_FragCoord.xy - u_resolution.xy * 0.5) / u_resolution.y;
// Apply Zoom and Pan
vec2 c = (c_uv / u_zoom) + u_center;
// Mandelbrot iteration
vec2 z = vec2(0.0);
float iter = 0.0;
float max_iter = 100.0;
float max_iter = 100.0 + log(u_zoom) * 20.0; // Increase details with zoom
for (float i = 0.0; i < 100.0; i++) {
z = vec2(z.x * z.x - z.y * z.y, 2.0 * z.x * z.y) + c;
if (length(z) > 4.0) break;
iter += 1.0;
for (float i = 0.0; i < 500.0; i++) {
if (i > max_iter) break;
// Z = Z^2 + C
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) > 4.0) {
iter = i;
break;
}
z.x = x;
z.y = y;
}
float f = iter / max_iter;
vec3 col = vec3(f);
col = 0.5 + 0.5 * cos(3.0 + f * 10.0 + vec3(0.0, 0.6, 1.0));
if (iter >= 99.0) col = vec3(0.0);
gl_FragColor = vec4(col, 1.0);
// Coloring
float t = iter / max_iter;
if (iter == 0.0) {
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
} else {
gl_FragColor = vec4(
sqrt(t),
t * t,
sin(t * 3.1415),
1.0
);
}
}