Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: stencil Shadow Volume zpass

  1. #1
    Junior Member Regular Contributor
    Join Date
    Oct 2004
    Posts
    153

    stencil Shadow Volume zpass

    i use this silhuette detection function:
    Code :
    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:



    everything works fine with simple objects.



    but with complex models i get this result:



    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

  2. #2
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: stencil Shadow Volume zpass

    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.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Oct 2004
    Posts
    153

    Re: stencil Shadow Volume zpass

    stencil wrap was the trick

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •