Shadow Rendering. CS7GV3 Real-time Rendering

Similar documents
INSTANCE VARIABLES (1/2) P. 1

VGP353 Week 2. Agenda: Assignment #1 due Introduce shadow maps. Differences / similarities with shadow textures Added benefits Potential problems

SUMMARY. CS380: Introduction to Computer Graphics Texture Mapping Chapter 15. Min H. Kim KAIST School of Computing 18/05/03.

Shadow Algorithms. CSE 781 Winter Han-Wei Shen

Computergraphics Exercise 15/ Shading & Texturing

Computergrafik. Matthias Zwicker. Herbst 2010

Shadows. Prof. George Wolberg Dept. of Computer Science City College of New York

Shadows in Computer Graphics. by Björn Kühl im/ve University of Hamburg, Germany

Shadow Rendering EDA101 Advanced Shading and Rendering

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

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

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

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

CS 432 Interactive Computer Graphics

Computer Graphics Shadow Algorithms

Advanced Shading I: Shadow Rasterization Techniques

Computer Graphics 10 - Shadows

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

Computer Graphics. Shadows

Best practices for effective OpenGL programming. Dan Omachi OpenGL Development Engineer

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

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

CS452/552; EE465/505. Image Processing Frame Buffer Objects

Recall: Indexing into Cube Map

Overview. By end of the week:

Soft shadows. Steve Marschner Cornell University CS 569 Spring 2008, 21 February

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

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

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

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

General Purpose computation on GPUs. Liangjun Zhang 2/23/2005

EECS 487: Interactive Computer Graphics

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

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

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

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

CSE 167: Introduction to Computer Graphics Lecture #7: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2018

CT5510: Computer Graphics. Texture Mapping

Moving Mobile Graphics Advanced Real-time Shadowing. Marius Bjørge ARM

Illumination and Geometry Techniques. Karljohan Lundin Palmerius

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

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

Shadows in the graphics pipeline

COMP371 COMPUTER GRAPHICS

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

CEng 477 Introduction to Computer Graphics Fall 2007

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

Discussion 3. PPM loading Texture rendering in OpenGL

Rasterization Overview

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

Picking (In WebGL) Picking idea

CS 418: Interactive Computer Graphics. Basic Shading in WebGL. Eric Shaffer

INF3320 Computer Graphics and Discrete Geometry

Texture Mapping. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

CHAPTER 1 Graphics Systems and Models 3

Computer Graphics. Bing-Yu Chen National Taiwan University The University of Tokyo

OUTLINE. Learn the basic design of a graphics system Introduce pipeline architecture Examine software components for a graphics system

RASTERISED RENDERING

CSE 167: Introduction to Computer Graphics Lecture #8: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2017

OpenGL Performances and Flexibility. Visual Computing Laboratory ISTI CNR, Italy

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

Shadow Mapping. Marc Stamminger, University of Erlangen-Nuremberg

Pipeline Operations. CS 4620 Lecture 10

Computer graphics 2: Graduate seminar in computational aesthetics

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

CS559 Computer Graphics Fall 2015

03 RENDERING PART TWO

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

Multi-View Soft Shadows. Louis Bavoil

Computer Graphics. Bing-Yu Chen National Taiwan University

INFOGR Computer Graphics

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

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

Deferred Rendering Due: Wednesday November 15 at 10pm

GLSL Applications: 2 of 2

Introduction to Computer Graphics with WebGL

Chapter 7 - Light, Materials, Appearance

Pipeline Operations. CS 4620 Lecture 14

Shaders. Slide credit to Prof. Zwicker

Models and Architectures

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

Texturing. Slides done bytomas Akenine-Möller and Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

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

Scanline Rendering 2 1/42

Projective Textures & Shadow Mapping. Prof. Aaron Lanterman School of Electrical and Computer Engineering Georgia Institute of Technology

CS 381 Computer Graphics, Fall 2008 Midterm Exam Solutions. The Midterm Exam was given in class on Thursday, October 23, 2008.

Real-Time Universal Capture Facial Animation with GPU Skin Rendering

Shadows. COMP 575/770 Spring 2013

Virtual Cameras and The Transformation Pipeline

Creating soft shadows

CSE 167: Lecture #17: Volume Rendering. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

CS452/552; EE465/505. Intro to Lighting

Objectives. Introduce the OpenGL shading Methods 1) Light and material functions on MV.js 2) per vertex vs per fragment shading 3) Where to carry out

CS452/552; EE465/505. Lighting & Shading

Efficient and Scalable Shading for Many Lights

C O M P U T E R G R A P H I C S. Computer Graphics. Three-Dimensional Graphics V. Guoying Zhao 1 / 65

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

CS452/552; EE465/505. Texture Mapping in WebGL

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Transcription:

Shadow Rendering CS7GV3 Real-time Rendering

