Jump to content

  • Log In with Google      Sign In   
  • Create Account


Stencil Shadows + Per-Pixel Lighting


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 polyfrag   Crossbones+   -  Reputation: 1825

Like
0Likes
Like

Posted 08 September 2012 - 05:36 AM

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.

Sponsor:

#2 Erik Rufelt   Crossbones+   -  Reputation: 3365

Like
1Likes
Like

Posted 08 September 2012 - 05:59 AM

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.

#3 Hodgman   Moderators   -  Reputation: 29497

Like
2Likes
Like

Posted 08 September 2012 - 06:10 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS