Shadow Mapping Chun-Fa Chang National Taiwan Normal University.

Slides:



Advertisements
Similar presentations
Exploration of advanced lighting and shading techniques
Advertisements

COMPUTER GRAPHICS SOFTWARE.
Technische Universität München Computer Graphics SS 2014 Graphics Effects Rüdiger Westermann Lehrstuhl für Computer Graphik und Visualisierung.
Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Graphics Pipeline.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
Projective Texture Mapping
CS6500 Adv. Computer Graphics © Chun-Fa Chang, Spring 2003 Texture Mapping II April 10, 2003.
CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics April 19, 2007.
3D Graphics Processor Architecture Victor Moya. PhD Project Research on architecture improvements for future Graphic Processor Units (GPUs). Research.
IN4151 Introduction 3D graphics 1 Introduction to 3D computer graphics part 2 Viewing pipeline Multi-processor implementation GPU architecture GPU algorithms.
Shadow Mapping RTR Team Why Shadows? 2 RTR Team 2009.
Global Illumination May 7, Global Effects translucent surface shadow multiple reflection.
GPUGI: Global Illumination Effects on the GPU
Advanced Texture Mapping May 10, Today’s Topics Mip Mapping Projective Texture Shadow Map.
IAT 3551 Computer Graphics Overview Color Displays Drawing Pipeline.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Models and Architectures Ed Angel Professor of Computer Science, Electrical and Computer.
GPU Graphics Processing Unit. Graphics Pipeline Scene Transformations Lighting & Shading ViewingTransformations Rasterization GPUs evolved as hardware.
Under the Hood: 3D Pipeline. Motherboard & Chipset PCI Express x16.
Computer Graphics Mirror and Shadows
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Geometric Objects and Transformations. Coordinate systems rial.html.
Programmable Pipelines. 2 Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Chris Kerkhoff Matthew Sullivan 10/16/2009.  Shaders are simple programs that describe the traits of either a vertex or a pixel.  Shaders replace a.
MIT EECS 6.837, Durand and Cutler Graphics Pipeline: Projective Transformations.
Week 2 - Friday.  What did we talk about last time?  Graphics rendering pipeline  Geometry Stage.
CSC 461: Lecture 3 1 CSC461 Lecture 3: Models and Architectures  Objectives –Learn the basic design of a graphics system –Introduce pipeline architecture.
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 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Stream Processing Main References: “Comparing Reyes and OpenGL on a Stream Architecture”, 2002 “Polygon Rendering on a Stream Architecture”, 2000 Department.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
1 Computer Graphics Week2 –Creating a Picture. Steps for creating a picture Creating a model Perform necessary transformation Lighting and rendering the.
1Computer Graphics Lecture 4 - Models and Architectures John Shearer Culture Lab – space 2
CS662 Computer Graphics Game Technologies Jim X. Chen, Ph.D. Computer Science Department George Mason University.
Programmable Pipelines Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
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.
2009 GRAPHICS : PROJECT 1 BASED ON DX9 BASICS. Documented by Dongjoon Kim SNU CS Ph.D Course Student Contact : NOTE.
Computer Graphics 3 Lecture 6: Other Hardware-Based Extensions Benjamin Mora 1 University of Wales Swansea Dr. Benjamin Mora.
11/24/ :45 Graphics II Shadow Maps Reflections Session 5.
From Turing Machine to Global Illumination Chun-Fa Chang National Taiwan Normal University.
COMPUTER GRAPHICS CS 482 – FALL 2015 SEPTEMBER 29, 2015 RENDERING RASTERIZATION RAY CASTING PROGRAMMABLE SHADERS.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Shadows David Luebke University of Virginia. Shadows An important visual cue, traditionally hard to do in real-time rendering Outline: –Notation –Planar.
GLSL I.  Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Models and Architectures 靜宜大學 資訊工程系 蔡奇偉 副教授 2012.
An Introduction to the Cg Shading Language Marco Leon Brandeis University Computer Science Department.
Computer Graphics Ken-Yi Lee National Taiwan University (the slides are adapted from Bing-Yi Chen and Yung-Yu Chuang)
Computer Graphics Overview
Programmable Pipelines
Graphics Processing Unit
Chapter 6 GPU, Shaders, and Shading Languages
From Turing Machine to Global Illumination
The Graphics Rendering Pipeline
Models and Architectures
Models and Architectures
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics
Models and Architectures
CS5500 Computer Graphics April 17, 2006 CS5500 Computer Graphics
CS5500 Computer Graphics May 29, 2006
Models and Architectures
Frame Buffer Applications
OpenGL-Rendering Pipeline
Presentation transcript:

