you can fuck with the mandelbrot

This commit is contained in:
2026-01-13 19:53:43 +00:00
parent 89c0bb5f7f
commit abab81ce53
4 changed files with 134 additions and 29 deletions

View File

@@ -6,32 +6,45 @@ uniform vec2 u_resolution;
uniform float u_zoom;
uniform vec2 u_center;
// Sliders
uniform float u_exponent;
uniform vec2 u_z_start;
uniform vec2 u_c_offset;
void main() {
// 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
// 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;
// Apply C Offset from sliders (allows Julia-like effects)
c += u_c_offset;
// Mandelbrot iteration
vec2 z = vec2(0.0);
// Initial Z
vec2 z = u_z_start;
float iter = 0.0;
float max_iter = 100.0 + log(u_zoom) * 20.0; // Increase details with zoom
float max_iter = 100.0 + log(u_zoom) * 20.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;
// Generalized Z^n
// Convert to Polar: r, theta
float r = length(z);
float theta = atan(z.y, z.x);
// Z^n = r^n * (cos(n*theta) + i*sin(n*theta))
float rn = pow(r, u_exponent);
float nt = theta * u_exponent;
float x = rn * cos(nt) + c.x;
float y = rn * sin(nt) + c.y;
if ((x * x + y * y) > 4.0) {
iter = i;
@@ -46,10 +59,11 @@ void main() {
if (iter == 0.0) {
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
} else {
// More colorful palette
gl_FragColor = vec4(
sqrt(t),
t * t,
sin(t * 3.1415),
0.5 + 0.5 * cos(3.0 + t * 10.0 + u_time),
0.5 + 0.5 * cos(3.0 + t * 10.0 + 2.0),
0.5 + 0.5 * cos(3.0 + t * 10.0 + 4.0),
1.0
);
}