I am trying to implement shadows with cubemaps but I ran into some problems. I put up the code, some screens and a little movie to show you what I mean. I have removed textures etc to minimize the code. Available here:

http://www.falksdomain.com/filedepot/Demo/

The first problem is shown in pointlight_Error2.jpg. Every object that I draw gets drawn half in black and half in white?

Another problem is shown in Pointligt_Error1.jpg. Whenever shadows cast on the floor, the shadow
disappears depending on the rotation of the object. But when shadows cast on any other side of the room it works fine. The movie shows this better. The red cube is the cubemap.

When I draw the cubemap I use Distance.vert and Distance.frag to draw the square distance. And then Shadows.vert/Shadows.frag to draw with lighting and shadows. GL_RGB16F_ARB is used as internal format of cubemap texture.

Any help is appreciated! :-)

Thanks in advance
Twooie

Komat

09-06-2006, 12:19 PM

You are using incorrect space to calculate the cubemap lookups and lighting. The light position and camera positions appear to be in world space yet the shaders use them as if they were in object space and then use the result to access world space aligned cube.

k_szczech

09-06-2006, 12:37 PM

This is also most likely the reason for holes in shadows - seems like you misunderstood gl_Vertex - this is exactly what you pass from application when you call glVertex - it's not yet affected by any matrix. You need to transform it by modelview matrix before you compute distance.

Twooie

09-07-2006, 03:14 AM

Thanks for pointing this out to me! I have a hard time understanding all these spaces. I seem to mix them together. There is camera space, world space, eye space (maybe the same as camera space?), object space, texture space etc.

If you know any tutorials and/or images to show the different spaces it would be great. Cause sometimes I think I understand but then it turns out I don't..

Thanks again!

Twooie

09-09-2006, 06:57 AM

I've done the lighting in world space now (since cubemap is world space aligned) as you guys said. Or at least I think I did because there is still problems, but the lighting seems to work now (if I remove shadows).

I put up another video and code to show you what I mean:

http://www.falksdomain.com/filedepot/Demo/Error2/

When multiplying gl_Vertex with modelview matrix it gets in eye space. So I stored the inverse view matrix in the texture matrix. And multiply the eye space vertex with that to get back to world space.

Everything works fine if I move the camera to the lights position? As you can see in the video the shadows are working when doing that, even on the bottom face which was the problem in my first post. Do you know what I'm doing wrong here? Probably a lot ;-)

Thanks
Twooie

Komat

09-09-2006, 08:09 AM

You store the inverse of the view matrix only during the shadow application. When you render individual faces of the cube, you do not set the correct inverses of appropriate view matrices so world space coordinates used to calculate distances inside the shadowmap are calculated incorrectly.

Twooie

09-09-2006, 08:26 AM

Yes that was it! It works now, thanks a lot Komat. I should have thought of that ;-)

flamz

09-11-2006, 08:38 AM

I tried implementing your code on my Quadro FX 4000 but the driver is complaining that it's using an unsupported format.. :(