Deferred Lighting.

Slides:



Advertisements
Similar presentations
Real-Time Rendering 靜宜大學資工研究所 蔡奇偉副教授 2010©.
Advertisements

Exploration of advanced lighting and shading techniques
POST-PROCESSING SET09115 Intro Graphics Programming.
Deferred Shading Optimizations
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 1/16 Deferred Lighting Deferred Lighting – 11/18/2014.
Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Understanding the graphics pipeline Lecture 2 Original Slides by: Suresh Venkatasubramanian Updates by Joseph Kider.
Graphics Pipeline.
The Art and Technology Behind Bioshock’s Special Effects
Week 7 - Monday.  What did we talk about last time?  Specular shading  Aliasing and antialiasing.
3D Graphics Rendering and Terrain Modeling
1. What is Lighting? 2 Example 1. Find the cubic polynomial or that passes through the four points and satisfies 1.As a photon Metal Insulator.
Rasterization and Ray Tracing in Real-Time Applications (Games) Andrew Graff.
1 CSCE 641: Computer Graphics Lighting Jinxiang Chai.
Status – Week 277 Victor Moya.
Global Illumination May 7, Global Effects translucent surface shadow multiple reflection.
4.2. D EFERRED S HADING Exploration of deferred shading (rendering)
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
SET09115 Intro Graphics Programming
Shadows Computer Graphics. Shadows Shadows Extended light sources produce penumbras In real-time, we only use point light sources –Extended light sources.
Shading (introduction to rendering). Rendering  We know how to specify the geometry but how is the color calculated.
GPU Programming Robert Hero Quick Overview (The Old Way) Graphics cards process Triangles Graphics cards process Triangles Quads.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
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.
09/09/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Event management Lag Group assignment has happened, like it or not.
TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain 
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Week 6 - Wednesday.  What did we talk about last time?  Light  Material  Sensors.
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.
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
Texture Mapping CAP4730: Computational Structures in Computer Graphics.
Emerging Technologies for Games Deferred Rendering CO3303 Week 22.
Computer Graphics Blending CO2409 Computer Graphics Week 14.
Lecture 6 Rasterisation, Antialiasing, Texture Mapping,
Visual Appearance Chapter 4 Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology.
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.
Real-Time Dynamic Shadow Algorithms Evan Closson CSE 528.
Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010.
1cs426-winter-2008 Notes. 2 Atop operation  Image 1 “atop” image 2  Assume independence of sub-pixel structure So for each final pixel, a fraction alpha.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
Applications and Rendering pipeline
Compositing and Rendering
Shaders, part 2 alexandri zavodny.
- Introduction - Graphics Pipeline
Week 7 - Monday CS361.
Photorealistic Rendering vs. Interactive 3D Graphics
Week 2 - Friday CS361.
The Graphic PipeLine
Patrick Cozzi University of Pennsylvania CIS Fall 2013
Visual Appearance Chapter 4
Robust Shadow Maps for Large Environments
Introduction to OpenGL
3D Graphics Rendering PPT By Ricardo Veguilla.
The Graphics Rendering Pipeline
CS451Real-time Rendering Pipeline
Real-time Computer Graphics Overview
Chapter 14 Shading Models.
Introduction to Computer Graphics with WebGL
The Graphics Pipeline Lecture 5 Mon, Sep 3, 2007.
UMBC Graphics for Games
Chapter IX Lighting.
CS5500 Computer Graphics May 29, 2006
Computer Graphics Introduction to Shaders
Chapter 14 Shading Models.
Introduction to OpenGL
Frame Buffer Applications
Presentation transcript:

Deferred Lighting

Motivation Per-vertex lighting is ugly Can increase number of vertices, but this requires lots of extra memory Per-pixel lighting looks a lot better But is much slower than per-vertex, must calculate lighting equation for each pixel instead of each vertex. Naïve implementation has many wasted calculations Why? Calculates lighting on pixels that are later overwritten by a closer triangle Deferred lighting removes most of the wasted calculations and provides further optimizations Deferred Lighting – 11/9/2016

Overview How can we avoid wasted calculations? First pass Second pass Only calculate lighting once for each pixel But the fragment shader has no way of knowing if the value it is calculating will be the final value for that pixel Solution: Multiple passes First pass Render geometry and keep track of data necessary to calculate lighting Second pass Calculate diffuse and specular values that are independent of material Third Pass Combine diffuse/specular from second pass with geometry and materials (ex. Object color) to complete lighting model Deferred Lighting – 11/9/2016

Passes A “pass” just means generating a texture (or multiple textures). Use framebuffer objects (FBOs) to group textures Most of the shaders you’ve written used a single pass Take in geometry and various uniforms, output a texture to the screen In the first part of lab 7 you used multiple passes to render geometry Use geometry/lights to output a texture with per-pixel phong lighting (first pass) Use phong texture, blur it horizontally (second pass) Use horizontally blurred texture, blur it vertically and output to screen (third pass) Deferred Lighting – 11/9/2016

