Computergrafik. Matthias Zwicker. Herbst 2010

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

Shadow Algorithms. CSE 781 Winter Han-Wei Shen

Procedural modeling and shadow mapping. Computer Graphics CSE 167 Lecture 15

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

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

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

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

Advanced Shading I: Shadow Rasterization Techniques

Rasterization Overview

Computer Graphics. Shadows

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

Deferred Rendering Due: Wednesday November 15 at 10pm

Pipeline Operations. CS 4620 Lecture 14

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

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

CSE 167: Lecture #17: Procedural Modeling. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Shadows. COMP 575/770 Spring 2013

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

Volume Shadows Tutorial Nuclear / the Lab

Computer Graphics Shadow Algorithms

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

Pipeline Operations. CS 4620 Lecture 10

Computer Graphics 10 - Shadows

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

CS 130 Final. Fall 2015

TSBK03 Screen-Space Ambient Occlusion

Shadows in the graphics pipeline

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

Shadow Rendering EDA101 Advanced Shading and Rendering

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

Advanced Shading and Texturing

Today. Texture mapping in OpenGL. Texture mapping. Basic shaders for texturing. Today. Computergrafik

Robust Stencil Shadow Volumes. CEDEC 2001 Tokyo, Japan

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

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

Models and Architectures

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

Advanced Lighting Techniques Due: Monday November 2 at 10pm

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

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

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

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

OpenGl Pipeline. triangles, lines, points, images. Per-vertex ops. Primitive assembly. Texturing. Rasterization. Per-fragment ops.

Recall: Indexing into Cube Map

CS 4620 Program 3: Pipeline

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

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

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

CS4620/5620: Lecture 14 Pipeline

Shaders. Slide credit to Prof. Zwicker

CS451Real-time Rendering Pipeline

CHAPTER 1 Graphics Systems and Models 3

Introduction to Visualization and Computer Graphics

Illumination and Geometry Techniques. Karljohan Lundin Palmerius

Graphics and Interaction Rendering pipeline & object modelling

The Traditional Graphics Pipeline

3D Rasterization II COS 426

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

CS 354R: Computer Game Technology

The Graphics Pipeline

Rendering Objects. Need to transform all geometry then

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

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

Shadow Techniques. Sim Dietrich NVIDIA Corporation

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

Real-Time Shadows. André Offringa Timo Laman

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

INF3320 Computer Graphics and Discrete Geometry

Getting fancy with texture mapping (Part 2) CS559 Spring Apr 2017

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

Computer Graphics I Lecture 11

CPSC GLOBAL ILLUMINATION

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

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

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

The Traditional Graphics Pipeline

Introduction to Computer Graphics with WebGL

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

The Traditional Graphics Pipeline

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

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Interpolation using scanline algorithm

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Direct Rendering of Trimmed NURBS Surfaces

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

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

Real Time Reflections Han-Wei Shen

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Mach band effect. The Mach band effect increases the visual unpleasant representation of curved surface using flat shading.

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

Introduction Rasterization Z-buffering Shading. Graphics 2012/2013, 4th quarter. Lecture 09: graphics pipeline (rasterization and shading)

CS452/552; EE465/505. Clipping & Scan Conversion

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

EECS 487: Interactive Computer Graphics

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

Visibility: Z Buffering

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

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

Transcription:

Computergrafik Matthias Zwicker Universität Bern Herbst 2010

Today Bump mapping Shadows Shadow mapping Shadow mapping in OpenGL

Bump mapping Surface detail is often the result of small perturbations in the surface geometry Modeling detailed surfaces would lead to impractical number of triangles Bump mapping alters the surface normal Normals are encoded in texture maps Provide the illusion of small scale surface detail Does not change geometry (triangles) Requires per-pixel shading using a fragment program

Bump mapping No bump mapping With bump mapping Bump mapped plane No bump mapping With bump mapping Bump texture

Bump mapping Generating and storing bump maps Rendering with bump maps

Generating bump maps Usually done in a pre-process Input Texture map that encodes small surface displacements Height field E.g., use gray scale image as height values Output t Texture map that encodes normals of displaced surface This texture will be stored as an image, read by the application

Generating bump maps Start with displacement map (height field) Normal Discrete case using central differencing Usually u v = 1 Usually, u, v 1 Normalize length of normal!

