Shadow Volume problem

I have wrote a program which use shadow volume.

When i use ZPass i work very well. (Except when the camera is inside the

Shadow, but it’s normal).

But when i use ZFail, i have a problem:
_ Shadow dosen’t work when my scene is inside a room. I have to not

apply the shadow computation to the walls and to the groud to solve the problem.

_ When i render an object under a ground, and when i compute shadow

only with the object meshes (but not with the ground), in some position,

my meshes are transparent.

Should be:

_ I have also a problem with some polygons. As you can see in this

picture, some polygons are not well tested by the stencil buffer and creat

shadow or create bug in the shadow.
In this picture, i have draw an arrow to see the bug and its source.

I compute the shadow volume to all of my meshes in the same time

(characters, walls, ground,…).
_ Do i have to compute shadow for every object in several pass (I render

the scene, i render the shadow of the 1st object, i render the shadow of

the 2nd object,…)?
_ How do i handle several object for shadow computation?

I think i use caps in the good way. But, could it be a problem of caps?


[This message has been edited by greg2 (edited 10-23-2003).]

I think in your geometries there are opened edges.

What do you mean by “there are opened edges.”?

Originally posted by greg2:
What do you mean by “there are opened edges.”?

Meaning there exist an edge which two triangles do not share. This would create a hole in the mesh. To use z-fail, your models must be 2-manifold, meaning only two triangles and no more can share one edge, and must be closed.


I have tried to replace the airplane by some spheres.

It solve the problem of the last picture.

But i have always the first 2 problems:
When i compute shadow of all mesh (object+walls+ground). I do not have shadow with Zfail.

When i compute shadow only for the object (the spheres), and not for ground, i have some bugs on the object.
There is some wrong shadow, and the objects seem to be transparent. When i move the camera, the wrong shadow move also.

My best guess is that you incorrectly have stencil writes on when you draw the objects themselves. You need to make sure your objects only fill the depth buffer and possibly color buffers before the stencil incs & decs of the volumes. They aren’t transparent, but they do seem to be writing to stencil and messing up the count making them appear transparent because of how they affect the stencil count.

You need to ensure:

  1. No stencil writes or tests when drawing the scene to the depth buffer.
  2. Draw ALL objects to the depth buffer before the shadow volumes are drawn.

I will check that.

Originally posted by SirKnight:
To use z-fail, your models must be 2-manifold, meaning only two triangles and no more can share one edge, and must be closed.

That is completely incorrect.

There are very simple ways to handle open edges… if an edge has only 1 triangle then that edge is a silhouette edge all the time, if that edges triangle is facing the light.

If an edge has more than 2 triangles associated with it, you can do the first 2 triangles as normal, but for each next triangle using that edge, set it to always cast from that edge given that the triangle is facing the light.

That works for 100% of the cases Ive tried, with open edges, and edges with more than 2 associated triangles. Simple and effective