Ligh%ng and Shading. Ligh%ng and Shading. q Is this a plate or a ball? q What color should I set for each pixel?

Similar documents
CEng 477 Introduction to Computer Graphics Fall

Overview. Shading. Shading. Why we need shading. Shading Light-material interactions Phong model Shading polygons Shading in OpenGL

Why we need shading?

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

CS Surface Rendering

Ligh%ng in OpenGL. The Phong Illumina%on Model. Vector Background

Illumination Model. The governing principles for computing the. Apply the lighting model at a set of points across the entire surface.

Illumination and Shading

Ambient reflection. Jacobs University Visualization and Computer Graphics Lab : Graphics and Visualization 407

Computer Graphics. Illumination and Shading

Shading and Illumination

Reading. Shading. An abundance of photons. Introduction. Required: Angel , 6.5, Optional: Angel 6.4 OpenGL red book, chapter 5.

INF3320 Computer Graphics and Discrete Geometry

Reading. Shading. Introduction. An abundance of photons. Required: Angel , Optional: OpenGL red book, chapter 5.

Lighting. CSC 7443: Scientific Information Visualization

Illumination and Shading ECE 567

CS5620 Intro to Computer Graphics

CS 4731: Computer Graphics Lecture 16: Phong Illumination and Shading. Emmanuel Agu

Illumination and Shading

CS Computer Graphics: Illumination and Shading I

CS Computer Graphics: Illumination and Shading I

Virtual Reality for Human Computer Interaction

Display Issues Week 5

Illumination Models & Shading

Today s class. Simple shadows Shading Lighting in OpenGL. Informationsteknologi. Wednesday, November 21, 2007 Computer Graphics - Class 10 1

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Computer Graphics. Shading. Based on slides by Dianna Xu, Bryn Mawr College

Lecture 4 Advanced Computer Graphics (CS & SE )

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

Comp 410/510 Computer Graphics. Spring Shading

Shading , Fall 2004 Nancy Pollard Mark Tomczak

Light Sources. Spotlight model

Illumination & Shading: Part 1

Shading I Computer Graphics I, Fall 2008

Light Transport Baoquan Chen 2017

Objectives Shading in OpenGL. Front and Back Faces. OpenGL shading. Introduce the OpenGL shading methods. Discuss polygonal shading

Shading. Brian Curless CSE 457 Spring 2015

Shading. CSE 457 Winter 2015

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

5.2 Shading in OpenGL

Methodology for Lecture. Importance of Lighting. Outline. Shading Models. Brief primer on Color. Foundations of Computer Graphics (Spring 2010)

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Illumination & Shading

Virtual Reality for Human Computer Interaction

Graphics and Visualization

Illumination in Computer Graphics

Illumination and Shading

Shading in OpenGL. Outline. Defining and Maintaining Normals. Normalization. Enabling Lighting and Lights. Outline

Illumination & Shading I

w Foley, Section16.1 Reading

CPSC 314 LIGHTING AND SHADING

Reflection and Shading

Shading. Why we need shading. Scattering. Shading. Objectives

CS Illumination and Shading. Slide 1

Sung-Eui Yoon ( 윤성의 )

Visualisatie BMT. Rendering. Arjan Kok

CS 148, Summer 2012 Introduction to Computer Graphics and Imaging

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

CSE 167: Lecture #8: Lighting. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Computer Graphics Lighting

Computer Graphics Lighting. Why Do We Care About Lighting?

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

Color and Light CSCI 4229/5229 Computer Graphics Fall 2016

Computer Graphics (CS 543) Lecture 8a: Per-Vertex lighting, Shading and Per-Fragment lighting

CS 4600 Fall Utah School of Computing

Shading Intro. Shading & Lighting. Light and Matter. Light and Matter

Local Illumination. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

Rendering. Illumination Model. Wireframe rendering simple, ambiguous Color filling flat without any 3D information

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

Computer Graphics. Illumination Models and Surface-Rendering Methods. Somsak Walairacht, Computer Engineering, KMITL

Lessons Learned from HW4. Shading. Objectives. Why we need shading. Shading. Scattering

Color and Light. CSCI 4229/5229 Computer Graphics Summer 2008

CS 325 Computer Graphics

Computer Graphics (CS 4731) Lecture 16: Lighting, Shading and Materials (Part 1)

CS452/552; EE465/505. Lighting & Shading

Projections and Hardware Rendering. Brian Curless CSE 557 Fall 2014

Chapter 10. Surface-Rendering Methods. Somsak Walairacht, Computer Engineering, KMITL

Lighting/Shading III. Week 7, Wed Mar 3

WHY WE NEED SHADING. Suppose we build a model of a sphere using many polygons and color it with glcolor. We get something like.

Today we will start to look at illumination models in computer graphics

Lights, Colour and Materials In OpenGL

Computer Graphics (CS 543) Lecture 7b: Intro to lighting, Shading and Materials + Phong Lighting Model

CS130 : Computer Graphics Lecture 8: Lighting and Shading. Tamar Shinar Computer Science & Engineering UC Riverside

LIGHTING AND SHADING

Topic 9: Lighting & Reflection models 9/10/2016. Spot the differences. Terminology. Two Components of Illumination. Ambient Light Source

Illumination and Shading

Introduction to Computer Graphics 7. Shading

University of British Columbia CPSC 314 Computer Graphics Sep-Dec Tamara Munzner (guest lecturing) Lighting/Shading

Introduction to Computer Graphics. Farhana Bandukwala, PhD Lecture 14: Light Interacting with Surfaces

OpenGl Pipeline. triangles, lines, points, images. Per-vertex ops. Primitive assembly. Texturing. Rasterization. Per-fragment ops.

Lighting and Shading II. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

CS452/552; EE465/505. Intro to Lighting

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

Lighting. Figure 10.1

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Topic 9: Lighting & Reflection models. Lighting & reflection The Phong reflection model diffuse component ambient component specular component

CSCI 4620/8626. Computer Graphics Illumination Models and Surface Rendering Methods (Chapter 17)

9. Illumination and Shading

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

Shading. Brian Curless CSE 557 Autumn 2017

Transcription:

Ligh%ng and Shading Ligh%ng and Shading Is this a plate or a ball? What color should I set for each pixel? 1

Physical Reality As light hits the surface: Part is absorbed Part is reflected Visible light includes all colors of the rainbow Physical Reality Physically, objects can be said to have the color of the light leaving their surfaces: White Light Colours Absorbed Green Light If a blue object is illuminated with red light, it will appear as. 2

Our Objec%ve: Understand and model what light does in a scene. A Model for Ligh%ng Follow rays from light source Only light that reaches the eye is ever seen direct light is seen as the color of the light source indirect light depends on interac%on between material and light 3

Ligh%ng in Computer Graphics For Computer graphics we replace viewer with projec%on plane Rays which reach COP amer passing through viewing plane are actually seen Color of pixels is determined by our interac%on model Light- Material Interac%ons Determine whether an object appears red or brown, light or dark, dull or shiny Reflec%on of light from a surface can be: Specular Diffuse Translucent 4

Specular Surfaces Smooth, shiny, glossy Mirror- like Reflec%on focused to one direc%on (angle of incidence = angle of reflec%on) Diffuse Surfaces Rough (grainy, maue) Light reflected almost uniformly in all direc%ons 5

Translucent Surfaces Allow some light to pass through Glass or water- like Light- Material Interac%on Summary Surfaces may be Specular Diffuse Translucent A surface is never perfectly diffuse or perfectly translucent or perfectly specular. May have all these proper%es! To model these proper%es, we must understand how light reflects off each of these surface types. 6

Basic Illumina%on Model Basic Illumina%on Model We will consider a basic illumina%on model which gives reasonably good results and is used in most graphics systems The important components are: Diffuse reflec%on Specular reflec%on Ambient light 7

Example The total reflected light from a surface is the sum of the contribu%ons from light sources and reflected light Ambient Light Walk around the back of box. No light beams hit it directly. Can you see the back face? This type of indirect light is called ambient light. 8

Ambient Light Like sunlight on a totally clouded day! Uniform level of light, posi%on- independent Tells us how bright an object looks when no light source can directly reach it Ambient Light Also called background light Not created by any light source A constant ligh%ng from all direc%ons Contributed by scauered light in a surrounding When used alone, does not produce very interes%ng pictures Ambient light only 9

