Deferred Shadow Mapping

Started by
8 comments, last by snake5 14 years, 6 months ago
Hello!! I am trying to implement shadow maps using the deferred rendering technique and I cant get it to work. The problem is I cant get the shadow coords right. What I'm doing is the following: //d is the pixels depth which I get from depth buffer vec4 p = vec4(gl_TexCoord[0].st * 2.0 - 1.0, d* 2.0 - 1.0, 1.0); vec4 coords = cameraMVPinverse* p; coords.xyz /= coords.w; coords *= lightMVP; coords.xyz /= coords.w; coords = coords * 0.5 + 0.5; Searching the net I found some solutions which pretty much the same as mine. Any ideas?
Advertisement
A screenshot of your problem could help to find out how you can fix it.
Well a screenshot wont help you cause the depth comparison
always fails.
Using incorrect coordinates I get the wrong value from the shadowmap
and that value is always bigger than the coords.z value.
So the result is not affected in any way.
Then at least the full shader code. The comparison always fails but I don't see it here. Don't exclude some parts of the code just because you think that they're not important. I've seen many bugs that hide in the most unexpected places. ;)
float sd = texture2D(shadowMap ,coords.st).z;
float f= sd < coords.z - 0.005? sd: 1.0 ;

this is the comparison.
anyway i'm certain the coords are not right cause at some
point they are greater than 1.0.
I know that caused I check them with an if statement
and at certain angles of the camera If returns true
best bet is to go back and verify all the steps, ie check your correclty reading the shadow map in the correct place by projecting a regular colour texture from the light view using the texture coord your calculating. Then you can verify the projection process is working and the light matrices etc are working correctly..

texture2D(shadowMap ,coords.st).z; what sort of texture / render target are you using here?


Quote:Original post by BlackSeeds
best bet is to go back and verify all the steps, ie check your correclty reading the shadow map in the correct place by projecting a regular colour texture from the light view using the texture coord your calculating. Then you can verify the projection process is working and the light matrices etc are working correctly..

texture2D(shadowMap ,coords.st).z; what sort of texture / render target are you using here?


It is the depth attachment of a framebuffer object i use to render from the light's point of view.
I will check again all steps as you said but I'm not very optimistic about it.
See I have implemented shadow maps before but know I wanna do it the deferred rendering way.
Quote:projecting a regular colour texture from the light view

Projecting the depth texture would be better - 2 tests with one run. (because the depth texture might not have anything in it) :)
Quote:Original post by snake5
Projecting the depth texture would be better - 2 tests with one run. (because the depth texture might not have anything in it) :)


I don't get what you are suggesting. If you are talking about the depth texture of the scene it is not a shadowmap cause it its not rendered from the light's point of view.

Oh, sorry, I forgot that we're dealing with deferred rendering here. I thought the texture to which you draw from the light's point of view - the shadowmap.

This topic is closed to new replies.

Advertisement