Storing bump maps Encode normal direction in RGB color channels Coordinates of unit normal are in [-1..1] 3 Need to map range [-1..1] to [0..255] for all channels RGB encoded bump map

Rendering with bump maps When applying a bump map to a curved surface, how are the normals specified in the bump map related to the surface? Normals are defined relative to local tangent/normal vectors Normals Local tangent vector Normals in bump map Bump map applied to curved surface

Rendering with bump maps Bump map normals are defined in tangent space Defined by two tangent vectors and normal Will define tangent space for each triangle Texture coordinates provide parameterization of each triangle, i.e., parametric patch x(u,v) Compute tangent vectors using partial derivatives of parameterization For shading, will need to transform normals from tangent space to camera space

Tangent space Triangle with texture coordinates can be expressed as parametric surface x(u,v) Triangle vertices in object space v 0, v 1, v 2 Texture coordinates (u 0, v 0 0), (u 1, v 1 1), (u 2, v 2 2), Interpolation constraints: we know

Tangent space Solve for affine function Using constraints at vertices

Tangent space Tangent space defined by two tangent vectors (tangent t, bi-tangent b), and normal vector n tbndefined t, b, in object space coordinates Tangent, bi-tangent not orthogonal in general No normalization necessary

Normal in object space Normal map stores normals in tangent coordinates Basis vectors t, b, n Can transform normal from tangent to object space Given values [bm 0,bm 1,bm 2 ] from bump map Unpacked from [0..1] to range [-1..1]

Storing tangent vectors Before rendering For each triangle, compute tangent, t bitangent vector At each vertex, average tangent, bi- tangent vectors over adjacent triangles to get smooth transitions between triangles Store tangent vector as additional vertex attributes Only one tangent vector and normal necessary Second tangent vector computed on the fly

Rendering Vertex shader Per-vertex input Vertex position, normal, tangent vector in object space Bump map texture coordinates Compute bi-tangent vector Transform everything to camera space using modelview matrix Output to fragment shader (will be interpolated to each pixel) Vertex position, texture coordinates, tangent, bitangent, normal vector in camera space Bump map texture t coordinates

Rendering with bump maps Fragment shader Transform normal [bm 0, bm 1, bm 2 ] stored in bump map to camera coordinates Use t, b, n basis to transform to object space Use modelview matrix to transform from object space to camera space Normalize Perform lighting in camera coordinates

Variations Perform lighting in different coordinate system than camera space Object space Tangent space Tangent space is more efficient Transform light direction to tangent space in vertex shader Rasterizer interpolates it across triangle No need to transform bump mapped normal at each pixel (in fragment shader)

Caveats Need mesh with texture coordinates to define tangent space Avoid triangles with zero area in texture space Cannot compute valid tangent space Avoid triangles with negative area in texture space May happen when texture is mirrored Avoid non-uniform stretching of bump map

Combination with env. map Environment mapped bump mapping (EMBM) Use bump mapped normal to compute reflection vector, look up cube map http://zanir.wz.cz/?paged=3&lang=en

Env. mapped bump mapping Use additional dirt texture to modulate strength of reflection from environment map

Tutorials Caution, slightly different derivation http://www.blacksmith- studios.dk/projects/downloads/bumpmapping_using_cg.php OpenGL shading language book Bump mapping uses shading p pp g g in tangent space

Today Bump mapping Shadows Shadow mapping Shadow mapping in OpenGL

Why are shadows important? Cues on scene lighting

Why are shadows important? Contact points Depth cues

Why are shadows important? Realism Without self-shadowing Without self-shadowing

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

Hard and soft shadows Point and directional lights lead to hard shadows, no penumbra Area light sources lead to soft shadows, with penumbra point directional area umbra penumbra

Hard and soft shadows Hard shadow, point light source Soft shadow, area light source

Shadows for interactive rendering Focus on hard shadows Soft shadows often too hard to compute in interactive graphics Two main techniques Shadow mapping Shadow volumes Many variations, subtleties Still active research area

Today Bump mapping Shadows Shadow mapping Shadow mapping in OpenGL

Shadow mapping http://en.wikipedia.org/wiki/shadow_mapping Main idea Scene point is lit by light source if it is visible from light source Determine visibility from light source by placing camera at light source position and rendering scene Scene points are lit if visible from light source Determine visibility from light source by placing camera at light source position