Global Illumination The incoming radiance L i (p,l) at some point p is the outgoing L o (r(p,l)-l) from another point

A Recursive Term r(r(p,l), l ) r(r(r(p,l), l ),l ) ad infinitum

Shadows

Shadows and Perception Position Cues

Shadows and Perception Position Cues

Shadows and Perception Geometric Information

Shadows and Perception Geometric Information

Shadows and Perception

Shadow Mapping History Leonardo Da Vinci. Codex Urbinas. 1490. Johann Heinrich Lambert. Die freye Perspektive. 1759.

Seminal Papers Williams 1978 zbuffer shadows Shadow Ray-casting Appel 1966

Real-time Shadows Projective Shadows Trivial for planar surface: project all vertices of blocker onto plane of receiver, draw in black Shadow Volumes Test points to see if inside space occluded by blocker Shadow Maps We look at these in more detail Ray Traced Shadows PRT (lightmaps) Pre-compute the lighting and bake into textures

Projective Shadows We project all vertices onto the receiver and draw them in black

Projective Shadows Even highly inaccurate shadow provide useful cues Extend lines from point light through centre of object, draw ellipse where this hits ground plane Alternatively extend lines through from light each vertex Use same math as projection matrix Could do it for several planes for reasonable no. of verts Doesn t work for curved surfaces, complex projection surfaces or self shadowing

Shadow Mapping Introduced by Williams in 1978 Casting Curved Shadows onto Curved Surfaces Image space shadowing technique Used in Renderman (Toy Story) Scales to an arbitrary number of objects Can be extended to soft shadows Handles self-shadowing No Selfshadowing Selfshadowing

Soft Shadows Heckberts and Herf s methode (256 passes) Haines methode (one pass)

Soft Shadows Heckberts and Herf s methode (256 passes) Haines methode (one pass)

Shadow Mapping Exploits image space shadow buffer Render scene from point of view of light For each visible point (pixel in image plane) Project into light space, determine distance to light Compare with stored value in depth map If depth > stored depth then in shadow Depth Image from Light Viewpoint Colour Image from Eye Viewpoint

Creating a Shadow Map Multipass technique By rendering from the light position we see all point visiable from that position There are no shadows Points not seen from the light will not be rendered if the depht test fails In the 2nd pass we project the surface coordinates into the light s refernec frame Then compair there depth

GeForce 8800 (2006) but didn t change much

1 st Step We need to create a depth texture Attach to a framebuffer object Important: The texture comparison mode allows us to compair between a reference value and a value stored in the texture This is performed by the texture hardware and not the shader

Creating a Framebuffer Object with a Depth Attached // Create a depth texture glgentextures(1, &depth_texture); glbindtexture(gl_texture_2d, depth_texture); // Allocate storage for the texture data glteximage2d(gl_texture_2d, 0, GL_DEPTH_COMPONENT32, DEPTH_TEXTURE_SIZE, DEPTH_TEXTURE_SIZE, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); // Set the default filtering modes gltexparameteri(gl_texture_2d, GL_TEXTURE_MIN_FILTER, GL_LINEAR); gltexparameteri(gl_texture_2d, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Set up deph comparison mode gltexparameteri(gl_texture_2d, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); gltexparameteri(gl_texture_2d, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);

Creating a Framebuffer Object with a Depth Attached //Set up wrapping modes gltexparameteri(gl_texture_2d, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); gltexparameteri(gl_texture_2d, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glbindtexture(gl_texture_2d, 0); // Create FBO to render depth into glgenframebuffers(1, &depth_fbo); glbindframebuffer(gl_framebuffer, depth_fbo); // Attach the depth texture to it glframebuffertexture(gl_framebuffer, GL_DEPTH_STENCIL_ATTACHMENT, depth_texture, 0); // Disable color rendering as there are color attachments gldrawbuffer(gl_none);

2 nd Step We need to setting up the Matrices for Shadow Map Generation

Setting up the Matrices for Shadow Map Generation // Time varying light position vec3 light_position = vec3(sinf(t * 6.0f * 3.141592f) * 300.0f, 200.0f, cosf(t * 4.0f * 3.141592f) * 100.0f + 250.0f); // Matrices for rendering the scene mat4 scene_model_matrix = rotate(t * 720.0f, Y); // Matrices used when rendering from the light s position mat4 light_view_matrix = lookat(light_position, vec3(0.0f), Y); mat4 light_projection_matrix(frustum(-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, FRUSTUM_DEPTH)); // Now we render from the light's position into the depth buffer. // Select the appropriate program gluseprogram(render_light_prog); gluniformmatrix4fv(render_light_uniforms.model_view_projection_matrix, 1, GL_FALSE, light_projection_matrix * light_view_matrix * scene_model_matrix);

3 rd Step Setting up shaders that generate the depth buffer from the ligth s position

