I'd like to optimize my realtime landscape renderer, every time i speed
up the algorithm it looks like shit.
Here's the basic algorithm:
set the camera matrix
for each ray do
* find the coordinates of the ray in voxel space
* with a 3d line algoritm, interpolate along the ray, starting at
the origin of the ray
- get the height of the voxel from the height-map (project the
pixel onto the plane y=0 to get the coordinates in bitmap )
- if the ray intersects, then set the pixel to the corresponding
color, and exit the loop.
end interpolation loop
end for each ray loop
My problem is the 3d line part. I need a quick algorithm which enables
you to start at any point (x1,y1,z1) and interpolate to (x2,y2,z2)...
In all the algorithms I know, you must swap some values, to start with
My algo currently uses 16.16 fixed point, and splits each case into 4
Dx>0 , Dz>0
Dx>0 , Dz<0
Dx<0 , Dz>0
Dx<0 , Dz<0
and then calculates the step, and just interpolates ( very naive isn't
it). Anyway, this looks crap, since due to lack of precision, you can
distinctly distinguish the different zones in the voxel...
If you got any ideas, please let me know...