Real-Time Rendering Shadow Volumes

Slides:



Advertisements
Similar presentations
Lecture 8 Transparency, Mirroring
Advertisements

Technische Universität München Computer Graphics SS 2014 Graphics Effects Rüdiger Westermann Lehrstuhl für Computer Graphik und Visualisierung.
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
Optimized Stencil Shadow Volumes
Graphics Pipeline.
Optimized Stencil Shadow Volumes
Game Programming 09 OGRE3D Lighting/shadow in Action
University of Sulaimani - School of Science - Computer Dept.
CSL 859: Advanced Computer Graphics Dept of Computer Sc. & Engg. IIT Delhi.
Computer Graphics methods
Week 10 - Monday.  What did we talk about last time?  Global illumination  Shadows  Projection shadows  Soft shadows.
03/12/02 (c) 2002 University of Wisconsin, CS559 Last Time Some Visibility (Hidden Surface Removal) algorithms –Painter’s Draw in some order Things drawn.
1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.
Real-Time Rendering SPEACIAL EFFECTS Lecture 03 Marina Gavrilova.
黃聰賢. Light Position Mesh Polygon Shadow Polygon  Clear color buffer and stencil buffer  Render the scene with ambient only.
Practical and Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering Cass Everitt and Mark J. Kilgard Speaker: Alvin Date: 5/28/2003 NVIDIA.
Approximate Soft Shadows on Arbitrary Surfaces using Penumbra Wedges Tomas Akenine-Möller Ulf Assarsson Department of Computer Engineering, Chalmers University.
© 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.
Computer Graphics Shadows
1 A Hierarchical Shadow Volume Algorithm Timo Aila 1,2 Tomas Akenine-Möller 3 1 Helsinki University of Technology 2 Hybrid Graphics 3 Lund University.
09/18/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Bump Mapping Multi-pass algorithms.
Hidden Surface Removal
Creating Reflections and Shadows Using Stencil Buffers Mark J. Kilgard NVIDIA Corporation.
Shadows Computer Graphics. Shadows Shadows Extended light sources produce penumbras In real-time, we only use point light sources –Extended light sources.
Erdem Alpay Ala Nawaiseh. Why Shadows? Real world has shadows More control of the game’s feel  dramatic effects  spooky effects Without shadows the.
Computer Graphics Mirror and Shadows
Shadow Algorithms Ikrima Elhassan.
CS 638, Fall 2001 Today Light Mapping (Continued) Bump Mapping with Multi-Texturing Multi-Pass Rendering.
CHAPTER 11 Shadows © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Shadow rendering algorithms – –Blinn’s shadow.
MIT EECS 6.837, Durand and Cutler Real-Time Shadows.
CS 638, Fall 2001 Multi-Pass Rendering The pipeline takes one triangle at a time, so only local information, and pre-computed maps, are available Multi-Pass.
1 10/24/ :01 UML Graphics II Shadows Session 4.
Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.
Shadows. Shadows is important in scenes, consolidating spatial relationships “Geometric shadows”: the shape of an area in shadow Early days, just pasted.
CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann.
Computer graphics & visualization Shadows / Transparency.
OpenGL Shadow. Content Shadowing using Stencil Buffer Shadowing using Projective Texture Shadow map Shadow volume.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
OpenGL Special Effects Jian-Liang Lin 2002 Blending: Alpha Channel Alpha value can be specify by glColor* When blending is enabled, the alpha value is.
Real-Time Dynamic Shadow Algorithms Evan Closson CSE 528.
Shadows David Luebke University of Virginia. Shadows An important visual cue, traditionally hard to do in real-time rendering Outline: –Notation –Planar.
1 Shadow Rendering Techniques: Hard and Soft Author: Jamiur Rahman Supervisor: Mushfiqur Rouf Department of CSE BRAC University.
Stencil Shadows Garrett Weng. What are stencil shadows? Also known as shadow volumes Relies on use of the stencil buffer Create volumes of the shadows.
09/23/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Reflections Shadows Part 1 Stage 1 is in.
Visible-Surface Detection Methods. To identify those parts of a scene that are visible from a chosen viewing position. Surfaces which are obscured by.
CENG 477 Introduction to Computer Graphics
- Introduction - Graphics Pipeline
Computer Graphics Implementation II
Stenciling Effects Glenn G. Chappell
A Geometry-Based Soft Shadow Volume Algorithm Using Graphics Hardware
Hidden Surfaces Dr. Scott Schaefer.
Jim X. Chen George Mason University
CSCE 441: Computer Graphics Hidden Surface Removal
Introduction to Computer Graphics with WebGL
Implementation II Ed Angel Professor Emeritus of Computer Science
Real-time Rendering Shadow Maps
Real-Time Rendering Intro to Shadows
Lecture 13 Clipping & Scan Conversion
UMBC Graphics for Games
Visibility (hidden surface removal)
A Hierarchical Shadow Volume Algorithm
Texture and Shadow Mapping
CS5500 Computer Graphics May 29, 2006
Introduction to Computer Graphics with WebGL
Last Time Presentation of your game and idea Environment mapping
Ref: OpenGL Programming Guide (The Red Book)
OpenGL Shadow.
Stencil Buffer & Decals
Frame Buffer Applications
Implementation II Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

Real-Time Rendering Shadow Volumes CSE 5542 Prof. Roger Crawfis

Real-Time Shadows Require: Dynamic lights Dynamic occluders Dynamic receivers Zombies optional

We Have Two Options Shadow Maps Shadow Volumes Image-based Half-Life 2 DOOM 3 Shadow Maps Image-based Shadow Volumes Geometry-based

What is shadow volume? A volume of space formed by an occluder Bounded by the edges of the occluder Any object inside the shadow volume is in shadow light source

Definitions (2D slice) Surface outside shadow volume (illuminated) Shadowing occluder Light source Shadow volume (infinite extent) Eye position (shadows are independent of the eye position) Surface inside shadow volume (shadowed) Partially shadowed receiver

Shadow Volumes Nice theory, but how do we use it? Key concerns: How do I determine whether a point (fragment) is in shadow? How do we create the shadow volumes? How do we get it real-time?

Point in Polygon Test A point p lies in polygon P if a ray (any ray) from p intersects the boundary of P an odd number of times. Ignoring end cases. o p Ray from p

Shadow Volume Example Assume the eye and light are at infinity and are not in the shadow volume. Ray hits 2 shadow volume polygons, hence the ray intersection with the triangle is not in shadow.

Shadow Volume Example Ray hits 1 shadow volume polygon

Shadow Volumes Per-object, construct shadow volume from light Multiple shadow volumes may interact Does the odd / even rule still hold?

Shadow Intersection Count Create a signed count of ray crossings Non-zero: shadowed Zero: lit Add one when entering a shadow volume. Subtract one on exit. Frank Crow (Siggraph ’78)

Shadow Intersection Count Light source Shadowing object zero +1 zero In shadow +2 +2 Eye position +1 +3

Creating a Shadow Volume For each edge in each occluder polygon Create a quad with the edge points and two points at infinity along the rays from the light through the edge point. Repeat for all lights. light source quadrilateral

Creating a Shadow Volume If we draw all of these extra quads.

Creating a Shadow Volume http://upload.wikimedia.org/wikipedia/commons/a/af/Shadow_volume_illustration.png

Shadow Intersection Count Key idea: Draw the shadow volume polygons to the stencil buffer. Draw all front facing shadow volume polygons and increment the stencil buffer. Draw all back facing shadow volume polygons and decrement the stencil buffer. Draw all scene polygons without lighting to set the depth buffer.

Stencil Buffer Same resolution as color and depth buffers Usually (and at least) 8-bits, but can vary Used to hold values related to elements being written into frame buffer Control whether a fragment is discarded or not Stencil function (Stencil test) - used to decide whether to discard a fragment Stencil operation – decide how the stencil buffer is updated as the result of the test

Stencil Buffer glutInitDisplayMode(GLUT_STENCIL); glEnable(GL_STENCIL_TEST); glClearStencil(0); glClear(GL_STENCIL_BUFFER_BIT);

Stencil Testing Recall OpenGL’s fragment operations

Stencil & Z Buffer

Stencil Testing void glStencilFunc( GLenum func, GLint ref, GLuint mask ); sets the function and reference value for stencil testing. func: test function, see next page. ref: reference value mask:A mask that is ANDed with both the reference value and the stored stencil value when the test is done.

Stencil Testing GL_NEVER Always fails. param Meaning GL_NEVER Always fails. GL_LESS Passes if ( ref & mask) < ( stencil & mask). GL_LEQUAL Passes if ( ref & mask) ≤ ( stencil & mask). GL_GEQUAL Passes if ( ref & mask) ≥ ( stencil & mask). GL_NOTEQUAL Passes if ( ref & mask) ( stencil & mask). GL_ALWAYS Always passes.

Modify The Stencil Buffer void glStencilOp( GLenum fail, GLenum zfail, GLenum zpass ); sets the stencil test actions. fail: The action to take when the stencil test fails zfail: Stencil action when the stencil test passes, but the depth test fails. zpass: both the stencil test and the depth test pass

Modify The Stencil Buffer param Meaning GL_KEEP keep the current value GL_ZERO set the value in stencil buffer to zero GL_REPLACE set the value in stencil buffer to ref in glStencilFunc() GL_INCR increase the current value in stencil buffer GL_DECR decrease the current value in stencil buffer GL_INVERT bitwise inverse the current value in stencil buffer

