Shadow Mapping. Render Scene and Access the Depth Texture. What is Projective Texturing? About Projective Texturing (1) About Projective Texturing (3)

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

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

Practical Shadow Mapping

Shadow Algorithms. CSE 781 Winter Han-Wei Shen

Real-time Shadow Mapping

Reflections, Shadows, Transparency, and Fog

Real-Time Graphics Architecture. Kurt Akeley Pat Hanrahan. Texture

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

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

Computergrafik. Matthias Zwicker. Herbst 2010

Rasterization Overview

Computer Graphics. Shadows

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

Computer Graphics 10 - Shadows

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

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

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

Computer Graphics Shadow Algorithms

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

Advanced Shading and Texturing

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

Shadow Mapping for Hemispherical and Omnidirectional Light Sources

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

Robust Stencil Shadow Volumes. CEDEC 2001 Tokyo, Japan

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

Projective Textures & Shadow Mapping. Prof. Aaron Lanterman School of Electrical and Computer Engineering Georgia Institute of Technology

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

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

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

CS 354R: Computer Game Technology

Creating soft shadows

Clipping. CSC 7443: Scientific Information Visualization

CS 130 Final. Fall 2015

Deferred Rendering Due: Wednesday November 15 at 10pm

Shadows. Prof. George Wolberg Dept. of Computer Science City College of New York

Spotlight Shadow Mapping in OpenGL

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

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

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

Hardware Shading: State-of-the-Art and Future Challenges

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

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

The Traditional Graphics Pipeline

Projection Matrix Tricks. Eric Lengyel

Real Ti - me R en ering (Echtzeitgraphik)

Shadow Techniques. Sim Dietrich NVIDIA Corporation

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

AGDC Per-Pixel Shading. Sim Dietrich

Programming Graphics Hardware

A Proposal for OpenGL 1.4 Matt Craighead NVIDIA Corporation

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Real Time Reflections Han-Wei Shen

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

CS 381 Computer Graphics, Fall 2012 Midterm Exam Solutions. The Midterm Exam was given in class on Tuesday, October 16, 2012.

Shadows in the graphics pipeline

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

The Traditional Graphics Pipeline

Lecture 2. Shaders, GLSL and GPGPU

Shadows & Programmable Shaders. Dr. Alexander G. Gee. Texture Mapping. Buffers Texture Mapping OpenGL Texture Mapping Compositing and Blending

Direct Rendering of Trimmed NURBS Surfaces

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

Applications of Explicit Early-Z Culling

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

Abstract. 2 Description of the Effects Used. 1 Introduction Phong Illumination Bump Mapping

Real Time Rendering of Expensive Small Environments Colin Branch Stetson University

Texture. Real-Time Graphics Architecture. Kurt Akeley Pat Hanrahan.

TEXTURE MAPPING. DVA338 Computer Graphics Thomas Larsson, Afshin Ameri

Shadow Volumes Revisited

Overview. By end of the week:

3D Rasterization II COS 426

Hardware Accelerated Volume Visualization. Leonid I. Dimitrov & Milos Sramek GMI Austrian Academy of Sciences

Real-Time Graphics Architecture

An Optimized Soft Shadow Volume Algorithm with Real-Time Performance

Simpler Soft Shadow Mapping Lee Salzman September 20, 2007

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Today. Rendering algorithms. Rendering algorithms. Images. Images. Rendering Algorithms. Course overview Organization Introduction to ray tracing

Models and Architectures

3D graphics, raster and colors CS312 Fall 2010

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

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

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

Hardware-Assisted Relief Texture Mapping

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

DEFERRED RENDERING STEFAN MÜLLER ARISONA, ETH ZURICH SMA/

CHAPTER 1 Graphics Systems and Models 3

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

Tutorial on GPU Programming #2. Joong-Youn Lee Supercomputing Center, KISTI

Projection and viewing. Computer Graphics CSE 167 Lecture 4

Game Architecture. 2/19/16: Rasterization

Real-Time Graphics Architecture

For each question, indicate whether the statement is true or false by circling T or F, respectively.