Ambient Light To incorporate background light we simply set a general brightness level I a for a scene Different surfaces may reflect different amount of ambient light, based on their reflectance proper%es. We model this by a constant factor for each surface: k a I a RGB Color Considera%ons For an RGB colour descrip%on each intensity specifica%on is a three element vector a ( I, I I ) I =, ar Similarly, the reflectance is given as a vector: a ag Red, green and blue ambient light intensi%es are ab ( k, k k ) k =, ar ag ab ( k I, k I, k I ) ar ar ag ag ab ab 10

Illumina%on: Ambient Light Material Color Ambient Light Color Hands- on Session Run the lightmaterial tutor, and right- click select Material Parameters Make the light source ambient- only (set all other material reflec%vity coefficients to 0). Try different color combina%ons of ambient light and material, and see how the scene reacts to these changes. 11

Diffuse Reflec%on Light scauered with equal intensity in all direc%ons (ideal diffuse reflec%on) Light from a point is independent on viewing direc%on (equally bright in all direc%ons) Intermezzo: Surface Normals N N where p0 is the center of the sphere 12

Diffuse Reflec%on The angle between the incoming light direc%on and a surface normal is referred to as the angle of incidence, denoted θ. L = unit vector to light source N = unit vector normal to surface Modeling Diffuse Reflec%on The amount of incident light depends on the orienta%on of the surface rela%ve to the light source direc%on. 13

Diffuse Reflec%on The amount of incident light on a surface depends on the angle of incidence: d L N N θ L? As θ increases, the brightness of the surface decreases by Recall: Dot Product N N L = N L cos θ L θ If N and L are unit vectors, then N L = cos θ 14

Diffuse Reflec%on If surface has brightness Ι when facing light, it has brightness Ι*cos(θ) when %lted at angle θ. N L θ N L = cos θ (N, L are unit vectors) You will see the brightness wriuen as I(N L) Diffuse Reflec%on A parameter k d set for each surface determines the frac%on of incident light scauered as diffuse reflec%ons from that surface This parameter is known as the diffuse reflec%on coefficient or the diffuse reflec%vity k d is assigned a value between 0.0 and 1.0 0.0 for dull surface that absorbs almost all light 1.0 for shiny surface that reflects almost all light 15

Diffuse Reflec%on Diffuse reflec%ons: I d k = d I( N L) 0 if if N L > 0 N L 0 Diffuse Reflec%on Spheres lit by diffuse (k d ) values of 0.0, 0.25, 0.5, 0.75, 1 respec%vely 16

Ambient Light vs. Diffuse Light Ambient ligh%ng only Diffuse ligh%ng only Hands- on Session Run the lightmaterial tutor Make the light source diffuse- only Check the color of a blue object illuminated with red light Try different color combina%ons of diffuse light and material Change the light posi%on and observe the changes in the brightest spots on the torus Combine diffuse and ambient light 17

Diffuse Ligh%ng: What s Missing? Material Color Ambient Only Diffuse Only Ambient + Diffuse Ambient + diffuse reflec%ons produce shaded images that appear three- dimensional But the surfaces look dull, somewhat like chalk What is missing? Specular Reflec%on Intensity depends on where the viewer is! White specular highlight The white specular highlight is the reflec%on of white light from the source in the direc%on of the viewer 18

Specular Reflec%on The bright spot that we see on a shiny surface is the result of incident light reflected in a concentrated region around the specular reflec%on angle The specular reflec%on angle equals the angle of the incident light L = vector to light source N = vector normal to surface R = direc%on of reflected light V = vector to viewer Specular Reflec%on A perfect mirror reflects light only in the specular- reflec%on direc%on Other objects exhibit specular reflec%ons over a finite range of viewing posi%ons around vector R 19

The Phong Specular Reflec%on Model The Phong model sets the intensity of specular reflec%on as propor%onal to the angle φ between the viewing vector and the specular reflec%on vector: I s = I ks α cos φ α = shineness exponent k s = specular reflec%vity of material The Phong Specular Model I s = I ks α cos φ α = shininess k s = reflec%vity The shineness α is determined by the type of surface we want to display Shiny surfaces have a very large value (>100) Rough surfaces would have a value near 1 The larger the α, the more concentrated the light is around R. For mirrors, α à infinity. 20

I s = I ks The Phong Specular Model α cos α = shininess k s = reflec%vity φ Recall that R V = cos φ I s ksi = ( V R) α if V R > 0 and N L > 0 0.0 if V R < 0 or N L 0 Illumina%on: Specular Ligh%ng Material Color Specular Light Color Specular Ambient + Diffuse Ambient + Diffuse + Specular Create shining surface (surface perfectly reflects) Viewpoint dependent 21

