shadow question

Hi,
I have a little scene with per-pixel lighting and stencil shadows. First I render the lit scene and then the shadows. This is ok for one light. But when I have two, the shadow of the second light don’t become brighter when they are near the first light. How can I render the shadows correctly?

-FA-

Shadows equals absence of light. Shadows do not equal a darkening of specific areas. Microsoft has done the world a dis-service by arguing for the “one darkening whole-screen quad” version of stencil shadows.

The real way to do it is something like:

foreach object
  render into depth and ambient

foreach light
  clear stencil buffer
  foreach object intersecting light
    render object into stencil buffer
  foreach object intersecting light
    add light contribution, unless in shadow volume

With modern cards, where “render light contribution” is single-pass for per-pixel bumped specular, this is no problem. For older cards (GF2 and back) you may need to settle on rendering specular into alpha and not getting a specular color, or using multiple passes, or both.

Originally posted by FullAmmo:
[b]Hi,
I have a little scene with per-pixel lighting and stencil shadows. First I render the lit scene and then the shadows. This is ok for one light. But when I have two, the shadow of the second light don’t become brighter when they are near the first light. How can I render the shadows correctly?

-FA-[/b]
this way you can’t get correct shadows with multiple lightsources.
you have to do it this way:

  1. ambient pass (scene geometry with ambient lighting and depth writes)
  2. for each light:
    • clear stencil buffer
    • draw shadowvolumes
    • draw scene geometry using stencil test and lighting.

this way you draw only lit pixels instead of drawing all first, and then trying to remove the shadowed areas.