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

Similar documents
Shadow Algorithms. CSE 781 Winter Han-Wei Shen

Computer Graphics Shadow Algorithms

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

Computergrafik. Matthias Zwicker. Herbst 2010

Shadows in the graphics pipeline

Computer Graphics. Shadows

Robust Stencil Shadow Volumes. CEDEC 2001 Tokyo, Japan

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

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

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

Shadow Rendering EDA101 Advanced Shading and Rendering

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

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

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

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

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

Computer Graphics 10 - Shadows

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

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

Shadows. COMP 575/770 Spring 2013

Advanced Shading I: Shadow Rasterization Techniques

Shadow Techniques. Sim Dietrich NVIDIA Corporation

Volume Shadows Tutorial Nuclear / the Lab

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

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

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

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

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

Shadow Volume History (1) Shadow Volumes. Shadow Volume History (2) Shadow Volume History (3) Shadow Volume Basics. Shadow Volume History (4)

Creating soft shadows

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

Simpler Soft Shadow Mapping Lee Salzman September 20, 2007

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

Real-time Shadow Mapping

03 RENDERING PART TWO

A Shadow Volume Algorithm for Opaque and Transparent Non-Manifold Casters

Hard Shadows Aliasing and Remedies

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

Pipeline Operations. CS 4620 Lecture 14

Advanced Shading and Texturing

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

Optimized Stencil Shadow Volumes. Cass Everitt & Mark J. Kilgard

Real-time Shadows in CG

CEng 477 Introduction to Computer Graphics Fall 2007

Multi-View Soft Shadows. Louis Bavoil

Rasterization Overview

Deferred Rendering Due: Wednesday November 15 at 10pm

CS 381 Computer Graphics, Fall 2008 Midterm Exam Solutions. The Midterm Exam was given in class on Thursday, October 23, 2008.

Models and Architectures

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

Practical Shadow Mapping

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

Illumination and Geometry Techniques. Karljohan Lundin Palmerius

Introduction to Computer Graphics with WebGL

CS 5610 / Spring Depth Buffering and Hidden Surface Removal

Projective Shadows. D. Sim Dietrich Jr.

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

TSBK03 Screen-Space Ambient Occlusion

Reflections, Shadows, Transparency, and Fog

Real-Time Universal Capture Facial Animation with GPU Skin Rendering

Rendering Algorithms: Real-time indirect illumination. Spring 2010 Matthias Zwicker

An Interactive Introduction to OpenGL Programming

Algorithms for Real-Time Rendering of Soft Shadows

FAST SELF-SHADOWING USING OCCLUDER TEXTURES. A Thesis CHRISTOPHER RYAN COLEMAN

CS 354R: Computer Game Technology

Stencil Shadow Volumes

Recollection. Models Pixels. Model transformation Viewport transformation Clipping Rasterization Texturing + Lights & shadows

Hardware-driven visibility culling

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

CSE 167: Introduction to Computer Graphics Lecture #9: Visibility. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2018

Practical Shadows. Outline

Projection Matrix Tricks. Eric Lengyel

CS4620/5620: Lecture 14 Pipeline

Other Rendering Techniques CSE 872 Fall Intro You have seen Scanline converter (+z-buffer) Painter s algorithm Radiosity CSE 872 Fall

In- Class Exercises for Shadow Algorithms

CHAPTER 3. Visualization of Vector Data. 3.1 Motivation

FRUSTUM-TRACED RASTER SHADOWS: REVISITING IRREGULAR Z-BUFFERS

CSE528 Computer Graphics: Theory, Algorithms, and Applications

High-quality Shadows with Improved Paraboloid Mapping

INFOGR Computer Graphics. J. Bikker - April-July Lecture 10: Ground Truth. Welcome!

Applications of Explicit Early-Z Culling

DOOM 3 : The guts of a rendering engine

FRUSTUM-TRACED RASTER SHADOWS: REVISITING IRREGULAR Z-BUFFERS

Shadow Mapping. Marc Stamminger, University of Erlangen-Nuremberg

6.837 Introduction to Computer Graphics Quiz 2 Thursday November 20, :40-4pm One hand-written sheet of notes allowed

Shadow Mapping for Hemispherical and Omnidirectional Light Sources

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

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

