yes ... another shadow mapping question

Hi,

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

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?

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.

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.

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 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.

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

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. :wink:

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. :smiley:

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

-SirKnight