manum3d

07-01-2013, 04:42 PM

Hello there I have some troubles when doing deferred shadow mapping, I have tried so many different aproches and this is the best I can get (using this http :// data.redplant. de/webgl/deferred/spot/), nevertheless still not good enought. And as this is getting really depresing I am coming here asking for some help. I have here all the breaking down of what I am doing and a picture with the final result. I would be so greatfully if someone could give me a hand with this as I am really stragling.Hello there I have some troubles when doing deferred shadow mapping, I have tried so many different approaches and this is the best I can get, nevertheless still not good enought. And as this is getting really depressing I am coming here asking for some help. Here is all the code related to what I am doing and a picture with the final result. I would be so gratefully if someone could give me a hand with this as I am really struggling.

GLSL Shader code:

float z = texture2D(DepthBuffer, vTexCoord).x;

float x = vTexCoord.x * 2.0 - 1.0;

float y = vTexCoord.y * 2.0 - 1.0;

vec4 projectedPos = vec4(x, y, z, 1.0);

vec4 posVS = camera.ProjectionInv * projectedPos;

posVS.xyz /= posVS.w;

posVS.w = 1.0;

vec4 posWS = camera.ModelViewInv * posVS;

vec4 posLightCS = light.ShadowProjection * posWS;

vec2 shadowCoord = (posLightCS.xy / posLightCS.w) * 0.5 + 0.5;

float shadow = texture2D( ShadowMap, shadowCoord).x;

float occlusion = 1.0;

if((posLightCS.z / posLightCS.w) > shadow) occlusion = 0.5;

gBuffer_lighting = vec4(worldNormals.xyz * occlusion, 1.0 );

Matrices:

camera.ProjectionInv is calculated like so:

m_ProjectionMatrix = glm::perspective ( m_Fov, (float) width / (float) height, m_NearClip, m_FarClip );

m_ProjectionInvMatrix = glm::inverse ( m_ProjectionMatrix );

camera.ModelViewInv is calculated like so:

m_ModelViewMatrix = glm::lookAt ( GetPosition ( ), GetPosition ( ) + GetOrientation ( ), glm::vec3 ( 0.f, 1.f, 0.f ));

m_ModelViewInvMatrix = glm::inverse ( m_ModelViewMatrix );

light.ShadowProjection is calculated like so:

m_ShadowMVProjection = m_pCameraProjection->GetProjectionMatrix ( ) * m_pCameraProjection->GetViewMatrix ( );

https://www.dropbox.com/s/vctk4f8vm7ocp0r/shadows_issue.jpg

Cheers

GLSL Shader code:

float z = texture2D(DepthBuffer, vTexCoord).x;

float x = vTexCoord.x * 2.0 - 1.0;

float y = vTexCoord.y * 2.0 - 1.0;

vec4 projectedPos = vec4(x, y, z, 1.0);

vec4 posVS = camera.ProjectionInv * projectedPos;

posVS.xyz /= posVS.w;

posVS.w = 1.0;

vec4 posWS = camera.ModelViewInv * posVS;

vec4 posLightCS = light.ShadowProjection * posWS;

vec2 shadowCoord = (posLightCS.xy / posLightCS.w) * 0.5 + 0.5;

float shadow = texture2D( ShadowMap, shadowCoord).x;

float occlusion = 1.0;

if((posLightCS.z / posLightCS.w) > shadow) occlusion = 0.5;

gBuffer_lighting = vec4(worldNormals.xyz * occlusion, 1.0 );

Matrices:

camera.ProjectionInv is calculated like so:

m_ProjectionMatrix = glm::perspective ( m_Fov, (float) width / (float) height, m_NearClip, m_FarClip );

m_ProjectionInvMatrix = glm::inverse ( m_ProjectionMatrix );

camera.ModelViewInv is calculated like so:

m_ModelViewMatrix = glm::lookAt ( GetPosition ( ), GetPosition ( ) + GetOrientation ( ), glm::vec3 ( 0.f, 1.f, 0.f ));

m_ModelViewInvMatrix = glm::inverse ( m_ModelViewMatrix );

light.ShadowProjection is calculated like so:

m_ShadowMVProjection = m_pCameraProjection->GetProjectionMatrix ( ) * m_pCameraProjection->GetViewMatrix ( );

https://www.dropbox.com/s/vctk4f8vm7ocp0r/shadows_issue.jpg

Cheers