CS 445 / 645 Introduction to Computer Graphics Lecture 18 Shading Shading.

Slides:



Advertisements
Similar presentations
GR2 Advanced Computer Graphics AGR
Advertisements

SI23 Introduction to Computer Graphics
7.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 7 Polygon Shading Techniques.
Virtual Realism TEXTURE MAPPING. The Quest for Visual Realism.
3D Graphics Rendering and Terrain Modeling
Computer Graphics Inf4/MSc Computer Graphics Lecture 13 Illumination I – Local Models.
Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
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.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Lighting/Shading III Week.
Computer Graphics - Class 10
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Lighting/Shading III Week.
IMGD 1001: Illumination by Mark Claypool
Computer Graphics (Fall 2005) COMS 4160, Lecture 16: Illumination and Shading 1
Lighting and Shading Wen-Chieh (Steve) Lin
(conventional Cartesian reference system)
CS 376 Introduction to Computer Graphics 03 / 30 / 2007 Instructor: Michael Eckmann.
6.1 Vis_04 Data Visualization Lecture 6 - A Rough Guide to Rendering.
©Larry F. Hodges (modified by Amos Johnson) 1 Shading Models.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Shading Week 5, Wed 1 Oct 2003 recap: lighting shading.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Lighting and Shading Week.
Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006
Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping.
1 Graphics CSCI 343, Fall 2013 Lecture 20 Lighting and Shading III.
Polygon Shading. Assigning color to a shape to make graphical scenes look realistic, or artistic, or whatever effect we’re attempting to achieve But first.
Shading (introduction to rendering). Rendering  We know how to specify the geometry but how is the color calculated.
University of Illinois at Chicago Electronic Visualization Laboratory (EVL) CS 426 Intro to 3D Computer Graphics © 2003, 2004, 2005 Jason Leigh Electronic.
COMPUTER GRAPHICS CS 482 – FALL 2014 AUGUST 27, 2014 FIXED-FUNCTION 3D GRAPHICS MESH SPECIFICATION LIGHTING SPECIFICATION REFLECTION SHADING HIERARCHICAL.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
COLLEGE OF ENGINEERING UNIVERSITY OF PORTO COMPUTER GRAPHICS AND INTERFACES / GRAPHICS SYSTEMS JGB / AAS 1 Shading (Shading) & Smooth Shading Graphics.
Computer Graphics An Introduction. What’s this course all about? 06/10/2015 Lecture 1 2 We will cover… Graphics programming and algorithms Graphics data.
Shading & Texture. Shading Flat Shading The process of assigning colors to pixels. Smooth Shading Gouraud ShadingPhong Shading Shading.
CS447/ Realistic Rendering -- Radiosity Methods-- Introduction to 2D and 3D Computer Graphics.
Rendering Overview CSE 3541 Matt Boggus. Rendering Algorithmically generating a 2D image from 3D models Raster graphics.
CS 325 Introduction to Computer Graphics 03 / 26 / 2010 Instructor: Michael Eckmann.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Lighting/Shading III Week.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Basic Rendering Pipeline and Shading Spring 2012.
Illumination and Shading How to shade surfaces based on the position,orientation,characteristics of the surfaces and the light sources illuminating them.
Smooth Shading Gouraud Phong
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading.
CS 325 Introduction to Computer Graphics 03 / 29 / 2010 Instructor: Michael Eckmann.
CS 445 / 645 Introduction to Computer Graphics Lecture 15 Shading Shading.
RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program.
Lecture Fall 2001 Illumination and Shading in OpenGL Light Sources Empirical Illumination Shading Transforming Normals Tong-Yee Lee.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
11/5/2002 (c) University of Wisconsin, CS 559 Last Time Local Shading –Diffuse term –Specular term –All together –OpenGL brief overview.
Local Illumination and Shading
Chris Mayer & Nic Shulver Shading Definitions Light emanating from small surfaces is called a Point light sourcee.g. the sun (not really small though!)
Render methods. Contents Levels of rendering Wireframe Plain shadow Gouraud Phong Comparison Gouraud-Phong.
Introduction to Meshes Lecture 22 Mon, Oct 20, 2003.
CDS 301 Fall, 2008 From Graphics to Visualization Chap. 2 Sep. 3, 2009 Jie Zhang Copyright ©
Lighting and Reflection Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
David Luebke3/16/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
Schedule Update GP 4 – Tesselation/Cg GDS 4 – Subdiv Surf. GP 5 – Object Modeling Lab: Mini-proj Setup GDS 5 – Maya Modeling MCG 6 – Intersections GP 6.
Illumination Models. Introduction 1 Illumination model: Given a point on a surface, what is the perceived color and intensity? Known as Lighting Model,
CPSC 314 LIGHTING AND SHADING UGRAD.CS.UBC.CA/~CS314 slide credits: Mikhail Bessmeltsev et al 1.
Computer Graphics Lecture 26 Mathematics of Lighting and Shading Part II Taqdees A. Siddiqi
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
3D Graphics Rendering PPT By Ricardo Veguilla.
Chapter 14 Shading Models.
CSC461: Lecture 23 Shading Computation
Vectors, Normals, & Shading
Lighting/Shading III Week 7, Wed Mar 3
Introduction to Computer Graphics with WebGL
Introduction to Meshes
ייצוג בעולם 3D ייצוג מצולעים (פוליגונים) צלע קודקוד צלעe0 : {v1,v2}
Computer Graphics (Fall 2003)
Chapter 14 Shading Models.
Introduction to Meshes
Presentation transcript:

