Shadow Mapping RTR Team 2009 0. 1 Why Shadows? 2 RTR Team 2009.

Slides:



Advertisements
Similar presentations
Exploration of advanced lighting and shading techniques
Advertisements

POST-PROCESSING SET09115 Intro Graphics Programming.
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 1/16 Deferred Lighting Deferred Lighting – 11/18/2014.
TEXTURE MAPPING JEFF CHASTINE 1. TEXTURE MAPPING Applying an image (or a texture ) to geometry 2D images (rectangular) 3D images (volumetric – such as.
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Today: - Make sure everyone is set up with an OpenGL environment - OpenGL basics:
Announcments Project 1 Project 2 Midterm Project 3.
Announcments Sign up for crits!. Reading for Next Week FvD – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.
GLSL Applications: 2 of 2 Patrick Cozzi University of Pennsylvania CIS Spring 2011.
Computer Graphics Shadows
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
Aaron Schultz. Idea: Objects close to a light shadow those far away. Anything we can see from the light’s POV is lit. Everything hidden is dark. Distance.
Image Processing.  a typical image is simply a 2D array of color or gray values  i.e., a texture  image processing takes as input an image and outputs.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
CS 4363/6353 TEXTURE MAPPING PART II. WHAT WE KNOW We can open image files for reading We can load them into texture buffers We can link that texture.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
OpenGL Conclusions OpenGL Programming and Reference Guides, other sources CSCI 6360/4360.
Real-time Shadow Mapping. Shadow Mapping Shadow mapping uses two-pass rendering - render depth texture from the light ’ s point-of-view - render from.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
GAM532 DPS932 – Week 2 Vertex Shaders. The Shader Pipeline Vertex Processing Primitive Assembly / Processing Rasterization Fragment Process Pixel Output.
Shadow Mapping Chun-Fa Chang National Taiwan Normal University.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
Hardware-accelerated Rendering of Antialiased Shadows With Shadow Maps Stefan Brabec and Hans-Peter Seidel Max-Planck-Institut für Informatik Saarbrücken,
CS559: Computer Graphics Lecture 27: Texture Mapping Li Zhang Spring 2008 Many slides from Ravi Ramamoorthi, Columbia Univ, Greg Humphreys, UVA and Rosalee.
CH8 Frame Buffer Object 1. Introduction Name OpenGL :Frame Buffer Object DirectX:Render Target Usage Render to Texture 2.
Sample Based Visibility for Soft Shadows using Alias-free Shadow Maps Erik Sintorn – Ulf Assarsson – uffe.
OpenGL Shadow. Content Shadowing using Stencil Buffer Shadowing using Projective Texture Shadow map Shadow volume.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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)
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
OpenGL-ES 3.0 And Beyond Boston Photo credit :Johnson Cameraface OpenGL Basics.
2009 GRAPHICS : PROJECT 1 BASED ON DX9 BASICS. Documented by Dongjoon Kim SNU CS Ph.D Course Student Contact : NOTE.
11/5/2002 (c) University of Wisconsin, CS 559 Last Time Local Shading –Diffuse term –Specular term –All together –OpenGL brief overview.
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
 Learn how you can use the shader through OpenGL ES  Add texture on object and make the object have a different look!!
 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame.
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.
Real-Time Dynamic Shadow Algorithms Evan Closson CSE 528.
Mouse Input. For Further Reading Learning WebGL, Lesson 11: 2.
Shadows David Luebke University of Virginia. Shadows An important visual cue, traditionally hard to do in real-time rendering Outline: –Notation –Planar.
GPGPU: Parallel Reduction and Scan Joseph Kider University of Pennsylvania CIS Fall 2011 Credit: Patrick Cozzi, Mark Harris Suresh Venkatensuramenan.
MP3 Frequently Asked Questions (IN OFFICE HOURS).
MP3.. Start at the very beginning. Almost. Either start from nothing yourself, or use the empty template for this MP. Run through the provided files are.
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.
Texture Mapping CEng 477 Introduction to Computer Graphics.
Reflective Shadow Mapping By: Mitchell Allen.
and an introduction to matrices
Deferred Lighting.
Texture Mapping Part II
CS451Real-time Rendering Pipeline
Introduction to Computer Graphics with WebGL
OpenGL Texture Mapping
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Day 05 Shader Basics.
Chapter V Vertex Processing
GPGPU: Parallel Reduction and Scan
OpenGL Texture Mapping
OpenGL Shadow.
Chapter XV Shadow Mapping
CS 480/680 Computer Graphics GLSL Overview.
Frame Buffer Applications
CS 480/680 (Fall 2018) Part 2: Texture Loading
Presentation transcript:

