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: GLSL shadow mapping problem

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    11

    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

    Code :
    		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
    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
    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

  2. #2
    Member Regular Contributor DmitryM's Avatar
    Join Date
    Mar 2009
    Location
    Toronto
    Posts
    436

    Re: GLSL shadow mapping problem

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

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    11

    Re: GLSL shadow mapping problem

    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

    Code :
    	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);

  4. #4
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: GLSL shadow mapping problem

    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.

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    11

    Re: GLSL shadow mapping problem

    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.

Posting Permissions

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