red hot lava!

Well it took long enough! I've been wanting to write a Lavalite screensaver for at least ten years, and I finally figured it out, thanks to more mining of Paul Bourke's fine pages. (Of course, it also helps that computers have gotten 30x faster in the intervening time.)

This is a combination of metaballs (alternative explanation here) and marching cubes. Basically, each bubble of lava is a few (4) overlapping spherical metaballs of various sizes that are following similar but slightly different steep, slow parabolic arcs from the bottom of the jar to the top and back. They are "30% fuzzy", so as they get near each other, they deform and combine. Then, for each frame, I generate a surface by running marching squares over it: basically, for each point in an NxNxN grid, you ask "is this point inside, or outside an object?" and from that, you can generate a lattice of triangles.

It's really slow. Just like real lavalites. Of course, if I wanted to do a proper simulation, I'd have it just sit there doing nothing for the first three hours after it started up. Somewhat surprisingly, the slow part is generating the scene, rather than rendering it: usually with 3D programs, it's the other way around.

Tags: , , ,
Current Music: Cabaret Voltaire - L21ST

6 Responses:

  1. otterley says:

    When is the next xscreensaver release due out? (Assuming it's going in there.)

    • jwz says:

      I just released 4.03 last week (it has "spheremonics" in it, the one I talked about last time) so it'll probably be about a month. I want to spend some time writing some more demos that take advantage of metaballs and/or marching cubes -- suggestions of pretty-looking field-functions are welcome... (I've started playing with the obvious ones, Mandelbrot and Julia, but they have been tending not to look very interesting except at prohibitively high polygon counts: those fractals, they're so damned crinkly.)

      • baconmonkey says:

        have you considered using a lower resolution marching cube grid and tesselating along splines between the points? since I'm assuming the actual field calculations are what take the longest.
        I have no idea how well that would work. but if it looked ok, you could probably add more, smaller clusters.

        bobs in a lava lamp tend to unjulate with a degree of elasticity when they disconnect from other blobs.

        it also seems to me that the clusters should have a little variability to their movement, like perhaps weak gravity to approxamate the effects of fluid dynamics.

        ooh, what about adding a faint environment map to the lavalamp?

        oh, and change the base to something better, like my lavalamp:

  2. anonymous says:

    Jamie, you might appreciate this:

    (I wanted to do a lavalite, too, once.)

    John Wiseman

  3. baconmonkey says:

    4th item.

    pretty speedy.

    is pascal, though.

    however, it might have some optimizations. I haven't looked at the code yet. it uses the matching cubes.

  4. hfx_ben says:

    I just found a doc on metaballs by ummm Ryan Geiss ... who has a page with some other graphics stuff (including a lavalamp download) ... and a largish FAQ on fractals. (I'm rummaging around for something on programming AVS.)
    *Can you believe it? The guy has a webpage that generates ASCII julia sets!*