Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


shadowmapping don't work


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 dreamjourney   Members   -  Reputation: 111

Like
0Likes
Like

Posted 08 July 2014 - 03:32 PM

hello guys,

 

i follow the shadow mapping tutorial of opengl, but i got some werid image, why the depth projected on the model like this?

 

111.png

 

 

the second problems is the projected texture matrix, i use the left hand coordinate,  in some tutorial the matrix is like this

 
[ 0.5f, 0.0f, 0.0f, 0.5f ]
0.0f, 0.5f, 0.0f, 0.5f ]
0.0f, 0.0f, 0.5f, 0.5f ]
0.0f, 0.0f, 0.0f, 1.0f ]
 

some are this,  

[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]
 

so i  am confused which one is the correct one,

 

 

thanks in advance!



Sponsor:

#2 HappyCoder   Members   -  Reputation: 2843

Like
3Likes
Like

Posted 08 July 2014 - 04:26 PM

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.



#3 dreamjourney   Members   -  Reputation: 111

Like
0Likes
Like

Posted 09 July 2014 - 12:52 AM

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

glGenTextures(1, &mTex);
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;
if (useZCompare)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
}
else
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
}
 
glsl code
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.


#4 Ashaman73   Crossbones+   -  Reputation: 7876

Like
1Likes
Like

Posted 09 July 2014 - 05:27 AM

You have encountered one of the many shadowmapping artifacts. Here's an article about this and some other issues with shadowmapping and how to counter them, thought there will be never a perfect  and simple solution.



#5 dreamjourney   Members   -  Reputation: 111

Like
0Likes
Like

Posted 09 July 2014 - 05:36 AM

You have encountered one of the many shadowmapping artifacts. Here's an article about this and some other issues with shadowmapping and how to counter them, thought there will be never a perfect  and simple solution.

 i have solved this artifacts by using

glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);

thanks to both of you

@HappyCoder   @Ashaman73


Edited by dreamjourney, 09 July 2014 - 05:36 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS