Advanced Shading and Texturing

Similar documents
Computergrafik. Matthias Zwicker. Herbst 2010

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

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!

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

CSE528 Computer Graphics: Theory, Algorithms, and Applications

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

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

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

Real-Time Graphics Architecture

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

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

Shadow Algorithms. CSE 781 Winter Han-Wei Shen

Computer Graphics. Shadows

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

Texture. Texture Maps

Computer Graphics Shadow Algorithms

Comparing Reyes and OpenGL on a Stream Architecture

Deferred Rendering Due: Wednesday November 15 at 10pm

TEXTURE MAPPING. DVA338 Computer Graphics Thomas Larsson, Afshin Ameri

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

1.2.3 The Graphics Hardware Pipeline

Computer Graphics. Lecture 14 Bump-mapping, Global Illumination (1)

CS 354R: Computer Game Technology

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

Overview. Hierarchy. Level of detail hierarchy Texture maps Procedural shading and texturing Texture synthesis and noise.

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

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

Computer Graphics 10 - Shadows

Programmable GPUS. Last Time? Reading for Today. Homework 4. Planar Shadows Projective Texture Shadows Shadow Maps Shadow Volumes

Lecture 2. Shaders, GLSL and GPGPU

Shadow Mapping for Hemispherical and Omnidirectional Light Sources

Shadow Rendering EDA101 Advanced Shading and Rendering

Multi-View Soft Shadows. Louis Bavoil

Texture. Detail Representation

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

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

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

Parallax Bumpmapping. Whitepaper

Advanced Shading I: Shadow Rasterization Techniques

CHAPTER 1 Graphics Systems and Models 3

Shadow and Environment Maps

frame buffer depth buffer stencil buffer

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

Multiple Importance Sampling

Reflections, Shadows, Transparency, and Fog

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

The Graphics Pipeline

3D Rasterization II COS 426

Robust Stencil Shadow Volumes. CEDEC 2001 Tokyo, Japan

EDAF80 Introduction to Computer Graphics. Seminar 3. Shaders. Michael Doggett. Slides by Carl Johan Gribel,

CS 450: COMPUTER GRAPHICS TEXTURE MAPPING SPRING 2015 DR. MICHAEL J. REALE

Hardware-Assisted Relief Texture Mapping

Real - Time Rendering. Graphics pipeline. Michal Červeňanský Juraj Starinský

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Textures. Texture coordinates. Introduce one more component to geometry

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

E.Order of Operations

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

Non-Linearly Quantized Moment Shadow Maps

Real-Time Graphics Architecture

Evolution of GPUs Chris Seitz

Shadow Volumes Revisited

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

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

Computer Graphics (CS 543) Lecture 10: Normal Maps, Parametrization, Tone Mapping

Interactive Cloth Simulation. Matthias Wloka NVIDIA Corporation

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

A Rendering Method on Desert Scenes of Dunes with Wind-ripples

The Traditional Graphics Pipeline

Parallelizing Graphics Pipeline Execution (+ Basics of Characterizing a Rendering Workload)

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

CS 498 VR. Lecture 19-4/9/18. go.illinois.edu/vrlect19

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

Those Delicious Texels or Dynamic Image-Space Per-Pixel

CS 431/636 Advanced Rendering Techniques

Real-Time Rendering (Echtzeitgraphik) Dr. Michael Wimmer

Towards Interactive Bump Mapping with Anisotropic Shift-Variant BRDFs

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

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

Direct Rendering of Trimmed NURBS Surfaces

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

Introduction to Visualization and Computer Graphics

Programming Graphics Hardware

Real-Time Reyes: Programmable Pipelines and Research Challenges. Anjul Patney University of California, Davis

Computer Graphics 7 - Texture mapping, bump mapping and antialiasing

Fall CSCI 420: Computer Graphics. 7.1 Rasterization. Hao Li.

Interactive Computer Graphics A TOP-DOWN APPROACH WITH SHADER-BASED OPENGL

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

CS451 Texturing 4. Bump mapping continued. Jyh-Ming Lien Department of Computer SCience George Mason University. From Martin Mittring,

Lecture 13: Reyes Architecture and Implementation. Kayvon Fatahalian CMU : Graphics and Imaging Architectures (Fall 2011)

Shadows in the graphics pipeline

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

GLOBAL EDITION. Interactive Computer Graphics. A Top-Down Approach with WebGL SEVENTH EDITION. Edward Angel Dave Shreiner

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

Shadows. COMP 575/770 Spring 2013

SGI OpenGL Shader. Marc Olano SGI

Models and Architectures

CSE4030 Introduction to Computer Graphics

Transcription:

Real-Time Graphics Architecture Kurt Akeley Pat Hanrahan http://www.graphics.stanford.edu/courses/cs448a-01-fall Advanced Shading and Texturing 1

Topics Features Bump mapping Environment mapping Shadow mapping Mechanisms Multipass Multitexturing Dependent texturing Texture addressing Texture combiners Readings Background 1. T. McReynolds et al., Advanced graphics programming techniques using OpenGL Compendium of multipass rendering techniques Available online 2. ATI and NVIDIA developer pages 2

