Der Schmale – David Lenaerts’s blog

Flash Platform Experiments

Marching Cubes using Pixel Bender: Metaballs / LoFi 4D Julia Set

Tags: , , , , , , , , , ,

juliasetAs promised in my previous post, I would elaborate on some of the things done for the demo. So I’m taking a quick break from work to get this post done :)

Marching Cubes

One thing I did was implement a marching cubes algorithm using Pixel Bender, which is a way to triangulate an isosurface in a scalar field. I had started to write up a whole explanation, but realized it was kinda pointless, as it has been covered plenty of times :) If you’re interested, you’re better off reading up about the subject starting here and here.

Pixel Bender

I know there’s plenty of marching cube implementations in ActionScript out there, but I haven’t seen one using Pixel Bender, so I thought I’d give it a try. I’m using it to calculate the values in the scalar field (at least on the marching cube’s grid corners), and to build the pattern ids needed for triangulation. The benefit of using Pixel Bender is that you can put in any kind of calculation that outputs scalar values, some of which you wouldn’t dare to put ActionScript through. The drawback is that it seems to have some precision problems while doing comparisons (or so it seems), so there’s some missing triangles on occasion.

No transforms, no sorting

Something I’ve realized that’s pretty neat about this algorithm is that you don’t actually need sorting. As long as you make sure the grid is aligned to the “camera” at all times, the triangulation occurs back to front and will already be correctly sorted. This of course means you can’t do any rotations on the triangles, but that’s no big deal. You can simply perform the transformation on the grid coordinates, and let the correct values be calculated for those points. Added bonus, you can do any scaling and translations together with the projection matrix in one call to Utils3D.projectVectors, annihilating the need for any calls to Matrix3D.transformVectors. Result: some extra fps.

Metaballsmetaballs

Metaballs are probably the most iconic example of isosurfaces out there (bar MRI and CT imagery). It was actually my test data for the MC system, but it ended up making a sneaky appearance in the demo (which I still consider a tribute to the undisputed king of ActionScript sticky substances ).

> Metaball demo (click to change textures)

Quaternion Julia Set

Another example I did was to triangulate a quaternion Julia set, which seems pretty popular lately ;) It definitely looks better raytraced, but I couldn’t resist! I’m using the distance estimator function to produce the grid values (see here), and an epsilon distance as the surface’s isovalue. Since things always look less crap with music, I added some for a change.

> Quaternion Julia Set Demo (might take a while to load the mp3)

Source

The marching cubes thingy, as well as the metaballs example source is up for grabs at Google Code . Enjoy! If you make any surfaces with it, I’d love to see them :)

Share and Enjoy:
  • Digg
  • TwitThis
  • del.icio.us
  • Facebook
  • Reddit
  • Netvibes
  • Technorati
  • Google Bookmarks

Tags: , , , , , , , , , ,

11 Responses to “Marching Cubes using Pixel Bender: Metaballs / LoFi 4D Julia Set”


  1. Tony Lukasavage
    on Aug 13th, 2010
    @ 2:05 am

    Incredible demo! It’s gonna take me a month just to understand the code, but I’m gonna give it a shot just the same.


  2. Linky Friday, lucky Friday the 13th edition « Kevin Goldsmith
    on Aug 14th, 2010
    @ 1:23 am

    [...] some more info (and source!) on how he achieved metaballs and 4D Julia sets using Pixel Bender: Marching Cubes using Pixel Bender: Metaballs / LoFi 4D Julia Set SSAO using Pixel [...]


  3. Will Costa
    on Aug 16th, 2010
    @ 3:02 pm

    Thanks for sharing the source David, im starting to study PixelBender and it’s very good to get some great reference to look at :D


  4. Rackdoll
    on Aug 17th, 2010
    @ 3:42 pm

    Beauty at its best!

    Nice work David!
    damn nice!


  5. nicoptere
    on Aug 21st, 2010
    @ 9:56 pm

    it sucks!

    ..

    ok, it rocks, as always…. just like the demo with simo… pfff

    yet I think that using the marching tetrahedra algorithm instead of the marching cubes would cut the computation time by… well… a signifiant uint. this will need a thourough take, I’ll let you know if I achieve something :)

    PS I just noticed that I have unconsciously chosen the same template as you…


  6. Stephan Tanguay`
    on Aug 27th, 2010
    @ 4:26 pm

    Your work is inspiring to say the least. This sort of experimentation is why allot of Flash developers got into the industry to begin with! As said by other users, thanks for sharing your exceptional work.


  7. Ray tracing with Pixel Bender using JITB | Der Schmale - David Lenaerts's blog
    on Oct 7th, 2010
    @ 3:15 pm

    [...] yet another quaternion Julia set. I mentioned last time that they look much better raytraced, and I hope you’ll agree. The sound synching is as [...]


  8. Lev
    on Jan 11th, 2011
    @ 4:56 pm

    thanks for the fabioulous metaballs-example. it seems, that there are great differences for internet explorer (your example does not work at all, but in my changed code, it just requires huge camera translation to make it visible (ie: z=-20000, firefox: z=-1500)

    why is this, does anybody know anything about that?
    thanks in advance,
    lev


  9. David
    on Jan 12th, 2011
    @ 12:09 pm

    Lev: There has been some issues with drawTriangles in very early versions of FP10. Are you sure you have a relatively new update for IE? Don’t have a problem with it here :/


  10. nkint
    on Jan 25th, 2011
    @ 10:50 pm

    really cool. Stephan Tanguay says the true,
    thanks for sharing


  11. Faster Metaballs in AS3 with Pixel Bender | Sicklebrick
    on Oct 21st, 2011
    @ 4:05 pm

    [...] To learn a little more, or play with some 3D meta balls, have a look at this link which describes using Pixel Bender to perform the calculations as opposed to producing the image. http://www.derschmale.com/2010/08/12/marching-cubes-using-pixel-bender-metaballs-lofi-4d-julia-set/ [...]

Leave a Reply

© 2009 Der Schmale – David Lenaerts’s blog. All Rights Reserved.

This blog is powered by Wordpress and Magatheme by Bryan Helmig.