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:

Voxel rendering for 3d objects -volume rendering is something a little different.
Mr doob gave us a very impressive demo(with source):
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

and this Isometric Voxels: (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:
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:
Ken Silverman created a fast cpu based voxel 3d engine -Voxlap using C and DirectX.

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.
A minecraft level render in flash:

1 comment:

  1. There are things I can not understand but I will learn it. I think nothing is too late. Then I realized that I had improved a lot.