CS 445 / 645 Introduction to Computer Graphics Lecture 18 Shading Shading

Ray Tracing Assignment Deadline extended until Tuesday the 13th

Ray Tracing Assignment Barycentric coordinates (Möbius, 1827) Consider a triangle defined by (A 1, A 2, A 3 )Consider a triangle defined by (A 1, A 2, A 3 ) –These points are defined relative to world origin –A point within triangle could also be defined as (x, y, z) relative to world origin A point can be defined as (t 1, t 2, t 3 ) corresponding to its position with respect to A 1, A 2, A 3.A point can be defined as (t 1, t 2, t 3 ) corresponding to its position with respect to A 1, A 2, A 3. Barycentric coordinates (Möbius, 1827) Consider a triangle defined by (A 1, A 2, A 3 )Consider a triangle defined by (A 1, A 2, A 3 ) –These points are defined relative to world origin –A point within triangle could also be defined as (x, y, z) relative to world origin A point can be defined as (t 1, t 2, t 3 ) corresponding to its position with respect to A 1, A 2, A 3.A point can be defined as (t 1, t 2, t 3 ) corresponding to its position with respect to A 1, A 2, A 3.

Barycentric Coordinates Solve for (t 1, t 2, t 3 ) such that –t 1 + t 2 + t 3 = 1 –t 1 A 1 + t 2 A 2 + t 3 A 3 = P Solve for (t 1, t 2, t 3 ) such that –t 1 + t 2 + t 3 = 1 –t 1 A 1 + t 2 A 2 + t 3 A 3 = P mathworld.com

Barycentric Coordinates An observation t 1, t 2, and t 3 are weights such that when they are used to represent the mass at the vertices of the triangle, P is at its center of masst 1, t 2, and t 3 are weights such that when they are used to represent the mass at the vertices of the triangle, P is at its center of mass t 1, t 2, and t 3 are weights that represent the ratio of the area of each of the three subtriangles to the area of the wholet 1, t 2, and t 3 are weights that represent the ratio of the area of each of the three subtriangles to the area of the whole An observation t 1, t 2, and t 3 are weights such that when they are used to represent the mass at the vertices of the triangle, P is at its center of masst 1, t 2, and t 3 are weights such that when they are used to represent the mass at the vertices of the triangle, P is at its center of mass t 1, t 2, and t 3 are weights that represent the ratio of the area of each of the three subtriangles to the area of the wholet 1, t 2, and t 3 are weights that represent the ratio of the area of each of the three subtriangles to the area of the whole

