PDA

View Full Version : stencil Shadow Volume zpass



H.Stony
04-24-2006, 11:17 AM
i use this silhuette detection function:

for(loop=0;loop<part[frame].planezahl*3;loop+=3) // loop through all triangles
{
n = fetchnormal; // set plane normal

NDotL = n.dotProduct(lPos); // caclulate angle beetween normal and lightdir

if(NDotL>0.0) // Triangle faces the light
{
pT[0] = fetchfirstvertex;
pT[1] = fetchsecondvertex;
pT[2] = fetchthirdvertex;

for(int i=0;i<3;i++) // loop through vertices
{
p1 = pT[i];
p2 = pT[(i+1)%3];

// Loop through silhuetteEdges vector
bool killed = false;
for(int i=0;i<silhuetteEdges.size();i++)
{
// if there neighbour already pushed bac:
if((p1.compareTo(silhuetteEdges[i].p1)&amp;&amp;p2.compareTo(silhuetteEdges[i].p2))&amp;#0124;&amp;#0124;(p1.compareTo(silhuetteEdges[i].p2)&amp;&amp;p2.compareTo(silhuetteEdges[i].p1)))
{
// kill neighbour
silhuetteEdges.erase(silhuetteEdges.begin()+i);
killed = true;
break;
}
}

// if nothing was killed -> push current edge back
if(!killed)
{
edge temp;
temp.p1 = p1;
temp.p2 = p2;
silhuetteEdges.push_back(temp);
}
}
}
}as shadowvolume i loop through the silhuetteEdges and render the quads with extruded vertices.

it looks like this:

http://hw4a.awx.at//uploads/Eitsch/silhuette.jpg

everything works fine with simple objects.

http://hw4a.awx.at//uploads/Eitsch/workfiemi.jpg

but with complex models i get this result:

http://hw4a.awx.at//uploads/Eitsch/killermull.jpg

i know there is antoher thread about stencil shadows here but i don't understand my problem.

(look at the silhuette determine function. i use Lightdirection dot Normalvector so only light facing triangles are submitted)

a possible problem i could think about is the orientation of the vertices. imagine some triangles have other oriented vertices and the shadowvolume quad is not clockwise anymore.

thanks a much

dorbie
04-25-2006, 12:24 AM
You need to extrude all silhouettes. Also geometry must be well formed (no cracks no random crap in the model hull.

It is best to use INC_WRAP and DEC_WRAP to avoid overflow and underflow issues.

Finally the stencil buffer needs sufficient bits to handle values you total to stencil by the time you use the contents for the test.

I think you may have several of these problems judging by the screenshot.

H.Stony
04-25-2006, 03:13 PM
stencil wrap was the trick