Specular Reflec%on Example specular ( k s ) values of 0, 0.25, 0.5, 0.75, 1 constant shineness shininess ( α ) values of 5, 25, 75, 125, 225 constant k s Add a Diffuse Red Component 22

Phong Reflec%on Model Summary Due to the ambient light, nothing can be en%rely black Mirror reflec%ons are possible Can be computed very fast (used in VR and games) Very good approxima%on of diffuse surfaces Physically inaccurate Expressed in terms of vector geometry PuSng it All Together The intensity of light from one point is a sum of the diffuse, specular and ambient components: + + Dark Red ambient Bluish diffuse Specular Highlight I = I + I + I a d s 23

PuSng it All Together 0.2 0.4 0.6 0.8 0.2 0.4 0.6 0.8 1.0 1.0 diffuse specular = 0 shininess = 0 specular diffuse = 0.5 shininess = 120 10 30 60 160 250 shininess diffuse = 0.5 specular = 0.5 OpenGL Ligh%ng Func%ons 24

OpenGL Ligh%ng Func%ons OpenGL provides func%ons for sejng up point light sources and spotlights, selec%ng surface reflec%on coefficients choosing values for several parameters in the basic illumina%on model Implements the Phong reflec%on model Steps in OpenGL Ligh%ng 1. Enable ligh%ng and select shading model 2. Specify normals 3. Specify material proper%es 4. Specify lights 25

Enable Ligh%ng Calcula%ons Ligh%ng calcula%ons are enabled globally in an OpenGL program using glenable (GL_LIGHTING); Once ligh%ng is enabled, glcolor*() ignored Enable Individual Light Sources Up to eight light sources (GL_MAX_LIGHTS) can be included in a standard OpenGL implementa%on Some implementa%ons may allow more than 8 Each light source is referenced by its iden%fier: GL_LIGHT0, GL_LIGHT1,..., GL_LIGHT7 A light source is enabled with: glenable (lightname); Example: glenable (GL_LIGHT0); 26

gllightmodel(gl_light_model_two_sided, ) Either shade only the outside of polygons, or both sides How does OpenGL know what is the outside? 2. Specify Normals In OpenGL the normal vector is part of the state Set by glnormal*() glnormal3f(x, y, z); glnormal3fv(p); Usually we want to set the normal to have unit length so cosine calcula%ons are correct Length can be affected by transforma%ons Note that scaling does not preserve length glenable(gl_normalize) allows for autonormaliza%on at a performance penalty 27

Intermezzo: Normal for a Triangle n = (p 2 p 1 ) (p 1 - p 0 ) n normalize n n/ n p p 2 p 1 p 0 Note that right- hand rule determines outward face. Intermezzo: Vector Cross Product Use the right-hand rule to determine a x b. 28

Intermezzo: Unit Vectors i, j, k Intermezzo: Vector Cross Product 29

Normal for a Sphere Associate a normal with each vertex: glbegin( ) glnormal3f(x,y,z) glvertex3f(x,y,z) glend() 3. Specify Material Proper%es Reflec%vity coefficients: GLfloat mat_ambient[] = {0.2, 0.2, 0.2, 1.0}; GLfloat mat_diffuse[] = {1.0, 0.8, 0.0, 1.0}; GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat mat_shine = 100.0; Material proper%es: glmaterialfv(gl_front, GL_AMBIENT, mat_ambient); glmaterialfv(gl_front, GL_DIFFUSE, mat_diffuse); glmaterialfv(gl_front, GL_SPECULAR, mat_specular); glmaterialfv(gl_front, GL_SHININESS, mat_shine); The default is to light only front faces 30

Transparency Material proper%es are specified as RGBA values The A value can be used to make the surface translucent The default is that all surfaces are opaque regardless of A 4. Specify Light Sources Proper%es of a light source such as posi%on, type, color, auenua%on, and spotlight effects can be specified using gllight* (lightname, lightproperty, propertyvalue); Each light source is referenced by its iden%fier: GL_LIGHT0, GL_LIGHT1,..., GL_LIGHT7 31