Barycentric coordinates The cross product computes a triangle’s area || (A 2 - A 1 ) x (A 3 -A 1 ) || = (area of A 1 A 2 A 3 ) * 2|| (A 2 - A 1 ) x (A 3 -A 1 ) || = (area of A 1 A 2 A 3 ) * 2 Where || x || = the area of the triangle x… the cross product The cross product computes a triangle’s area || (A 2 - A 1 ) x (A 3 -A 1 ) || = (area of A 1 A 2 A 3 ) * 2|| (A 2 - A 1 ) x (A 3 -A 1 ) || = (area of A 1 A 2 A 3 ) * 2 Where || x || = the area of the triangle x… the cross product

Barycentric Coordinates All points of triangle are unique, all points in space can be represented with barycentric coordinates A 1, A 2, and A 3 form an affine spaceA 1, A 2, and A 3 form an affine space If 0 ≤ t 1, t 2, t 3 ≤ 1, the point is in the triangleIf 0 ≤ t 1, t 2, t 3 ≤ 1, the point is in the triangle All points of triangle are unique, all points in space can be represented with barycentric coordinates A 1, A 2, and A 3 form an affine spaceA 1, A 2, and A 3 form an affine space If 0 ≤ t 1, t 2, t 3 ≤ 1, the point is in the triangleIf 0 ≤ t 1, t 2, t 3 ≤ 1, the point is in the triangle

Applying Illumination We have an illumination model for a point on a surface Assuming that our surface is defined as a mesh of polygonal facets, which points should we use? Keep in mind: It’s a fairly expensive calculationIt’s a fairly expensive calculation Several possible answers, each with different implications for the visual quality of the resultSeveral possible answers, each with different implications for the visual quality of the result We have an illumination model for a point on a surface Assuming that our surface is defined as a mesh of polygonal facets, which points should we use? Keep in mind: It’s a fairly expensive calculationIt’s a fairly expensive calculation Several possible answers, each with different implications for the visual quality of the resultSeveral possible answers, each with different implications for the visual quality of the result

Applying Illumination With polygonal/triangular models: Each facet has a constant surface normalEach facet has a constant surface normal If the light is directional, the diffuse reflectance is constant across the facet. Why?If the light is directional, the diffuse reflectance is constant across the facet. Why? With polygonal/triangular models: Each facet has a constant surface normalEach facet has a constant surface normal If the light is directional, the diffuse reflectance is constant across the facet. Why?If the light is directional, the diffuse reflectance is constant across the facet. Why?

Flat Shading The simplest approach, flat shading, calculates illumination at a single point for each polygon: If an object really is faceted, is this accurate? The simplest approach, flat shading, calculates illumination at a single point for each polygon: If an object really is faceted, is this accurate?

Is flat shading realistic for faceted object? No: For point sources, the direction to light varies across the facetFor point sources, the direction to light varies across the facetNo: – For specular reflectance, direction to eye varies across the facet

Flat Shading We can refine it a bit by evaluating the Phong lighting model at each pixel of each polygon, but the result is still clearly faceted:

Vertex Normals To get smoother-looking surfaces we introduce vertex normals at each vertex Usually different from facet normalUsually different from facet normal Used only for shadingUsed only for shading Think of as a better approximation of the real surface that the polygons approximateThink of as a better approximation of the real surface that the polygons approximate To get smoother-looking surfaces we introduce vertex normals at each vertex Usually different from facet normalUsually different from facet normal Used only for shadingUsed only for shading Think of as a better approximation of the real surface that the polygons approximateThink of as a better approximation of the real surface that the polygons approximate

Vertex Normals Vertex normals may be Provided with the modelProvided with the model Computed from first principlesComputed from first principles Approximated by averaging the normals of the facets that share the vertexApproximated by averaging the normals of the facets that share the vertex Vertex normals may be Provided with the modelProvided with the model Computed from first principlesComputed from first principles Approximated by averaging the normals of the facets that share the vertexApproximated by averaging the normals of the facets that share the vertex

Gouraud Shading This is the most common approach Perform Phong lighting at the verticesPerform Phong lighting at the vertices Linearly interpolate the resulting colors over facesLinearly interpolate the resulting colors over faces –Along edges –Along scanlines This is the most common approach Perform Phong lighting at the verticesPerform Phong lighting at the vertices Linearly interpolate the resulting colors over facesLinearly interpolate the resulting colors over faces –Along edges –Along scanlines C1C1 C2C2 C3C3 c 1 + t 1 (c 2 -c 1 ) c 1 + t 2 (c 3 -c 1 ) c 1 + t 1 (c 2 -c 1 ) + t 3 (c 1 + t 2 (c 3 -c 1 )- c 1 + t 1 (c 2 -c 1 )) –This is what OpenGL does l Does this eliminate the facets?

