Why Are Zoom Colors Dull?
In your code below, you increase max_iteration to get more colors. However, that approach provides few colors at 1x magnification and a wider variety when zoomed in. This occurs because there are no actual colors in the "true" Mandelbrot set, and by increasing max_iteration, you only move closer to that ideal.
How to Achieve Vibrant Colors Throughout Zoom Process:
To achieve this, you need to compute fractional point iterations, which is also known as Mandelbrot Escape. Instead of uniformly wasting many colors on unused indexes, you distribute the gradient's color more effectively by employing a histogram approach and a specific visually pleasing gradient function.
Implementing Floating Point Iterations:
To compute floating-point iterations, you can use the following formula:
mu = m + frac = n + 1 - log(log|Z(n)| / log2)
Where n is your iteration count and Z(n) is the complex domain sub-result of the equation you're iterating on.
Applying Fractional Escape to GLSL Mandelbrot Shader:
The provided code demonstrates a GLSL Mandelbrot shader with fractional escape and multicolored recoloring:
Vertex Shader:
<code class="glsl">// Vertex #version 420 core layout(location = 0) in vec2 pos; // glVertex2f <-1,+1> out smooth vec2 p; // texture end point <0,1> void main() { p = pos; gl_Position = vec4(pos, 0.0, 1.0); }</code>
Fragment Shader:
<code class="glsl">// Fragment #version 420 core uniform vec2 p0 = vec2(0.0, 0.0); // mouse position <-1,+1> uniform float zoom = 1.000; // zoom [-] uniform int n = 100; // iterations [-] uniform int sh = 7; // fixed point accuracy [bits] uniform int multipass = 0; // multi pass? in smooth vec2 p; out vec4 col; const int n0 = 1; // forced iterations after escape to improve precision vec3 spectral_color(float l) // RGB <0,1> <- lambda l <400,700> [nm] { float t; vec3 c = vec3(0.0, 0.0, 0.0); // Spectral color calculation based on wavelength if ((l >= 400.0) && (l < 410.0)) { t = (l - 400.0) / (410.0 - 400.0); c.r = +(0.33 * t) - (0.20 * t * t); } else if ((l >= 410.0) && (l < 475.0)) { t = (l - 410.0) / (475.0 - 410.0); c.r = 0.14 - (0.13 * t * t); } else if ((l >= 545.0) && (l < 595.0)) { t = (l - 545.0) / (595.0 - 545.0); c.r = +(1.98 * t) - (t * t); } else if ((l >= 595.0) && (l < 650.0)) { t = (l - 595.0) / (650.0 - 595.0); c.r = 0.98 + (0.06 * t) - (0.40 * t * t); } else if ((l >= 650.0) && (l < 700.0)) { t = (l - 650.0) / (700.0 - 650.0); c.r = 0.65 - (0.84 * t) + (0.20 * t * t); } if ((l >= 415.0) && (l < 475.0)) { t = (l - 415.0) / (475.0 - 415.0); c.g = +(0.80 * t * t); } else if ((l >= 475.0) && (l < 590.0)) { t = (l - 475.0) / (590.0 - 475.0); c.g = 0.8 + (0.76 * t) - (0.80 * t * t); } else if ((l >= 585.0) && (l < 639.0)) { t = (l - 585.0) / (639.0 - 585.0); c.g = 0.84 - (0.84 * t); } if ((l >= 400.0) && (l < 475.0)) { t = (l - 400.0) / (475.0 - 400.0);</code>
The above is the detailed content of How to Achieve Vibrant Colors in a Mandelbrot Set Throughout Zoom?. For more information, please follow other related articles on the PHP Chinese website!