Textures. Texture coordinates. Introduce one more component to geometry

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

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

Shadow Rendering EDA101 Advanced Shading and Rendering

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

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

Effects needed for Realism. Ray Tracing. Ray Tracing: History. Outline. Foundations of Computer Graphics (Spring 2012)

Evolution of GPUs Chris Seitz

Module 13C: Using The 3D Graphics APIs OpenGL ES

Transcription:

Render Scene and Access the Depth Texture Shadow Mapping Cass Everitt NVIDIA Corporation cass@nvidia.com Realizing the theory in practice Fragment s light position can be generated using eye-linear texture coordinate generation specifically 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 2 What is Projective Texturing? Projective Texturing (1) An intuition for projective texturing The slide projector analogy Source: Wolfgang Heidrich [99] First, what is perspective-correct texturing? Normal 2D texture mapping uses (s, t) coordinates 2D perspective-correct texture mapping means (s, t) should be interpolated linearly in eyespace so compute per-vertex s/w, t/w, and 1/w linearly interpolate these three parameters over polygon per-fragment compute s = (s/w) / (1/w) and t = (t/w) / (1/w) results in per-fragment perspective correct (s, t ) 3 4 Projective Texturing (2) Projective Texturing (3) So what is projective texturing? Now consider homogeneous texture coordinates (s, t, r, q) --> (s/q, t/q, r/q) Similar to homogeneous clip coordinates where (x, y, z, w) = (x/w, y/w, z/w) Idea is to have (s/q, t/q, r/q) be projected perfragment This requires a per-fragment divider yikes, dividers in hardware are fairly expensive Hardware designer s view of texturing Perspective-correct texturing is a practical requirement otherwise, textures swim perspective-correct texturing already requires the hardware expense of a per-fragment divider Clever idea [Segal, et.al. 92] interpolate q/w instead of simply 1/w so projective texturing is practically free if you already do perspective-correct texturing! 5 6 1

Projective Texturing (4) Back to the Shadow Mapping Discussion... Tricking hardware into doing projective textures By interpolating q/w, hardware computes perfragment (s/w) / (q/w) = s/q (t/w) / (q/w) = t/q Net result: projective texturing OpenGL specifies projective texturing only overhead is multiplying 1/w by q but this is per-vertex Assign light-space texture coordinates via texgen Transform eye-space (x, y, z, w) coordinates to the light s view frustum (match how the light s depth map is generated) Further transform these coordinates to map directly into the light view s depth map Expressible as a projective transform load this transform into the 4 eye linear plane equations for S, T, and Q coordinates (s/q, t/q) will map to light s depth map texture 7 8 Shadow Map Operation Dedicated Hardware Shadow Mapping Support Automatic depth map lookups After the eye linear texgen with the proper transform loaded (s/q, t/q) is the fragment s corresponding location within the light s depth texture r/q is the Z planar distance of the fragment relative to the light s frustum, scaled and biased to [0,1] range Next compare texture value at (s/q, t/q) to value r/q if texture[s/q, t/q] r/q then not shadowed if texture[s/q, t/q] < r/q then shadowed 9 SGI RealityEngine, InfiniteReality, and GeForce3 Hardware Performs the shadow test as a texture filtering operation looks up texel at (s/q, t/q) in a 2D texture compares lookup value to r/q if texel is greater than or equal to r/q, then generate 1.0 if texel is less than r/q, then generate 0.0 Modulate color with result zero if fragment is shadowed or unchanged color if not 10 OpenGL Extensions for Shadow Map Hardware (See Page 445) Two extensions work together SGIX_depth_texture (see page 445) supports high-precision depth texture formats copy from depth buffer to texture memory supported SGIX_shadow (see page 445) adds shadow comparison texture filtering mode compares r/q to texel value at (s/q, t/q) Multi-vendor support: SGI, NVIDIA, others? Brian Paul has implemented these extensions in Mesa! 11 New Depth Texture Internal Texture Formats SGIX_depth_texture supports textures containing depth values for shadow mapping Three new internal formats GL_DEPTH_COMPONENT16_SGIX GL_DEPTH_COMPONENT24_SGIX GL_DEPTH_COMPONENT32_SGIX (same as 24-bit on GeForce3) Use GL_DEPTH_COMPONENT for your external format Work with glcopysubteximage2d for fast copies from depth buffer to texture NVIDIA optimizes these copy texture paths 12 2

Depth Texture Details Usage example: glcopyteximage2d(gl_texture_2d, level=0, internalfmt=gl_depth_component24_sgix, x=0, y=0, w=256, h=256, border=0); Then use glcopytexsubimage2d for faster updates once texture internal format initially defined Hint: use GL_DEPTH_COMPONENT for your texture internal format Leaving off the n_sgix precision specifier tells the driver to match your depth buffer s precision Copy texture performance is optimum when depth buffer precision matches the depth texture precision 13 14 Need to scale/bias too! 15 16 //Calculate texture matrix for projection //This matrix takes us from eye space to the light's clip space //It is postmultiplied by the inverse of the current view matrix when specifying texgen static MATRIX4X4 biasmatrix (0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 0.5f, 0.5f, 1.0f); MATRIX4X4 texturematrix=biasmatrix*lightprojectionmatrix*lightviewmatrix; //Set up texture coordinate generation. gltexgeni(gl_s, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); gltexgenfv(gl_s, GL_EYE_PLANE, texturematrix.getrow(0)); glenable(gl_texture_gen_s); gltexgeni(gl_t, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); gltexgenfv(gl_t, GL_EYE_PLANE, texturematrix.getrow(1)); Need to scale/bias too! glenable(gl_texture_gen_t); gltexgeni(gl_r, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); gltexgenfv(gl_r, GL_EYE_PLANE, texturematrix.getrow(2)); glenable(gl_texture_gen_r); gltexgeni(gl_q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); gltexgenfv(gl_q, GL_EYE_PLANE, texturematrix.getrow(3)); glenable(gl_texture_gen_q); 17 Careful about Back Projecting Shadow Maps (1) Just like standard projective textures, shadow maps can back-project Pentagon would be incorrectly lit by backprojection if not specially handled Back-projection of spotlight s cone of illumination Spotlight s cone of illumination where true shadows can form Spotlight casting shadow (a hooded light source) 18 3

Careful about Back Projecting Shadow Maps (2) Techniques to eliminate back-projection: Modulate shadow map result with lighting result from a single per-vertex spotlight with the proper cut off (ensures light is off behind the spotlight) Use a small 1D texture where s is planar distance from the light (generate s with a planar texgen mode), then 1D texture is 0.0 for negative distances and 1.0 for positive distances. Use a clip plane positioned at the plane defined by the light position and spotlight direction Use the stencil buffer Simply avoid drawing geometry behind the light when applying the shadow map (better than a clip plane) NV_texture_shader s GL_PASS_THROUGH_NV mode Combine with Projective Texturing for Spotlight Shadows Use a spotlight-style projected texture to give shadow maps a spotlight falloff 19 20 Combining Shadows with Atmospherics Hybrid of Shadow Volumes and Shadow Mapping Shadows in a dusty room Simulate atmospheric effects such as suspended dust 1) Construct shadow map 2) Draw scene with shadow map 3) Modulate projected texture image with projected shadow map 4) Blend back-to to-front shadowed slicing planes also modulated by projected texture image Very clever idea [McCool 98] Render scene from light source with depth testing Read back the depth buffer Use computer vision techniques to reconstruct the shadow volume geometry from the depth buffer image Very reasonable results for complex scenes Only requires stencil no multitexture and texture environment differencing required Shadow volume reconstruction from depth maps, ACM Transactions on Graphics (Jan. 2000) Also on Michael McCool s web site 21 22 Hybrid of Shadow Volumes and Shadow Mapping Conclusions 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 Dual-texturing technique supports legacy hardware Same basic technique used by Pixar to generate shadows in their computer-generated movies 23 24 4

Soft Shadows 26 Heckbert & Herf Idea: several point lights distributed over area light source Add contributions to scene using accumulation buffer 2x2 16x16 27 28 Heckbert & Herf Mark Kilgard 29 30 5