1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson.

Slides:



Advertisements
Similar presentations
Exploration of advanced lighting and shading techniques
Advertisements

Technische Universität München Computer Graphics SS 2014 Graphics Effects Rüdiger Westermann Lehrstuhl für Computer Graphik und Visualisierung.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Optimized Stencil Shadow Volumes
Optimized Stencil Shadow Volumes
Game Programming 09 OGRE3D Lighting/shadow in Action
CSL 859: Advanced Computer Graphics Dept of Computer Sc. & Engg. IIT Delhi.
Computer Graphics methods
Real-Time High Quality Rendering CSE 291 [Winter 2015], Lecture 3 Shadow and Environment Mapping
Week 7 - Monday.  What did we talk about last time?  Specular shading  Aliasing and antialiasing.
Week 10 - Monday.  What did we talk about last time?  Global illumination  Shadows  Projection shadows  Soft shadows.
3D Graphics Rendering and Terrain Modeling
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.
Chapter 6: Vertices to Fragments Part 2 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
Real-Time Rendering COMS , Lecture 9. Real-Time Rendering Demo Motivation: Interactive rendering with complex natural illumination and realistic,
Practical and Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering Cass Everitt and Mark J. Kilgard Speaker: Alvin Date: 5/28/2003 NVIDIA.
1 CSCE 441: Computer Graphics Hidden Surface Removal (Cont.) Jinxiang Chai.
Real-Time High Quality Rendering COMS 6160 [Fall 2004], Lecture 4 Shadow and Environment Mapping
Approximate Soft Shadows on Arbitrary Surfaces using Penumbra Wedges Tomas Akenine-Möller Ulf Assarsson Department of Computer Engineering, Chalmers University.
Part I: Basics of Computer Graphics Rendering Polygonal Objects (Read Chapter 1 of Advanced Animation and Rendering Techniques) Chapter
© 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.
CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Other Rendering Techniques Types of rendering – Wireframe techniques – Scan-line conversion – Reyes.
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping.
Computer Graphics Shadows
09/18/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Bump Mapping Multi-pass algorithms.
9/20/2001CS 638, Fall 2001 Today Finishing Up Reflections More Multi-Pass Algorithms Shadows.
Hidden Surface Removal
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.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 19 Other Graphics Considerations Review.
1 Computer Graphics Week13 –Shading Models. Shading Models Flat Shading Model: In this technique, each surface is assumed to have one normal vector (usually.
CS 638, Fall 2001 Today Light Mapping (Continued) Bump Mapping with Multi-Texturing Multi-Pass Rendering.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
1 SIC / CoC / Georgia Tech MAGIC Lab Rossignac Textures and shadows  Generation  Mipmap  Texture coordinates,
Computer Graphics An Introduction. What’s this course all about? 06/10/2015 Lecture 1 2 We will cover… Graphics programming and algorithms Graphics data.
09/09/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Event management Lag Group assignment has happened, like it or not.
Cass Everitt NVIDIA Corporation Shadow Mapping.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 14 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 14 Going-through.
Week 2 - Friday.  What did we talk about last time?  Graphics rendering pipeline  Geometry Stage.
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.
Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth texture from the light ’ s point-of-view - render from.
Shadows. Shadows is important in scenes, consolidating spatial relationships “Geometric shadows”: the shape of an area in shadow Early days, just pasted.
Shadow Mapping Chun-Fa Chang National Taiwan Normal University.
CS-378: Game Technology Lecture #8: More Mapping Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica.
Rendering Fake Soft Shadows with Smoothies Eric Chan Massachusetts Institute of Technology.
CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann.
Texture Mapping May 4, Many slides are borrowed from UNC-CH COMP236 Course (Spring 2003) taught by Leonard McMillan
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Visible Surface Determination (VSD) To render or not to render, that is the question… 1 of.
11/24/ :45 Graphics II Shadow Maps Reflections Session 5.
Real-Time Dynamic Shadow Algorithms Evan Closson CSE 528.
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
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.
01/28/09Dinesh Manocha, COMP770 Visibility Computations Visible Surface Determination Visibility Culling.
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.
Jim X. Chen George Mason University
CSCE 441: Computer Graphics Hidden Surface Removal
Real-time Rendering Shadow Maps
UMBC Graphics for Games
Frame Buffer Applications
Presentation transcript:

1 Shadows © Jeff Parker, 2011 " What is written without effort is in general read without pleasure.” -- Samuel Johnson

2 Outline Fill out your course evaluations! Look at a vexing problem: How to deal with shadows We will see a variety of topics that provide a good review of course topics Hidden Surface Removal Clipping Counting Crossings – in or out? zBuffer Transformations Aliasing We'll look at several shadow algorithms in some detail Images from a number of sources, including SIGGRAPH courses by Björn Kühl and by Mark Kilgard of Nvidia

3 Why do we need shadows?

4 Shadows Shadows help to create atmosphere

Shadows provide clues Clues to the position of objects casting and receiving shadows Clues to the position of the light sources

Shadows provide clues Clues about the shape of casting objects Clues about the shape of receiving objects

Shadows make images realistic

9 Ground Plane Shadows Described by Blinn in “Me and My (Fake) Shadow” Given light position and ground plane, project all objects in scene onto ground plane. The shadow is a pile of polygons on the ground plane. Polygons are co-planar, so pile has no height. The trick is to construct the projection matrix, then concatenate the matrix with the model-view matrix. Then the shadow is rasterized into the ground plane by re- rendering the object.

10 Directional Shadow We project a point P onto the plan x = 0 to get it's shadow, S The light is directional (infinite) in direction L Where do we hit y = 0?

11 Directional Shadow Use this to compute where (x, y, z) ends up

12 Directional Shadow We can write this as a matrix operation

13 Point Source Shadow How does a point source differ from directional source? Imagine the light in the second picture is on a lamp post

14 Point Source Shadow How does a point source differ from directional source?

15 Point Source Shadow We project a point P onto the plan x = 0 to get it's shadow, S The light is directional is from a point source at L

16 Point Source Shadow Use this to compute where (x, y, z) ends up We show how to compute x: z is similar

17 Point Source Shadow We can write this as a matrix operation using perspective geometry

18 Point Source Shadow Since y P < y L in most cases, y P -y L is negative Rather than divide by negative, multiply through by -1

19 Limitations This only works when projecting onto planes Assumes an infinite plane Gives hard edged shadows Textured surfaces are hard to deal with To get a good match with texture floor that is not in shadow, we want to blend If we blend, we blend once for each polygon. But multiple polygons may overlap See figure Deals best with isolated objects Does not cast shadows on other objects

20 Improved algorithm Use stencil buffer to make limits of plane and limits of shadow Assign a unique non-zero stencil value to the pixels belonging to the ground plane. Then draw the ground plane polygons This only works when projecting onto planes Assumes an infinite plane Gives hard edged shadows Textured surfaces are hard to deal with To match with texture floor, we want to blend If we blend, we blend once for each polygon. But multiple polygons may overlap Deals best with isolated objects Does not cast shadows on other objects

21 Two Bit test Blending is adequate for quick-and-dirty rendering, but you may be able to have more realistic rendering with a separate pass. When selecting an otherwise unused stencil value v for tagging the planar surface’s shadow, also ensure that v+1 is also otherwise unused. When rendering the projected shadow, instead of blending with the pixels on the planar surface, increment the pixel’s stencil value and do not update the color buffer. Then re-render the planar surface again with lighting enabled but the blocked light source disabled and use stenciling to replace only pixel’s with the the value v+1.

22 Evaluation Can handle multiple light sources: need unique v, v+1 for each Still assumes ground is a plane Still creates hard shadows Deals best with isolated objects Does not cast shadows on other objects

Miner's headlamp What does a miner see?

Appel and Bouknight & Kelly Alexander, upon meeting Diogenes, asked if there was any favor he might do for him. Diogenes replied: "Yes, stand out of my sunlight" Create data structure telling us which polygons occlude others Project objects onto sphere centered at light source For each object, keep track of any other objects between it and the light Diogenes -  Alexander The Great

Appel and Bouknight & Kelly Perform normal scan-line conversion on polygon P Look at occluding object S If S does not cover the scan line, draw If S covers all the scan line, draw with darker shade Is S covers part of the scan line, split scan line in two and recurse

Appel and Bouknight & Kelly Evaluation Need to build data structure Assumes we can quickly decide if all of a scan line is hidden – assumed polygons

Atherton, Weiler & Greenberg Adapt hidden surface removal to generate shadows Build the image from the light's point of view Sort from back to front Build list of visible polygons: subdivide and clip Split a polygon into parts: Lit and Unlit Keep lists of lit and unlit polygons Merge lit set with rest of polygons When drawing, those in unlit set are in shadow

Atherton, Weiler & Greenberg Image from Allan Watt, 3D Computer Graphics

Atherton, Weiler & Greenberg Evaluation: Works in Object Space Marks polygons as in light or shadow Once we cast the shadows, can view from any point Can handle multiple lights: repeat the algorithm To do clipping right is hard work

Shadow Volumes Crow, Shadow algorithms for computer graphics, 1977 Compute regions of shadow in 3D Object-space algorithm Cast shadows onto arbitrary receiver geometry From the School of Leonardo Da Vinci

Shadow Volumes Extend occluder polygons to form semi-infinite volumes Light source is center-of-projection Everything behind occluder is in shadow Test if point is in at least one volume Extend to reach outside of view frustum Light Source Shadow Region Occluder

Shadow Volumes shadowing object shadow volume (infinite extent) partially shadowed object light source eye position surface inside shadow volume (shadowed) surface outside shadow volume (illuminated)

Shadow Volumes Shadow volume generation Trivial way: One volume for each polygon Better: Silhouette-based approach Goal: one shadow volume per connected component Selected occluders only

Shadow Volumes Detect silhouette edges An edge is a silhouette edge if it is an edge shared by a front-facing and back-facing triangle/polygon Light FF BF FF Silhouette Edge (v0,v1) ! No Silhouette Edge !

Shadow Volumes Shadow test: in-out counter Counter == 0: lit Counter >=0: shadowed

Use Stencil Buffer as Counter Render scene in ambient color – in shade Render front-facing parts of shadow volumes with stencil operation increment (enter) Render back-facing parts of shadow volumes with stencil operation decrement (exit) Render scene (fully lit) with stencil test equal zero

Shadow Volumes Implementation Generate volumes in software (object space) Counting can be done in hardware (image space) Images from Mark Kilgard’s shadow volume demo (NVIDIA).

Shadow Volumes Counting problems Viewer in shadow (correct counter initialization) Correct ownership of adjacent polygons (no double hits) OpenGL renderer should do this (specification) Clipping of shadow volumes Near clipping plane could cut-away parts of the shadow volume. Need to cap shadow volumes !

Shadow Volumes near plane eye light volume be clipped ! missing stencil increment near plane eye light correct stencil in-out

Shadow Volume Summary Shadow volumes in object precision CPU intensive, requires polygon representation Shadow test in image precision Stencil buffer count Hardware-accelerated Many, large shadow polygons Fill rate, geometry processing Frustum clipping can destroy volumes see Robust Stencil Shadow Volumes (NVIDIA 2002)

Shadow Mapping Lance Williams, Casting Curved Shadows on Curved Surfaces, 1978 Fast technique: two passes over objects Image-space based (we'll see what that means) Very general: can deal well with arbitrary shapes Has issues with Aliasing when light, eye are far apart Widely used: Pixar's RenderMan

Shadow Map Concept First pass: render depth buffer from the light’s point-of-view "Paint" all visible points Second pass: render from observer's viewpoint If the pixel is not painted, it is in the shade Problems: How do we "paint" a pixel? Pixels do not exist in object space – they are an artifact of screen space

Shadow Map Concept Fast z-Buffer Depth testing from the light’s point-of-view Need to remember z-Buffer for each light source First pass: render depth buffer from the light’s point-of-view The resulting “depth map” is called the “shadow map” 2D map indicating the distance of the closest pixels to light Second pass: render from observer's viewpoint Use the shadow map to decide which pixels are in shade Map from one view to the other

Second Phase First pass prepares shadow map from Light's point of view In second phase, have (x, y, z) – is it in shadow map?

Second Phase Second Pass renders scene from observer's point-of-view For each rasterized fragment We know the (x, y, z) position Translate into Light's view, and extract depth If the depth matches, point is light. If it does not, point is in shade. It is customary to use the term z – but note that the light's z may be the observer's x, or x+y-z.

Example A fairly complex scene with shadows the point light source

Example Compare with and without shadows with shadows without shadows

Example The scene from the light’s point-of-view from the eye’s point-of-view again

Example The depth buffer from the light’s point-of-view from the light's point-of-view

Example Projecting the depth map onto the eye’s view from the light's point-of-view

Example Comparing light distance to light depth map Green is where the light planar distance and the light depth map are approximately equal Non-green is where shadows should be

Example Complete scene with shadows Notice how specular highlights never appear in shadows Notice how curved surfaces cast shadows on each other

Comparison Two values A = Z value from depth map at fragment’s light XY position B = Z value of fragment seen from the eye If B is greater than A, then there must be something closer to the light than the fragment Then the fragment is shadowed If A and B are approximately equal, the fragment is lit

Shadow Mapping The A < B shadowed fragment case light source eye position depth map Z = A fragment’s light Z = B depth map image plane eye view image plane, a.k.a. the frame buffer

The A == B shadowed fragment case Shadow Mapping light source eye position depth map Z = A fragment’s light Z = B depth map image plane eye view image plane, a.k.a. the frame buffer

The depth map could be at a different resolution from the framebuffer This mismatch can lead to artifacts Shadow Mapping with a Picture in 2D (3) Note image precision mismatch!

Construct Shadow Map Realizing the theory in practice Constructing the depth map Use existing hardware depth buffer Use glPolygonOffset to offset depth value back Read back the depth buffer contents Depth map can be copied to a 2D texture Unfortunately, depth values tend to require more precision than 8-bit typical for textures Depth precision typically 16-bit or 24-bit

Dual-texture Shadow Mapping Precision Conserving your 8-bit depth map precision Frustum confined to objects of interest Frustum expanded out considerably breaks down the shadows

More Precision Allows Larger Lights Frustums Compare 8-bit to 16-bit precision for large frustum 8-bit: Large frustum breaks down the shadows, not enough precision 16-bit: Shadow looks just fine

Why Extra Precision Helps Where the precision is for previous images Most significant 8 bits of the depth map, pseudo-color inset magnifies variations Least significant 8 bits of the depth map, here is where the information is!

Aliasing issues Two types of problems Jagged shadow edges Blocky Pixels in second pass

Dueling Frusta Blocky Edges Light position out here pointing towards the viewer. Blocky shadow edge artifacts. Notice that shadow edge is well defined in the distance.

Shadow Boundaries Shadow map (depth buffer) has finite resolution Many pixels could map to the same texel Resolution mismatch Can be arbitrarily bad using projection!

Example Look at shadow/lit edge Aliasing issue in initial pass

Sampling Issue Depth buffer contains “window space” depth values Post-perspective divide means non-linear distribution glPolygonOffset is guaranteed to be a window space offset Doing a “clip space” glTranslatef is not sufficient Common shadow mapping implementation mistake Actual bias in depth buffer units will vary over the frustum No way to account for slope of polygon

Precision Mismatch Depth buffer contains “window space” depth values Post-perspective divide means non-linear distribution glPolygonOffset is guaranteed to be a window space offset Doing a “clip space” glTranslatef is not sufficient Common shadow mapping implementation mistake Actual bias in depth buffer units will vary over the frustum No way to account for slope of polygon

Depth Map Bias Differences in polygon offset bias Too little bias, everything begins to shadow Too much bias, shadow starts too far back Just right

How to do this in practice? Realizing the theory in practice Fragment’s light position can be generated using eye- linear texture coordinate generation OpenGL’s GL_EYE_LINEAR texgen generate homogenous (s, t, r, q) texture coordinates as light-space (x, y, z, w) T&L engines such as GeForce accelerate texgen! Relies on projective texturing

Shadow Mapping Issues Prone to aliasing artifacts “percentage closer” filtering helps this normal color filtering does not work well Depth bias is not completely foolproof Requires extra shadow map rendering pass and texture loading Higher resolution shadow map reduces blockiness but also increase texture copying expense

Shadow Mapping Issues Shadows are limited to view frustums could use six view frustums for omni-directional light Objects outside or crossing the near and far clip planes are not properly accounted for by shadowing Move near plane in as close as possible But too close throws away valuable depth map precision when using a projective frustum

Four Images of Dueling Frusta Case Eye’s View Light’s View Eye’s View with projection of color-coded mipmap levels from light: Red = minification Blue = magnification Light’s View with re-projection of above image from the eye

Interpretation of the Images of the Dueling Frusta Case Eye’s View Light’s View Region that is smallest in the light’s view is a region that is very large in the eye’s view. This implies that it would require a very high- resolution shadow map to avoid obvious blocky shadow edge artifacts.

Good Situation, Close to the Miner’s Lamp Eye’s View Light’s View Very similar views Note how the color- coded images share similar pattern and the coloration is uniform. Implies single depth map resolution would work well for most of the scene. Ghosting is where projection would be in shadow.

Evaluation Shadow mapping offers real-time shadowing effects Independent of scene complexity Very compatible with multi-texturing Does not mandate multi-pass as stenciled shadow volumes do Ideal for shadows from spotlights Consumer hardware shadow map support here today GeForce3, GeForce4 Ti, Xbox Dual-texturing technique supports legacy hardware Same basic technique used by Pixar to generate shadows in their computer-generated movies

References Atherton, Weiler, and Greenberg, "Polygon Shadow Generation" James Blinn, "Me and my (fake) Shadow Mark Kilgard, "Improving Shadows and Reflections via the Stencil Buffer" Everitt and Kilgard, "Practical and Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering" Shadow Maps Lance Williams, “Casting Curved Shadows on Curved Surfaces,” SIGGRAPH 78 William Reeves, David Salesin, and Robert Cook (Pixar), “Rendering antialiased shadows with depth maps,” SIGGRAPH 87 Mark Segal, et. al. (SGI), “Fast Shadows and Lighting Effects Using Texture Mapping,” SIGGRAPH 92

Sample Programs SIGGRAPH Advanced OpenGL class, 1996 shadowfun.c – Mark Kilgard – Projection with Stencil shadowvol.c – Tom McReynolds – demonstration of shadow volumes shadowmap.c – Tom McReynolds – shadow map, using OpenGL extensions softshadows.c – Tom McReynolds –Soft Shadows SIGGRAPH Advanced OpenGL class, 1997 softshadow2.c – Simon Hui – Uses method of Heckbert and Herf projtex.c – David Yu – based on Segal, Korobkin, van Widenfelt, Foran, and Haeberli, "Fast Shadows and Lighting Effects Using Texture Mapping", SIGGRAPH '92