Jump to content
  • Advertisement
Sign in to follow this  
Geometrian

GLSL ShadowMapping

This topic is 3672 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm trying to get GLSL shadowmapping working. I've made functions so that they wouldn't clutter the main. I believe the problem is in the texture matrix projecting. Here's the draw part of the main:
glLibUseShader(BlankShader)

#Clears color/depth buffers, resets matrix
Window.clear()
#Set the view from the light's point of view.
LightView.set_view()
gluLookAt(0,100,0,
          0,0,-4,
          0.0,1.0,0.0)

#Self-explanatory
DrawTeapot()
DrawFloor()

#Not quite sure if this is right.  I'll provide function later.
projmat = glLibShadowGetProjMat([0,100,0],[0,0,-4],5,96,102)
#Render scene to a depth texture.  I've tested this, and I'm sure it works.
depthmap = glLibSceneToDepthMap(512,depthmap)

#Clear window again
Window.clear()
#Set the camera's view (no call to gluLookAt() because camera at origin).
View3D.set_view()

glLightfv(GL_LIGHT0,GL_POSITION,[0,100,0,1.0])

glLibUseShader(ShadowShader)
ShadowShader.pass_shadow_texture(depthmap)

#Not entirely sure about these either.
glMatrixMode(GL_TEXTURE)
glLoadMatrixf(projmat)

DrawTeapot()
DrawFloor()

Here's where the texture matrix is projected:
def glLibShadowGetProjMat(lightpos,center,angle,near,far):
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluPerspective(angle,1.0,near,far)
    LightProjectionMatrix = glGetFloatv(GL_PROJECTION_MATRIX)
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
    gluLookAt(lightpos[0],lightpos[1],lightpos[2],
              center[0],center[1],center[2],
              0.0,1.0,0.0)
    
    LightViewMatrix = glGetFloatv(GL_MODELVIEW_MATRIX)

    glMatrixMode(GL_TEXTURE)
    glPushMatrix()
    glLoadMatrixf([[0.5,0.0,0.0,0.0],
                   [0.0,0.5,0.0,0.0],
                   [0.0,0.0,0.5,0.0],
                   [0.5,0.5,0.5,1.0]])
    glMultMatrixf(LightProjectionMatrix)
    glMultMatrixf(LightViewMatrix)
    TextureMatrix = glGetFloatv(GL_TEXTURE_MATRIX)
    glPopMatrix()
    return TextureMatrix

Finally, the relevant parts of the shaders:
//RELEVANT VERTEX SHADER SECTION
ProjCoord = gl_TextureMatrix[0]*(gl_ModelViewMatrix*gl_Vertex);
//ProjCoord is then sent to the fragment shader.

//RELEVANT FRAGMENT SHADER SECTION

//color created, set by a phong lighting model here

float rValue = shadow2DProj(shadtex1,ProjCoord).r + 0.3;
rValue = clamp(rValue, 0.0, 1.0);

vec3 CoordPos = ProjCoord.xyz / ProjCoord.w;

if(CoordPos.x>=0.0 && CoordPos.y>=0.0 && CoordPos.x<=1.0 && CoordPos.y<=1.0) {
    color *= rValue;
}

All this doesn't work, though. Strangely, I don't see the teapot object at all (should be about mid-screen here). I do however see the floor (gold on the bottom), which isn't entirely blank. I see a ghost image of the teapot on it, which looks like someone took the depth texture, and combined it with the floor material: Ghost Teapot on Floor Please help me fix this! Thanks, Geometrian

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!