CS-378: Game Technology Lecture #8: More Mapping Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica.

Slides:



Advertisements
Similar presentations
Exploration of advanced lighting and shading techniques
Advertisements

Lecture 8 Transparency, Mirroring
Technische Universität München Computer Graphics SS 2014 Graphics Effects Rüdiger Westermann Lehrstuhl für Computer Graphik und Visualisierung.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Optimized Stencil Shadow Volumes
Graphics Pipeline.
Game Programming 09 OGRE3D Lighting/shadow in Action
CSL 859: Advanced Computer Graphics Dept of Computer Sc. & Engg. IIT Delhi.
Computer Graphics methods
Week 10 - Monday.  What did we talk about last time?  Global illumination  Shadows  Projection shadows  Soft shadows.
CS-378: Game Technology Lecture #9: More Mapping Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica.
03/12/02 (c) 2002 University of Wisconsin, CS559 Last Time Some Visibility (Hidden Surface Removal) algorithms –Painter’s Draw in some order Things drawn.
CAP4730: Computational Structures in Computer Graphics Visible Surface Determination.
9/25/2001CS 638, Fall 2001 Today Shadow Volume Algorithms Vertex and Pixel Shaders.
Introduction to 3D Graphics Lecture 5: From Realism to Real-Time Anthony Steed University College London.
1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.
Real-Time Rendering SPEACIAL EFFECTS Lecture 03 Marina Gavrilova.
Shadow Algorithms Gerald Matzka Computer Science Seminar.
CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Other Rendering Techniques Types of rendering – Wireframe techniques – Scan-line conversion – Reyes.
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Beyond Meshes Spring 2012.
Computer Graphics Shadows
09/18/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Bump Mapping Multi-pass algorithms.
9/20/2001CS 638, Fall 2001 Today Finishing Up Reflections More Multi-Pass Algorithms Shadows.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Hidden Surface Removal
Shadows Computer Graphics. Shadows Shadows Extended light sources produce penumbras In real-time, we only use point light sources –Extended light sources.
Erdem Alpay Ala Nawaiseh. Why Shadows? Real world has shadows More control of the game’s feel  dramatic effects  spooky effects Without shadows the.
Computer Graphics Mirror and Shadows
Shadow Algorithms Ikrima Elhassan.
CS 638, Fall 2001 Today Light Mapping (Continued) Bump Mapping with Multi-Texturing Multi-Pass Rendering.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
NVIDIA PROPRIETARY AND CONFIDENTIAL Occlusion (HP and NV Extensions) Ashu Rege.
02/26/02 (c) 2002 University of Wisconsin, CS 559 Last Time Canonical view pipeline Orthographic projection –There was an error in the matrix for taking.
09/09/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Event management Lag Group assignment has happened, like it or not.
09/11/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Graphics Pipeline Texturing Overview Cubic Environment Mapping.
Week 2 - Friday.  What did we talk about last time?  Graphics rendering pipeline  Geometry Stage.
Game Programming (Mapping) Spring.
CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica.
CS 638, Fall 2001 Multi-Pass Rendering The pipeline takes one triangle at a time, so only local information, and pre-computed maps, are available Multi-Pass.
Week 10 - Wednesday.  What did we talk about last time?  Shadow volumes and shadow mapping  Ambient occlusion.
1 10/24/ :01 UML Graphics II Shadows Session 4.
CS-378: Game Technology Lecture #4: Texture and Other Maps Prof. Okan Arikan University of Texas, Austin V Lecture #4: Texture and Other Maps.
Shadows. Shadows is important in scenes, consolidating spatial relationships “Geometric shadows”: the shape of an area in shadow Early days, just pasted.
CS-378: Game Technology Lecture #2.2: Clipping and Hidden Surfaces Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney,
CS-378: Game Technology Lecture #7: More Mapping Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica.
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
Advanced Computer Graphics Shadow Techniques CO2409 Computer Graphics Week 20.
Computer graphics & visualization Shadows / Transparency.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
Global Illumination. Local Illumination  the GPU pipeline is designed for local illumination  only the surface data at the visible point is needed to.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Where We Stand At this point we know how to: –Convert points from local to window coordinates –Clip polygons and lines to the view volume –Determine which.
11/24/ :45 Graphics II Shadow Maps Reflections Session 5.
Real-Time Dynamic Shadow Algorithms Evan Closson CSE 528.
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
Shadows David Luebke University of Virginia. Shadows An important visual cue, traditionally hard to do in real-time rendering Outline: –Notation –Planar.
1 Shadow Rendering Techniques: Hard and Soft Author: Jamiur Rahman Supervisor: Mushfiqur Rouf Department of CSE BRAC University.
09/23/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Reflections Shadows Part 1 Stage 1 is in.
Visible-Surface Detection Methods. To identify those parts of a scene that are visible from a chosen viewing position. Surfaces which are obscured by.
Rendering Pipeline Fall, 2015.
CS-378: Game Technology Lecture #7: More Mapping Prof. Okan Arikan
Week 2 - Friday CS361.
Game Programming (Mapping)
Jim X. Chen George Mason University
Real-Time Rendering Intro to Shadows
CS-378: Game Technology Lecture #4: Texture and Other Maps
Frame Buffer Applications
Presentation transcript:

