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:

	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 ( );

Cheers

 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.

[QUOTE=thokra;1252316]

 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.[/QUOTE]

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/
www.codinglabs.net/tutorial_opengl_deferred_rendering_shadow_mapping.aspx
www.neuroproductions.be/opengl/making-a-3d-game-with-opengl-deferred-shading-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

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.

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.

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).

I have made one screenshot from the position buffer (posVS variable) just in case.

Again thank you for your help