Shadow Mapping RTR Team

1 Why Shadows?

2 RTR Team 2009

3 Why Shadows? Shadows make a scene look more three-dimensional... tell us about the positions of objects relative to each other... tell us where the light comes from... should really be there RTR Team 2009

4 Shadow Determination Several techniques, e.g. Shadow Mapping Shadow Volumes Let’s take a closer look at shadow mapping 2 pass algorithm fast on today’s GPUs relatively easy to implement RTR Team 2009

5 Shadow Mapping Overview 1 st pass: we assume the light source has a “view frustum” just like a camera render scene from light source’s position save depth values only we end up with a shadow (depth-) map 2 nd pass: render scene as usual, but transform vertices to light space, too for each fragment, compare rasterized fragment depth to previously stored depth (read it from shadow map) z fragment > z from_shadow_map => fragment lies in shadow both fragments must be in light space!!! RTR Team 2009

6 Scene – “Meta” View Eye Light Source RTR Team 2009

7 Scene – Light Source View RTR Team 2009

8 Scene – Light Source View (Depth Only) RTR Team 2009

9 Scene – Eye View RTR Team 2009

10 Shadowed Fragment Eye View “Meta“ View RTR Team 2009

11 Shadowed Fragment “Meta“ View Fragment Distance Distance from Shadow Map Eye View RTR Team 2009

12 Lit Fragment “Meta“ View Eye View RTR Team 2009

13 Lit Fragment “Meta“ View Fragment Distance Distance from Shadow Map RTR Team 2009 Eye View

14 Coordinate Systems Eye Light World Model RTR Team 2009

15 Coordinate Systems Eye Light World Model RTR Team 2009

16 Transforming to World Space Eye Light World Model RTR Team 2009

17 Transforming to Light Space Eye Light World Model Light (V light ) rendering from the light source‘s point of view RTR Team 2009

18 Transforming to Eye Space Eye Light World Model rendering from the eye‘s point of view RTR Team 2009

19 1 st pass: Create Shadow Map Create an FBO // create the texture we'll use for the shadowmap glGenTextures(1, &shadow_tex_ID); glBindTexture(GL_TEXTURE_2D, shadow_tex_ID); glTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, SM_width, SM_height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); glGenFramebuffers(1, &shadow_FBO); glBindFramebuffer(GL_FRAMEBUFFER, shadow_FBO); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadow_tex_ID, 0); glDrawBuffer(GL_NONE); // essential for depth-only FBOs!!! glReadBuffer(GL_NONE); // essential for depth-only FBOs!!! // then, just before rendering glBindFramebuffer(GL_FRAMEBUFFER, shadow_FBO); // create the texture we'll use for the shadowmap glGenTextures(1, &shadow_tex_ID); glBindTexture(GL_TEXTURE_2D, shadow_tex_ID); glTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, SM_width, SM_height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); glGenFramebuffers(1, &shadow_FBO); glBindFramebuffer(GL_FRAMEBUFFER, shadow_FBO); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadow_tex_ID, 0); glDrawBuffer(GL_NONE); // essential for depth-only FBOs!!! glReadBuffer(GL_NONE); // essential for depth-only FBOs!!! // then, just before rendering glBindFramebuffer(GL_FRAMEBUFFER, shadow_FBO); RTR Team 2009

