Ok, I have shadow mapping working perfectly using the fixed-function pipeline. I use glTexGen with GL_EYE_LINEAR on GL_S, GL_T, GL_R, GL_Q, etc… Only problem is though, that to use shaders, I have to do shadow mapping in the shader as well.

I think I’ve officially found and tried every single GLSL shadow mapping tutorial and code bit that can be found online. And the ones I could get to work, all end up having the same issue: my shadows aren’t projected correctly.

The following is a simple scene using plain opengl without any shaders:

It works great.

The following is the same scene rendered using the shadow mapping shaders from the opengl orange book:

I haven’t blended anything with the base textures yet, since I want to solve the shadow mapping problem first. But, as you can see, the shadows aren’t being projected properly. And I’ve run into this same projection problem with every other GLSL shadow mapping shader I’ve gotten to “work.”

My guess is that it has something to do with how I’m setting up and creating the shadow map texture, but I fail to see why my method would work with the plain-opengl method and not a shader method? I’ve tried fiddling with my light’s matrices and perspective without any luck so far. About the only thing I haven’t been able to try is a non-power-of-two texture for the shadowmap to match the screen resolution (when I try that, my machine just freezes for some reason). Still, I don’t understand why it works fine when not using shaders.

Any ideas? Code examples? A possible tutorial I haven’t found yet?

ANY help is greatly appreciated! I’ve been stuck on this for a while now.

For an update (and a shameless bump), I’ve noticed that when moving the walls and other objects in the scene, the shadows don’t change on the object. It appears that the shadowmap is being mapped to each object individually.

Also, for reference, here is the shader code I’m using (it’s right out of the Orange Book):

Yes, I’ve used that tutorial (and it’s a great tutorial), but I still get the same problem. That’s why I’m thinking I’m either doing something wrong on my end (I’m converting the tutorial over to Java in order to use it), or maybe there’s something wrong with my hardware setup I suppose.

For reference, I’m on a Mac Pro with an ATI 1900.

I also tried removing the divide by w line in the shader, but I get the exact same outcome as before. Is it possible that the shader isn’t actually picking up the texturematrix from the pipeline correctly? Maybe I’ll try passing it in manually and see what happens.

You could use glGetTexImage to download the shadow map from the GPU to the CPU and compare what you have in your 2 approaches. This would at least tell you if the problem is with the shadow generation or the application.

I’m not sure if that would help actually. Both versions use the same code base to generate the initial shadow map. I’m pretty sure it has to do with mapping that texture. In the fixed-function-pipeline version I use GL_EYE_PLANE with glTexGen (for s,t,r, and q) to create the coordinates. When I use the shader, I just don’t get the same result for some reason; the texture updates properly, but the way it’s mapped onto objects stays static even if the objects move around.

Also, as an update, I tried passing the texture matrix into the shader via a uniform, but it didn’t change anything.

And now that I just posted that… I realized somewhere the problem might be!! The shader doesn’t seem to realize where the objects are located! It’s mapping everything as if it were at the origin!!! So how do I update the proper texture matrix with object locations?