Bumps Readings: Bump mapping Required 1. M. Peercy, J. Airey, B. Cabral, Efficient Bump mapping hardware, 2000 2. M. Kilgard, A practical and robust bump mapping for today s GPUS, 2001 Recommended 1. J. Blinn, Simulation of wrinkled surfaces, 1978 3

Bump Mapping [Blinn 1978] Offset surface position Displacement Pu(,) uv Pv(,) uv N(,) uv = P(,) uv P(,) uv u P (,) uv = P(,) uv + huv (,) N(,) uv Perturb normal P u(,) uv P v(,) uv N (,) uv = P (,) uv P (,) uv v From Blinn 1978 u v Bumps from Heights P = P + N+ N = P + N+ P + N 2 u u hu h u u hu O( u ) u hu P = P + N+ N = P + N+ P + N 2 v v hv h v v hv O( v ) v hv N = N h ( P N) h ( N P ) u v v u huv (,) N h u P u P u 4

Tangent Space Concept from differential geometry The set of all tangents on a surface Orthonormal coordinate system or frame at each point P P u v N = P u P v u T = P P u B= N T B T N Normals Maps In tangent frame ht N = ( T B N ) h B 1 N N T Normal map ( ) N = T B N N N N T B N B Directional derivatives ht hb = ( T ) h = ( B ) h 5

Distortions Classic texture mapping Length of parametric derivatives and Jacobian Area changes over surface controls local resolution Bump mapping Scale transformation Controls absolute height of the bumps wrt the surface Length of parametric derivatives Controls relative height of bumps across the surface Modeling vs. Rendering? Bump Map Representations 1. Height field ~ Embossing Single high precision component Directional derivative: Lˆ Nˆ = ( Lˆ ) h 2. Derivatives (HI,LO) ( ht, hb) = ( ht, hb,1) Scale factor needed to maintain control height 3. Normal maps (R,G,B) ( NT, NB, NN) 4. Normal index maps (index) Index addresses a table of precomputed normals 16-bit indices more than sufficient 6

Tangent Space on Triangles N 3 P 3 T 3 B 3 N 1 P 1 T 1 N 2 B 1 T 2 B 2 P 2 Transformation Transformation from tangent space to object space Tx Bx Nx R= ( T B N) = Ty By Ny Tz Bz Nz Transformation from object space to tangent space T T T = = = Nx Ny Nz x y z 1 1 T R ( T B N) ( T B N) Bx By Bz Remember that normals tranform as R -T =R 7

Basic Algorithm (Eye Space) For scene (assumes infinite L and E, otherwise per-v or per-f) Transform L and E to eye space and normalize Compute normalized H For each vertex Transform N from object space to eye space For each fragment Interpolate and renormalize N Compute Pu and Pv in eye space (may require transform) Fetch (hu, hv) = texture(s,t,q,r) Compute N = N + hu (N x Pu) + hv (Pv x N) Normalize N Compute max(l.n,0) and max(h.n,0) s Combine using the standard diffuse+specular equation Fast Algorithm (Tangent Space) For each vertex Transform L and E to tangent space and normalize Compute normalized H For each fragment Interpolate L and H (no need to interpolate N) Renormalize L and H Fetch N = texture(s,t,q,r) Compute max(l.n,0) and max(h.n,0) s Combine using the standard diffuse+specular lighting equation 8

Normalizing Vectors Cubemap(R) = R/ R, [Voorhies and Foran, 1994] +Y face -X face +Z face +X face -Z face -Y face Alternatively, use one iteration of a Newton-Raphson reciprocal square root algorithm Cubical Environment Map cubemap(r) Note: Easy to produce with rendering system Possible to produce from photographs Uniform resolution Simple texture coordinates calculation 9

Reflective Bump Mapping From Reflective Bump Mapping presentation, C. Everett Reflective Bump Mapping Algorithm For each vertex Transform E to world space Compute tangent space to world space transform (T,B,N) For each fragment Interpolate and renormalize E Interpolate frame (T,B,N) Lookup N = texture(s,t,q,r) Transform N from tangent space to world space Compute reflection vector R (in world space) R = E+ 2 N( N E) Lookup C = cubemap(r) Note: This is an example of dependent texturing 10

Shading Space How to avoid transformations? Definition space: E in eye space L in light space H in eye space (transform L to eye space) Shadow maps in light space Environment maps in world space Normal maps in tangent space Important now, important in the future? See Miller, Halstead and Clifton for algorithms Filtering Bump Maps Ideally Compute reflection at different positions on the surface with different perturbed normals a high resolution Average reflected values Practically Average perturbed normals Compute reflection using the average normal Still an unsolved problem 11

Shade-First Uniformly or adaptively tesselate the surface Shade the surface (in object- or tangent-space) Warp shaded surface to image-space L E Catmull and Smith, 1980 Shadows 12

