Weird problem with shadow volumes


I am having a strange problem when computing polygon visibility as seen from the light source for volumetric shadows (z-fail). I am using the dot product of polygon normal and vector from polygon center to light source for the test. The result changes depending on the viewer position and facing. For a test I have isolated a single polygon and painted its normal and vector from its center to the light source. Polygon blue, lines red and yellow: Polygon visible. Polygon green, lines light and dark blue: Polygon invisible.

If I am in front of the polygon and look a little down, it gets invisible. Behind the polygon its the other way round. The entire calculation takes place after light source and model vertices have been transformed (translate & rotate). This is done by software, not using the OpenGL transformation functions. Everything is rendered properly, even the vector from polygon to light source and the normal. I have no clue what’s going wrong here.

Here’s three images:


Polygon visible from light source:

Polygon not visible from light source:

As you can see, the angle between normal and vector from polygon to light source doesn’t change in the images. Nevertheless the computation doesn’t work. I have found out that the distance between viewer and polygon center changes when rotating the view. The projection has some scaling (X = 3:4, Y = 1:1, Z = 9/16:1).

Problem solved.