GLSL ShadowMapping

Started by
-1 comments, last by Geometrian 15 years, 5 months ago
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

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

This topic is closed to new replies.

Advertisement