DirectX 9 : shadow mapping problem

Started by
12 comments, last by Dawoodoz 12 years, 8 months ago

ShadowOffset is what we sometimes call "epsilon" ? The value to correct the imprecision of floats ?
CameraSpace is in fact the depth of the scene ? (just to be sure :P)


Yes, shadow offset / bias / epsilon.

CameraSpace.z is linear depth in the light source's orthogonal camera space.
Advertisement

[quote name='blueShadow' timestamp='1313321970' post='4848925']
ShadowOffset is what we sometimes call "epsilon" ? The value to correct the imprecision of floats ?
CameraSpace is in fact the depth of the scene ? (just to be sure :P)


Yes, shadow offset / bias / epsilon.

CameraSpace.z is linear depth in the light source's orthogonal camera space.
[/quote]

Ok thanks for your infos :)



[quote name='Tom KQT' timestamp='1313316551' post='4848907']
[quote name='blueShadow' timestamp='1313305751' post='4848875']
i use :


D3DXMatrixOrthoLH( &lightWVProjMatrix, 512.0f, 512.0f, 1.0f, 1000.0f );



Should I use what you told me ?
Can you explain me a little more the code you wrote ? I have problems to understand what are the variables.


What scale does your scene have? I mean how large is the car - 0.1 units or 1 unit or 10 units or 100 units...?
My point is that you should set your shadow camera as tightly around the scene as you can, especially the near and far planes, because that will limit your shadow precision and can lead to really strange behaviour in extreme cases.
[/quote]

I reduced the values to fit correctly to the car :

D3DXMatrixOrthoLH( &lightWVProjMatrix, 32.0f, 32.0f, 20.0f, 700.0f )

But now the orientation is still not correct :( and the shadow is duplicated sad.gif The width of my car is of 5 units like say 3ds max but when i put these values, the car fits in width the shadow map.
Am I doing something wrong in the shaders ?

pixel shader which renders the shadow map (there are questions below):


float4 pixel_main( VSOUTPUT_SHADOW IN ) : COLOR0
{
IN.fDepth.x /= IN.fDepth.y ;// where x is in fact 'z' and y the 'w' coordinate of the position of the pixel in light space, is it right ?? Or am I supposed to divide by the far clip value ?
// Output the scene depth
return float4( IN.fDepth.x, IN.fDepth.x, IN.fDepth.x, 1.0f );
}


[color="#1C2837"][color="#880000"]where x is in fact 'z' and y the 'w' coordinate of the position of the pixel in light space, is it right ?? Or am I supposed to divide by the far clip value ?
[/quote]

[font=arial, verdana, tahoma, sans-serif][size=2]This my current result (to illustrate the message above) : [attachment=4924:bug.png][/font]
Don't add any light when the UV sampling the depth map is out of bound.

Don't add any light when the UV sampling the depth map is out of bound.



What do you mean by don't add any light in this case ?

Pseudo:

SumOfDiffuseLight = AmbientLight
SumOfSpecularLight = Black
For each light {
Measure distance between light source and pixel.
if close enough {
Do matrix inverse by multiplying with the transpose of an orthogonal unprojected 3x3 light space matrix
and handle the position using subtraction to convert the world space position to orthogonal light space.
Divide the sideway coordinates with the slopes and the depth to get the projected UV coordinate.
Lerp the UV to pick the current tile in your depth atlas.
if UV is inside bound {
SumOfDiffuseLight += Diffuse light from phong model
SumOfSpecularLight += Specular light from phong model
}
}
}

This topic is closed to new replies.

Advertisement