• Advertisement
Sign in to follow this  

Stencil Shadows + Per-Pixel Lighting

This topic is 1958 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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 ([i]which will only show up in the masked area[/i]).


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" ([url="http://mynameismjp.wordpress.com/samples-tutorials-tools/deferred-shadow-maps-sample/"]here[/url], [url="http://aras-p.info/blog/2009/11/04/deferred-cascaded-shadow-maps/"]here[/url], [url="http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/soft-edged-shadows-r2193"]here[/url]). 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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement