Sign in to follow this  
SaTANO

deferred shadow maps

Recommended Posts

[font="arial, verdana, tahoma, sans-serif"][size="2"][font="arial, verdana, tahoma, sans-serif"][size="2"]
[font="arial, verdana, tahoma, sans-serif"][size="2"][size="2"][font="arial, verdana, tahoma, sans-serif"][size="2"][font="arial, verdana, tahoma, sans-serif"][size="2"][size="2"][font="arial, verdana, tahoma, sans-serif"][size="2"][font="arial, verdana, tahoma, sans-serif"][size="2"][size="2"]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.

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

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
[/size][/size][/font][font="arial, verdana, tahoma, sans-serif"][size="2"][size="2"][i]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.[/i]

[/size][/size][/font][/size][/font][/size][/size][quote][size="2"][size="2"][font="arial, verdana, tahoma, sans-serif"][size="2"][font="arial, verdana, tahoma, sans-serif"][size="2"][size="2"]ModelMatrix = CameraModelMatrix x CameraProjectionMatrix[sup]-1[/sup] [/size][/size][/font][/size][/font]
[font="arial, verdana, tahoma, sans-serif"][size="2"][size="2"]ViewMatrix = LightModelMatrix[sup]-1[/sup]
ProjectionMatrix = LightProjectionMatrix[/size][/size][/font][/size][/size]
[font="arial, verdana, tahoma, sans-serif"][size="2"][size="2"]
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[/size][/size][/font][/quote][font="arial, verdana, tahoma, sans-serif"][size="2"][size="2"]

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: [url="http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/soft-edged-shadows-r2193"][color="#2810EE"][u]above method[/u][/color][/url]
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.[/size][/size][/font][/font][/size][/font][/size][/size][/font][/size][/font][/size][/font]

Share this post


Link to post
Share on other sites
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).

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this