Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Deferred Shadow Mapping (another one)

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    4

    Deferred Shadow Mapping (another one)

    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:

    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:
    Code :
    		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:
    Code :
    		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:
    Code :
    		m_ShadowMVProjection = m_pCameraProjection->GetProjectionMatrix ( ) * m_pCameraProjection->GetViewMatrix ( );

    https://www.dropbox.com/s/vctk4f8vm7...dows_issue.jpg

    Cheers
    Last edited by manum3d; 07-02-2013 at 05:18 AM. Reason: Fixed copy and paste mistake

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,129
    Code :
     m_ShadowMVProjection = m_pCameraProjection->GetViewMatrix ( ) * m_pCameraProjection->GetProjectionMatrix ( );

    This is the wrong order. Don't get confused by the order of words in [model-]view-projection matrix. The correct order of matrices to calculate a final transformation matrix T = M_Proj * M_View [* M_Model].

    With T, you express a transformation from object- to world- (if any), then from world- to eye- and finally, from eye- to clip-space.

    Other than that, your shader seems ok at first sight.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    4
    Quote Originally Posted by thokra View Post
    Code :
     m_ShadowMVProjection = m_pCameraProjection->GetViewMatrix ( ) * m_pCameraProjection->GetProjectionMatrix ( );

    This is the wrong order. Don't get confused by the order of words in [model-]view-projection matrix. The correct order of matrices to calculate a final transformation matrix T = M_Proj * M_View [* M_Model].

    With T, you express a transformation from object- to world- (if any), then from world- to eye- and finally, from eye- to clip-space.

    Other than that, your shader seems ok at first sight.
    Sorry thokra, I copy and paste in the wrong order.. that was my mistake, nevertheless yeah I do have:

    First: MVP = Projection * ModelView;
    then I do for every object in the scene: MVP * ModelMatrix which I pass to the shader...

    So the funny thing is, I have tried lot of different ways and I can not find where the mistake is, I have compared line by line with other approaches like:

    www.data.redplant.de/webgl/deferred/spot/
    http://www.codinglabs.net/tutorial_o...w_mapping.aspx
    http://www.neuroproductions.be/openg...ing-and-stuff/ (actually this one for calculating the shadowProjection does ModelInv * LightViewMatrix * LightProjectionMatrix)

    I don't know if it is a stupid mistake that I am having... or what... any other idea ?

    Thanks

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,129
    I can't see anything either atm. What I do see is that the arcs are being rendered, the pillars, however, are not. Can you post a screenshot of your depth buffer?

    In any case, when dealing with shadow mapping, always check your depth buffer for correctness. If you've got nonsense in there, even the coolest algorithm won't give you plausible results.

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    4
    Hey thokra, Thank you for your quick answer, I have made a screenshot where you can see the pillars too, also to mention that the shadow moves when you move the camera which I think it shouldn't do. Here is the link for that.
    https://www.dropbox.com/s/rl1jd9kiv5...ow_compare.jpg

    Here is the depth buffer from the camera (left) and from the light source (right), also I have tweak the levels in photoshop to make it more visible (which are the bottom ones).
    https://www.dropbox.com/s/7uv2xwd3zhdk3kn/depth.jpg

    I have made one screenshot from the position buffer (posVS variable) just in case.
    https://www.dropbox.com/s/merrmlq3oyjlh2s/position.jpg

    Again thank you for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •