Skip to main content
gamedev.net
🔒 Locked

Shadow Volume problems

Started by b3rs3rk 2 replies 1.1k views
Original Post
b3rs3rk
b3rs3rk
i've created the shadow volume for the model (i've implemented also silouhette determination), but i've got some problem when i try to render the shadow...i'm trying to implement the depth pass algo. this is my code:

void DrawScene()
{
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(	50, 90, -50.0f,	0, 0, 0,	0, 1, 0);

    glBegin(GL_QUADS);							
	glColor3f(0.8f, 0.8f, 0.8f);

	glNormal3f(0.0f, 0.0f, 1.0f);
	glVertex3f(90.0f, 90.0f, 60.0f);
	glVertex3f(-90.0f, 90.0f, 60.0f);
	glVertex3f(-90.0f, -50.0f, 60.0f);
	glVertex3f(90.0f, -50.0f, 60.0f);

	glNormal3f(0.0f, 1.0f, 0.0f);
	glVertex3f(90.0f, -50.0f, 60.0f);
	glVertex3f(-90.0f, -50.0f, 60.0f);
	glVertex3f(-90.0f, -50.0f, -60.0f);
	glVertex3f(90.0f, -50.0f, -60.0f);
    glEnd();

    if(Rotate_Model)			
	g_RotateX += g_RotationSpeed;	
    glRotatef(g_RotateX, 0, 1.0f, 0);		
    g_Model.DrawModel();

    glDisable( GL_LIGHTING );
    glDisable(GL_TEXTURE_2D);
    glPushMatrix();
        glLightfv( GL_LIGHT0, GL_POSITION, lightPosition );
        glTranslatef( lightPosition[0], lightPosition[1], lightPosition[2] );
        glColor3f(1.0f, 1.0f, 0.5f);
        glutSolidSphere( 2, 8, 8 );
    glPopMatrix();
    glEnable( GL_LIGHTING );

}

void RenderScene( void )
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );

    glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
    DrawScene();

    glEnable( GL_CULL_FACE );
    glEnable( GL_STENCIL_TEST );
    glDepthMask( GL_FALSE );
    glStencilFunc( GL_ALWAYS, 0, 0 );

    glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
    glCullFace( GL_BACK );
    g_Model.DrawShadows(lightPosition);

    glStencilOp( GL_KEEP, GL_KEEP, GL_DECR );
    glCullFace( GL_FRONT );
    g_Model.DrawShadows(lightPosition);

    glDepthMask( GL_TRUE );
    glDepthFunc( GL_LEQUAL );
    glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
    glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
    glCullFace( GL_BACK );
    glDisable( GL_CULL_FACE );

    glStencilFunc( GL_EQUAL, 1, 1 );
    glDisable( GL_LIGHT0 );
    DrawScene();

    glStencilFunc( GL_EQUAL, 0, 1 );
    glEnable( GL_LIGHT0 );
    DrawScene();

    glDepthFunc( GL_LESS );
    glDisable( GL_STENCIL_TEST);

    if( Draw_Volume ) {
       // glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
        g_Model.DrawShadows(lightPosition);
       // glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
    }

    SwapBuffers( g_hDC );
}


the most part of RenderScene is taken from the shadow volumes demo on codesampler.com (thank you guys!) What can i do? EDIT: thank you nife :) Here's the two screenshots: Volume Error [Edited by - b3rs3rk on March 19, 2005 5:10:52 PM]
Khaos Dragon
Khaos Dragon
First of all you need to verify that the mesh is a closed hull, meaning every edge is connected to exactly two triangles (I suppose later you could add support for open meshes).

Perhaps try with some meshes that are guaranteed to be closed like a dedecahedron or something. If it works consistently for those, then the closedness of the model needs to be fixed.
nife
nife
Quote:
Original post by b3rs3rk
EDIT: what tag should i use to post screenshots?!?!?!? o_O


A normal HTML tag;
Screenshot 1 Remove the ! at first, which makes it:
Screenshot 1
Killers don't end up in jailThey end up on a high-score!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.