PDA

View Full Version : Infinite shadow volumes



Alessandro_dup1
04-08-2005, 03:49 AM
[Again, i know]
I'm building a flight simulator (web site) (http://www.flighzone.us) and i'm still having trouble with shadow volumes.
If i setup the near clip plane at 0.1 shadows are correctly displayed but far terrain is messed up (z-buffer fighting, see figure here (http://www.flightzone.us/01.jpg) ).
If i setup the near clip plane at 1.0 terrain is ok but shadows are not displayed ( see figure here (http://www.flightzone.us/10.jpg) ).

From what i understood, setting up infinite shadow volumes can solve this. Right ?
Or is it something relative only to depth buffer precision ?
I tried also to render first the terrain (with near plane at 1.0), then cleaning the depth_buffer and rendering near objects (with near plane at 0.1). Failure again.

Any idea ? Enabling GL_DEPTH_CLAMP_NV solves the problem, but only on nvidia hardware of course.

If infinite shadow volumes is the way to go, i have several questions about it.
First of all, i'd like to know if the pseudo code could look like this:


void main_loop()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
ReSizeGLScene(screen_x, screen_y, perspective_angle, 1.0, 1000000); //near_plane=1.0 //far_plane=1000000
Render_Terrain();
Render_Aircraft();
infinite_frustum();
Render_Shadows_two_passes();
}where infinite_frustum() is the following:


float fAspect = (float)screen_x / (float)screen_y, fFOV = float(perspective_angle);
float fNear = 0.001f, fFar = 10.0f;
float fTop = fNear*(float)tan(double(fFOV/2.0f)), fBottom = -fTop, fRight = fAspect * fTop, fLeft = fAspect * fBottom;
float epsilon=3.0e-5F;
result_mt[0] = 2.0f*fNear/(fRight-fLeft);
result_mt[1] = 0.0f;
result_mt[2] = 0.0f;
result_mt[3] = 0.0f;
result_mt[4] = 0.0f;
result_mt[5] = 2.0f*fNear/(fTop-fBottom);
result_mt[6] = 0.0f;
result_mt[7] = 0.0f;
result_mt[8] = (fRight+fLeft)/(fRight-fLeft);
result_mt[9] = (fTop+fBottom)/(fTop-fBottom);
result_mt[10] = epsilon-1.0f;
result_mt[11] = -1.0f;
result_mt[12] = 0.0f;
result_mt[13] = 0.0f;
result_mt[14] = (epsilon-2.0f)*fNear;
result_mt[15] = 0.0f;
glLoadMatrixf((GLfloat *)result_mt);I have read also http://developer.nvidia.com/view.asp?IO=robust_shadow_volumes and Eric Langyel article at Gamasutra, but since i'm a not very experienced programmer (trying perhaps to do something complicate), i understood the concepts but could not "translate" them in code.
Thanks for any help and excuse me for this "recurring" subject of mine.

Alex

dorbie
04-08-2005, 11:59 AM
It's not clear what your problem is from the picture. Infinite shadow volumes reduce the need to manage volume caps at the far plane by projecting the ends of a volume to infinity with w=0, so I doubt they're your problem but it depends on the details of what you're seeing.