Light Proper%es gllight* (lightname, lightproperty, propertyvalue); lightproperty can be one of: GL_POSITION GL_AMBIENT GL_DIFFUSE GL_SPECULAR GL_CONSTANT_ATTENUATION GL_LINEAR_ATTENUATION GL_QUADRATIC_ATTENUATION GL_SPOT_DIRECTION GL_SPOT_CUTOFF GL_SPOT_EXPONENT Example Sejng the posi%on of a point light source: Glfloat light0_pos[]={1.0, 2.0, 3,0, 1.0}; glenable(gl_lighting); glenable(gl_light0); gllightv(gl_light0, GL_POSITION, light0_pos); 32

Light Types Two types of lights Local (point) light sources that are near the objects Light sources at infinity The type of a light source is independent of the 3d posi%on we assign to a light source. It is determined by a fourth parameter value: 1.0 indicates local light source 0.0 indicates light source at infinity Local Light Source For a local light source, the emiued light radiates in all direc%ons and the posi%on of the light is used in the ligh%ng calcula%ons i.e., the light direc%on changes for every object In OpenGL, it is referred to as Posi%onal Light Point (Positional) Light (Emit in all directions) 33

Infinite Light Source For a light source at infinity, the emiued light radiates in one direc%on only and this direc%on is applied to all objects in the scene I.e., the light direc%on is constant for every object In OpenGL, it is referred to as Direc%onal Light Directional Light (Infinitely far away) Hands- on Session Run the lightposi-on tutor, play with light parameters (Point) Posi%onal light Direc%onal light 34

Light Source Colors You can specify three different color proper%es to a light source This is unrealis%cally flexible compared to real- world lights which have one color We can specify the ambient, diffuse, and specular components of a light source with different colors. Example Sejng the RGBA values for the ambient, diffuse and specular components of a point light source. GLfloat diffuse0[]={1.0, 0.0, 0.0, 1.0}; GLfloat ambient0[]={1.0, 0.0, 0.0, 1.0}; GLfloat specular0[]={1.0, 0.0, 0.0, 1.0}; Glfloat light0_pos[]={1.0, 2.0, 3,0, 1.0}; glenable(gl_lighting); glenable(gl_light0); gllightv(gl_light0, GL_POSITION, light0_pos); gllightv(gl_light0, GL_AMBIENT, ambient0); gllightv(gl_light0, GL_DIFFUSE, diffuse0); gllightv(gl_light0, GL_SPECULAR, specular0); 35

Example Black ambient White diffuse White specular Black ambient Red diffuse Blue specular OpenGL Light Defaults Light 0 is unique in having a default diffuse and specular sejng of fully bright white (1,1,1,1) saves us the hassle of sejng up lights All other lights have a default sejngs of totally dark (0,0,0,1). All lights also have a default posi%on of (0,0,1,0) this would effec%vely place it as a direc%onal light, facing forward, from just behind the camera 36

Spotlights a.k.a Direc%onal Light Sources Limit the light to a cone- shaped region of space Use gllightv to set Direc%on GL_SPOT_DIRECTION Cutoff (θ) GL_SPOT_CUTOFF AUenua%on(α) GL_SPOT_EXPONENT Propor%onal to cos α φ -θ φ θ Direc%onal Local Light Sources Example: GLfloat dirvector [] = {1.0, 0.0, 0.0}; gllighy (GL_LIGHT3, GL_SPOT_DIRECTION, dirvector); gllighy (GL_LIGHT3, GL_SPOT_CUTOFF, 30.0); gllighy (GL_LIGHT3, GL_SPOT_EXPONENT, 2.5); 37

Example Emissive Light Used to add a fixed color to surfaces. Do not add any actual light to the scene. GLfloat mat_emission[] = {0.0, 0.3, 0.3, 1.0}; glmaterialfv(gl_front, GL_EMISSION, mat_emission); 38

Emissive Light Example 3D sphere reflec%ng green emissive light. Effect similar to ambient light, un%l light sources are introduced. Apply a light source with red ambient light, red diffuse light, and white specular light. Same sphere, with no emissive light Global Ambient Light Ambient light depends on color of light sources A red light in a white room will cause a red ambient term that disappears when the light is turned off OpenGL also allows a global ambient term that is omen helpful for tes%ng: GLfloat global_ambient[] = {0.1, 0.1, 0.1, 1.0} gllightmodelfv(gl_light_model_ambient, global_ambient); 39

