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:
(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:
More about Bresenham's line algorithm:;topicseen#msg9213

No comments:

Post a Comment