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 :)

Leave a comment (11 comments)

Assembly 2010: EvoFlash FTW!

Tags: , , , , ,

spiralOutA few months ago, Simo Santavirta (aka simppa.fi, aka jac) from EvoFlash invited me to do some effects for a demo they were planning to release at Assembly 2010. I hadn’t actually done anything for the demoscene before, but how could I say no; it’s Assembly, home of Second Reality! (and I do believe there was beer involved at some point). The category was “Real Wild”, which basically means “demos for any platform that can run real-time graphics”, including Flash. And… We ended first! Champagne for all!

Linkage

Demo building for the creatively challenged

Before I start yapping too much, first things first: Simo did >90% of the demo, just need to clarify that!

Okay, to continue… I did get confronted with some facts of life in that I am not an artistic person! With code as a starting point, it’s hard for me to come up with something that looks good. Feels like a wall in my brain that’s preventing me to go that way. Typically, I work the other way around and try to turn “looks” into code (like references from real life). With the abstract beauty of many demos, it had me cursing plenty of times. Luckily, Simo was able to adapt my pieces and make them look good, so I’m very proud of the end result! ;)

From the technical side of things, here’s what I did: normal mapping on dynamic models (procedural of course), projection+shadow mapping, and marching cubes (metaballs and, I dunno, some weird tunnely thing). The metaballs are slightly tongue in cheek, and I consider them an homage to the “metaball guy”. I’ll probably get back to some of the effects in future blog posts, so I won’t delve into any detail right now. Most of them were done using Away3D Lite, preferring it over the main engine because it’s so lightweight/fast and darn easy to hack and extend. For me, it makes an excellent playground!

The demo itself was built upon the evoTinyEngine demo framework, which made it very easy to collaborate, sync, and hook effects into the main demo.

In closing

Obviously, many thanks to Simo for giving me the opportunity to join in! Too bad I couldn’t be there in person, but there were some other things I was up to during the weekend. Time to recover ;)

Enjoy the demo!

Leave a comment (3 comments)

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

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