The pattern you see is due to a loss of precision in the z buffer. The problem comes from when you compare the distance to a light against the distance stored in the shadow map. When calculating these two separate values, there are some rounding errors. So even though the values should come out equal in theory, in practice they rarely are equal. To fix this you need to add some sort of bias where you add a small amount to the distance read from the shadow map.
As for the matrices, both are correct. The first one you listed is the column vector version of the matrix. The second is the row vector form. For any given graphics engine you should pick one style and stick with it.
hi happycoder, thanks for your reply~ its really helpful.
i'am using the auto z compare feature with GL_COMPARE_R_TO_TEXTURE flag
glBindTexture (GL_TEXTURE_2D, mTex);
glTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, mSize, mSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
bool uUseZCompare = true;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
uniform sampler2DShadow uShadowMapTex;
float shadow = shadow2DProj(uShadowMapTex, vProjTexCoord).x;
gl_FragColor = textureColor * shadow;
const glm::mat4 PROJ_MATRIX = glm::mat4(
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);
i'am current use texturematrix with PROJ_MATRIX * cropMatrix * LightProjectionMatrix * LightViewMatrix to project the pos to texture coord
the problems is , where can i add "some sort of bias" as you said, looking forward of your replys, thanks.
Edited by dreamjourney, 09 July 2014 - 12:55 AM.