CENG 477 Introduction to Computer Graphics

Slides:



Advertisements
Similar presentations
Exploration of advanced lighting and shading techniques
Advertisements

Lecture 8 Transparency, Mirroring
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 1/16 Deferred Lighting Deferred Lighting – 11/18/2014.
Technische Universität München Computer Graphics SS 2014 Graphics Effects Rüdiger Westermann Lehrstuhl für Computer Graphik und Visualisierung.
Graphics Pipeline.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
CSL 859: Advanced Computer Graphics Dept of Computer Sc. & Engg. IIT Delhi.
GAM532 DPS932 – Week 7 Introduction to shadows. Shadow Effects Light Surface No Shadows Shadows.
Computer Graphics methods
Week 10 - Monday.  What did we talk about last time?  Global illumination  Shadows  Projection shadows  Soft shadows.
CAP4730: Computational Structures in Computer Graphics Visible Surface Determination.
Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a.
SIGGRAPH ASIA 2011 Preview seminar Shading and Shadows.
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.
Practical and Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering Cass Everitt and Mark J. Kilgard Speaker: Alvin Date: 5/28/2003 NVIDIA.
Approximate Soft Shadows on Arbitrary Surfaces using Penumbra Wedges Tomas Akenine-Möller Ulf Assarsson Department of Computer Engineering, Chalmers University.
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.
Computer Graphics Shadows
09/18/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Bump Mapping Multi-pass algorithms.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
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.
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
Week 2 - Friday.  What did we talk about last time?  Graphics rendering pipeline  Geometry Stage.
CHAPTER 11 Shadows © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Shadow rendering algorithms – –Blinn’s shadow.
Advanced Computer Graphics Depth & Stencil Buffers / Rendering to Textures CO2409 Computer Graphics Week 19.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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.
1 10/24/ :01 UML Graphics II Shadows Session 4.
Shadows. Shadows is important in scenes, consolidating spatial relationships “Geometric shadows”: the shape of an area in shadow Early days, just pasted.
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
Sample Based Visibility for Soft Shadows using Alias-free Shadow Maps Erik Sintorn – Ulf Assarsson – uffe.
Computer graphics & visualization Shadows / Transparency.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Visible Surface Determination (VSD) To render or not to render, that is the question… 1 of.
11/24/ :45 Graphics II Shadow Maps Reflections Session 5.
Real-Time Dynamic Shadow Algorithms Evan Closson CSE 528.
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.
Stencil Shadows Garrett Weng. What are stencil shadows? Also known as shadow volumes Relies on use of the stencil buffer Create volumes of the shadows.
09/23/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Reflections Shadows Part 1 Stage 1 is in.
- Introduction - Graphics Pipeline
Stenciling Effects Glenn G. Chappell
Discrete Techniques.
Photorealistic Rendering vs. Interactive 3D Graphics
Week 2 - Friday CS361.
Deferred Lighting.
Robust Shadow Maps for Large Environments
Real-Time Rendering Shadow Volumes
3D Graphics Rendering PPT By Ricardo Veguilla.
CENG 477 Introduction to Computer Graphics
The Graphics Rendering Pipeline
CS451Real-time Rendering Pipeline
Interactive Computer Graphics
Jim X. Chen George Mason University
CSCE 441: Computer Graphics Hidden Surface Removal
(c) 2002 University of Wisconsin
Introduction to Computer Graphics with WebGL
Lighting.
Real-time Rendering Shadow Maps
UMBC Graphics for Games
Lecture 13 Clipping & Scan Conversion
UMBC Graphics for Games
Visibility (hidden surface removal)
Texture and Shadow Mapping
Sweep Fill Details For row = min to row=max
Frame Buffer Applications
Presentation transcript:

CENG 477 Introduction to Computer Graphics Shadows in Forward Rendering

