Mandelbrot in 3d (Composition by psonice)

Author: psonice
License: Creative Commons Attribution
Date: 2011.11.09
Compatibility: 10.7
Categories:
Required plugins:
(none)

More lunchbreak adventures.. although this one took a few lunch breaks ;) It's a raymarch into a mandelbrot rendered as a height map. Fully interactive, you can move around (arrow keys), zoom (w/s) and rotate the view (trackball).

It's hacky as hell, glitchy (don't look up ;), and unoptimised. Needs a fast-ish GPU, forget it on anything intel. Speed is ok on my 2010 iMac. No plugins needed.

Technical details: First part is a plain mandelbrot render in 2d. During animation (zoom or pan) it renders at half-res for a good speed/quality tradeoff. View rotation keeps full resolution.

2nd part is kind of a raymarch/trace, treating the mandelbrot as a height map, and stepping into it as a volume. It could be much better quality and much faster with a bit more work. Maybe I'll do that. There's a bit of lighting in there (fake hacky AO, regular diffuse + specular, although it's all buggy and broken :).

psonice's picture
Re: Mandelbrot in 3d (Composition by psonice)

New + improved! The algorithm is now much higher quality AND much faster. Still don't even consider running it on an intel GPU though ;)

new stuff:

  • Proper colours, in lovely rainbow out of tradition
  • A little AO because the deep pits look really spiky and glitchy otherwise
  • Some lighting that's not super buggy
  • I made it repeat, so it's rendering infinite 3d mandelbrots. That can be turned off, but there's no performance hit.

Try zooming in really deep - eventually you hit the limits of 32bit precision, and it renders lots of bit-sized cubes :D

http://www.interealtime.com/misc/mandelbrot2.jpg http://www.interealtime.com/misc/mandelbrot3.jpg

PreviewAttachmentSize
mandelbrot.qtz52.54 KB

harrisonpault's picture
Re: Mandelbrot in 3d (Composition by psonice)

I've been enjoying your heightfield interpretation of the mandelbrot equation. The interealtime linkage above appears broken.

gtoledo3's picture
Re: Mandelbrot in 3d (Composition by psonice)

This is cool...

You remember when we were talking about metaball snakes along time ago? Well, the one thing that kept vexing me was the "out of time" thing that would happen when panning - and I see that happening here. I can say that I solved it in my instance by making sure that I generated my depth/normals at the same time I was generating the color channel.

Here, the setup generates the shadow map from the color, which results in this lag sometimes. I haven't delved into it deep enough to see if you can work around that, but it's something I'm mentioning, not out of criticism, but b/c I've had the same thing happen to me. Actually... I'm messing with it now, and making the chains totally parallel doesn't really help much here.

What is the reasoning in generating the shadow map from the color texture instead of the heightmap? (again, not critical, curious).

psonice's picture
Re: Mandelbrot in 3d (Composition by psonice)

Thanks. Links seem to work fine here, wonder what's going on there? It's just a couple of screenshots anyway.

psonice's picture
Re: Mandelbrot in 3d (Composition by psonice)

Hmm... I vaguely remember the metaball snakes (nice, autocorrect keeps writing 'meatball snakes' :D) but I don't remember an 'out of time' issue.

I don't see anything like that here though. I guess you mean the normals would be 1 frame behind the depth, something like that? If so, it's not happening for me (on 10.7). It does drop the resolution to 1/4 while panning/zooming though, maybe that's what you're seeing? (that was kind of necessary, as I wanted it doing both a high res/iteration count fractal zoom AND a high quality ray trace through a complex volume, while still being interactive..)

As to why the colours/shadows get generated like that.. they don't unless I mess up :D The first RII generates the height map only. The second generates colour from the height map, and encodes height in the alpha channel. The 3rd generates the normals (RGB) + shadow map (A) from the height map. I feed that last RII the colour + height texture, because 1. there's no disadvantage 2. maybe I'll use the colour for something in the light map at some point :)

Also, note that this is a totally for fun project, and I've made zero effort to keep it tidy and readable. Attempt to follow the code at your own risk, it's full of broken bits, dirty hacks and unused code ;D

On a more general note: it turns out that mandelbrots (and probably most fractals) are very hard to render like this. Not because the maths is particularly hard or anything, they're just a really nasty shape. Notice how mine goes 'in' instead of sticking up like you'd expect (i.e. it's a mandelhole)? If you do it the obvious way you get loads of extreme spikes everywhere, which are ugly as hell and get really tricky to trace at decent speed without glitching.

Last thing: anyone noticed lots of issues with mipmapping? I thought I could accelerate the ray trace by tracing through high level mipmaps first, to get a fast approximation, then drop down to higher detail levels and smaller ray steps. When I try it, sometimes it works, sometimes it just looks like the mipmap levels are corrupt.