Vincent Forest, Loïc Barthe, Mathias Paulin. IRIT-UPS-CNRS University of Toulouse, France

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

Enabling immersive gaming experiences Intro to Ray Tracing

Computer Graphics Introduction. Taku Komura

Gaël Guennebaud Loïc Barthe, Mathias Paulin IRIT UPS CNRS TOULOUSE FRANCE Gaël Guennebaud Cyprus June 2006

Thesis Report. Thesis Title: Soft Shadow Rendering in Real Time. Shihab Rezwan Manzur ID: CSE Department BRAC University

BCC Sphere Transition

CHAPTER 1 Graphics Systems and Models 3

Transcription:

Shadows

What for? Shadows tell us about the relative locations and motions of objects Vienna University of Technology 2

What for? Shadows tell us about the relative locations and motions of objects And about light positions Vienna University of Technology 3

What for? Objects look like they are floating Shadows can fix that! Vienna University of Technology 4

Motivation Shadows contribute significantly to realism of rendered images Anchors objects in scene Global effect expensive! Light source behaves very similar to camera Is a point visible from the light source? shadows are hidden regions Shadow is a projection of caster on receiver projection methods Best done completely in hardware through shaders Vienna University of Technology 5

Shadow Algorithms Static shadow algorithms (lights + objects) Radiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow maps (Williams 78) Projective image-space algorithm Soft shadow extensions for all above algorithms Still hot research topic (500+ shadow publications) Vienna University of Technology 6

Shadow Terms light source creator (occluder, blocker, caster) creator and receiver receiver (occludee) Vienna University of Technology 7

Hard vs. Soft Shadows point source area source umbra hard shadow +fast penumbra penumbra -only good for localized lights (sun, projectors) +fake soft shadow through filtering Vienna University of Technology 8 + very realistic - very expensive + becomes more and more usable

Static Shadows Glue to surface whatever we want Idea: incorporate shadows into light maps For each texel, cast ray to each light source Bake soft shadows in light maps Not by texture filtering alone, but: Sample area light sources Vienna University of Technology 9

Static Soft Shadow Example no filtering filtering 1 sample n samples Vienna University of Technology 10

Approximate Shadows Hand-drawn approximate geometry Perceptual studies suggest: shape not so important Minimal cost Vienna University of Technology 11

Approximate Shadows Dark polygon (maybe with texture) Cast ray from light source through object center Blend polygon into frame buffer at location of hit May apply additional rotation/scale/translation Incorporate distance and receiver orientation Problem with z-quantization: light viewer Blend at hit polygon Z-test equal z-buffer quantization errors! Vienna University of Technology 12

Approximate Shadows Elevate above hit polygon Z-test less or equal shadow too big may appear floating light viewer No z-test, only one eye ray shadow too big, maybe in wrong place Vienna University of Technology 13

Projection Shadows (Blinn 88) Shadows for selected large planar receivers Ground plane Walls Projective geometry: flatten 3D model onto plane and darken using framebuffer blend Vienna University of Technology 14

Projection for Ground Plane Use similar-triangle tricks l y l l p l y = y y y x x x x v l l l v l p y y x x l l v = y y y x x y x v l v l v l p y=0 y=0 = y z z y y y v l v l p p = 0 y y z p v l p Vienna University of Technology 15 0 y p

Projection Matrix M Projective 4x4 matrix: l y lx 0 0 0 0 0 0 = 0 lz ly 0 0 1 0 l y Arbitrary yplane: Intersect line p = l α (v l) with plane nx+ d = 0 Express result as a 4x4 matrix Append this matrix to view transform Vienna University of Technology 16 n l v p

Projection Shadow Algorithm Render scene (full lighting) For each receiver polygon Compute projection matrix M Append to view matrix Render selected shadow caster With framebuffer blending enabled Vienna University of Technology 17

Projection Shadow Artifacts Bad Good extends off ground region Z fighting double blending Vienna University of Technology 18