First Pass Takes in all our geometry as input Doesn’t need material properties (ex. textures) It outputs exactly the information we need to calculate lighting Normals Positions – but we can use a trick to save space Shininess – store as alpha channel of normal Deferred Lighting – 11/9/2016

Second Pass (1/2) Diffuse: 𝑛 ∙ 𝑙 ∗𝑙𝑖𝑔ℎ𝑡𝐶𝑜𝑙𝑜𝑟 Takes in normals, shininess and positions from first pass and light data Outputs diffuse and specular light contributions Can save space by rendering to a single texture and storing specular contribution as alpha (but we only get monochromatic specular highlights) Or render diffuse and specular to separate textures How do we send light data to GPU? For each light: Set necessary uniforms (position, direction, etc…) Naïve: render full-screen quad to run the fragment shader on each pixel Can do better, see slide 10 But each light would overwrite data from previous light Solution: glBlendFunc(GL_ONE, GL_ONE) for additive blending Specular: 𝑟 ∙ 𝑣 𝑛 ∗𝑙𝑖𝑔ℎ𝑡𝐶𝑜𝑙𝑜𝑟 Deferred Lighting – 11/9/2016

Second Pass (2/2) Diffuse Specular Deferred Lighting – 11/9/2016

Third Pass (1/2) Takes in diffuse and specular contribution from second pass and geometry, textures, etc… (whatever we need to calculate object’s diffuse color) Render the scene again, this time applying any materials and finishing the lighting equation (i.e. finish calculating diffuse and specular term and add ambient + diffuse + specular) Output is our final lit scene which goes to the screen Deferred Lighting – 11/9/2016

Third Pass (2/2) Deferred Lighting – 11/9/2016

Optimizations Instead of calculating lighting on every pixel for every light, calculate lighting on only the subset of pixels that a light can possibly affect. Restrict the lighting calculations to the geometric shape that represents the volume of the light. In the second pass render this 3D shape instead of a full-screen quad. Point light: sphere (radius usually based on attenuation) Spot light: cone Directional light: full-screen quad What if the camera is inside the shape of the light? Represent light as a full-screen quad We will still have some wasted calculations, but this is much better (especially for small lights). Deferred Lighting – 11/9/2016

Optimizations How the light is represented Light visualized in scene Deferred Lighting – 11/9/2016

Optimizations Diffuse contribution Final scene Visualization of lights Deferred Lighting – 11/9/2016

Optimizations The second pass needs to know the position of each pixel in world space Our first pass shader can easily write this position to a texture Doing this uses an extra texture (i.e. twice as much memory) Instead, use the depth buffer from the first pass. First pass already uses a depth buffer, so we don’t need any additional space. Depth buffer has z value from 0 to 1 for each pixel in screen space (convert x/y to screen space based on width/height). Use the (x,y,z) triplet in screen space and the inverse projection and view matrices to transform to world space. Deferred Lighting – 11/9/2016

Deferred Shading Deferred shading is another method for speeding up per-pixel lighting, almost the same as deferred lighting. Note that the word “shading” here doesn’t refer to interpolating lighting values, its just the name of this technique Uses only 2 passes First pass renders geometry storing normals as in deferred lighting, but also stores all material properties (diffuse color, for example) in one or more additional textures Second pass calculates lighting and uses material properties to calculate final pixel color Pros: Less computation (don’t need to render the scene twice) Cons: Uses more memory and bandwidth (passing extra textures around) Deferred Lighting – 11/9/2016

Overview Deferred Lighting Deferred Shading Render normals, positions, and shininess to textures Calculate diffuse and specular contributions for every light and output to textures Render scene again using diffuse/specular light data to calculate final pixel color (according to lighting model) Deferred Shading Render normals, positions, shininess, and material properties to textures Calculate lighting for every light and combine with material properties to output final pixel color Deferred Lighting – 11/9/2016

Disadvantages of Deferred Rendering Can’t easily handle transparency (this is a generic issue with z-buffer rendering techniques) Solutions: Naïve: Sort transparent objects by distance Slow Can’t handle intersecting transparent objects Order-independent transparency: Depth peeling Use forward-rendering for transparent objects Forward-rendering is the standard rendering pipeline that you’ve been using Really great overview of modern transparency techniques from SIGGRAPH 2016 Can’t use traditional anti-aliasing techniques MSAA (Multisample anti-aliasing), one of the most common AA techniques, doesn’t work at all with deferred lighting Usually use some sort of screen-space anti-aliasing instead (FXAA, MLAA, SMAA) Deferred Lighting – 11/9/2016

Deferred Lighting in “Uncharted 4” (From “Advances in Real-Time Rendering in Games” as part of SIGGRAPH 2016) Graphics programmer from Naughty Dog, Inc. talks about “Uncharted 4” and how they built the game on a lighting system that is completely deferred, and some of the optimizations they made use of to allow for support of a huge range of materials. Advances in Real-Time Rendering in Games course Deferred Lighting in Uncharted 4