deferred shadow maps

Started by
0 comments, last by SaTANO 12 years, 6 months ago
[font="arial, verdana, tahoma, sans-serif"][font="arial, verdana, tahoma, sans-serif"]
[font="arial, verdana, tahoma, sans-serif"][font="arial, verdana, tahoma, sans-serif"][font="arial, verdana, tahoma, sans-serif"][font="arial, verdana, tahoma, sans-serif"][font="arial, verdana, tahoma, sans-serif"]Hi everybody

There are some topics in gamedev forum, but none of those describe my situation
After some time of working with matrix stuff I thought I am finally really good in it. Well of course I was wrong.
I was playing a lot with skeletal animations cascaded shadow maps and other stuff which require matrix math, but when I tried do simple shadow mapping deferred using two depth textures I got stuck.

What am I trying to achieve is to make correct shadow mapping using two depth textures (light and camera).

I can represent texture UV as X,Y and value (depth) as Z and that is basically how the shadow mapping works. It is just about moving vector from one space to another, so where is the problem? I've quickly make a formula and generate texture matrix. And guess what. It doesn't work.

My idea of compare was simple
[/font][font="arial, verdana, tahoma, sans-serif"]Data stored in camera depth texture will be used for vertex world position reconstruction.
Grab depth value at UV and generate postion vector with UV*2.0-1.0 (from [0,1] into [-1,1]) and depth. Using inverse camera projection I should get position in camera space so multiplying camera matrix with inverse camera projection multiplied by vertex i should get vertex in world position (modelMatrix * vertex). On the rest I should use basic formula known from camera transformation but instead of camera I will use light.


[/font][/font]
[font="arial, verdana, tahoma, sans-serif"][font="arial, verdana, tahoma, sans-serif"]ModelMatrix = CameraModelMatrix x CameraProjectionMatrix[sup]-1[/sup] [/font][/font]
[font="arial, verdana, tahoma, sans-serif"]ViewMatrix = LightModelMatrix[sup]-1[/sup]
ProjectionMatrix = LightProjectionMatrix[/font]
[font="arial, verdana, tahoma, sans-serif"]
ModelViewMatrix = LightModelMatrix[sup]-1 [/sup]x CameraModelMatrix x CameraProjectionMatrix[sup]-1[/sup]
ModelViewProjectionMatrix = LightProjectionMatrix x LightModelMatrix[sup]-1 [/sup]x CameraModelMatrix x CameraProjectionMatrix[sup]-1[/sup]

VertexCameraSpacePosition = U*2-1,V*2-1,depthFromCameraSpace at UV position
VertexLightSpacePosition = LightProjectionMatrix x LightModelMatrix[sup]-1 [/sup]x CameraModelMatrix x CameraProjectionMatrix[sup]-1[/sup] x VertexCameraSpacePosition

So If I now compare VertexLightSpacePosition.z with depthFromLightSpace (value of depth texture stored form light space) at VertexLightSpacePosition.xy I should know if fragment is in shadow[/font][/quote][font="arial, verdana, tahoma, sans-serif"]

It is not a big deal because I can make correct light shadow texture in forward render, store it (another render target with MRT) and compare/smooth it deferred without need of camera depth texture.
Recently I found this method right here at gamedev: [color="#2810EE"]above method
But I am curious guy so I would like to know how to do the whole process deferred (if there is an easy solution to deal with this).

I am not asking directly for answer, but rather for some resource(I was googling a lot but I didn't find any good resource for deferred shadow mapping).
Of course someone who can describe his solution will be welcome.[/font][/font][/font][/font][/font][/font]
Advertisement
All right I've solve this and the problem was really simple.
Formula for matrix is correct.

I tried to visualize coordinates and found strange issue because one of coordinate was moving in light space. Speed of movement was exactly half of my camera speed so I quickly discovered that problem is bias.
What happened is that after I get depth value from texture I forget to bias it too (depth is stored from 0.0 to 1.0 like other textures and goal is -1.0 to 1.0 like in unit cube).
So after I change this little bug everything works fine.

Main advantage of this approach is that this method is independent on other shaders so I don't need to modify my shaders and I can also process shadows in different resolution (also great for bluring).
What is worse is that this method is much more difficult for fragment so I should watch my fillrate (matrix multiplications, texture lookup for light texture is dependent on texture lookup of scene depth texture).

This whole problem of deferred shadow maps is probably better explained in some deferred shading oriented publication but I really did not found any which explain screen space mapping

This topic is closed to new replies.

Advertisement