Shadow Algorithms. CSE 781 Winter Han-Wei Shen

Similar documents
Computergrafik. Matthias Zwicker. Herbst 2010

CMSC427 Advanced shading getting global illumination by local methods. Credit: slides Prof. Zwicker

Real-Time Shadows. Last Time? Today. Why are Shadows Important? Shadows as a Depth Cue. For Intuition about Scene Lighting

Computer Graphics. Shadows

Real-Time Shadows. Last Time? Textures can Alias. Schedule. Questions? Quiz 1: Tuesday October 26 th, in class (1 week from today!

Real-Time Shadows. MIT EECS 6.837, Durand and Cutler

Computer Graphics 10 - Shadows

What for? Shadows tell us about the relative locations. Vienna University of Technology 2

Real-Time Shadows. Last Time? Schedule. Questions? Today. Why are Shadows Important?

Shadows. COMP 575/770 Spring 2013

Computer Graphics Shadow Algorithms

Shadows in the graphics pipeline

Advanced Shading I: Shadow Rasterization Techniques

Computer Graphics (CS 543) Lecture 10: Soft Shadows (Maps and Volumes), Normal and Bump Mapping

Basic GPU techniques Josef Pelikán CGG MFF UK Praha.

For Intuition about Scene Lighting. Today. Limitations of Planar Shadows. Cast Shadows on Planar Surfaces. Shadow/View Duality.

Last Time. Why are Shadows Important? Today. Graphics Pipeline. Clipping. Rasterization. Why are Shadows Important?

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Lecture 17: Shadows. Projects. Why Shadows? Shadows. Using the Shadow Map. Shadow Maps. Proposals due today. I will mail out comments

Pipeline Operations. CS 4620 Lecture 10

Last Time. Reading for Today: Graphics Pipeline. Clipping. Rasterization

Rasterization Overview

Shadows. Real-Time Hard Shadows. Collected by Ronen Gvili. Most slides were taken from : Fredu Durand Stefan Brabec

Acknowledgement: Images and many slides from presentations by Mark J. Kilgard and other Nvidia folks, from slides on developer.nvidia.

Soft shadows. Steve Marschner Cornell University CS 569 Spring 2008, 21 February

CEng 477 Introduction to Computer Graphics Fall 2007

CS4620/5620: Lecture 14 Pipeline

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

Shadow Rendering EDA101 Advanced Shading and Rendering

Computer Graphics. Lecture 02 Graphics Pipeline. Edirlei Soares de Lima.

Visible-Surface Detection Methods. Chapter? Intro. to Computer Graphics Spring 2008, Y. G. Shin

Deferred Rendering Due: Wednesday November 15 at 10pm

Pipeline Operations. CS 4620 Lecture 14

Overview. A real-time shadow approach for an Augmented Reality application using shadow volumes. Augmented Reality.

Intro to OpenGL III. Don Fussell Computer Science Department The University of Texas at Austin

Illumination and Geometry Techniques. Karljohan Lundin Palmerius

Shadows in Computer Graphics. by Björn Kühl im/ve University of Hamburg, Germany

TDA362/DIT223 Computer Graphics EXAM (Same exam for both CTH- and GU students)

Soft Shadow Maps. Soft Shadow Maps for Linear Lights

Models and Architectures

Real-Time Shadows. Computer Graphics. MIT EECS Durand 1

Computing Visibility. Backface Culling for General Visibility. One More Trick with Planes. BSP Trees Ray Casting Depth Buffering Quiz

CSE 690: GPGPU. Lecture 2: Understanding the Fabric - Intro to Graphics. Klaus Mueller Stony Brook University Computer Science Department

Culling. Computer Graphics CSE 167 Lecture 12

Shadows. Shadows. Thanks to: Frédo Durand and Seth Teller MIT. Realism Depth cue

Robust Stencil Shadow Volumes. CEDEC 2001 Tokyo, Japan

CS 130 Final. Fall 2015

CS 428: Fall Introduction to. Polygon rendering: additional topics. Andrew Nealen, Rutgers, /14/2009 1

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Computer Graphics 1. Chapter 7 (June 17th, 2010, 2-4pm): Shading and rendering. LMU München Medieninformatik Andreas Butz Computergraphik 1 SS2010

The Graphics Pipeline. Interactive Computer Graphics. The Graphics Pipeline. The Graphics Pipeline. The Graphics Pipeline: Clipping

Homework #2. Shading, Ray Tracing, and Texture Mapping

CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

CPSC GLOBAL ILLUMINATION

Ray tracing. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 3/19/07 1

Intro to OpenGL III. Don Fussell Computer Science Department The University of Texas at Austin

Shadows. Shadows. Spatial relationship between objects. Shadows as depth cue. Spatial relationship between objects

Models and Architectures. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

03 RENDERING PART TWO

CS 354R: Computer Game Technology

Real-Time Shadows. André Offringa Timo Laman

Chapter 5. Projections and Rendering

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

CS 130 Exam I. Fall 2015

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

Introduction to Computer Graphics with WebGL

Advanced Shading and Texturing

Advanced Lighting Techniques Due: Monday November 2 at 10pm

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Soft Shadows: Heckbert & Herf. Soft shadows. Heckbert & Herf Soft Shadows. Cornell University CS 569: Interactive Computer Graphics.

Creating soft shadows

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Projections and Hardware Rendering. Brian Curless CSE 557 Fall 2014

Chapter 2 A top-down approach - How to make shaded images?

Texture Mapping II. Light maps Environment Maps Projective Textures Bump Maps Displacement Maps Solid Textures Mipmaps Shadows 1. 7.

Topics and things to know about them:

EECS 487: Interactive Computer Graphics

Computer Graphics. Rendering. by Brian Wyvill University of Calgary. cpsc/enel P 1

Reading. 18. Projections and Z-buffers. Required: Watt, Section , 6.3, 6.6 (esp. intro and subsections 1, 4, and 8 10), Further reading:

Announcements. Written Assignment 2 is out see the web page. Computer Graphics

Projection Matrix Tricks. Eric Lengyel

Visibility. Tom Funkhouser COS 526, Fall Slides mostly by Frédo Durand

CHAPTER 1 Graphics Systems and Models 3

Fondamenti di Grafica 3D The Rasterization Pipeline.

Today. Anti-aliasing Surface Parametrization Soft Shadows Global Illumination. Exercise 2. Path Tracing Radiosity

Homework #2. Shading, Projections, Texture Mapping, Ray Tracing, and Bezier Curves

CSE 167: Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Viewing. Reading: Angel Ch.5

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

Shadow Techniques. Sim Dietrich NVIDIA Corporation

Real Time Reflections Han-Wei Shen

CS 498 VR. Lecture 18-4/4/18. go.illinois.edu/vrlect18

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

lecture 19 Shadows - ray tracing - shadow mapping - ambient occlusion Interreflections

Lecture 4. Viewing, Projection and Viewport Transformations

CSE 167: Introduction to Computer Graphics Lecture #18: More Effects. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2016

Motivation. Sampling and Reconstruction of Visual Appearance. Effects needed for Realism. Ray Tracing. Outline

Computer Graphics. Lecture 13. Global Illumination 1: Ray Tracing and Radiosity. Taku Komura

Transcription:

Shadow Algorithms CSE 781 Winter 2010 Han-Wei Shen

Why Shadows? Makes 3D Graphics more believable Provides additional cues for the shapes and relative positions of objects in 3D

What is shadow? Shadow: comparative darkness given by shelter from direct light; patch of shade projected by a body intercepting light

Terminology (area) light source occluder penumbra umbra fully shadowed region penumbra partially shadowed region umbra shadow receiver

Hard and Soft Shadows Depends on the type of light sources Point or Directional ( Hard Shadows, umbra) point directional area Area ( Soft Shadows, umbra, penumbra), more difficult problem

Hard and Soft Shadows Hard shadow Soft shadow point light source area light source

Simple Approach: Ray tracing Cast ray to light (shadow rays) Surface point in shadow if the shadow rays hits an occluder object. Ray tracing is slow, can we do better? (perhaps at the cost of quality)

Shadow Algorithms We will first focus on hard shadows Planar Shadows Shadow Maps Shadow Volume

Planar Shadows The simplest algorithm shadowing occurs when objects cast shadows on planar surfaces (projection shadows) y light y light shadow shadow y=0 n.x + d =0

Planar Shadows Special case: the shadow receiver is an axis plane Just project all the polygon vertices to that plane and form shadow polygons y v light Given: - Light position l - Plane position y = 0 - Vertex position v Calculate: p shadow p y=0

Planar Shadows We can use similar triangles to solve p y l light px-lx vx-lx = ly ly-vy v px = ly vx lx vy shadow p ly - vy y=0 x Same principle applied to different axis planes

Planar Shadows How about arbitrary plane as the shadow receiver? y l light Plane equation: n.x + d = 0 ax + by + cz + d = 0 or where n = (a,b,c) - plane normal p v shadow n.x + d =0 Again, given light position l, v Find p

Planar Shadows Finding p We know: p = l + (v-l) x α y l light Also we know: n.p + d = 0 Because p is on the plane We can solve α easily: p v shadow n.x + d =0 p = l - (v - l) d + n.l n. (v l)

Issues about planar shadows Shadow polygon generation (z fighting) Add an offset to the shadow polygons (glpolygonoffset) Draw receivers first, turn z-test off, then draw the shadow polygons. After this, draw the rest of the scene. Shadow polygons fall outside the receiver Using stencil buffer draw receiver and update the stencil buffer Shadows have to be rendered at each frame Render into texture Restrictive to planar objects

Issues about planar shadows Anti-shadows and false shadows correct anti-shadow false shadow

Shadow Volumes A more general approach for receivers that have arbitrary shapes

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

2D Cutaway of a Shadow Volume Light source Shadowing object Surface outside shadow volume (illuminated) Shadow volume (infinite extent) Eye position (note that shadows are independent of the eye position) Partially shadowed object Surface inside shadow volume (shadowed)

In Shadow or not? Use shadow volume to perform such a test How do we know an object is inside the shadow volume? 1. Allocate a counter 2. Cast a ray into the scene 3. Increment the counter when the ray enter a front-facing polygon of the shadow volume (enter the shadow volume) 4. Decrement the counter when the ray crosses a backfacing polygon of the shadow volume (leave the shadow volume) 5. When we hit the object, check the counter. If counter >0 ; in shadow Otherwise - not in shadow

Counter for Shadow Volume Light source Shadowing object zero +1 zero Eye position +1 +2 +2 +3 In shadow

Real time shadow volume How can we render the idea of shadow volume in real time? Use OpenGL Stencil buffer as the counter Stencil buffer? Similar to color or depth buffer, except it s meaning is controlled by application (and not visible) Part of OpenGL fragment operation after alpha test before depth test 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 Function Comparison test between reference and stencil value GL_NEVER always fails GL_ALWAYS always passes GL_LESS passes if reference value is less than stencil buffer GL_LEQUAL passes if reference value is less than or equal to stencil buffer GL_EQUAL passes if reference value is equal to stencil buffer GL_GEQUAL passes if reference value is greater than or equal to stencil buffer GL_GREATER passes if reference value is greater than stencil buffer GL_NOTEQUAL passes if reference value is not equal to stencil buffer If the stencil test fails, the fragment is discarded and the stencil operations associated with the stencil test failing is applied to the stencil value If the stencil test passes, the depth test is applied If the depth test passes, the fragment continue through the graphics pipeline, and the stencil operation for stencil and depth test passing is applied If the depth test fails, the stencil operation for stencil passing but depth

Stencil Operation Stencil Operation: Results of Operation on Stencil Values GL_KEEP stencil value unchanged GL_ZERO stencil value set to zero GL_REPLACE stencil value replaced by stencil reference value GL_INCR stencil value incremented GL_DECR stencil value decremented GL_INVERT stencil value bitwise inverted Remember you can set different operations for Stencil fails Stencil passes, depth fails Stencil passes, depth passes

OpenGL for shadow volumes Z-pass approach Z-fail approach Ideas used by both of the algorithms are similar Z-pass: see whether the number of visible front-facing shadow volume polygons and the number of visible backfacing polygons are equal. If yes objects are not in shadow Z-fail: see whether the number of invisible back-facing shadow volume polygons and the number of invisible frontfacing polygons are equal. If yes objects are not in shadow

Z-pass approach Render visible scene with only ambient and emssion and update depth buffer Turn off depth and color write, turn on stencil (but still keep the depth test on) Init. stencil buffer Draw shadow volume twice using face culling 1st pass: render front faces and increment stencil buffer when depth test passes 2nd pass: render back faces and decrement when depth test passes stencil pixels!= 0 in shadow, = 0 are lit Render the scene again with diffuse and specular when stencil pixels =0

Problems of Z-pass algorithm 1. When the eye is in the shadow volume Counter= 0 does not imply out of shadow anymore In this case, the stencil buffer should be init. with the number of shadow volumes in which the eye is in (instead 0) 2. When the near plane intersects with the shadow volume faces (and thus will clip the faces)

Z-pass algorithm problem illustration light eye near far Mistakenly determined as not in shadow

Z-fail approach Render visible scene to depth buffer Turn off depth and color, turn on stencil Init. stencil buffer given viewpoint Draw shadow volume twice using face culling 1st pass: render back faces and increment when depth test fails 2nd pass: render front faces and decrement when depth test fails stencil pixels!= 0 in shadow, = 0 are lit

Problem of z-fail algorithm Shadow volume can penetrate the far plane Depth clamping Solution: depth clamping - close up the shadow volume

Shadow Map Basic idea: objects that are not visible to the light are in shadow How to determine whether an object are visible to the eye? Use z-buffer algorithm, but now the eye is light, i.e., the scene is rendered from light s point of view This particular z-buffer for the eye is called shadow map

Shadow Map Algorithm illustration

Shadow Map Algorithm 1. Render the scene using the light as the camera and perform z-buffering 2. Generate a light z buffer (called shadow map) 3. Render the scene using the regular camera, perform z-buffering, and run the following steps: (next slide)

Shadow Map Algorithm (cont d) 3.1 For each visible pixel with [x,y,z] in world space, perform a transformation to the light space (light as the eye) [x1,y1,z1] 3.2 Compare z1 with z = shadow_map[x1,y1] - If z1 <=z (closer to light), then the pixel in question is not in shadow; otherwise the pixel is shadowed

1st Pass View from light Depth Buffer (shadow map)

2nd Pass Visible surface depth

2nd Pass Non-green in shadow Final Image

Shadow map issues Shadow quality depends on Shadow map resolution aliasing problem Z resolution the shadow map is often stored in one channel of texture, which typically has only 8 bits Some hardware has dedicated shadow map support, such as Xbox and GeForce3 Self-shadow aliasing caused by different sample positions in the shadow map and the screen

Shadow map aliasing problem The shadow looks blocky when one single shadow map pixel covers several screen pixels This is a similar problem to texture magnification Where bi-linear interpolation or nearest neighbor are used in OpenGL

Percentage Closer Filtering Could average binary results of all depth map pixels covered Soft anti-aliased shadows

Shadow Maps With Graphics Hardware Render scene using the light as a camera Read depth buffer out and copy into a 2D texture. We now have a depth texture. Fragment s position in light space can be generated using eye-linear texture coordinate generation specifically OpenGL s GL_EYE_LINEAR texgen Using light-space (x, y, z, w) to generate homogenous (s, t, r, q) texture coordinates Transform the texture coodrinates

Real time soft shadowing Only area light source can generate soft shadows We can sample the area light source at different points and then average the results Many research done Example: Herf and Heckbert s algorithm

Herf and Heckbert s Basic Ideda Sample multiple points from the area light For each shadow receiver For each point light source Draw the receiver, shaded Project the environment onto the shadow receiver (draw in black) Draw the projection result into the OpenGL accumulation buffer Save the accumulation buffer content into a texture Draw the shadow receiver using the texture

Project onto the shadow receiver Transform the pyramid formed by the light and the receiver into a parallelepiped The parallelepiped has x, y ranged from (0,0) to (1,1) and z from 1 to infinity Essentially the light is viewing the receiver, and a perspective projection is performed Use OpenGL to render the environment between (0,0,1) and (1,1,infinity) in black

The projection setup a

The Projection Matrix Remember a is the point light source, b is one corner of the receiver parallelogram And ex ey are the two vectors for the parallelogram

Orthographic rendering make_projmatrix(m); // see the previous slide // OpenGL stuff glmatrixmode(gl_projection); glloadidentity(); glortho(0.0, 1.0, 0.0, 1.0, 0.999, 1000); glmultmatrixf(m); glmatrixmode(gl_modelview); // render the scene