CENG 477 – Computer Graphics Shadows Shadows are an important element of visual realism From Sintorn et al. – Siggraph Asia 2012 CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Shadows Shadows give important cues about light positions From wikipedia.com CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Shadows Shadows also give cues about object positions CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Shadows in OpenGL OpenGL does not have built-in support for shadows CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Shadows in OpenGL Compare this to a ray traced image: Note that it is natural to get shadows via Ray Tracing Here we address the forward rendering pipeline, which is the opposite CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Shadows in OpenGL OpenGL does not natively support generating shadows (neither does D3D) That is, it does not have a function like glMakeShadow()! But, several shadowing algorithms can easily be implemented using features of OpenGL (or D3D) Stencil buffer Depth buffer Render to texture … CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Generating Shadows Two algorithms that are commonly used are: Shadow volumes (Crow, 1977) Shadow mapping (Williams, 1978) Both algorithm has advantages and disadvantages and many variants Still an active research area: An improved shadow volume algorithm presented at Siggraph Asia 2012: An Efficient Alias-free Shadow Algorithm for Opaque and Transparent Objects using per-triangle Shadow Volumes, by Sintorn et al. We’ll study the basic versions of these algorithms - CROW, F. C. 1977. Shadow algorithms for computer graphics. SIGGRAPH Comput. Graph. 11 (July), 242–248. - WILLIAMS, L. 1978. Casting curved shadows on curved surfaces. SIGGRAPH Comput. Graph. 12 (August), 270–274. CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Shadow Volumes The idea is to create a 3D shape that represents the shadow that is casted by an object Unshadowed object Shadow volume (extends to infinity) Light Shadow caster Shadowed object CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Shadow Volumes A shadow volume can be created for any arbitrary object. We need to determine the contour edges (silhouette-edges) of the object as seen from the light source A contour edge has one adjacent polygon facing the light source and the other away from the light source From John Tsiombikas CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Contour Edges A contour edge has one adjacent polygon facing the light source and the other away from the light source We can use dot product to decide whether a face is toward or away from the light source Face normals Light Shadow caster object CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Contour Edges // transform the light to the coordinate system of the object LightPosition = Inverse(ObjectWorldMatrix) * LightPosition; for (every polygon) { IncidentLightDir = AveragePolyPosition - LightPosition; // if the polygon faces away from the light source.... if (DotProduct(IncidentLightDir, PolygonNormal) >= 0.0) { for (every edge of the polygon) { if (the edge is already in the contour edge list) { // then it can't be a contour edge since it is // referenced by two triangles that are facing // away from the light remove the existing edge from the contour list; } else { add the edge to the contour list; } From John Tsiombikas CENG 477 – Computer Graphics

Extruding Contour Edges Once the contours are found, we need to extrude them to create a large shadow volume Light CENG 477 – Computer Graphics

Extruding Contour Edges Extrusion amount should be large enough to cover all objects which can receive shadow from this light source ExtrudeMagnitude = A_BIG_NUMBER; for (every edge) { ShadowQuad[i].vertex[0] = edge[i].vertex[0]; ShadowQuad[i].vertex[1] = edge[i].vertex[1]; ShadowQuad[i].vertex[2] = edge[i].vertex[1] + ExtrudeMagnitude * (edge[i].vertex[1] - LightPosition); ShadowQuad[i].vertex[3] = edge[i].vertex[0] + ExtrudeMagnitude * (edge[i].vertex[0] - LightPosition); } From John Tsiombikas CENG 477 – Computer Graphics

Extruding Contour Edges The shadow caster object’s contour vertices serve as the cap of the shadow volume. The bottom can also be capped to obtain a closed volume. Light CENG 477 – Computer Graphics

Extruding Contour Edges This is how it looks like for a complex object From John Tsiombikas CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Rendering Shadows Now what? Any ideas about how we can proceed? light From John Tsiombikas camera CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Rendering Shadows Assume a ray originating from the eye If it enters the shadow volume from a front face and exits from a back face, the point it reaches is not in shadow However, if it does not exit before hitting the object, the point should be in shadow light camera CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Rendering Shadows But we are not ray tracing! How can we know if the ray enters or exits? This is where depth and stencil buffers come in handy Stencil buffer: An integer buffer that stores a value for every pixel (usually an 8-bit value) We can clear it to any value that we want (glClearStencil(int) and glClear(GL_STENCIL_BUFFER_BIT)) Has operations such as increment and decrement based on the result of the depth test (glStencilOp(sfail, dpass, dfail)) Think of stencil buffer as a counter buffer, which keeps a counter for every pixel CENG 477 – Computer Graphics

Shadow Volume Algorithm (Part I) Clear the depth (to 1.0) and stencil buffer (to 0) Enable depth testing and disable stencil testing Render the scene with ambient light (note that ambient light does not produce shadows). This updates the depth buffer value for every pixel that corresponds to an object Disable writing to the depth buffer 100 1.0 0.5 Color Buffer Depth Buffer Stencil Buffer CENG 477 – Computer Graphics

Shadow Volume Algorithm (Part II) Draw the front faces of the shadow volume. Increment the stencil value for every pixel that passes the depth test (glStencilOp(GL_KEEP, GL_KEEP, GL_INCR)). Draw the back faces of the shadow volume. Decrement the stencil value for every pixel that passes the depth test (glStencilOp(GL_KEEP, GL_KEEP, GL_DECR)). Stencil Buffer – First Pass Stencil Buffer – Second Pass 1 1 CENG 477 – Computer Graphics

Shadow Volume Algorithm (Part III) Enable stencil testing such that pixels whose stencil value is zero will be rendered. Enable writing to the depth buffer and clear it. Enable the point light source. Enabling color buffer blending so the contribution of passing pixels will be added to the previous ambient values. Color Buffer Depth Buffer Stencil Buffer 150 100 1.0 0.5 1 CENG 477 – Computer Graphics

