shiben.tech

x youtube linkedin instagram bluesky

Mandelbrot Set on GPU with Double-Single Precision floats

Mandelbrot Set on GPU with Double-Single Precision floats

Saturday, 04 July 2026, 12:51 PM
# tech art

Mandelbrot Set deep zoom videos have always fascinated me. The equation zₙ₊₁=zₙ²+c looked far too simple to produce such incredible complexity. For the longest time, I kept overlooking one crucial detail: both z and c are complex numbers. Being a dummy, I was thinking in regular Cartesian coordinates instead of the complex plane. Once that clicked, my question of “How can this equation ever converge?” finally disappeared.

Mandelbrot Set on GPU with Double-Single Precision floats

The Bare Minimum

My first attempt was simply to render the fractal, end to end. When the first image finally appeared, beyond the self-congratulatory feeling of getting it to work, I could hardly believe my eyes. It was amazing that such a simple shader could produce something so beautiful.

Mandelbrot set always fascinated me, but I never found time to understand the math properly. 🧐

I kept reading it is this simple equation 𝚣 = 𝚣² + 𝚌 and got distracted by something else. The part that I was missing is that 𝚣 and 𝚌 are complex numbers. Mandelbrot set… pic.twitter.com/2ZANuKVqES

— Shiben Bhattacharjee (@shibentech) June 14, 2026

Check out the shader code and run it live: Shadertoy or FragCoord

Julia, the Companion Set

Once you understand the Mandelbrot Set, it’s hard to ignore the Julia Set. The two are deeply connected, and exploring one naturally makes you curious about the other. Unlike Mandelbrot which parametrises c, here you parametrise z, and animate c as c=0.7885(cos(a)+isin(a)) with a cycling over time between 0 and .

Julia Set cannot be ignored once you have talked about Mandelbrot set 🧐. Once you understand Mandelbrot set, Julia Set is nothing but parametrizing 𝚣 instead of 𝚌 in the equation 𝚣 = 𝚣² + 𝚌.

The circular motion is from a prescribed polar values of c 😎 that automatically… pic.twitter.com/QVq1wK2YbL

— Shiben Bhattacharjee (@shibentech) June 19, 2026

Check out the shader code and run it live: Shadertoy or FragCoord

Implementing Deep Zoom

At this point, I wanted to explore deep zoom videos. The basic idea is surprisingly simple: pick a point of interest (a value of c) to center the view on, then continuously scale down the coordinates to visually zoom in.

Mandelbrot Set Zoom Equation

Seemed simple enough, so I went ahead and put it together in a shader. I dwelled into some turbo nerd forums and curated a nice collection of coordinates. The fun part was creating the transition between the locations.

Check out the shader code and run it live: Shadertoy or FragCoord

But the zoom turned out to be incredibly shallow. Push it a little further, and the image starts breaking into large, flat rectangles of solid color as floating-point precision loses the battle against the tiny scales involved. Simply switching to double felt like a cop-out. Besides, I ran into all kinds of compatibility issues with double precision on GPUs.

So I rolled up my sleeves and … asked AI for a solution. 😐

Emulating Double using Single

That’s when I learned about double-single precision: representing a 64-bit value using two 32-bit floats. It allows you to explore much deeper while staying compatible with standard GLSL shaders. A simplified way to think about it is this: take a number, keep the first ~7 decimal digits in one float, and store the remaining decimals in a second. Specialized arithmetic handles addition, subtraction, and multiplication on this pair. Since it’s computationally expensive, I used it only for the fractal calculations. Everything else like coloring, zooming, visual effects etc. continued to use regular floats.

And voila - 11 Best Spots to Visit: A Mandelbrot Set Tourist Itinerary. A travel guide through one of the most mesmerizing mathematical landscapes ever discovered.

Check out the shader code and run it live: FragCoord

Warning: This is a fairly heavy shader. Don’t open the link unless you have a reasonably capable GPU, or your browser may become noticeably slow or unresponsive.

And that's it!

Hope you enjoyed reading this post. While I often use AI for help with tech, when it comes to writing, I like to do it myself. Regardless, in my experience, it often ends up being about the same amount of work: prompting, iterating, and choosing between drafts. I rather enjoy the creative process of writing myself and it motivates me if people read the stuff I write. If you found this post useful or interesting, consider following me on X for more posts on art, graphics, shaders, and programming.