Friday, April 17, 2009

Ray Tracing - Voxel Rendering in Flash

I did some experiments on ray tracing in as3 before and I'm interested in this technology because it is simple but can create convincing 3D effects like shadows and reflections.
The problem is efficiency, real time rendering for complicated objects seems impossible for
hardware limitations nowadays.

Voxel rendering is another interesting thing, I once played with voxel terrains, you can find some work here:
http://bruce-lab.blogspot.com/2009/01/terrain-rendering-in-flash.html
http://bruce-lab.blogspot.com/2008/10/open-source-as30-voxel-terrain-engine.html

Voxel rendering for 3d objects -volume rendering is something a little different.
Mr doob gave us a very impressive demo(with source):http://www.mrdoob.com/blog/post/571
That swf load a confusing "data.v" file, at first I thought it is a Vista/Lipsia medical CT data format file, but now I think I was wrong. It is just a compressed bytearray data storing the voxel head data -x,y,z and colour values of voxels, please check the loading part of the source code for details. I don't know how they created such data file, maybe use some other software or mybe just by as3. That source is not very readable, what's more I can't figure out how to get those voxel data.

After I saw zevan's work http://shapevent.com/sketchbook/2008/12/28/voxel-play/

and this Isometric Voxels: http://actionsnippet.com/?p=431 (with code)

I decide to do something myself. I tried a simple way - create my own voxel data and use ray tracing to render it. Ray tracing is slow, so I give up real time. I can only create some simple voxel object - cube&sphere, I used six pictures as textures, five for cube and one for the sphere. I use 256*256*256 voxels to represent a simple scene - a sphere in a cube and stored the values in an array, convert and compress it into a bytearray and then save it as 'cube_sphere.vd'. The data file is still large - 3.23MB! The 'voxel_data_tracer.swf' loads this voxel data file and renders the voxels.

This is what I got:

You can download the demo here:
http://flaswf.googlecode.com/files/raytracing%20voxel%20rendering.zip
but it is NOT RECOMMEND, it is slow and eats too much, too much memory - about 200,000k when initing, cpu 50% and more than 120,000k memory needs while rendering.
Source code needs too much optimization so I can't put it here now.
[Update:2011/08/26] Source code for the demo:
http://bruce-lab.blogspot.com/2011/08/simple-ray-tracing-voxel-demo.html
--------------------------------------------
Ken Silverman created a fast cpu based voxel 3d engine -Voxlap using C and DirectX.
http://www.advsys.net/ken/voxlap/voxlap05.htm

The world of Voxlap is fully destructible, yes , you can destroy everything there!
That is the most exciting part of voxels!
Voxlap is open source, but God understands what those crazy codes mean!

An open source game using Voxlap is V O X E L S T E I N 3 D - a FPS game inspired by Wolfenstein 3D.
http://voxelstein3d.blogspot.com/
http://voxelstein3d.sourceforge.net/
Links:
A minecraft level render in flash:
http://liquify.eu/flash/MCExplorer
http://www.minecraftforum.net/viewtopic.php?f=25&t=96591

No comments:

Post a Comment

Sponsors