Hi RocketTree, Thanks for replying to my thread...
http://www.gamedev.net/community/forums/topic.asp?topic_id=388043
I have changed my code:
OpenGL depth map initiation:
glGenTextures(1, &shadowMapTexture); glBindTexture(GL_TEXTURE_2D, shadowMapTexture); glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16_ARB, shadowMapSize, shadowMapSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL ); glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB,GL_INTENSITY); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glActiveTextureARB(GL_TEXTURE4_ARB); glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);
Main rendering:
void ShadowMap::drawMap(){ glEnable(GL_TEXTURE_2D); // First pass - from light's point of view renderShadowMap(); cgGLEnableProfile(cgVertexProfile); cgGLBindProgram(cgVertexShader); cgGLEnableProfile(cgFragmentProfile); cgGLBindProgram(cgFragmentShader); // Second pass - from camera's point of view renderFromCamera(); glDisable(GL_TEXTURE_2D); angle +=1.0; cgGLDisableTextureParameter(cgShadowMap); cgGLDisableProfile(cgVertexProfile); cgGLDisableProfile(cgFragmentProfile);}void renderShadowMap(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDepthFunc(GL_LEQUAL); glMatrixMode(GL_PROJECTION); glLoadMatrixf(lightProjectionMatrix); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(lightViewMatrix); glViewport(0, 0, shadowMapSize, shadowMapSize); glCullFace(GL_FRONT); glShadeModel(GL_FLAT); glColorMask(0, 0, 0, 0); //glFrontFace(GL_CW); glEnable(GL_CULL_FACE); RenderWorld(update); glBindTexture(GL_TEXTURE_2D, shadowMapTexture); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowMapSize, shadowMapSize); //restore states glCullFace(GL_BACK); glShadeModel(GL_SMOOTH); glColorMask(1, 1, 1, 1);}void renderFromCamera(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadMatrixf(cameraProjectionMatrix); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(cameraViewMatrix); glViewport(0, 0, 640, 480); 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); 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); textureMatrix = biasMatrix*lightProjectionMatrix*lightViewMatrix ; glMatrixMode(GL_TEXTURE); glLoadMatrixf(textureMatrix); RenderWorld(update2);void update(){}void update2(){ cgGLSetStateMatrixParameter(cgTextureMatrix, CG_GL_TEXTURE_MATRIX, CG_GL_MATRIX_IDENTITY); cgGLSetStateMatrixParameter(cgModelViewProj, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); cgGLSetTextureParameter(cgShadowMap,shadowMapTexture); cgGLEnableTextureParameter(cgShadowMap);}
The current results:
The scene as it should look like without shadows:
But this is what I get with shadows turned on:
Looks to me like the shadow is being projected but the actual scene is not there and being projected correctly and I can't for the life of me figure out what I have done wrong in the setting up of texture matrix... so is it possible for you to check where I have gone wrong?...I mean if it is not too much trouble...or show me your implementation of the shadow map... just the relevant bits? I would'nt normally ask this kind of thing but it is just driving me nuts and I have spent about 4 days on this with no improvement... I would really appreciate any help you can give.
Thank you