Shadow Mapping Chun-Fa Chang National Taiwan Normal University

Advanced Texture Mapping  Using multiple textures  Multi-Pass textures 1 st Pass: render the scenes as usual Create textures from the output images 2 nd Pass: render the scenes again using the created texture

Using Textures in GLSL Shader  sampler2D data type in GLSL  Binding to the C/C++ program through glGetUniformLocation()  See the myTexture variable in Lab 7 in both the fragment shader and, the C code setShaders().

Shadow Map  Using two textures: color and depth  Relatively straightforward design using pixel (fragment) shaders on GPUs.

Image Source: Cass Everitt et al., “Hardware Shadow Mapping” NVIDIA SDK White PaperHardware Shadow Mapping Eye’s ViewLight’s ViewDepth/Shadow Map

Basic Steps of Shadow Maps 1. Render the scene from the light’s point of view, 2. Use the light’s depth buffer as a texture (shadow map), 3. Projectively texture the shadow map onto the scene,  Use “TexGen” or shader 4. Use “texture color” (comparison result) in fragment shading.

What’re in the Example Code?  A C++ class for storing matrix state: class OpenGL_Matrix_State { void Save_Matrix_State(); void Restore_Matrix_State(); void Set_Texture_Matrix(); }  A proxy rectangle for debug

(1) Rendering from Light’s View  Set the camera to the light position.  Viewport set to the same size as the texture.  To avoid the floating point precision problem (casting its own shadow to a surface), depth must be shifted: glPolygonOffset(...,...); glEnable(GL_POLYGON_OFFSET_FILL);  Shading could be turned off We only care about the depth!

(2) Creation of Shadow Map (Texture)  Draw the objects (from light’s view)  To create a depth texture, use: glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowMapSize, shadowMapSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);  Then use glCopyTexSubImage2D() to copy the frame buffer to the depth texture.

(3) Generation of Texture Coordinates  When we render the scene again from the normal camera view: We store the light’s view to the texture matrix. The texture matrix is then passed to the GLSL shaders. gl_TextureMatrix[0] * vertex gives us the homogeneous coordinates in light space Divide by w to obtain the texture coordinates. Watch out! Must shift from [-1, 1] to [0,1]

Normalized Coordinates  Independent of the screen resolution or window size.  Clip coordinates: after Model-View and Projection transformation.  Normalized Device Coordinates (NDC): after division by w.

(4) Depth Comparison in Fragment Shader  Compare two depths: Depth read from the shadow map Depth by transformation to the light space  In the shadow if ____?_(your exercise)____  Set a darker color for shadowed surfaces

More GPU Programming and GPGPU Chun-Fa Chang National Taiwan Normal University

Calculator vs. Computer  What is the difference between a calculator and a computer?  Doesn ’ t a compute-r just “ compute ” ?  The Casio fx3600p calculated can be programmed (38 steps allowed).

Turing Machine  Can be adapted to simulates the logic of any computer that could possibly be constructed.  von Neumann architecture implements a universal Turing machine.  Look them up at Wikipedia!

Simplified View  The Data Flow: 3D Polygons (+Colors, Lights, Normals, Texture Coordinates … etc.)  2D Polygons  2D Pixels (I.e., Output Images) Transform (& Lighting) Rasterization

Global Effects translucent surface shadow multiple reflection

Local vs. Global

How Does GPU Draw This?

Quiz  Q1: A straightforward GPU pipeline give us local illumination only. Why?  Q2: What typical effects are missing? Hint: How is an object drawn? Do they consider the relationship with other objects? Shadow, reflection, and refraction…

 Wait but I ’ ve seen shadow and reflection in games before … With ShadowsWithout Shadows

Faked Global Illumination  Shadow, Reflection, BRDF … etc.  In theory, real global illumination is not possible in current graphics pipeline: Conceptually a loop of individual polygons. No interaction between polygons.  Can this be changed by multi-pass rendering?

Case Study: Shadow Map  Using two textures: color and depth  Relatively straightforward design using pixel (fragment) shaders on GPUs.

Adding “ Memory ” to the GPU Computation  Modern GPUs allow: The usage of multiple textures. Rendering algorithms that use multiple passes. Transform (& Lighting) Rasterization Textures