Stencil-based Shadow Volumes Drawing the quads Stencil buffer contents Shadowed scene red = stencil value of 1 green = stencil value of 0 GLUT shadowvol example credit: Tom McReynolds

Stencil-based Shadow Volumes 1. Render all the objects using only ambient lighting. Make sure depth buffer is written. 2. Starting with a light source, extrude all the occluders with respect to the light source. 4. Clear the stencil buffer, and then render the shadow volumes using the depth-pass technique (next slide). The depth-pass technique will set a value 1 in the stencil buffer position for every fragment that is inside the shadow volume. 5. Using the updated stencil buffer, render all objects using diffuse and specular lighting for this light for all fragments that correspond to zero stencil values. 6. Accumulate the colors from step 5. 7. Repeat step 2 to 6 for all the lights in the scene.

Stencil-based Shadow Volumes Depth-pass (or zPass) technique: Render front face of shadow volume. If depth test passes, increment stencil value, else do nothing. Disable draw to color and depth buffers. Render back face of shadow volume. If depth test passes, decrement stencil value, else do nothing. Disable draw to color and depth buffers. The depth pass technique works for multiple intersecting shadow volumes.

Z-pass by example What we have... What we wnat... © 2004 Tomas Akenine-Möller

Z-Pass Problems Geometry containing vital information was clipped by the near plane

Z-Pass Problems

Z-Pass Problems Previous work tries to cap the near plane Compute cap on CPU somehow Can cause cracks in shadow due to numerical issues From http://developer.nvidia.com/object/cedec_stencil.html

Z-Fail Shadow Volumes Reversing depth test gives equivalent result in the stencil Shadow volume fragments that fail the depth test influence the stencil Near plane will never clip relevant geometry since geometry behind the viewer could never fail the depth test

© 2004 Tomas Akenine-Möller Z-fail by example © 2004 Tomas Akenine-Möller

Z-Fail Caps Far plane can still clip sides Still need caps Fortunately, Z-Fail caps are robust and easy

Shadow Volume Efficiency Create a shadow volume from the silhouette of an object instead of each polygon. Required a CPU-based computation before geometry shaders. Again, you can cheat with shadows and have the shadow volume geometry be a simplified proxy occluder. Need to recompute silhouettes for dynamic scenes.

Merging shadow volumes Edge shared by two occluders creates both a front- and a back-facing quad. This interior edge makes two quads, which cancel out Instead, use only potential silhouette edges as seen from the light:

Shadow Volume Efficiency Object (as seen from light) Silhouette (used to create shadow volume)

Shadow Volume Advantages Omni-directional approach Not just spotlight frustums as with shadow maps Automatic self-shadowing Everything can shadow everything, including self Without shadow acne artifacts as with shadow maps Window-space shadow determination Shadows accurate to a pixel (Object method) Required stencil buffer broadly supported

Shadow Maps vs. Shadow Volumes Sindholt, Joen. “A comparison of shadow algorithms” Examination thesis for MSE, TU Denmark. May 2005

Shadow Volume Disadvantages Ideal light sources only Limited to local point and directional lights No area light sources for soft shadows Requires polygonal models with connectivity Models must be closed (2-manifold) Models must be free of non-planar polygons Silhouette computations are required Can burden CPU Particularly for dynamic scenes Inherently multi-pass algorithm Consumes lots of GPU fill rate

zFail versus zPass Summary When stencil increment/decrements occur Zpass: on depth test pass Zfail: on depth test fail Increment on Zpass: front faces Zfail: back faces Decrement on Which clip plane creates a problem Zpass: near clip plane Zfail: far clip plane

Wrapped Stencil Counts Traditionally, stencil counts could not go negative, so we had to: First, render increment pass Second, render decrement pass Wrapped Stencil operations Decrement on 0 yields 255. Increment on 255 yields 0. New Glenum’s GL_INCR_WRAP and GL_DECR_WRAP

Two-sided Stencil Testing Implementation wise, we would set the cull-face states and render the shadow volume geometry twice: Rasterizing front-facing geometry Rasterizing back-facing geometry Order dependent on zPass or zFail. Would be great if we could do this in one pass, incrementing if the geometry faces one direction and decrementing otherwise. Two sets of stencil state: front- and back-facing Rasterizes just as many fragments, but more efficient for CPU & GPU See glStencilFuncSeparate.

Two-sided Stencil Testing glStencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass) Specifies what action to take as a result of stencil test and depth test: GL_KEEP, GL_ZERO, GL_INCR_WRAP, GL_DECR_WRAP, etc. sfail - fails stencil test dpfail - passes stencil test, fails depth test dppass- passes both stencil and depth test