Shadow Volume Algorithm No blending versus blending: From John Tsiombikas CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Used Applications Doom 3 is the most well-known example. From http://http.developer.nvidia.com/GPUGems/gpugems_ch09.html CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Pros and Cons Requires preprocessing of the scene geometry to create the shadow volume. Needs to be updated if lights and/or objects move. Can be time consuming for complex geometry. Requires 4 rendering passes for each frame. Ambient pass, SV front-face pass, SV back-face pass, final light source pass. No need to update shadow volume if only the camera moves. CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Pros and Cons Inaccurate models can cause leaking artifacts. From http://http.developer.nvidia.com/GPUGems/gpugems_ch09.html CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Pros and Cons For speed-up, two versions of objects can be created. High polygon version is used for actual rendering of the object. Low polygon version is used to cast shadows of the object. From wikipedia.com CENG 477 – Computer Graphics

Exercises and Questions How can the shadow volume algorithm be extended to deal with: Camera inside the shadow volume? Multiple light sources and multiple shadow casters? Transparent shadow casters? Further reading: http://http.developer.nvidia.com/GPUGems/gpugems_ch09.html For the adventurous: Read the recent Siggraph Asia 2011 paper that proposes an improvement for shadow volumes: Sintorn, E., Olsson, O., Assarsson, U. 2011. An Efficient Alias-free Shadow Algorithm for Opaque and Transparent Objects using per-triangle Shadow Volumes. ACM Trans. Graph. 30, 6, Article 153 (December 2011), 10 pages. http://doi.acm.org/10.1145/2024156.2024187. CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Shadow Mapping The idea introduced by Lance Williams in his 1978 paper “Casting Curved Shadows on Curved Surfaces”. Image space technique. Advantages: No knowledge or processing of scene geometry is required! No need to use stencil buffer. Fewer rendering passes than shadow volumes for a single light source. Disadvantages: Need an extra rendering pass for each additional light. Aliasing artifacts may occur (shadows may look jaggy). CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Shadow Mapping Part 1: Render the scene from the point of view of the light source (as if the light source was a camera). Objects that are not visible are in shadow with respect to that light source. Part II: Determine whether an object as seen from the camera is in shadow in the “light’s view”. CENG 477 – Computer Graphics

Part I: Rendering from the Light Source Pretend that there is a camera at the light position. Use perspective projection for spot (and point) lights. Use orthographic projection for directional lights. Original camera view Light source view CENG 477 – Computer Graphics

Part I: Extracting the Depth Map Actually, we only need the depth buffer values from the light source view. Save this depth buffer to an off-screen texture. Depth map from the light’s view CENG 477 – Computer Graphics

Part I: Extracting the Depth Map To implement this idea, apply model view projection matrix of the light source to each scene point (glVertex) Now the transformed vertices have the desired depth values to be compared for shadow situation If the depth of point A is larger than that of B, then A is in shadow (behind B w.r.t. light’s position) CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Projective Texturing For every pixel in the camera view, we need to find the corresponding pixel in the light’s view. From http://www.riemers.net/images/Tutorials/DirectX/Csharp/Series3 CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Projective Texturing Assume inPos represents the world coordinates of an object. Its camera coordinates are computed by: Its light view coordinates are computed by: We can use Output.ShadowMapSamplingPos to fill the depth texture Output.Position = mul(inPos, cameraWorldViewProjection); Output.ShadowMapSamplingPos = mul(inPos, lightWorldViewProjection); CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Shadow Mapping We have omitted some minor details but you can read more online: Projective texturing: http://developer.nvidia.com/object/Projective_Texture_Mapping.html http://en.wikipedia.org/wiki/Projective_texture_mapping OpenGL fixed function implementation: http://www.paulsprojects.net/tutorials/smt/smt.html OpenGL shader (GLSL) implementation: www.gamedev.net/community/forums/topic.asp?topic_id=316147 http://sombermoon.com/shadowmappingdoc.html CENG 477 – Computer Graphics

Importance of Shadow Map Resolution Camera is close to object A, but light is far When we move camera to light’s position, A will occupy few pixels, so there will be few depth values to be used in shadow computation This may cause artifacts as we loose info from a distant cam To fix this, use a larger viewport (higher resolution) while rendering the distant camera at the light’s position Can be done easily because we are actually rendering to frame buffer, which is not an actual texture image CENG 477 – Computer Graphics

Importance of Shadow Map Resolution If the depth texture we create in Part I does not have enough resolution, we can see blocking artifacts: From http://bytechunk.net 160x120 shadow map 1280x960 shadow map CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Projection Artifacts If an object falls outside the viewing frustum of the light, we can see artifacts with a naïve implementation: For how to fix these, read more at: http://bytechunk.net/shadowmapping/index.php CENG 477 – Computer Graphics

Improving the Shadow Quality Shadow map can be filtered in various ways to create soft shadows: From http://www.gamedev.net CENG 477 – Computer Graphics

Applications Using Shadow Maps Most games use shadow mapping. Rage CENG 477 – Computer Graphics

Applications Using Shadow Maps Riddick 2: Assault on Dark Athena From http://uk.ps3.ign.com CENG 477 – Computer Graphics

Applications Using Shadow Maps Dragon Age From https://graphics.stanford.edu CENG 477 – Computer Graphics

Applications Using Shadow Maps Assassin’s Creed From http://kotaku.com CENG 477 – Computer Graphics