Stencil Shadows + Per-Pixel Lighting
How do stencil shadows interact with shaders? Do I have to rewrite the stencil shadows in the shader? Just wondering because I haven't written it yet but I want to include stencil shadows (or any kind of shadows) and per-pixel lighting.
Stencil shadows work by first creating a stencil mask for where lighting is applied, and then drawing your lit geometry, masking out everything that is in a shadowed area. The masking is done by the stencil-test, which works independently of shaders, so your shaders don't even know that there's any shadowing going on. In that regard they are perhaps the simplest shadowing technique.
As for constructing the actual shadow volume to create the mask, that can done with the geometry shader for example.
As for constructing the actual shadow volume to create the mask, that can done with the geometry shader for example.
The traditional implementations of stencil shadows are compatible with pixel shaders without any changes. The way it traditionally works is:
Render scene with ambient lighting only.
Generate stencil mask using a stencil-shadow-volumes technique.
Render scene with diffuse/specular lighting (which will only show up in the masked area).
However, to avoid the two-pass lighting, my personal approach would be to render the shadow mask into a full-screen texture as is done with "deferred shadows" (here, here, here). Your lighting shaders can then be one-pass, and fetch the value from that full-screen texture do determine if they are in light or shadow. Furthermore, you can switch seamlessly between stencil volumes or shadow-mapping, or both, when generating the full-screen mask.
Render scene with ambient lighting only.
Generate stencil mask using a stencil-shadow-volumes technique.
Render scene with diffuse/specular lighting (which will only show up in the masked area).
However, to avoid the two-pass lighting, my personal approach would be to render the shadow mask into a full-screen texture as is done with "deferred shadows" (here, here, here). Your lighting shaders can then be one-pass, and fetch the value from that full-screen texture do determine if they are in light or shadow. Furthermore, you can switch seamlessly between stencil volumes or shadow-mapping, or both, when generating the full-screen mask.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement