PDA

View Full Version : Shadow Mapping in OpenGL



royconejo
05-09-2001, 01:10 AM
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.

Mahjii
05-09-2001, 05:17 AM
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-

cass
05-09-2001, 06:37 AM
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

royconejo
05-09-2001, 06:48 PM
Originally posted by Mahjii:
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-

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.

jwatte
05-09-2001, 07:18 PM
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 :-)

royconejo
05-09-2001, 08:44 PM
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.

cass
05-10-2001, 07:11 AM
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

royconejo
05-10-2001, 12:25 PM
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.

santyhamer
05-10-2001, 12:51 PM
No tendrás una hermana que se llama vanessa?

royconejo
05-10-2001, 02:41 PM
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.

cass
05-10-2001, 02:48 PM
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

Hull
05-10-2001, 04:27 PM
Hey Cass.

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

http://www.opengl.org/discussion_boards/ubb/smile.gif

Zeno
05-10-2001, 06:38 PM
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\neato\main.cpp(32) : error C2146: syntax error : missing ';' before identifier 'shadow0'
c:\download\cass\demos\neato\main.cpp(32) : error C2501: 'texture_env_combine' : missing storage-class or type specifiers
c:\download\cass\demos\neato\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

Korval
05-10-2001, 08:38 PM
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.

santyhamer
05-11-2001, 05:04 AM
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....!!

royconejo
05-11-2001, 10:50 AM
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.

mcraighead
05-11-2001, 11:08 AM
Every texture has its own set of parameters. When you set the parameter, it affects only the currently bound texture.

- Matt

cass
05-11-2001, 12:50 PM
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

Hull
05-11-2001, 01:21 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif )

royconejo
05-11-2001, 02:38 PM
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'? http://www.opengl.org/discussion_boards/ubb/smile.gif


- Royconejo.

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

royconejo
05-11-2001, 02:50 PM
Originally posted by santyhammer:
Porque yo conocía a una vanessa conejo que fue conmigo al instituto y tenía un hermano programador que se llamaba rodrigo...
No, no soy yo.. ni siquiera tengo una hermana.

- Royconejo.