Gouraud Shading Artifacts Often appears dull, chalkyOften appears dull, chalky Lacks accurate specular componentLacks accurate specular component –If included, will be averaged over entire polygon Artifacts Often appears dull, chalkyOften appears dull, chalky Lacks accurate specular componentLacks accurate specular component –If included, will be averaged over entire polygon C1C1 C2C2 C3C3 Can’t shade that effect!

Gouraud Shading C1C1 C2C2 C3C3 l Artifacts –Mach Banding n Artifact at discontinuities in intensity or intensity slope C4C4 Discontinuity in rate of color change occurs here

Phong Shading Phong shading is not the same as Phong lighting, though they are sometimes mixed up Phong lighting: the empirical model we’ve been discussing to calculate illumination at a point on a surfacePhong lighting: the empirical model we’ve been discussing to calculate illumination at a point on a surface Phong shading: linearly interpolating the surface normal across the facet, applying the Phong lighting model at every pixelPhong shading: linearly interpolating the surface normal across the facet, applying the Phong lighting model at every pixel –Same input as Gouraud shading –Usually very smooth-looking results: –But, considerably more expensive Phong shading is not the same as Phong lighting, though they are sometimes mixed up Phong lighting: the empirical model we’ve been discussing to calculate illumination at a point on a surfacePhong lighting: the empirical model we’ve been discussing to calculate illumination at a point on a surface Phong shading: linearly interpolating the surface normal across the facet, applying the Phong lighting model at every pixelPhong shading: linearly interpolating the surface normal across the facet, applying the Phong lighting model at every pixel –Same input as Gouraud shading –Usually very smooth-looking results: –But, considerably more expensive

Phong Shading Linearly interpolate the vertex normals Compute lighting equations at each pixelCompute lighting equations at each pixel Can use specular componentCan use specular component Linearly interpolate the vertex normals Compute lighting equations at each pixelCompute lighting equations at each pixel Can use specular componentCan use specular component N1N1 N2N2 N3N3 N4N4 Remember: Normals used in diffuse and specular terms Discontinuity in normal’s rate of change is harder to detect

Shortcomings of Shading Polygonal silhouettes remain Gouraud Phong

Perspective Distortion         Z – into the scene Image plane Notice that linear interpolation in screen space does not align with linear interpolation in world space Break up large polygons with many smaller ones Nonlinear color shift from blue (left) to red (right) Linear interpolation in image space is not accurate sampling of 3D space Polygon

Perspective Distortion Notice that linear interpolation in screen space does not align with linear interpolation in world space Z – into the scene Image plane Break up large polygons with many smaller ones

Interpolation dependent on polygon orientation  A D C B Interpolate between AB and AD  B A D C Interpolate between CD and AD Rotate -90 o and color same point

Problems at Shared Vertices B A C Vertex B is shared by the two rectangles on the right, but not by the one on the left E D F H G The first portion of the scanline is interpolated between DE and AC The second portion of the scanline is interpolated between BC and GH A large discontinuity could arise

Bad Vertex Averaging

Shading Models (Direct lighting) Flat Shading Compute Phong lighting once for entire polygonCompute Phong lighting once for entire polygon Gouraud Shading Compute Phong lighting at the vertices and interpolate lighting values across polygonCompute Phong lighting at the vertices and interpolate lighting values across polygon Phong Shading Interpolate normals across polygon and perform Phong lighting across polygonInterpolate normals across polygon and perform Phong lighting across polygon Flat Shading Compute Phong lighting once for entire polygonCompute Phong lighting once for entire polygon Gouraud Shading Compute Phong lighting at the vertices and interpolate lighting values across polygonCompute Phong lighting at the vertices and interpolate lighting values across polygon Phong Shading Interpolate normals across polygon and perform Phong lighting across polygonInterpolate normals across polygon and perform Phong lighting across polygon