Readings: Shadows Required 1. F. Crow, Shadow algorithms for computer graphics, SIGGRAPH 77 2. L. Williams, Casting curved shadows on curved surface, SIGGRAPH 78 Recommended 1. W. Reeves, D. Salesin, and R. Cook (Pixar), Rendering antialiased shadows with depth maps, SIGGRAPH 87 2. M. Segal, et al. (SGI), Fast shadows and lighting effects using texture mapping, SIGGRAPH 92 Shadow Volumes [Crow 1977] Example from NVIDIA Web Site Light source Given a point light source: 1. Each back-facing triangle is culled 2. Each silhouette edge generates an infinite quadrilateral 3. Each front-facing triangle is kept 13

Stencil Stage Fragment Owner Test Scissor Test Alpha Test Stencil Test Depth Test Blend Dither Logic Op FB Stencil buffer (0-32 bits) Stencil test Tests against value from stencil buffer; rejects fragment if stencil test fails. Operations on stencil buffer depending on the results of the stencil and depth tests. Stencil Test Compares reference value to stencil buffer value glstencilfunc(op, ref, mask); Same comparison functions as alpha and depth tests NEVER, ALWAYS LESS, LEQUAL GREATER, GEQUAL EQUAL, NOTEQUAL Bit mask controls comparison test = ((ref & mask) op (svalue & mask)) 14

Stencil Operations Three possible stencil side effects glstencilop(fail, zfail, zpass); Possible operations Increment, Decrement (saturates) Increment, Decrement (wrap, DX6 option) Keep, Replace Zero, Invert Stencil mask controls write-back glstencilmask(mask); Stencil Shadow Algorithm 1. Render scene to create depth buffer Don t shade when rendering 2. Render the shadow volume to create stencil buffer Invert stencil bits when depth test passes glstencilop(gl_keep,gl_keep,gl_invert); Result: Pixels outside the shadow volume are inverted an even number of times Pixels inside the shadow volume are inverted an odd number of times 15

Example From Kilgard L Shadowing triangle 0 (2 inverts) E 1 (1 invert) 0 (no inverts) Render In and Out of Shadow 3. Render the scene with the light disabled, update only pixels with an odd stencil bit setting 4. Render the scene with the light enabled, update only pixels with an even stencil bit setting 16

Multiple Shadow Volumes Use the GL_INCR stencil operation for front facing shadow volume polygons Use the GL_DECR stencil operation for back facing shadow volume polygons L shadowing triangle E 0 +1 0 +2 +2 +1 +3 Shadow Maps Depth buffer 17

William s Shadow Map Algorithm 1. Render the scene from the point of view of the light source to create a depth map Note: No need to shade 2. Render the scene from the point of view of the eye 1. Transform fragment positions to light space 2. Compare light z with shadow map z Alpha = (zl < shadow[xl][yl].z + bias) 3. Modulate color by shadow matte Problem: Attenuates after reflection, not before! Shadow Map Algorithm 1. Render the scene from the point of view of the light source to create a depth map 2. Copy texture to shadow texture map 3. Render the scene from the point of view of the eye 1. Transform vertex eye positions to light space positions 2. Perspectively-correct interpolate light space positions 3. Compare light z with shadow map z 4. Set stencil 18

Projected Textures [Segal et al.] For each vertex Transform P to light space Set texture coordinates to light space positions For each fragment Interpolate light space projective texture coords. (sr,tr,qr,r) Compute projective texture coordinates (sr/r,tr/r,qr/r,1) Lookup color in textures v = texture(sr/r,tr/r) Slide Projector Source: Heidrich [99] 19

Bias Too little bias, everything begins to shadow Too much bias, shadow starts too far back Just right From NVIDIA Percentage-closer Filtering Reeves, Salesin and Cook, 1991 z00 z10 Shadow buffer z s 1 1 1 1 zf zf z44 1 1 1 1 1 1 0 0 11/16 1 0 0 0 zf Fragment z 20

Summary: Shadows Shadow volumes Drawing shadow volumes consumes lots of fill rate Relatively accurate Shadow maps Relatively efficient: one additional drawing only (no shading) pass per light source Precision and biasing issues lead to cruftiness and hand tuning per scene; difficult for dynamic scenes Maybe extended to linear and area light sources to create soft shadows with penumbras Shadows are very important But still remain difficult to implement and are quite costly Trends and Observations Reduced features to orthogonal mechanisms Texture types (normals, shadows, environments) Multitexturing Dependent texturing Texture addressing Texture combining and multipass Quickly becomes very general: programmable Defining moments filled with tricks and approximations These tricks often become fundamental and are built upon 21

Trends and Observations Shading and texturing costs dominate 99.99% of the rendering time in movie production Where in the pipeline? Vertex shading Lights and texture maps in object space; floating point Low shading rate (per-vertex), no texturing Fragment shading Access to limited data; low precision fixed point High shading rate (per-fragment), texturing Evolve towards Reyes Ray tracing 22