CSL 859: CSL 859: Advanced Advanced Computer Computer Graphics Graphics Dept of Computer Sc. & Dept of Computer Sc. & Engg. Engg. IIT Delhi IIT Delhi
Jan 21, 2016
CSL 859: CSL 859: Advanced Advanced Computer Computer GraphicsGraphicsDept of Computer Sc. & Engg.Dept of Computer Sc. & Engg.
IIT DelhiIIT Delhi
Shadow VolumesShadow Volumes
Shadow VolumesShadow Volumes
Stencil BufferStencil Buffer Like color/z buffer; one entry per pixelLike color/z buffer; one entry per pixel
Traditionally a few bits of Z-bufferTraditionally a few bits of Z-buffer Stencil value also masks whether to renderStencil value also masks whether to render Render to StencilRender to Stencil
Stencil operationStencil operationvoid void StencilFuncStencilFunc (enum (enum funcfunc, int , int refref, uint , uint maskmask ) )
NEVER, ALWAYS, LESS, LEQUAL, EQUAL, NEVER, ALWAYS, LESS, LEQUAL, EQUAL, GEQUAL, GREATER, or NOTEQUALGEQUAL, GREATER, or NOTEQUAL
void void StencilOpStencilOp (enum (enum sfailsfail, enum , enum zfailzfail, enum , enum zpasszpass) ) KEEP, ZERO, REPLACE, INCR, DECR, INVERTKEEP, ZERO, REPLACE, INCR, DECR, INVERT
glEnableglEnable((GL_STENCIL_TESTGL_STENCIL_TEST))
Stencil Shadow Volume Stencil Shadow Volume OverviewOverview
Render the scene with shadow colorRender the scene with shadow color For each light sourceFor each light source
Using the depth from pass 1, construct a Using the depth from pass 1, construct a mask in the stencil buffer enabling mask in the stencil buffer enabling pixels not in shadowpixels not in shadow
Shadow volume constructed by Shadow volume constructed by computing silhouettes of occluderscomputing silhouettes of occluders And capping the volumesAnd capping the volumes
Render the scene again, lit this time.Render the scene again, lit this time. Stencil buffer masks out shadowed areasStencil buffer masks out shadowed areas
Stencil GenerationStencil Generation Disable depth and color writesDisable depth and color writes Set the stencil operation to increment on Set the stencil operation to increment on
depth depth passpass (counting shadows in front of (counting shadows in front of the object)the object)
Enable back-face culling (ie front drawing)Enable back-face culling (ie front drawing) Draw the shadow volumes (ie front faces)Draw the shadow volumes (ie front faces) Set the stencil operation to decrement on Set the stencil operation to decrement on
depth depth passpass Enable front-face cullingEnable front-face culling Draw the shadow volumes (ie back faces)Draw the shadow volumes (ie back faces)
What if Eye is in shadow?What if Eye is in shadow?
Stencil Shadow VolumesStencil Shadow Volumes
a b
Reverse StencilReverse Stencil Disable depth and color writesDisable depth and color writes Enable front-face cullingEnable front-face culling Set the stencil operation to increment on Set the stencil operation to increment on
depth depth failfail (counting shadows behind the (counting shadows behind the object).object).
Render the shadow volumes (ie back faces)Render the shadow volumes (ie back faces) Enable back-face cullingEnable back-face culling Set the stencil operation to decrement on Set the stencil operation to decrement on
depth depth failfail.. Render the shadow volumes (ie front faces)Render the shadow volumes (ie front faces)
Shadow Map AliasingShadow Map Aliasing
single shadow map pixel
Perspective Shadow Perspective Shadow MapsMaps
[Stamminger & Grettakis 02][Stamminger & Grettakis 02]
Deep Shadow MapDeep Shadow Map
Deep shadow mapsDeep shadow maps Instead of storing a Instead of storing a
depth at each pixeldepth at each pixel Store a series of Store a series of
depths w/ reduction depths w/ reduction of light transmittedof light transmitted
Important for Important for complex self-complex self-shadowing modelsshadowing models
Hair, cloudsHair, clouds
[Lokovic & Veach 2000]
Deep Shadow MapsDeep Shadow Maps
With self-shadowingWithout self-shadowing
Shadows from Area LightShadows from Area Light
Accumulation bufferAccumulation buffer Higher resolution than final imageHigher resolution than final image
Sample area lightSample area light Render from multiple light-pointsRender from multiple light-points
AverageAverage
[Heckbert & Herf 97]Overlapping shadows have undesired artifacts
Fake Soft ShadowsFake Soft Shadows
Extend shadow map [Chan & Durand Extend shadow map [Chan & Durand 03]03]
Use extra primitives (Use extra primitives (smoothiessmoothies) to ) to soften shadowssoften shadows
light’s view (blockers only) light’s view (blockers + smoothies)
Fake Soft ShadowsFake Soft Shadows
Shadows not geometrically correct Shadows not geometrically correct Shadows appear Shadows appear qualitativelyqualitatively like like
soft shadowssoft shadows
Hard shadows Fake soft shadows
Shadow Map CreationShadow Map Creation
Render blockers into depth mapRender blockers into depth map
light’s view
observer’s view
Silhouette DetectionSilhouette Detection
Find blockers’ silhouette edges in Find blockers’ silhouette edges in object spaceobject space
object-space silhouettesobject-space silhouettes
observer’s view
light’s view
Construct SmoothiesConstruct Smoothies
Blocker only:Blocker only:silhouette vertex
silhouette edges
blocker exterior
Construct SmoothiesConstruct Smoothies
Blocker + smoothies:Blocker + smoothies:
silhouette vertex
silhouette edges
smoothie edge
smoothie corner
t
t
blocker exterior
Construct SmoothiesConstruct Smoothies Smoothie edgesSmoothie edges: rectangles in screen : rectangles in screen
space with a fixed widthspace with a fixed width Smoothie corners:Smoothie corners: connect adjacent connect adjacent
smoothie edgessmoothie edges
t
t
geometry shading
Render SmoothiesRender Smoothies Store depth and alpha values into Store depth and alpha values into
smoothie buffersmoothie bufferSmoothie Buffer (depth) Smoothie Buffer (alpha)
light’s viewpoint
Compute ShadowsCompute Shadows
Compute intensity using depth Compute intensity using depth comparisonscomparisons
smoothie
light source
blocker
receiver
Hard ShadowHard Shadow
Image sample behind blocker Image sample behind blocker (intensity = 0)(intensity = 0)
smoothie
light source
blocker
receivercompletely in shadow
Soft ShadowsSoft Shadows
Image sample behind smoothie Image sample behind smoothie (intensity = (intensity = ))
partially in shadow
smoothie
light source
blocker
receiver
No ShadowNo Shadow
Image sample illuminated Image sample illuminated (intensity = 1)(intensity = 1)
illuminated
smoothie
light source
blocker
receiver