I believe that in reverse method you should render shadow volumes using GL_GREATER depth function. The idea is to render shadow volume only on parts where it is “behind” other scene geometry.
Code would look something like this:
jeppa: that’s the right algorithm.
What’s wrong with this implementation ?
spartacus: your algorithm works fine, but that’s exactly what jeppa’s algorithm does there’s just a slight different philosophy, but results are simply the same.
> You’ll have to compute a MaxZ value that will completely
> enclose all your shadow volumes and use that when
> you specify your frustum far plane.
That’s what I understood when I read the “other” thread, but I ended up in applying a 10000.0 far plane and I still get ugly effects. I computed vertex coordinates from OpenGL modelview matrix and the farthest vertex is at Z=1000.0f (approximatively).
Edit: Aw, I think I need to display the cap… If so, that’s a bad thing since it needs to draw more polygons…
[This message has been edited by vincoof (edited 02-04-2002).]
Originally posted by jeppa:
[b]I change order of the vertexs of polygons???
es:0,1,2,3 ->3,2,1,0??
[/b]
Well, if you declare shadow volume verts in wrong order, it will generate wrong results. So you could try to change shadow volume vert order. By the way what kind of artifacts you get on the screen? (screenshot maybe?)
Vincoof: There is a great difference between rendering with depth func GL_GREATER and GL_LESS. With GL_GREATER you can eliminate problems when shadow volume intersects with near clipping plane. Or am I completely wrong? These things can get quite confusing
Render back faces of shadow volume using depth func GL_GREATER and increment stencil. Basically this simply renders only parts of volume that are behind rendered scene geometry.
Render front faces using GL_GREATER and decrement stencil.
Render scene unlit whre stencil other than 0.
This way shadow volume can intersect with near clipping plane, and still create correct shadow. Offcourse shadow volume caps should also be rendered to create the right effect. This makes life lot easier because you don’t have to project shadow volume cap to near plane.