PDA

View Full Version : yes ... another shadow mapping question



binary
06-07-2005, 05:33 PM
Hi,

i searched through the forum and fond this topic discussed many times.
Sorry for bothering u again . :)

I implemnted a (noobish) 3-pass shadow mapping algorithm.
1st render depth map from lights view
2nd render scene shadowed
3rd render lit scene without shadowed areas (with alpha test)

In the 3d pass texgen is setup to project the shadow texture on the cams view. But now all textures (i call a display list for the scene) are projected that way and shadows arent renderd at all.
Do i have realy to brake up the whole 3D Model and push the texture attribs?

Is there maybe a way to get hands on each single texel an bake it into an statement like

if(testfails)
render shadow
else
render light

so i have 2 passes?

capedica
06-07-2005, 08:36 PM
i remember that i implemented shadow mapping following a tutorial that makes shadow mapping in two passes, try search paul's tutorial, if you don't find it ask me and i'll send you via email.

binary
06-08-2005, 03:56 AM
Hi capedica,

thanks for your reply. I have found Paul's shadow tutorial, but its done in 3 passes too and dosnt adress the usage problem of 'regular' texture mapping.

execom_rt
06-08-2005, 06:08 AM
Actually, I'm doing like that:

- Create shadow map (render from view to depth map).

- Render the scene, lighted, bump mapped, with all your shaders and textures.

- Render the scene, with shadow map comparision enabled and using the depth map as primary texture

- Enable blending

glEnable(GL_BLEND);
glBlendFunc(GL_DST_COLOR, GL_ZERO);

- So if the test comparision returns zero, its draw a black pixel over the top of the 'lighted' scene, else, it draws nothing (keep the lighted scene).

- You can use the ARB_shadow_ambient (http://oss.sgi.com/projects/ogl-sample/registry/ARB/shadow_ambient.txt) extension or write a pixel shader in order to not write zero on black area but just 0.2 in order to 'dim' the shadow.

On nVidia, the PCF will blurs also the results for free.

- Eventually, the third pass can be renderered in a texture, then gaussian blurred in order to get soft shadows.

zed
06-08-2005, 12:19 PM
u should be able to combine these two into one (depending on hardware).
- Render the scene, lighted, bump mapped, with all your shaders and textures.
- Render the scene, with shadow map comparision enabled and using the depth map as primary texture

ie, for each light u render what it lights + ignore what it shadows

binary
06-09-2005, 02:19 PM
Yessss that worked!
Thanks!

Thats the cleaner way to do the scene first and than the shadows and The ARB_shadow_ambient is a nice tipp.

To solve the texture projection problem i had to reset texGen and disable shadow comparsion when that part was done ... grrr thats late night (or early morning?) fun, i just should take a brake after 8 hrs. ;)

SirKnight
06-09-2005, 03:08 PM
If you plan on using shaders to do the shadow map lookup and lighting you can do the shadow lookup and kill the back projection by doing this:


float shadow = ( vert.projCoords.w < 0 ) ? 0 : tex2Dproj( shadowMap, vert.projCoords ).r;If you have a projected light texture map also then you'd of course then do this:


float4 lightTex = ( vert.projCoords.w < 0 ) ? 0 : tex2Dproj( projLightTexture, vert.projCoords );BTW, projCoords are your tex coords generated in the vertex program from the [scale/bias]*[light proj]*[light view] matrix.

Then from here in your shader, do the lighting you want and multiply that by 'shadow' and you're all set. :D


finalColor = float4( ( Kd.xyz * ambient ) + ( Kd.xyz * diffuse + Ks.xyz * specular ) * shadow * lightTex.xyz, 1 );-SirKnight