Light Aaenua%on in OpenGL AUenua%on: gllighy(gl_light0, GL_CONSTANT_ATTENUATION, a); gllighy(gl_light0, GL_LINEAR_ATTENUATION, b); gllighy(gl_light0, GL_QUADRATIC_ATTENUATION, c); Default OpenGL values: a = 1, b = 0, c = 0 (no auenua%on with distance) Applying Transforma%ons A light source is like an object in the scene and included in the scene descrip%on Geometric transforma%on matrices and viewing transforma%on matrices are applied to light posi%ons as applied to other objects If you want to fix your light posi%on rela%ve to the objects in your scene, you need to set the light posi%on amer you specify geometric and viewing transforma%ons If we want the light to move as the viewpoint moves, set its posi%on before glulookat(...) 40

Summary To successfully model ligh%ng effects, must consider: Ambient light Diffuse reflec%ons Specular reflec%ons Ambient component is independent of the surface orienta%on and viewer posi%on Diffuse component is independent of the viewer posi%on but depends on the rela%ve orienta%on of the light source and the surface In specular reflec%on the posi%on of the viewer is also important Polygonal Shading 41

Ligh%ng Revisited Light calcula%on so far is at ver%ces Vertex illumina%on from a light of intensity I = ambient + diffuse + specular α = ( k + k cosθ + k cos φ I a d s ) Pixel may not fall right on vertex Shading: calculates color of interior pixels Polygonal Shading Technique to render solid surfaces Determines how surfaces will be filled Process for compu%ng the color intensity value for each pixel contained in a polygon The most common shading techniques are: Flat Shading Gouraud Shading Phong Shading 42

Flat Shading Simplest, Cheapest, Fastest Shading Method Works well for objects really made of flat faces. Appearance depends on number of polygons for curved surface objects. Fills an en%re polygon with one color intensity This model is only valid (realis%c) if: The light source is imagined to be at infinity The viewer is at infinity The polygon is not an approximation to a curved surface Flat Shading in OpenGL Specify using glshademodel(gl_flat); The color at the first vertex will determine the shade of the whole polygon 43

Mach Band Effect Flat shading suffers from mach band effect human eyes accentuate the discon%nuity at the boundary Smooth Shading Fix the mach band effect remove edge discon%nuity Compute ligh%ng for more points on each face Two popular methods: Gouraud shading (used by OpenGL) Phong shading (beuer specular highlight, used in Blender, not in OpenGL) 44

Gourad Shading The default shading algorithm used in OpenGL: glshademodel(gl_smooth) Ligh%ng is calculated for each of the polygon ver%ces Colors are interpolated for interior pixels Flat Smooth Gourad Shading Per- vertex ligh%ng calcula%on Normal is needed for each vertex Per- vertex normal can be computed by averaging the adjacent face normals: n n = 1 + n2 3 + n4 + n 4 Requires knowledge about adjacent faces 45

Gourad Shading Use normals to compute vertex illumina%on (color) before the projec%on transforma%on Shade interior pixels: color interpola%on (normals not needed) Gouraud Shading Color Interpola%on Algorithm Interpolation along polygon edges Interpolation across polygon surfaces Given: Colors c 0,c 1, c 2,c 3 Coordinates of points colored c 0,c 1, c 2,c 3, c a, c b Determine the colors c a, c b using linear interpola%on. 46

Try It Out Given the coordinates: P0 = (0, 3) P1 = (1, 2) P2 = (0, 1) and normals n1, n2, and n3, we can use the Phong reflec%on model to obtain a color ci for each vertex. Let c0 = 60, c1 = 50, and c2 = 20. Find Ca and Cb for a scanline with coordinates Pa = (0, 1.8) Pb = (0.8, 1.8). Ca Cb Gourad Shading Problem Ligh%ng in the polygon interior can be inaccurate: 47

Phong Shading Instead of interpola%on, we calculate ligh%ng for each pixel inside the polygon (per pixel ligh%ng) Need normals for all the pixels not provided by user Phong shading algorithm interpolates the normals and compute ligh%ng for each pixel Phong Shading Interpola%on Over Normal Vector, NOT Vertex Color: Slower 48

Polygonal Shading Summary Gouraud shading Set vertex normals Calculate colors at ver%ces Interpolate colors across polygon Must calculate vertex normals! Must normalize vertex normals to unit length! Phong Shading Creates greater realism than Gouraud shading Computa5onally intense 49