This topic is 4470 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

i am still trying to get my stencil shadow volumes working. i am using zpass algorithm. my createSilhuette-edges code:
	for(loop=0;loop&lt;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&gt;0.0)                // Triangle faces the light
{
pT[0] = fetchfirstvertex;
pT[1] = fetchsecondvertex;
pT[2] = fetchthirdvertex;

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

// Loop through silhuetteEdges vector
bool killed = false;
for(int i=0;i&lt;silhuetteEdges.size();i++)
{
// if this edge is already pushed back:
if((p1.compareTo(silhuetteEdges.p1)&&p2.compareTo(silhuetteEdges.p2))
||(p1.compareTo(silhuetteEdges.p2)&&p2.compareTo(silhuetteEdges.p1)))
{
// kill neighbour
silhuetteEdges.erase(silhuetteEdges.begin()+i);
killed = true;
break;
}
}

// if nothing was killed -&gt; push current edge back
if(!killed)
{
edge temp;
temp.p1 = p1;
temp.p2 = p2;
silhuetteEdges.push_back(temp);
}
}
}
}


		glBegin(GL_QUADS);
for(int i=0;i&lt;silhuetteEdges.size();i++)
{
glVertexAttrib1f(AWXExtrudorLocation,0.0);
glVertex3f(silhuetteEdges.p1.x,silhuetteEdges.p1.y,silhuetteEdges.p1.z);
glVertex3f(silhuetteEdges.p2.x,silhuetteEdges.p2.y,silhuetteEdges.p2.z);

glVertexAttrib1f(AWXExtrudorLocation,1.0);
glVertex3f(silhuetteEdges.p2.x,silhuetteEdges.p2.y,silhuetteEdges.p2.z);
glVertex3f(silhuetteEdges.p1.x,silhuetteEdges.p1.y,silhuetteEdges.p1.z);

}
glEnd();

i use a vertexshader to extrude. vertexshader is controlled by a vertexattrib
attribute float extrude;

const float extrudeWidth = 0.6;

void main()
{
float extrudeBool = extrude;

if(extrudeBool == 1.0)
{
gl_FrontColor = vec4(1.0,0.0,0.0,1.0);
vec4 pos =  gl_ModelViewMatrix * gl_Vertex;
vec4 temp = pos + (pos - gl_LightSource[0].position) * extrudeWidth;
gl_Position =  gl_ProjectionMatrix * temp;
}

else
{
gl_FrontColor = vec4(1.0,1.0,1.0,1.0);
gl_Position = gl_ModelViewProjectionMatrix  * gl_Vertex;
}
}


my stencil setup is correct. but i get strange results (shadow volume is rendered as polygonmode LINES) following image illustrates, that stencil setup and zpass algorithm is correct implemented: (in the stencil pass the sphere is simply rendered at y=0. so i got the shadowed fragments) following image illustrates, that the extrusion code should be ok too: hope you can help me. [Edited by - Eitsch on April 25, 2006 7:47:29 AM]

Share on other sites
i changed clearstencil to 1.

my stencil part is now:
glClearStencil(1);			glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_LIGHTING_BIT | GL_STENCIL_BUFFER_BIT);				glPushAttrib(GL_COLOR_BUFFER_BIT | GL_LIGHTING_BIT | GL_DEPTH_BUFFER_BIT | GL_POLYGON_BIT | GL_STENCIL_BUFFER_BIT);					float pos[] = {0.0,90.0,2.0,1.0};				glLightfv(GL_LIGHT0,GL_POSITION,pos);								glUseProgramObjectARB(shadowshader.p);						glColorMask(0,0,0,0);				glDepthMask(0);				glEnable(GL_CULL_FACE);				glEnable(GL_STENCIL_TEST);							glStencilFunc(GL_ALWAYS,1,0xFFFFFFFFL);							glStencilOp(GL_KEEP,GL_KEEP,GL_INCR);				glFrontFace(GL_CCW);						glPushMatrix();				glTranslatef(wx,5,wz);				level10.data[54].renderExtrusion();				glPopMatrix();									glStencilOp(GL_KEEP,GL_KEEP,GL_DECR);				glFrontFace(GL_CW);						glPushMatrix();				glTranslatef(wx,5,wz);				level10.data[54].renderExtrusion();				glPopMatrix();						glUseProgramObjectARB(NULL);				glPopAttrib();			glEnable(GL_STENCIL_TEST);		glDepthFunc(GL_EQUAL);		glStencilFunc(GL_EQUAL,0,0xFFFFFFFFL);		glStencilFunc(GL_KEEP,GL_KEEP,GL_KEEP);			glDisable(GL_DEPTH_TEST);						glMatrixMode(GL_PROJECTION);			glPushMatrix();			glLoadIdentity();			gluOrtho2D(0.0,1.0,0.0,1.0);							glMatrixMode(GL_MODELVIEW);				glPushMatrix();				glLoadIdentity();				//glTranslatef(0.0,0.0,-5.0);								glColor4f(0.0,0.0,0.0,0.3);								glDisable(GL_LIGHTING);				glDisable(GL_TEXTURE_2D);				glDepthMask(0);								glBegin(GL_QUADS);					glVertex3f(0.0,0.0,0.0);					glVertex3f(1.0,0.0,0.0);					glVertex3f(1.0,1.0,0.0);					glVertex3f(0.0,1.0,0.0);				glEnd();								glPopMatrix();						glPopMatrix();						glEnable(GL_DEPTH_TEST);		glPopAttrib();

current results:

i have still the problem with the house:

could the vertexdirection (counterclockwise) be the problem here??

[Edited by - Eitsch on April 25, 2006 7:01:06 AM]

no idea?

push.

Share on other sites
Edit: Please use [ source] [ /source] (without the space) aroung long code dumps

have you set up your normals right?

Share on other sites
glStencilOp(GL_KEEP,GL_KEEP,GL_INCR_WRAP) was the trick..

1. 1
2. 2
3. 3
Rutin
24
4. 4
JoeJ
18
5. 5

• 14
• 23
• 11
• 11
• 9
• Forum Statistics

• Total Topics
631766
• Total Posts
3002226
×