CS-378: Game Technology Lecture #8: More Mapping Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica Hodgins V

Today Background on math Ongoing Course Assessment More on mapping Reflections Shadows

Planar Reflections (Flat Mirrors) Use the stencil buffer, color buffer and depth buffer Basic idea: We need to draw all the stuff around the mirror We need to draw the stuff in the mirror, reflected, without drawing over the things around the mirror Key point: You can reflect the viewpoint about the mirror to see what is seen in the mirror, or you can reflect the world about the mirror

Reflecting Objects If the mirror passes through the origin, and is aligned with a coordinate axis, then just negate appropriate coordinate Otherwise, transform into mirror space, reflect, transform back MirrorWall

Small Problem Reflecting changes the apparent vertex order as seen by the viewer Why is this a problem? Reflecting the view has the same effect, but this time it also shifts the left-right sense in the frame buffer Works, just harder to understand what’s happening

Rendering Reflected First First pass: Render the reflected scene without mirror, depth test on Second pass: Disable the color buffer, Enable the stencil buffer to always pass but set the buffer, Render the mirror polygon Now, set the stencil test to only pass points outside the mirror Clear the color buffer - does not clear points inside mirror area Third Pass: Enable the color buffer again, Disable the stencil buffer Render the original scene, without the mirror Depth buffer stops from writing over things in mirror

Reflection Example The stencil buffer after the second pass The color buffer after the second pass – the reflected scene cleared outside the stencil

Reflection Example The color buffer after the final pass

Making it Faster Under what circumstances can you skip the second pass (the stencil buffer pass)? These are examples of designing for efficient rendering

Making it Faster Under what circumstances can you skip the second pass (the stencil buffer pass)? Infinite mirror plane (effectively infinite) Solid object covering mirror plane These are examples of designing for efficient rendering

Reflected Scene First (issues) Objects behind the mirror cause problems: Will appear in reflected view in front of mirror Solution is to use clipping plane to cut away things on wrong side of mirror Curved mirrors by reflecting vertices differently Doesn’t do: Reflections of mirrors in mirrors (recursive reflections) Multiple mirrors in one scene (that aren’t seen in each other)

Rendering Normal First First pass: Render the scene without the mirror Second pass: Clear the stencil, Render the mirror, setting the stencil if the depth test passes Third pass: Clear the depth buffer with the stencil active, passing things inside the mirror only Reflect the world and draw using the stencil test. Only things seen in the mirror will be drawn

Normal First Addendum Same problem with objects behind mirror Same solution Can manage multiple mirrors Render normal view, then do other passes for each mirror Only works for non-overlapping mirrors (in view) But, could be extended with more tests and passes A recursive formulation exists for mirrors that see other mirrors

Frame Buffer Blending When a fragment gets to the frame buffer, it is blended with the existing pixel, and the result goes in the buffer Blending is of the form: s=source fragment, d = destination buffer, RGBA color In words: You get to specify how much of the fragment to take, and how much of the destination, and you add the pieces together All done per-channel

Blending Factors The default is: S rgba =(1,1,1,1), D rgba =(0,0,0,0) Overwrite buffer contents with incoming fragment You can use the colors themselves as blending functions: eg S rgba =(R d,G d,B d,A d ), D rgba =(0,0,0,0) What use is this? Hint: What if there is an image in the buffer and the source is a constant gray image? A light map? Common is to use the source alpha: S rgba =(A s,A s,A s,A s ), D rgba =(1-A s,1-A s,1-A s,1-A s ) What does this achieve? When might you use it? Note that blending can simulate multi-texturing with multi- pass

Accumulation Buffer The accumulation buffer is not available for writing directly It is more like a place to hold and compute on pixel data Operations: Load the contents of a color buffer into the accumulation buffer Accumulate the contents of a color buffer, which means multiply them by a value then add them into the buffer Return the buffer contents to a color buffer (scaled by a constant) Add or multiply all pixel values by a given constant It would appear that it is too slow for games Lots of copying data too and fro

Accum. Buffer Algorithms Anti-aliasing: Render multiple frames with the image plane jittered slightly, and add them together Hardware now does this for you, but this would be higher quality Motion blur: Render multiple frames representing samples in time, and add them together More like strobing the object Depth of field: Render multiple frames moving both the viewpoint and the image plane in concert Keep a point – the focal point – fixed in the image plane while things in front and behind appear to shift

Why Shadows? Shadows tell us about the relative locations and motions of objects

Facts about Shadows Shadows can be considered as areas hidden from the light source Suggests the use of hidden surface algorithms A shadow on A due to B can be found by projecting B onto A with the light as the center of projection Suggests the use of projection transformations For scenes with static lights and geometry, the shadows are fixed Can pre-process such cases Cost is in moving lights or objects Point lights have hard edges, and area lights have soft edges

Ground Plane Shadows Shadows cast by point light sources onto planes are an important case that is relatively easy to compute Shadows cast by objects (cars, players) onto the ground Accurate if shadows don’t overlap Can be fixed, but not well (x p,y p,z p ) (x sw,y sw,z sw ) L(directional light)

Ground Shadow Math The shadow point lies on the line from the light through the vertex: The shadow is on the ground, z sw =0, so  =z p /z l, giving: Matrix form:

Drawing the Shadow We now have a matrix that transforms an object into its shadow Drawing the shadow: Draw the ground and the object Multiply the shadow matrix into the model transformation Redraw the object in gray with blending on Tricks: Lift the shadow a little off the plane to avoid z-buffer quantization errors (can be done with extra term in matrix) Works for other planes by transforming into plane space, then shadow, then back again Take care with vertex ordering for the shadow (it reverses)

Point Light Shadows Blinn ’88 gives a matrix that works for local point light sources Takes advantage of perspective transformation (and homogeneous coordinates) Game Programming Gems has an approximation that does not use perspective matrices, Chapter 5.7

Shadows in Light Maps Static shadows can be incorporated into light maps When creating the map, test for shadows by ray- casting to the light source - quite efficient Area light sources should cast soft shadows Interpolating the texture will give soft shadows, but not good ones, and you loose hard shadows Sampling the light will give better results: Cast multiple rays to different points on the area light, and average the results Should still filter for best results What about light map resolution?

Soft Shadow Example

Quick Dirty Shadows Blend a dark polygon into the frame-buffer in the place where the shadow should be Cast a ray from light source, through object center, and see where it hits something Blend a fixed shape polygon in at that location (with depth) Why dirty? Use a fixed shape - shadow won’t match object Use a single ray-cast to determine shadow location - no partial shadow and wrong parts of shadow may be drawn Good for things like car games for under-car shadow Fast action and near planar receiving surfaces

Drawing Quick Dirty Shadows ViewerLight

Shadows in Games Grand Theft Auto Metal Gear Megaman

