Shadow Mapping in OpenGL

Hi, this is a brief explanation of what I’m trying to do:

Some time ago I’ve read about a technique called ‘Projective Shadow Mapping’, and now I’m trying to implement it using OpenGL.

I can render the light view of an object in a 256x256 texture (the shadow map), with glTexSubImage2D etc… that works fine, but when I try to set the texture matrix with the matrix I’ve used to render the shadow map (that’s correct?) to project the shadow map to a wall or some other object, I got very strange ‘projections’…

The shadow map is working as well as the rendering of the shadow on other objects, but I don’t know whats wrong… the projection matrix (texture matrix) used to render the shadow map to an object (to project it to that object) is really the light view matrix? If there’s someone that knows how to do it right (I’m not) please help me…

Thanks…

  • Royconejo.

Sounds like you need to handle the projection matrix and the depth comparision to find if a pixel is in shadow in the light view space-

The best advice is to read the Nvidia tutorials and download their OpenGL sample w/ source. It works quite fine, exposes a 16bpp compare via Register Combiners, and really helps you understand the pros/cons of the method-

Buena Suerte-

I would also encourage you to look at the shadow mapping examples for GeForce3 that use the SGIX_shadow and SGIX_depth_texture extensions. These are much more efficient and higher quality if you have direct hardware support.

A whitepaper on this is coming soon.

Cass

Originally posted by Mahjii:
[b]Sounds like you need to handle the projection matrix and the depth comparision to find if a pixel is in shadow in the light view space-

The best advice is to read the Nvidia tutorials and download their OpenGL sample w/ source. It works quite fine, exposes a 16bpp compare via Register Combiners, and really helps you understand the pros/cons of the method-

Buena Suerte-[/b]

Gracias.

I have every demo and doc. on the nvidia site… The one you are speaking about uses a Zbuffer algorithm, but I’m only trying to project a texture over an object. It’s just a ‘shadow’ texture map, that I have to project… no Zbuffer op. is involved, just the light view of the object, renderer in black, with a white background, and then I only have to project it (using the texture matrix) to some geometry… that’s it.

I think that Quake2/3 uses this technique… (or some less expensive one, but it’s not based on the Zbuffer info).

My problem basically is that I don’t know how to build that projection matrix…

  • Royconejo.

PS: Thanks cass… I’ll use that extensions when I get a GF3.

The texture matrix for the shadow texture should be the light matrix as seen from the current modelview – which is not the same as the projection matrix you used to render the shadow as seen from the light. Uh, if that’s clear, or even correct, it might help :slight_smile:

So… I shoudn’t be using the light view matrix (the matrix I’ve used to render the texture shadow, the ‘point of view of the light’), as the shadow projection?

Could you be more specific? do you have some code or something? sorry but I’m very confused…

Thanks…

  • Royconejo.

There’s a whitepaper on the NVIDIA web site that discusses this. You can find it at:
http://www.nvidia.com/Marketing/Developer/DevRel.nsf/bookmark/BAB26B3133023C2088256A38007DE5E6

I’ll have another specifically on shadow mapping Real Soon.

Thanks -
Cass

Thanks Cass, I’m reading it now…

The problem was that I recently started to use OpenGL, I didn’t even know about texgen…

  • Royconejo.

No tendrás una hermana que se llama vanessa?

Sorry Cass, but I can’t find the ‘projspot’ and ‘qcoord’ demos in the latest nvidia OpenGL sdk, they are really there?

santyhammer: Porque me preguntas eso?

  • Royconejo.

Um, no. They will be in the next rev though. I was expecting it to be out already but it should be this week. In the mean time you can get them from my personal web page http://www.r3.nu/

Thanks -
Cass

Hey Cass.

Your link to etopo5.bin.gz that belongs to the terrain demo does not work.

Hi Cass. I just looked at your web site. I’m interested in taking a look at your “cool shadowing effects” demo but it does not compile correctly for me. The output I get in VC++ 6.0 is:

c:\download\cass\demos
eato\main.cpp(32) : error C2146: syntax error : missing ‘;’ before identifier ‘shadow0’
c:\download\cass\demos
eato\main.cpp(32) : error C2501: ‘texture_env_combine’ : missing storage-class or type specifiers
c:\download\cass\demos
eato\main.cpp(32) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

Basically, things are #ifdef’d such that your texture_env_combine struct isn’t getting declared. I tried taking out the #ifdef’s. This caused it to not recognize your enumerants in that class, so I did a #include <GL/glext.h> at the top of my file (which is on my system). What’s strange is, this didn’t fix the enumerant problem. So now I’m confused…any ideas?

Thanks,

– Zeno

You may want to check to see which glext.h it is pointing to. It should be pointing to the gl/glext.h in the sdk.

Porque yo conocía a una vanessa conejo que fue conmigo al instituto y tenía un hermano programador que se llamaba rodrigo… ¡¡¡ y como tú te llamas roy conejo…!!

Originally posted by Zeno:
Hi Cass. I just looked at your web site. I’m interested in taking a look at your “cool shadowing effects” demo but it does not compile correctly for me …

I’m having the same problem compiling that demo… but the projspot demo works fine, and it helps me a lot, thanks Cass!

About the glTexParameteri function, when I set the MIN/MAG_FILTER/anisotropy & texture wrap mode, these params. are valid for the actual texture (binded) or are used by any texture of the specified target (TEXTURE_1D/2D, etc)?

  • Royconejo.

Every texture has its own set of parameters. When you set the parameter, it affects only the currently bound texture.

  • Matt

Yeah, the old version of that demo makes the (bad) assumption that you have glext.h included at the end of gl.h. The updated version of the SDK that includes these demos was completed today and will be pushed to the web site early next week.

In the mean time, you can probably include glext.h right after gl.h. Sorry for the inconvenience.

Cass

By the way Cass, I loved your templates for everything.

Is quaternions really worth the effort in rotations?

(btw, no problem with the glext.h header here, because I saw that note you made in the code )

Well… my program is working now, but the shadow looks very ‘unreal’? is there a good an fast (or just good) way to do soft shadows with this technique (Projective Shadow Mapping) in OpenGL?

(Oh my god, I wrote ‘binded’?

  • Royconejo.

PS: Cass, is really useful the Q texcoord. in texgen?