Stencil Buffer Projection Shadows Stencil can solve all of these problems Separate 8-bit frame buffer for numeric ops Stencil buffer algorithm (requires 1 bit): Clear stencil to 0 Draw ground polygon last and with glstencilop(gl_keep, GL_KEEP, GL_ONE); fail zfail pass Draw shadow caster with no depth test but glstencilfunc(gl_equal, 1, 0xFF); glstencilop(gl_keep, GL_KEEP, GL_ZERO); Every plane pixel is touched at most once Vienna University of Technology 19

Stencil Buffer Planar Reflections Draw object twice, second time with: glscalef(1, -1, 1) Reflects through floor Bad Vienna University of Technology 20 Good, stencil used to limit reflection.

Projection Shadow Summary Easy to implement GLQuake first game to implement it Only practical for very few, large receivers No self shadowing Possible remaining artifacts: wrong shadows Objects behind light source Objects behind receiverer Vienna University of Technology 21

Shadow Volumes (Crow 1977) Occluders and light source cast out a 3D shadow volume Shadow through new geometry Results in Pixel correct shadows Light source Shadowed scene Visualization of shadow volume Vienna University of Technology 22

Shadow Volumes (Crow 1977) Heavily used in Doom3 Vienna University of Technology 23

2D Cutaway of Shadow Volume Occluder polygons extruded to semi-infinite volumes light source shadowing object surface outside shadow volume (illuminated) shadow volume (infinite extent) eye position partially shadowed object surface inside shadow volume (shadowed) Vienna University of Technology 24

Shadow Volume Algorithm 3D point-in-polyhedron indide-outside test Principle similar to 2D point-in-polygon test Choose a point known to be outside the volume Count intersection ti on ray from test t point to known point with polyhedron faces Front face +1 Back face -1 Like non-zero winding rule! Known point will distinguish algorithms: Infinity: Z-fail algorithm Eye-point: Z-pass algorithm Vienna University of Technology 25

Enter/Leave Approach Increment on enter, decrement on leave Simultaneously l test t all visible ibl pixels Stop when hitting object nearest to viewer light source shadowing object zero +1 zero eye +1 position +2 +2 +3 Vienna University of Technology 26

Shadow Volume Algorithm Shadow volumes in object precision Calculated by CPU/Vertex Shaders Shadow test in image precision Using stencil buffer as counter! Vienna University of Technology 27

Shadow Volume Algorithm Step 1: Render scene Z-values Vienna University of Technology 28

Shadow Volume Algorithm Front face: +1 Back face: -1 Step 2: Render shadow volume faces Vienna University of Technology 29

Shadow Volume Algorithm Front face: ±0 (Depth test) Back face: ±0 (Depth test) Σ = ±0 Vienna University of Technology 30

Shadow Volume Algorithm ±0 Front face: +1 Back face: ±0 (Depth test) Σ = +1 Vienna University of Technology 31

Shadow Volume Algorithm +1 ±0 Front face: +1 Back face: -1 Σ = ±0 Vienna University of Technology 32

Shadow Volume Algorithm ±0 +1 ±0 Step 3: Apply shadow mask to scene Vienna University of Technology 33

Shadow Volume Algorithm (Zpass) Render scene to establish z-buffer Can also do ambient illumination For each light Clear stencil Draw shadow volume twice using culling Render front faces and increment stencil Render back faces and decrement stencil Illuminate all pixels not in shadow volume Render testing stencil = 0 Use additive blend Vienna University of Technology 34

Zpass Technique (Before Shadow) Light source Shadowing object zero +1 zero Eye +1 position +2 +2 +3 Unshadowed object Shadow Volume Count = 0 (no depth tests passes) Vienna University of Technology 35

Zpass Technique (In Shadow) Light source Shadowing object zero +1 zero + + + - Eye +1 position +2 +2 +3 Shadowed object Shadow Volume Count = +1+1+1-1 1 = 2 Vienna University of Technology 36

Zpass Technique (Behind Shadow) Light source Shadowing object zero +1 zero + + + - - - +2 +2 Eye +1 +3 position Unshadowed object Shadow Volume Count = +1+1+1-1-1-1 1 1 1 1 1 = 0 Vienna University of Technology 37

Zpass Near Plane Problem Missed shadow volume intersection due to near clip plane clipping; leads to mistaken count zero Far clip plane +1 +2 +3 +1 zero +2 Near clip plane Vienna University of Technology 38

