Ray marching the distance. March 22, 2011 at 10:46 am

Being right back from FITC Amsterdam and with an eye toward my upcoming talk at the FFK Cologne 2011 conference, I finally found some time the last days to get my teeth into ‘ray marching’ (ray tracing done in discrete steps) once again. It was about time to explore and modify some new or different distance field formulas.

Based on my first ‘Raymarching article‘ I now intended to experiment with various distance field formulas and see what beauty may come to light by applying them. ‘Distance fields’, never heared? Ok, put simply, distance fields provide minimum distances to any surface in a scene from any point. As a result out of this, you can use distance fields as a look up for your rays position and step at the minimum of the returned distance in its direction before a new look up is required. The key thereby lies in defining a distance field cause it offers you the freedom to shape an entire implicit volume or surface out of it. Cool?

Gee, damn cool! Just have a look at Bluflame´s ‘Lunaquatic‘ or Youth Uprising´s 4k ‘Muon Baryon‘. But what´s the catch? Let´s face it. Because when it comes to calculate distance fields, there is the need of using lots of mathematic functions like sin() and cos(), so doing this with Flash might not be your best idea ever. But to say it in advance, I went for a pure AS3 attempt as well, of which more later…

There´s another solution that´s not far to seek by using WebGL GLSL shaders (like i did here). So this time I tried diverse formulas for my distance field and added some more values to the process. For instance, by simply clicking on the generated output image, you can now square the entire field or switch back to the normal view as you like.

square my distance
Launch
(You need a modern WebGL enabled browser like Google Chrome 9+ or Firefox 4+)

And like I hinted before, I was up for coding an AS3 only based raymarcher as well. In the final analysis I must admit that this version is nothing more just like a proof of concept, as it is commonly known that too much of Math.sin() and Math.cos() or Math.sqrt() means FlashPlayer.sucks()! So it´s only logical that you can´t go for any too advanced distance field calculations at all, but still it´s fun, so here we go…

AS3 only raymarching a simple distance field
Launch

Lastly… ‘Phew,’ I can hardly wait to show you some very nice Pixel Bender, Alchemy and Molehill stuff I prepared for my upcoming FFK Cologne 2011 talk, and in the meantime, feel free to download the sources and march into the distance as you like!

All right, see you at FFK Cologne in a few weeks or maybe before that at upcoming Geekybynature conference in New York next week? Anyway, enjoy!
 

Leave a Reply