GLSL shadow mapping problem

hi
i am trying to apply shadow mapping on the scene using glsl. but scene looks weird. there is no problem depth texture calculating because i tested it on the full screen quad. my code is below


		glActiveTexture(GL_TEXTURE1);
			glBindTexture(GL_TEXTURE_2D, depthTexture);
			glMatrixMode(GL_TEXTURE);
			glLoadIdentity();
			glTranslatef(0.5f, 0.5f, 0.5f);
			glScalef(0.5f, 0.5f, 0.5f);
			glMultMatrixf(lproj); // light projection matrix
			glMultMatrixf(lview); // light view matrix
			glMultMatrixf(invView.m); // inverse view matrix

vertex shader code


varying vec4 shadowCoord;
varying vec4 texCoord;

void main()
{
gl_Position = ftransform();
vec4 pos = gl_ModelViewMatrix * gl_Vertex;
texCoord = gl_TextureMatrix[0] * gl_MultiTexCoord0;
shadowCoord = gl_TextureMatrix[1] * pos;
}

fragment shader code


varying vec4 shadowCoord;
varying vec4 texCoord;
uniform sampler2D diffuseTexture;
uniform sampler2D depthTexture;

void main()
{
vec4 color = texture2D(diffuseTexture, texCoord.xy);
float shadowFactor = texture2DProj(depthTexture, shadowCoord).r;		
gl_FragColor = color * shadowFactor ;
}

what i made wrong. thanks in advence

I don’t see where you are comparing the actual depth value with the one stored in the shadow texture.

Thank you DmitryM for interest. i resolved the problem. now my problem is how i can get rid of shadow acne on back face surface. i am forming depth texture from light point of view with front face culling enabled but this doesn’t solve problem.
output screen :

first render pass point of light view


	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
		glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
		glMatrixMode(GL_PROJECTION);
			glPushMatrix();
			glLoadIdentity();
			gluPerspective(60, 1, 2, 40);
			glGetFloatv(GL_PROJECTION_MATRIX, lproj);
		glMatrixMode(GL_MODELVIEW);
			glPushMatrix();
			glLoadIdentity();
			gluLookAt(light1Pos.v[0], light1Pos.v[1], light1Pos.v[2], 0,0,0,0,1,0);	
			glGetFloatv(GL_MODELVIEW_MATRIX, lview);


	glEnable(GL_CULL_FACE);
	glCullFace(GL_FRONT);

		glPushMatrix();
			floor();
		glPopMatrix();

		glPushMatrix();
			glTranslatef(-3,2,0);
			box1();
		glPopMatrix();

		glPushMatrix();
			glTranslatef(5,3,0);
			box2();
		glPopMatrix();

	glDisable(GL_CULL_FACE);

	glBindFramebuffer(GL_FRAMEBUFFER, 0);


In the shadow compare step of the shader are you adding a small offset to the z component of the texture coordinate ?
This should help remove the surface acne.

Thanks you BionicBytes. shadow mapping acne problem was solved by enabling front face culling and enabling polygon offset the way you said.
have a good day.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.