Alternative: Zfail Technique Zpass near plane problem difficult to solve Have to cap shadow volume at near plane Expensive and not robust, many special cases Try reversing test t order Zfail technique (also known as Carmack s reverse) Start from infinity and stop at nearest intersection Render shadow volume fragments only when depth test t fails Render back faces first and increment Then front faces and decrement Need to cap shadow volume at infinity or light extent Vienna University of Technology 39

Zfail, Behind Shadow Light source Shadowing object zero +1 zero Eye +1 position +2 +2 +3 Unshadowed object Shadow Volume Count = 0 (zero depth tests t fail) Vienna University of Technology 40

Zfail, in Shadow Light source Shadowing object zero +1 zero Eye +1 position + + +2 +2 +3 Shadowed object Shadow Volume Count = +1+1 = 2 Vienna University of Technology 41

Zfail, before Shadow Light source Shadowing object zero +1 zero - - - + + + Eye +1 position +2 +2 +3 Unshadowed object Shadow Volume Count = -1-1-1+1+1+1 1 1+1+1+1 = 0 Vienna University of Technology 42

Shadow Volumes Shadow volume = closed polyhedron Actually 3 sets of polygons! 1. Object polygons facing the light ( light cap ) 2. Object polygons facing away from the light and projected to infinity (with w = 0) ( dark cap ) 3. At Actual shadow hd volume polygons (extruded dd object edges) ( sides ) but which h edges? Vienna University of Technology 43

Zpass vs. Zfail Equivalent, but reversed Zpass Zfail Faster (light cap and dark cap not needed) Light cap inside id object always fails z-test t Dark cap infinitely far away either fails or falls on background Problem at near clip plane (no robust solution) Slower (need to render dark and light caps!) Problem at far clip plane when light extends farther than far clip plane Robust solution with infinite shadow volumes! Vienna University of Technology 44

Zpass vs. Zfail Idea: Combine techniques! Test whether viewport in shadow Zfail Otherwise Zpass Idea: avoid far plane clipping in Zfail! Send far plane to infinity in projection matrix Easy, but loses some depth buffer precision Draw infinite vertices using homogeneous coordinates: project to infinity w = 0 robust solution! Vienna University of Technology 45

W=0 Rasterization At infinity, vertices become vectors (-3,-1,z1,1) (2,-2,z2,1) (2,-2,z2,0) (-1,-3,z1,0) (2,-2,z2,0) Vienna University of Technology 46

Computing Actual SV Polygons Trivial but bad: one volume per triangle 3 shadow volume polygons per triangle Better: find exact silhouette Expensive on CPU Even better: possible silhouette edges Edge shared by a back-facing and frontfacing polygon (with respect to light source!), extended to infinity Actual extrusion can be done by vertex shader Vienna University of Technology 47

Possible Silhouette Edges Vienna University of Technology 48

Shadow Volumes Summary Advantages Arbitrary receivers Fully dynamic Omnidirectional lights (unlike shadow maps!) Exact shadow boundaries (pixel-accurate) Automatic self shadowing Broad hardware support (stencil) Disadvantages Fill-rate intensive Difficult to get right (Zfail vs. Zpass) Silhouette computation required Doesn t work for arbitrary casters (smoke, fog ) Vienna University of Technology 49

Shadow Volume Issues Stencil buffering fast and present in all cards With 8 bits of stencil, maximum shadow depth is 255 EXT_stencil_wrap overcomes this Two-sided stencil tests can test front- and back triangles simultaneously Saves one pass available on NV30+ p NV_depth_clamp (hardware capping) Regain depth precision with normal projection Requires watertight models with connectivity, and watertight ti rasterization ti Vienna University of Technology 50

Shadow Maps Casting curved shadows on curved surfaces Image-space algorithm, 2 passes Final scene Shadow map Vienna University of Technology 51

Shadow Map Algorithm Eye view Eye Light Shadow map Render from light; save depth values Render from eye Transform all fragments to light space Compare z eye and z light (both in light space!!!) z eye > z Licht Vienna University of Technology 52 y g fragment in shadow