Projective Shadows Create a texture (dark on white) representing the appearance of the occluder as seen by the light Game programmers frequently call this a shadow map Can create it by “render to texture” with the light as viewpoint Use projective texturing to apply it to receivers Works if the appearance of the occluder from the light is reasonably constant Requires work to identify occluders and receivers Resolution issues Better than quick-dirty shadows, worse than other methods

Shadow Volumes A shadow volume for an object and light is the volume of space that is shadowed That is, all points in the volume are in shadow for that light/object pair Creating the volume: Find silhouette edges of shadowing object as seen by the light source Extrude these edges away from the light, forming polygons Clip the polygons to the view volume

Shadow Volumes

Shadow Volume

Practicalities For many algorithms, it is not necessary to find silhouette edges – just use all edges Silhouette edges can be found by looking at polygon normals Silhouette edges are those between a front facing face and back facing face (from light’s point of view) The result is a sequence of edges with common vertices Assuming convex shadowing objects Extend all the vertices of silhouette edges away from the light source Clip them to the view volume, and form the polygons that bound the shadow volume Final result are a set of shadow volume boundary polygons

Key Observation All points inside a shadow volume are in shadow Along a ray from the eye, we can track the shadow state by looking at intersections with shadow volume boundaries Assume the eye is not in shadow Each time the ray crosses a front facing shadow polygon, add one to a counter Each time the ray crosses a back facing shadow polygon, subtract one from a counter Places where the counter is zero are lit, others are shadowed We need to count the number of shadow polygons in front of a point. Which buffer can count for us?

Using Shadow Volumes

Real-Time Shadow Volumes Compute shadow volumes per frame Not a problem for only a few moving objects Use simplified object geometry to speed things up Vertex programs can be used to create volumes Four pass algorithm Render scene with ambient light only (everything shadowed) Render front facing shadow polygons to increment stencil buffer Render back facing shadow polygons to decrement stencil buffer Render scene again only for non-shadowed (stencil=0) regions Horrible details follow…

Details Turn off any light sources and render scene with ambient light only, depth on, color buffer active Disable the color and depth buffers for writing, but leave the depth test active Initialize the stencil buffer to 0 or 1 depending on whether the viewer is in shadow or not (ray cast) Set the stencil test to always pass and the operation to increment if depth test passes Enable back face culling Render the shadow volumes - this will increment the stencil for every front facing polygon that is in front of a visible surface Cont…

Details Enable front face culling, disable back face culling Set the stencil operation to decrement if the depth test passes (and leave the test as always pass) Render the shadow volumes - this decrements for all the back facing shadow polygons that are in front of visible objects. The stencil buffer now has positive values for places in shadow Set the stencil function to equality with 0, operations to keep Clear the depth buffer, and enable it and the color buffer for writing Render the scene with the lights turned on Voila, we’re done

Alternate 2 Problems: Finding how many shadow volumes the viewer is in, and the near clip plane Solution: Count the number of shadow volume faces behind the visible scene Assume shadow volumes are capped Why does it work? New problem? Resolved by Nvidia extension NV_depth_clamp Resolved by smart homogeneous coordinate math Textbook has details

Why Use Shadow Volumes? They correctly account for shadows of all surfaces on all other surfaces No shadow where there shouldn’t be shadow No problem with multiple light sources Adaptable quality by creating shadow volumes with approximate geometry Shadow volumes for static object/light pairs can be pre-computed and don’t change More expensive than light maps, but not too bad on current hardware Can’t combine the techniques. Why not?

Why Not Use Shadow Volumes? Place very high demands on rendering pipeline In particular, fill rate can be a major problem Shadow volume polygons tend to cover very large parts of the screen Using coarse occluder geometry won’t help this much Sharp shadows, and hard to make soft

Variant Render fully lit, then add shadows (blend a dark polygon) where the stencil buffer is set – in what cases is it wrong?

Shadow Buffer Algorithms Compute z-buffer from light viewpoint Put it into the shadow buffer Render normal view, compare world locations of points in the z-buffer and shadow buffer Have to transform pts into same coordinate system Points with same location in both buffers are lit. Why? Problems: Resolution is a big issue – both depth and spatial Only some hardware supports the required computations