Simple Vertex Shader for Shadow Map Generation #version 330 uniform mat4 model_view_projection_matrix; layout (location = 0) in vec4 position; void main(void) { gl_position = model_view_projection_matrix * position; }

Simple Fragment Shader for Shadow Map Generation #version 330 layout (location = 0) out vec4 color; void main(void) { color = vec4(1.0); }

4 th Step Now we render the scene from the light s view Notice: Polygon offset is used to prevent depth fighting

Rendering the Scene from the light s point of view // Bind the 'depth only' FBO and set the viewport to the size of the depth texture glbindframebuffer(gl_framebuffer, depth_fbo); glviewport(0, 0, DEPTH_TEXTURE_SIZE, DEPTH_TEXTURE_SIZE); // Clear glcleardepth(1.0f); glclear(gl_depth_buffer_bit); // Enable polygon offset to resolve depth-fighting isuses glenable(gl_polygon_offset_fill); glpolygonoffset(2.0f, 4.0f); // Draw from the light's point of view DrawScene(true); gldisable(gl_polygon_offset_fill);

5 th Step After rendering the scene from the light s point of view In order to calcuate the depth We render the scene with regular shaders Important: Shadow matrix Transforms world coordinates into the light s projective space

Matrix Calculation for Shadow Map Rendering // Matrices for rendering the scene mat4 scene_model_matrix = rotate(t * 720.0f, Y); mat4 scene_view_matrix = translate(0.0f, 0.0f, -300.0f); mat4 scene_projection_matrix = frustum(-1.0f, 1.0f, -aspect, aspect, 1.0f, FRUSTUM_DEPTH); const mat4 scale_bias_matrix = mat4(vec4(0.5f, 0.0f, 0.0f, 0.0f), vec4(0.0f, 0.5f, 0.0f, 0.0f), vec4(0.0f, 0.0f, 0.5f, 0.0f), vec4(0.5f, 0.5f, 0.5f, 1.0f)); mat4 shadow_matrix = scale_bias_matrix * light_projection _matrix * Light_view_matrix;

6 th Step In this step the vertex shader will apply these matrices to incoming vertices

Vertex Shader for Rendering from Shadow Maps #version 330 uniform mat4 model_matrix; uniform mat4 view_matrix; uniform mat4 projection_matrix; uniform mat4 shadow_matrix; layout (location = 0) in vec4 position; layout (location = 1) in vec3 normal; out VS_FS_INTERFACE { vec4 shadow_coord; vec3 world_coord; vec3 eye_coord; vec3 normal; } vertex;

Vertex Shader for Rendering from Shadow Maps void main(void) { vec4 world_pos = model_matrix * position; vec4 eye_pos = view_matrix * world_pos; vec4 clip_pos = projection_matrix * eye_pos; vertex.world_coord = world_pos.xyz; vertex.eye_coord = eye_pos.xyz; vertex.shadow_coord = shadow_matrix * world_pos; vertex.normal = mat3(view_matrix * model_matrix) * normal; } gl_position = clip_pos;

7th Step The Fragment Shader will perform the lighting calculation Important: uniform sampler2dshadow depth_texture; float f = textureproj(depth_texture, fragment.shadow_coord); This is where the comparison takes place

Fragment Shader for Rendering from Shadow Maps #version 330 uniform sampler2dshadow depth_texture; uniform vec3 light_position; uniform vec3 material_ambient; uniform vec3 material_diffuse; uniform vec3 material_specular; uniform float material_specular_power; layout (location = 0) out vec4 color; in VS_FS_INTERFACE { vec4 shadow_coord; vec3 world_coord; vec3 eye_coord; vec3 normal; } fragment;

Fragment Shader for Rendering from Shadow Maps void main(void) { vec3 N = fragment.normal; vec3 L = normalize(light_position - fragment.world_coord); float LdotN = dot(n, L); vec3 R = reflect(-l, N); float diffuse = max(ldotn, 0.0); float specular = max(pow(dot(normalize(-fragment.eye_coord), R), material_specular_power), 0.0); float f = textureproj(depth_texture, fragment.shadow_coord); } color = vec4(material_ambient + f * (material_diffuse * diffuse + material_specular * specular), 1.0);

Shadow Map

Shadow Map Precision Shadow map has fixed precision = bit depth Limits accuracy of depth test Leads to problems e.g. Surface acne

Shadow Map Bias One hack is to bias the depth Shift shadow map depth a little bit Just moves the problem but is still useful We did this in the previous example

Perspective Aliasing Stairstepping Artifacts

Perspective Aliasing Stairstepping Artifacts

Hierarchical Shadow Maps Use variable resolution Shadow maps across the scene Split view frustum into separate volumes Create bounding box for each volume Use this to determine which shadow map to use

Percentage Closer Filtering Sample depth map at multiple locations around a point Assume area light source: causing variable exposure of projection surface Instead of sampling the light over an area, use point-light model and sample around the projection point instead Also creates soft shadows