Shadow Maps in Hardware Render scene to z-buffer (from light source) Copy depth buffer to texture Render to depth texture + pbuffer Project shadow map into scene (remember projective texturing!) Hardware shadow test (ARB_shadow) Use homogeneous texture coordinates Compare r/q with texel at (s/q, t/q) Output 1 for lit and 0 for shadow Blend fragment color with shadow test result Vienna University of Technology 53

Shadow Maps in Hardware Shadow extension available since GeForce3 Requires high precision texture format (ARB_depth_texture) On modern hardware: Render lightspace depth into texture In vertex shader: Calculate texture coordinates as in projective texturing In fragment shader: Depth compare Vienna University of Technology 54

Problem: Perspective Aliasing Sufficient resolution far from eye Insufficient resolution near eye Vienna University of Technology okay 55 aliased

Problem: Projection Aliasing Shadow receiver ~ orthogonal to Shadow Map - viewplane Vienna University of Technology 56

Problem: Incorrect Self-Shadowing Polygon Vienna University of Technology 57

Problem: Incorrect Self-Shadowing Polygon z eye > z light Incorrect Self-shadowing Vienna University of Technology 58

Solution for Perspective Aliasing Insufficient resolution near eye okay aliased Vienna University of Technology 59

Solution for Perspective Aliasing Insufficient resolution near eye Redistribute values in shadow map Vienna University of Technology 60

Solution for Perspective Aliasing Sufficient resolution near eye Redistribute values in shadow map okay okay Vienna University of Technology 61

Solution for Perspective Aliasing How to redistribute? Use perspective p transform Additional perspective matrix, used in both: Light pass Eye pass More details: [WSP2004] [WSP2004] M. Wimmer, D. Scherzer, and W. Purgathofer; Light space perspective shadow maps; In Proceedings of Eurographics Symposium on Rendering 2004 Vienna University of Technology 62

Solution for Projection Aliasing Shadow receiver ~ orthogonal to Shadow Map plane Redistribution does not work But... Vienna University of Technology 63

Solution for Projection Aliasing Diffuse lighting: I = I L max( dot( L, N ), 0 ) Almost orthogonal receivers have small I Dark artifacts not very visible! L N Vienna University of Technology 64

Solution for Projection Aliasing Recommendations Small ambient term Diffuse term hides artifacts Specular term not problematic Light and view direction almost identical Shadow Map resolution sufficient Vienna University of Technology 65

Solution for Projection Aliasing Blur shadows Hides artifacts Soft shadow borders Render shadow result values to separate texture and blur Vienna University of Technology 66

Solution for Incorrect Self-Shadowing Polygon Shifted Polygon z Aug > z Licht z Aug < z Licht Incorrect Self-shadowing No Self-shadowing Vienna University of Technology 67

Solution for Incorrect Self-Shadowing How to choose bias? No Bias Vienna University of Technology 68 Constant Bias Slope-Scale Bias

Depth Bias glpolygonoffset(1.1,4.0) works well Works in window coordinates Too little bias, everything begins to shadow Too much bias, shadow starts too far back Vienna University of Technology 69

Solution for Incorrect Self-Shadowing Other possibility: Previous: render front faces into Shadow Map Now: render back faces into Shadow Map: Back- Side Rendering Vienna University of Technology 70

Problem: Aliasing Artifacts Resolution mismatch image/shadow map! Use perspective shadow maps Use percentage closer filtering Normal color filtering cannot be used Filter lookup result, not depth map values! 2x2 PCF in hardware for NVIDIA Better: Poisson-disk distributed samples (e.g., 6 averaged aged samples) Vienna University of Technology 71

Shadow Map Filtering GL_NEAREST GL_LINEARLINEAR Vienna University of Technology 72

Shadow Map Summary Advantages Fast only one additional pass Independent of scene complexity (no additional shadow polygons!) Self shadowing (but beware bias) Can sometimes reuse depth map Disadvantages Problematic for omnidirectional o lights Biasing tweak (light leaks, surface acne) Jagged edges (aliasing) i Vienna University of Technology 73

OGRE shadow demo Vienna University of Technology 74

Conclusions Shadows are very important but still difficult Many variations based on shadow volumes/shadow maps to do shadowing: Variance shadow mapping (VSM) Perspective shadow mapping (PSM) Hierarchical shadow volume Subdivided shadow maps Vienna University of Technology 75