Thursday, August 25, 2011

Simple Ray Tracing Voxel Demo


Just a simple demo using Ray Tracing to render Voxels.
I use a 1D array - voxelData[] to represent voxels/3D points with colors. It's easier for understanding if I use a 3D array, voxelData[x][y][z], where x, y, z is the position of the voxel in 3D space and the value of the array is color for that voxel. Note that voxelData[x][y][z] = voxelData[x<<16|y<<8|z] if the dimension is set to 256 at max.

The rendering idea is simple, since we want to fill the screen using colors, for each pixel in the screen, trace a ray, and march the ray in the voxel space, until the ray hit a voxel, then we get the color and write it to the screen. This is the so-called "first-hit" algorithm.

Ray tracing is slow,  a fast way to render voxel is ray casting, such as the algorithm used in Bengine. But using ray tracing, you can easily add some reflection/shadow effect after calculate normal vectors of the voxels.

Source code: https://flaswf.googlecode.com/svn/trunk/RaytracingVoxel
(similar to the source code of the voxel ray tracing demo in my earlier post)

====================
 Update: November, 27, 2011
====================

Ray Tracing Voxel Demo using 3D DDA/Bresenham's line algorithm


Source code: https://flaswf.googlecode.com/svn/trunk/RaytracingVoxel/3DDDA
More about Bresenham's line algorithm:
http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
http://www.cobrabytes.com/index.php?topic=1150.0
http://www.jonof.id.au/forum/index.php?topic=1338.msg9213;topicseen#msg9213

No comments:

Post a Comment

Sponsors