PDA

View Full Version : Shadowmapping without GL_depth_texture



mir
08-25-2004, 09:51 AM
Shadowmapping without GL_depth_texture, gl_shadow.
I need something that is not supported only on the latest video cards. Ex. my Radeon9200 does not support these extensions.

mir
08-25-2004, 09:53 AM
Is it possible?
Links is usefull.

PfhorSlayer
08-25-2004, 11:45 AM
I implemented shadow mapping on my GF2MX not too long ago. If you'd like, I'll give you the source.

It doesn't run too fast, and wasn't really optimized that much, and uses register combiners for parts of it, but it works.

Making it work without register combiners may take another pass, I'm not sure.

Korval
08-25-2004, 05:34 PM
The 9200 should be able to do it OK, though your textures won't have the resolution of a depth texture. The key is the comparison operator that the 9200 can access with ATI_fragment_shader. You will need a vertex program to help the fragment program compute the depth and write that into the "shadow" texture (which is just an intensity or RGB texture). Then, when you do your regular rendering, compute the depth relative to the camera (computed like before), and the value from the texture.

JustHanging
08-25-2004, 09:36 PM
You can also implement shadow mapping using only tex_env_combine (or tex_env_add if you prefer) by calculating the difference into the alpha channel and using alpha test to cull out shadowed fragments.

-Ilkka

mir
08-26-2004, 05:03 AM
PfhorSlayer
Yes, give me please the sources. I think I can use texture_env_combine instead of register combiners?
My email smb@hotmail.ru
JustHanging
//calculating the difference into the alpha channel
How can I do this?
Korval
I understood the idea, but can I use extensions that are supported on older cards and not only on Radeons. Something universal :)

JustHanging
08-26-2004, 11:32 PM
Basically you bind the shadow map to texture0 and depth from the light to texture1 (both in texture alpha channels), and then

// Pass the shadow map to the next unit
glActiveTexture(GL_TEXTURE0);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

glActiveTexture(GL_TEXTURE1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);

// Copy the primary color into the fragment color
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PRIMARY_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);

// Subtract the shadowmap depth from the lightspace depth
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_SUBTRACT);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);

Now the difference is in the fragment alpha, and you can cull away the shadowed fragments by:

glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_EQUAL, 0);

The code's out of my head, so forgive me if there are mistakes.

-Ilkka