Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a 1920x1200 shadowmap which just has the depth values of my scene drawn from the point of view of the light.

I also have a 1920x1200 gbuffer that draws my scene to a fullscreen quad.

How can I sample the shadowmap from the gbuffer lighting phase? What kind of maths needs to be performed? I have access to view space normal and view space position.

share|improve this question
1  
Why are you rendering a 1920x1200 shadow map? Your shadow map isn't in screen space; it's in light space. –  Nicol Bolas Apr 13 '12 at 1:46
    
Dont know, its just for schoolwork I don't really care about performance. –  Dave Apr 13 '12 at 21:36
    
It's not a question of performance so much as quality. –  Nicol Bolas Apr 13 '12 at 21:52
    
What should I set it to for better quality? I assumed that the larger the better. –  Dave Apr 13 '12 at 22:39
    
My point is that the shadow map's size doesn't need to be the same size as the screen. You can make it bigger, smaller, whatever you feel works best. –  Nicol Bolas Apr 13 '12 at 22:41

1 Answer 1

Once you have the position of the shaded point, it's just the same as applying a shadow map in regular forward lighting. You need to convert the shaded point to shadow map screen space, which means getting its world position and then transforming it through the same view and projection matrices used to render the shadow map. You can bake all down into one 4x4 "view space to shadow" matrix that you pass in to your lighting shader.

Then once you have the point in shadow map space, do a texture lookup with comparison mode enabled, as usual for shadow maps.

share|improve this answer
    
Your the best! Helping newbies like that, You should be rewarded for your efforts. I managed to get it working, no matter what text I read it was unclear until I read your simple answer here. –  Dave Apr 13 '12 at 21:35
    
Question: In the forward rendering setup, it was enough to do this transformation in the vertex shader and hand the pixel shader a set of interpolated texture lookup coordinates. It looks to me though like I have to do this transformation per-pixel in deferred rendering because the coordinates that I need are inside a texture that I can only access in the fragment shader. Is there a way around that? –  TravisG Aug 16 '13 at 15:27
    
@TravisG Sort of. You can do most of the transformation in the vertex shader, and all the fragment shader has to do is convert the depth buffer to linear and do a mad to get the final position. Matt Pettineo has a blog post on the subject: Position From Depth. –  Nathan Reed Aug 16 '13 at 16:42
    
@NathanReed thanks. –  TravisG Aug 16 '13 at 17:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.