Hello,
Yes! Once again, a shadow mapping problem! I have search on the forum and google but I don’t find the solution of my problem…
So, I would like to make shadow mapping with the glsl shaders. After somes issues with transformations matrices, now I am sure that the matrices that calculate the shadowmap coordinates are correct.
NB: I don’t forgot to multiply this last matrix by this one:
{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};
In order to have texture coordinates scaled in [0 1] range
But I am not sure that the shadowmap is correctly given to the shader.
This is what I do in the vertex shader to calculate shadowmap texture coordinates:
uniform mat4 LightModelViewProjectionMatrix;
...
ShadowCoord = LightModelViewProjectionMatrix * gl_Vertex;
gl_Position = ftransform();
where LightModelViewProjectionMatrix is the matrice that give the transformations that we have to do if we want to see the scene from the light point of view. This matrice is correct.
then in the fragment shader I do that:
uniform sampler2DShadow ShadowMap;
float shadeFactor;
...
shadeFactor = shadow2DProj(ShadowMap, ShadowCoord).r;
But what I see is an object completly shaded in the scene!
I create the shadowmap in this way:
glActiveTexture( GL_TEXTURE0_ARB );
glEnable(GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, shadowTex);
glCopyTexImage2D (GL_TEXTURE_2D,
0,
GL_DEPTH_COMPONENT,
0,
0,
shadowMapSize,
shadowMapSize,
0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
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);
where shadowtex is a GLuint variable that has been initialized with:
glGenTextures(1, &shadowTex);
At this point depth buffer data should be in the shadowtex texture
Then when I render the scene, I enable this texture to create shadows:
glActiveTexture( GL_TEXTURE0_ARB );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, shadowTex );
glUniform1iARB(ShadowMapLoc, 0);
ShadowMapLoc is the location of the uniform sampler2DShadow ShadowMap variable.
I don’t see where is the problem in this code…but all I see is a completely shadowed scene!
Otherwise, I have tried to do this job with FBO but nothing more, the scene is still entirely shadowed as if the depth buffer texture is entirely black…
here is how I get the depth buffer after the scene has been rendered:
glActiveTexture( GL_TEXTURE0_ARB );
glEnable(GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, shadowTex);
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowMapSize, shadowMapSize,
0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBuffer);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, shadowTex, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
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);
printOglError();
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
I generate shadowTex and frameBuffer like that:
glGenTextures(1, &shadowTex);
glGenFramebuffersEXT(1, &frameBuffer);
I found some pieces of code that explain how to render depth buffer in a texture but it seems to not works in my program…
Thanks a lot for your help.