Sign in to follow this  
Rozen

Shadow map problem

Recommended Posts

Hi, I am developing a game with shadow map algorithm but the result of shadows doesn't look good. I still cannot handle with the artifacts on the back side of the models. My decisive rendering routine is presented below. Can someone point me in the right direction ? Thank you. glDisable(GL_LIGHTING); //Rendering from the light view glMatrixMode(GL_PROJECTION); glLoadMatrixf(lightProjectionMatrix); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(lightViewMatrix); glViewport(0, 0, shadow_map_size, shadow_map_size); glEnable(GL_CULL_FACE) glCullFace(GL_FRONT); glShadeModel(GL_FLAT); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glDisable(GL_COLOR_MATERIAL); glDisable(GL_NORMALIZE); glDisable(GL_TEXTURE_2D); //I could only eliminated very bad artifacts from the scene //but other values don't make any differences then glPolygonOffset(8.0f, 4.0f); glEnable(GL_POLYGON_OFFSET_FILL); Octree.DrawOctree(&Octree,Frustum); RenderFigures(false,false,true); glBindTexture(GL_TEXTURE_2D, shadow_tex); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadow_map_size,shadow_map_size); glClear(GL_DEPTH_BUFFER_BIT); glDisable(GL_POLYGON_OFFSET_FILL); glCullFace(GL_BACK); glShadeModel(GL_SMOOTH); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glShadeModel(GL_SMOOTH); glEnable(GL_NORMALIZE); //Rendering from camera view glMatrixMode(GL_PROJECTION); glLoadMatrixf(cameraProjectionMatrix); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(cameraViewMatrix); glViewport(0, 0, width, height); GLfloat light_position[]={LightPos.x,LightPos.y,LightPos.z,1.0f}; glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_AMBIENT, black); glLightfv(GL_LIGHT0, GL_DIFFUSE, black); glLightfv(GL_LIGHT0, GL_SPECULAR, black); glEnable(GL_LIGHTING); Octree.DrawOctree(&Octree,Frustum); RenderFigures(false,false); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_color_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_color_specular); glLightfv(GL_LIGHT0, GL_AMBIENT, light_color_ambient); static MATRIX4X4 biasMatrix(0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 0.5f, 0.5f, 1.0f); MATRIX4X4 textureMatrix=biasMatrix*lightProjectionMatrix*lightViewMatrix; //Shadow texture GLExt->glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, shadow_tex); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGenfv(GL_S, GL_EYE_PLANE, textureMatrix.GetRow(0)); glEnable(GL_TEXTURE_GEN_S); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGenfv(GL_T, GL_EYE_PLANE, textureMatrix.GetRow(1)); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGenfv(GL_R, GL_EYE_PLANE, textureMatrix.GetRow(2)); glEnable(GL_TEXTURE_GEN_R); glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGenfv(GL_Q, GL_EYE_PLANE, textureMatrix.GetRow(3)); glEnable(GL_TEXTURE_GEN_Q); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL); glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY); glAlphaFunc(GL_GEQUAL, 0.99f); glEnable(GL_ALPHA_TEST); GLExt->glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,Ground->GetTextureObject(0)->Texture->texid); Octree.DrawOctree(&Octree,Frustum); RenderFigures(false,true); GLExt->glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glDisable(GL_TEXTURE_GEN_R); glDisable(GL_TEXTURE_GEN_Q); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_COMPARE_MODE_ARB,GL_NONE); glDisable(GL_LIGHTING); glDisable(GL_ALPHA_TEST); GLExt->glActiveTextureARB(GL_TEXTURE0_ARB); [Edited by - Rozen on September 6, 2006 3:14:39 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this