Shadowmapping with weird results

Hello,

I’m currently trying to implement ShadowMapping after reading a while about it and following this tutorial, working my best on it to no avail.

The rendering from the light source point of view:

And the depth map from the lightsource perspective

I’m the using the following method:

#1 set the lightsource as the view source
#2 render the depth map from the light source point for the scene using a simple shader:

void main(void){	
	gl_Position = modelViewProjMat * vertexPos;
}

#3 set the camera as the view source
#4 render all the scene with the following shader:

VERTEX

void main(void){
	gl_Position = modelViewProjMat * vertexPos;
	vPosLight   = (light_viewProjMat * modelMat) * vertexPos;
	
	vPos   = vec3(modelViewMat * vert);
	vNor   = vec3(normalize(normalMat * normal));
	vTex   = texCoord;
}

FRAGMENT

float shadow_calc(){
	vec3 pos     = vPosLight.xyz * 0.5f + 0.5f;
	float depth  = texture(textureDepth, pos.xy).r;
	float shadow = depth < pos.z ? 0.0 : 0.5;
    return shadow;
} 

light_viewProjMat: the lightsource view matrix x lightsource projection matrix
modelViewMat: the camerasource view matrix x camerasource projection matrix

and this is the result I’m having:

a comb-like effect, that repeats itself over to the sides of the light source’s point of view, if I set the lightsource on top, pointing down, this is what I get:

I can’t figure whats wrong with it, although I’m a bit skeptical regarding these calculations

any tips are appreciated,

Regards,
Jakes

What do you have your texture wrap modes set to for S and T (i.e. GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T)?

If not GL_CLAMP_TO_EDGE, try that as a test.

Keep in mind though that sampling outside of the bounds of the shadow map is meaningless. You have no data there.

Found it, while rearranging the code I must’ve dropped the binding of the texture, and it was sampling from an empty texture.

Took me 2 days over this…

Thanks anyway, I appreciate it.