Jump to content
  • Advertisement
Sign in to follow this  
Rozen

Shadow map problem

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

If you intended to correct an error in the post then please contact us.

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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!