Two pass algorithm First pass Render scene by placing camera at light source position Store depth image (shadow map) depth value in shadow map Depth image seen Depth image seen from light source

Two pass algorithm Second pass Render scene from d h l camera (eye) position At each pixel, compare distance to light source (yellow) with value in shadow map (red) depth value in shadow map v b is in shadow If yellow distance is larger than red, we are in shadow If distance is smaller or equal, pixel is lit Fi l i Final image with shadows pixel seen from eye v b

Issues Limited field of view of shadow map Z-fighting Sampling problems

Limited field of view What if a scene point is outside the field of view of the shadow map? fi ld f i field of view of shadow map

Limited field of view What if a scene point is outside the field of view of the shadow map? Use six shadow maps, arranged in a cube Requires rendering pass for each shadow map! shadow maps

z-fighting In theory, depth values for points visible from light source are equal in both rendering passes Because of limited resolution, depth of pixel visible from light could be larger than shadow map value Need to add bias in first pass to make sure pixels are lit Shadow map Shadow map pixels Depth of shadow map Camera image Depth of pixel Image pixels Pixel is considered in shadow!

Solution Add bias when rendering shadow map Move geometry away from light by small amount Finding correct amount of bias is tricky Correct bias Not enough bias Too much bias

Bias Not enough Too much Correct

Sampling problems Shadow map pixel may project to many image pixels Ugly gystair-stepping artifacts

Solutions Increase resolution of shadow map Not always sufficient Split shadow map into several slices Tweak projection for shadow map rendering Light space perspective shadow maps (LiSPSM) http://www.cg.tuwien.ac.at/research/vr/lispsm/ With GLSL source code! Combination of splitting and LiSPSM Basis for most serious implementations List of advanced techniques see http://en.wikipedia.org/wiki/shadow_mapping

LiSPSM Basic shadow map Light space perspective shadow map

Percentage closer filtering Goal: avoid stair-stepping artifacts Similar il to texture t filtering, i but with a twist Simple shadow mapping Percentage closer filtering http://http.developer.nvidia.com/gpugems/gpugems_ch11.html

Percentage closer filtering Instead of looking up one shadow map pixel, look up several Perform depth test for each shadow map pixel Compute percentage of lit shadow map pixels

Percentage closer filtering Supported in hardware for small filters (2x2 shadow map pixels) Can use larger filters (look up more shadow map pixels) at cost of performance penalty Fake soft shadows Larger filter, softer shadow boundary

Today Bump mapping Shadows Shadow mapping Shadow mapping in OpenGL

Shadow mapping with OpenGL Recommended book: OpenGL Shading Language by Randi Rost

First pass Render scene by placing camera at light source position Compute light view (look at) matrix Similar to computing camera matrix from look-at, up vector Compute its inverse to get world-to-light transform Determine view frustum such that scene is completely enclosed Use several view frusta/shadow maps if necessary

First pass Each vertex point is transformed by (1,1) Light space Object-to-world (modeling) matrix M World-to-light li space matrix V light Light frustum (projection) matrix P light Object space Remember: points within frustum are transformed to unit cube [-1,1] 3 by projection matrix P light (-1,-1)-1)

First pass Use glpolygonoffset to apply depth bias Store depth image in a texture Use glcopyteximage with internal format GL_DEPTH_COMPONENT Final result with shadows Scene rendered from light source Depth map from light source

Second pass Render scene from camera At each pixel, look up corresponding location in shadow map Compare depths with respect to light source Shade accordingly

Looking up shadow map Need to transform each point from object space to shadow map Shadow map texture coordinates are in [0,1] 2 Transformation from object to shadow map coordinates (set it as texture matrix, see below) (1,1) After perspective projection we have shadow map coordinates (0,0) Object space Light space Shadow map

Looking up shadow map Transform each vertex to normalized frustum of light Pass s,t,r,q as texture coordinates to fragment shader Rasterizer interpolates s,t,r,q to each pixel Use projective texturingt to look up shadow map This means, the texturing unit automatically computes s/q,t/q,r/q,1 s/q,t/q are shadow map coordinates in [0,1] 2 r/q is depth in light space Shadow depth test: compare shadow map at (s/q,t/q) to r/q

