I wrote a simple function to render these voxels:
for each pixel on screen:
{
calculate the direction and starting position of the ray
Vec3 cur_pos = ray_start_pos
Voxel voxel = Nothing
for( temp=0; temp+=VOXEL_SIZE; temp<RAY_LENGTH )
{
voxel = get_voxel( cur_pos );
if ( voxel != Nothing )
break;
cur_pos += ray_direction * VOXEL_SIZE
}
if ( voxel != Nothing )
set_pixel( voxel.r, voxel.g, voxel.b );
else
set_pixel( background color );
}
Rendering 80x80x100 (=640k) voxels at resolution 700x444, it takes about 20 seconds to render one frame (on AMD Phenom II X6 @ 3.4 GHz).
Although I'm using just one thread for rendering, the performance is absolutely unacceptable! I need at least 25 frames per second.
And this algorithm has some other problems than performance as well:
- Aliasing artifacts
- Some voxels are processed twice
- Lots of empty voxels are processed even if the ray doesn't hit anything
I have searched the internet but I didn't find any good articles about rendering voxels that don't involve octrees or cuda.
So, do you know of any good voxel rendering algorithms?