20 1 st pass: Create Shadow Map The “view” matrix must be set to V light Note: No projection matrix used up to now! but light-”camera” involves another projection! Turn off all effects when rendering to the shadow map No textures, lighting, etc. RTR Team 2009

21 2 nd pass: Render from Eye’s POV Transform vertices to eye space and project as usual p‘ = P cam * V cam * M * p RTR Team 2009

22 2 nd pass: Render from Eye’s POV Also transform vertices to light space and project one possibility: Use V cam -1, the inverse view matrix of the camera p proj_lightspace = (P light * V light * V cam -1 ) * V cam * M * p save as texture coordinates for accessing shadow map Note: the light‘s projection matrix may be different from the eye‘s projection matrix RTR Team 2009

23 2 nd pass: Render from Eye’s POV one last issue... p lightspace is in the interval [-1…..+1] shadow map coordinates in range [0….+1] scaling/translation necessary  (*0.5, +0.5) SM texcoords = (M translate *M scale *P light *V light *V cam -1 )* V cam * M * p RTR Team 2009

Shadow Mapping: Vertex Shader texture_matrix = (M translate *M scale *P light *V light *V cam -1 ) #version 140 uniform mat4 M; // model matrix uniform mat4 V_cam; // view matrix for the camera uniform mat4 P_cam; // projection matrix for the camera uniform mat4 texture_matrix; in vec4 vertex; // from the application out vec4 SM_tex_coord; // pass on to the FS void main(void) { // standard transformation gl_Position = P_cam * V_cam * M * vertex; // shadow texture coords in projected light space SM_tex_coord = texture_matrix * V_cam * M * vertex; } #version 140 uniform mat4 M; // model matrix uniform mat4 V_cam; // view matrix for the camera uniform mat4 P_cam; // projection matrix for the camera uniform mat4 texture_matrix; in vec4 vertex; // from the application out vec4 SM_tex_coord; // pass on to the FS void main(void) { // standard transformation gl_Position = P_cam * V_cam * M * vertex; // shadow texture coords in projected light space SM_tex_coord = texture_matrix * V_cam * M * vertex; } 24 RTR Team 2009

Shadow Mapping: Fragment Shader Fragment Shader: #version 140 uniform sampler2D shadow_map; in vec4 SM_tex_coord; // passed on from VS out vec4 fragment_color; // final fragment color destination void main(void) { // note the perspective division! vec3 tex_coords = SM_tex_coord.xyz/SM_tex_coord.w; // read depth value from shadow map float depth = texture(shadow_map, tex_coords.xy).r; float inShadow = (depth < tex_coords.z) ? 1.0 : 0.0; // do something with that value... } #version 140 uniform sampler2D shadow_map; in vec4 SM_tex_coord; // passed on from VS out vec4 fragment_color; // final fragment color destination void main(void) { // note the perspective division! vec3 tex_coords = SM_tex_coord.xyz/SM_tex_coord.w; // read depth value from shadow map float depth = texture(shadow_map, tex_coords.xy).r; float inShadow = (depth < tex_coords.z) ? 1.0 : 0.0; // do something with that value... } 25 RTR Team 2009

Add Offset to polygons when rendering shadow map Artifacts glPolygonOffset(1.1, 4.0);// these values work well 26 RTR Team 2009

Decrease ambient term Filter shadow map... Artifacts 27 RTR Team 2009

GPU can do depth compare in hardware and also PCF! Filter shadow map glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 28 RTR Team 2009

Shadow Mapping: Fragment Shader Fragment Shader for Hardware PCF: #version 140 uniform sampler2DShadow shadow_map; in vec4 SM_tex_coord; // passed on from VS out vec4 fragment_color; // final fragment color destination void main(void) { float shadow = textureProj(shadow_map, SM_tex_coord); // do something with that value... } #version 140 uniform sampler2DShadow shadow_map; in vec4 SM_tex_coord; // passed on from VS out vec4 fragment_color; // final fragment color destination void main(void) { float shadow = textureProj(shadow_map, SM_tex_coord); // do something with that value... } 29 RTR Team 2009

References RTR Team 2009