GLSL specifics In application Store matrix T in OpenGL texture matrix Set usingglmatrixmode(gl_texture) In vertex shader Access texture matrix through predefined uniform gl_texturematrix In fragment shader Declare shadow map as sampler2dshadow Look up shadow map using projective texturing with vec4 texture2dproj(sampler2d, vec4)

GLSL specifics When you do a projective texture look up on a sampler2dshadow, the depth test is performed automatically Return value is (1,1,1,1) if lit Return value is (0001)if (0,0,0,1) shadowed Simply multiply result of shading with current light source with this value

Shadow volumes 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 Test if surface visible in given pixel is inside or outside shadow volume 1. Allocate a counter per pixel 2. Cast a ray into the scene, starting from eye, going through given pixel 3. Increment the counter when the ray enters the shadow volume 4.Decrement the counter when the ray leaves the shadow volume 5.When we hit the object, check the counter. If counter > 0, in shadow Oh Otherwise, not in shadow

In shadow or not Light source Occluder Eye position +1 +2 +3 +2 +1 In shadow

Implementation in rendering pipeline Ray tracing not possible to implement directly Use a few tricks...

Shadow volume construction Need to generate shadow polygons to bound shadow volume Extrude silhouette edges from light source Extruded shadow volumes

Shadow volume construction Needs to be done on the CPU Silhouette edge detection An edge is a silhouette if one adjacent triangle is front facing, the other back facing with respect to the light Extrude polygons from silhouette edges

Shadow test without ray tracing Using the stencil buffer A framebuffer channel (like RGB colors, depth) that contains a per-pixel counter (integer value) Available in OpenGL Stencil test Similar to depth test (z-buffering) Control whether a fragment is discarded or not Stencil function: is evaluated to decide whether to discard a fragment Stencil operation: is performed to update the stencil buffer depending on the result of the test

Stencil test Comparison test between reference and stencil value Different modes GL_NEVER always fails GL_ALWAYS always passes GL_LESS LESS passes if reference value is less than stencil buffer GL_EQUAL passes if reference value is equal to stencil buffer Etc. 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 t passes, the fragment continue through h 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 failing is applied

Stencil operation Can set different operations for Stencil fails Stencil passes, depth fails Stencil passes, depth passes Options 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

Shadow volume algorithms Z-pass approach Count leaving/entering shadow volume events as described Use stencil buffer to count number of visible (i.e. not occluded from camera) front-facing and back facing shadow volume polygons for each pixel If equal, pixel is not in shadow Z-fail approach Count number of invisible (i.e. occluded from camera) front-facing and back-facing shadow volume polygons If equal, pixel is not in shadow

Z-pass approach: details Render scene with only ambient light Update depth buffer Turn off depth and color write, turn on stencil, keep the depth test on Init stencil buffer to 0 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 At each pixel Stencil!= 0, in shadow Stencil = 0, lit Render the scene again with diffuse and specular lighting Write to framebuffer only pixels with stencil = 0

Issues Z-pass fails if Eye is in shadow Shadow polygon clipped by near clip plane

Issues Z-fail fails if Shadow polygon clipped by far plane Various workarounds, but tricky Usually based on combination of z-pass and z- fail

Shadow volumes Pros Does not require hardware support for shadow mapping Pixel accurate shadows, no sampling issues Cons More CPU intensive (construction of shadow volume polygons) Fill-rate intensive i (need to draw many shadow volume polygons) Expensive for complex geometry Tricky to handle all cases correctly Hard to extend to soft shadows

Shadow maps Pros: Little CPU overhead No need to construct extra geometry to represent shadows Hardware support Can fake soft shadows easily Cons: Sampling issues Depth bias is not completely foolproof Shadow mapping has become more popular with better hardware support

Resources Overview, lots of links http://www.realtimerendering.com/ Basic shadow maps http://en.wikipedia.org/wiki/shadow_mapping Avoiding sampling problems in shadow maps http://www.comp.nus.edu.sg/~tants/tsm/tsm.pdf p p http://www.cg.tuwien.ac.at/research/vr/lispsm/ Faking soft shadows with shadow maps http://people.csail.mit.edu/ericchan/papers/smoothie/ Alternative: shadow volumes http://en.wikipedia.org/wiki/shadow_volume http://developer.nvidia.com/object/robust_shadow_volumes.html http://www.gamedev.net/reference/articles/article1873.asp p

Next time Advanced topics, outlook

Bachelorarbeiten Contact Prof. Zwicker to discuss possible topics!