+ All Categories
Home > Documents > Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse...

Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse...

Date post: 25-Mar-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
77
CSC 706 Computer Graphics CSC 706 Computer Graphics Light Light
Transcript
Page 1: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

CSC 706 Computer GraphicsCSC 706 Computer Graphics

LightLight

Page 2: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Definitions

Illumination: the transport of energy from light sources to surfaces & points– Note: includes direct and indirect illuminationLighting: the process of computing the luminous intensity (i.e., outgoing light) at a particular 3-D point, usually on a surfaceShading: the process of assigning colors to pixels

Page 3: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Components of Illumination

Two components of illumination: light sources and surface propertiesLight sources (or emitters)– Spectrum of emittance (i.e., color of the light)– Geometric attributes

PositionDirectionShape

– Directional attenuation

Page 4: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Components of Illumination

Surface properties– Reflectance spectrum (i.e., color of the surface)– Geometric attributes

PositionOrientationMicro-structure

Common simplifications in interactive graphics– Only direct illumination from emitters to surfaces– Simplify geometry of emitters to trivial cases

Page 5: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

LightingThree vectors are needed to compute theintensity of reflected light

– m: normal vector at a surface point

– v: vector from a surface point to the viewer

– s: vector from a surface point to the light

Page 6: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

LightingTwo types of lights in scenes– point light sources

– ambient light• Light is

– absorbed, reflected, transmitted

• Reflected light– diffuse

– specular

Page 7: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Ambient Light Sources

Objects not directly lit are typically still visible– E.g., the ceiling in this room, undersides of desks

This is the result of indirect illumination from emitters, bouncing off intermediate surfacesToo expensive to calculate (in real time), so we use a hack called an ambient light source– No spatial or directional characteristics;

illuminates all surfaces equally– Amount reflected depends on surface properties

Page 8: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Ambient LightUniform background glow– the amount of ambient light reflected depends on

the material of the surface

tcoefficien reflectionambient theis where, aaaII ρρ=

0.7 0.5, ,3.0 ,0.1 ,0=aρ

Page 9: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Ambient Light Sources

For each sampled wavelength, the ambient light reflected from a surface depends on– The surface properties, kambient

– The intensity of the ambient light source (constant for all points on all surfaces )

Ireflected = kambient Iambient

Page 10: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Ambient Light Sources

A scene lit only with an ambient light source:

Page 11: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Directional Light Sources

For a directional light source we make the simplifying assumption that all rays of light from the source are parallel– As if the source were infinitely far away

from the surfaces in the scene– A good approximation to sunlight

The direction from a surface to the light source is important in lighting the surfaceWith a directional light source, this direction is constant for all surfaces in the scene

Page 12: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Directional Light Sources

The same scene lit with a directional and an ambient light source

Page 13: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Point Light Sources

A point light source emits light equally in all directions from a single point The direction to the light from a point on a surface thus differs for different points:– So we need to calculate a

normalized vector to the light source for every point we light:

p

l

Page 14: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Point Light Sources

Using an ambient and a point light source:

Page 15: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Other Light Sources

Spotlights are point sources whose intensity falls off directionally. – Requires color, point

direction, falloffparameters

– Supported by OpenGL

Page 16: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Other Light Sources

Area light sources define a 2-D emissive surface (usually a disc or polygon)– Good example: fluorescent light panels

– Capable of generating soft shadows (why? )

Page 17: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Ideal diffuse reflection– An ideal diffuse reflector, at the microscopic level,

is a very rough surface (real-world example: chalk) – Because of these microscopic variations, an

incoming ray of light is equally likely to be reflected in any direction over the hemisphere:

– What does the reflected intensity depend on?

The Physics of Reflection

Page 18: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Diffuse reflectionReflected intensity does not depend on thedirection of the viewer– no contribution from the surface point to viewer

vectorIncoming light does depend on the directionof the light– proportional to the area subtended by the facet

Lamberts Law: intensity relationship betweenlight source and surface orientation

Page 19: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Diffuse reflectionLight to surface point vector parallel ornearly parallel to surface normal– little variation in reflected intensity

As light to surface point vector vector isperpendicular or nearly perpendicular to thesurface normal– small amount of reflection

Model with the cosine– dot product between s and m

Page 20: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Lambert’s Cosine Law

Ideal diffuse surfaces reflect according to Lambert’s cosine law:

The energy reflected by a small portion of a surface from a light source in a given direction is proportional to the cosine of the angle between that direction and the surface normal

These are often called Lambertian surfacesNote that the reflected intensity is independent of the viewing direction, but does depend on the surface orientation with regard to the light source

Page 21: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Lambert’s Law

Page 22: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Computing Diffuse Reflection

The angle between the surface normal and the incoming light is the angle of incidence:

Idiffuse = kd Ilight cos θIn practice we use vector arithmetic:

Idiffuse = kd Ilight (n • l)

nl

θ

Page 23: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Diffuse Lighting Examples

We need only consider angles from 0° to 90° (Why?)A Lambertian sphere seen at several different lighting angles:

Page 24: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Diffuse reflectionLambert’s model– diffuse reflection

constant reflective diffuse theis where

0 ,MAX

d

dsd msmsII

ρ

ρ

⋅=

1 ,8.0 ,6.0 ,4.0 ,2.0 ,0=dρ

Page 25: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Specular Reflection

Shiny surfaces exhibit specular reflection– Polished metal– Glossy car finish

A light shining on a specular surface causes a bright spot known as a specular highlightWhere these highlights appear is a function of the viewer’s position, so specular reflectance is view-dependent

Page 26: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

The Optics of Reflection

Reflection follows Snell’s Laws:– The incoming ray and reflected ray lie in a plane

with the surface normal– The angle that the reflected ray forms with the

surface normal equals the angle formed by the incoming ray and the surface normal:

θ(l)ight = θ(r)eflection

Page 27: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Non-Ideal Specular ReflectanceSnell’s law applies to perfect mirror-like surfaces, but aside from mirrors (and chrome) few surfaces exhibit perfect specularityIn general, we expect most reflected light to travel in direction predicted by Snell’s LawBut because of microscopic surface variations, some light may be reflected in a direction slightly off the ideal reflected rayAs the angle from the ideal reflected ray increases, we expect less light to be reflected

Page 28: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Non-Ideal Specular Reflectance: An Empirical Approximation

An illustration of this angular falloff:

How might we model this falloff?

Page 29: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Phong Lighting

The most common lighting model in computer graphics was suggested by Phong:

( ) shinynlightsspecular IkI φcos=

The nshiny term is a purelyempirical constant that varies the rate of falloffThough this model has no physical basis, it works (sort of) in practice

v

Page 30: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Specular reflectionLighting highlights for shiny surfaces– Phong model

• simple, reasonable results, OpenGL support• Amount of reflected light is greatest when the

reflection angle equals the incident angle• reflected light falls off and reflection differes

Page 31: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Specular reflection– r depends on s and m

– specular light falls off as the angle between r andv increases

– Phong models this drop-off as a cosine of theangle raised to a power (1 - 200)

constant reflectivespecular theis where

0 ,MAX

s

sssp vrvrII

ρ

ρ

⋅=

( ) mm

mssr 22 - ⋅+=

Page 32: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Phong Lighting: The nshiny Term

This diagram shows how the Phong reflectance term drops off with divergence of the viewing angle from the ideal reflected ray:

What does this term control, visually?

Page 33: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Calculating Phong Lighting

The cos term of Phong lighting can be computed using vector arithmetic:

– V is the unit vector towards the viewer– R is the ideal reflectance direction

An aside: we can efficiently calculate R

( ) shinynlightsspecular RVIkI ˆˆ ⋅=

( )( ) LNLNR ˆˆˆˆ2ˆ −⋅=

Page 34: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Calculating The R Vector

This is illustrated below:

( )( ) LNLNR ˆˆˆˆ2ˆ −⋅=

( )( )NLNLR ˆˆˆ2ˆˆ ⋅=+

Page 35: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Phong Examples

These spheres illustrate the Phong model as L and nshiny are varied:

Page 36: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Specular reflection

200 25, 9, 6, 3, f0.75 ,5.0 ,25.0

==dρ

Page 37: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Total LightAdd diffuse, specular, and ambient terms tocompute the total amount of light that reachesthe eye from a point P

⋅+

⋅+=

mhmhI

msmsIII sspddaa ,0max,0max ρρρ

Page 38: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

ColorsOpenGL deals with colors individually– computes red, green, and blue components

separately)phong()lambert( sprsprdrdrararr IIII ρρρ ++=

)phong()lambert( spgspgdgdgagagg IIII ρρρ ++=

)phong()lambert( spbspbdbdbababb IIII ρρρ ++=

⋅=

msms,0max lambert

⋅=

mhmh,0max phong

Page 39: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection
Page 40: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

40

Page 41: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

41

OpenGL Lighting

• Making a light source– maximum of 8 light sources

• GL_LIGHT0, GL_LIGHT1, … GL_LIGHT7– properties

• position• ambient, diffuse, and specular components• distance attenuation• local or remote viewpoint• front and back face lighting• global ambient light

Page 42: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

42

OpenGL Lighting

– Position• directional or positional• maintained in my LightInfo struct

• initialized with a single white light

// Lightingstatic int numActiveLights;typedef struct _LightInfo { GLfloat xyz[4]; GLfloat *rgb; int enable;} LightInfo;

// Light informationLightInfo linfo[] = {

{{ 0.0f, 0.0f, 2.0f, 0.0f}, white},};const int MAX_LIGHTS = (sizeof(linfo) / sizeof(linfo[0]));

Page 43: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

43

OpenGL Lighting

– Initialize OpenGL with LightInfo

– Tell OpenGL to perform lighting calculations

• for light num

– Bind material properties

glLightfv(G L_LIGHT0 + num, G L_SPECU LAR, dim); glLightfv(G L_LIGHT0 + num, G L_PO SITION, linfo[num].xyz); glLightfv(G L_LIGHT0 + num, G L_D IFFUSE, linfo[num].rgb);

glEnable(GL_LIGHT0 + num);

glEnable(GL_LIGHTING);

glM aterialfv(G L_F R O N T , G L_A M B IE N T , m atA m b); glM aterialfv(G L_F R O N T , G L_D IFFU SE , m atD iff); glM aterialfv(G L_F R O N T , G L_SP E C U L A R , m atSpec); glM aterialfv(G L_F R O N T , G L_E M ISSIO N , m atE m ission); glM aterialf(G L_F R O N T , G L_SH IN IN E S S, 100 .0);

Page 44: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

44

OpenGL Lighting

• Front and back face rendering, default

• front face rendering only glCullFace(GL_BACK); glEnable(GL_CULL_FACE);

Page 45: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

45

OpenGL Lighting

– movable, directional, light• change position after setting viewpoint

– global ambient light

// Global ambient lightGLfloat modelAmb[4] = {0.7, 0.1, 0.1, 1.0};glLightModelfv(GL_LIGHT_MODEL_AMBIENT, modelAmb);

// C h an ge ligh t an gle , rese t ligh t p o sitio nif (sp in n in g_ ligh t) { ligh t_an g le = (ligh t_an gle + 1 ) % 360 ; lin fo [0].x yz [1 ] = ligh t_d is t * s in (D E G 2 R A D (ligh t_ an gle)); lin fo [0].x yz [2 ] = ligh t_d is t * co s(D E G 2 R A D (ligh t_ an gle)); g lL igh tfv (G L _ L IG H T 0 , G L _P O S IT IO N , lin fo [0 ].x yz);}

Page 46: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

46

OpenGL Lighting

• Backface lighting– assign material properties to backfaces

– bind material properties

– enable two sided lighting

// B ackface m aterial properties for all shapesG L float m atA m bB ack[4] = {0 .0 , 0 .0, 0 .2 , 1 .0};G L float m atD iffB ack[4] = {0.0 , 0 .0 , 0 .8 , 1 .0};G L float m atSpecB ack[4] = {0 .0 , 0.0 , 0 .4 , 1 .0};G L float m atE m issionB ack[4] = {0 .0 , 0 .0 , 0 .2 , 1 .0};

// bind backface material propertiesglMaterialfv(GL_BACK, GL_AMBIENT, matAmbBack);glMaterialfv(GL_BACK, GL_DIFFUSE, matDiffBack);glMaterialfv(GL_BACK, GL_SPECULAR, matSpecBack);glMaterialfv(GL_BACK, GL_EMISSION, matEmissionBack);glMaterialf(GL_BACK, GL_SHININESS, 1000.0);

glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);

Page 47: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

47

Page 48: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

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?

Page 49: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Is flat shading realistic for faceted object?

No:– For point sources, the direction to light varies

across the facet

– For specular reflectance, direction to eye varies across the facet

Page 50: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

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:To get smoother-looking surfaceswe introduce vertex normals at eachvertex– Usually different from facet normal– Used only for shading– Think of as a better approximation of the real

surface that the polygons approximate

Page 51: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Vertex Normals

Vertex normals may be – Provided with the model– Computed from first principles – Approximated by averaging the normals of the

facets that share the vertex

Page 52: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

52

Flat Shading

Page 53: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Gouraud Shading

This is the most common approach– Perform Phong lighting at the vertices– Linearly interpolate the resulting colors over faces

Along edgesAlong scanlines C1

C2

C3

c1 + t1(c2-c1)

c1 + t2(c3-c1)c1 + t1(c2-c1) + t3(c1 + t2(c3-c1)- c1 + t1(c2-c1))

– This is what OpenGL doesDoes this eliminate the facets?

Page 54: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

54

Gouraud ShadingGouraud Shading• Gouraud shading

attempts to smooth out the shading across the polygon facets

• Begin by calculating the normal at each vertex

N

Page 55: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

55

Gouraud ShadingGouraud Shading• A feasible way to do this

is by averagingaveraging the normals from surrounding facets

• Then apply the reflection model to calculate intensitiesintensities at each vertex

N

Page 56: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

56

Gouraud ShadingGouraud Shading• We use linear linear

interpolation interpolation to calculate intensity at edge intersection P

IPRED = (1-α)IP1

RED + αIP2

RED

where P divides P1P2 in the ratio α : 1−α

• Similarly for Q

P4

P2

P1

P3

P Q

Page 57: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

57

Gouraud ShadingGouraud Shading• Then we do further

linear interpolation to calculate colour of pixels on scanlinePQ

P2

P1

P3

P Q

Page 58: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

58

Gouraud Shading

Page 59: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

59

Gouraud Shading Limitations -Specular Highlights

Gouraud Shading Limitations -Specular Highlights

• Gouraud shading gives intensities within a polygon which are a weighted average of the intensities at vertices– a specular highlight at a vertex tends to be

smoothed out over a larger area than it should cover

– a specular highlight in the middle of a polygon will never be shown

Page 60: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Gouraud ShadingArtifacts– Often appears dull, chalky– Lacks accurate specular component

If included, will be averaged over entire polygon

C1

C2

C3

Can’t shade that effect!

Page 61: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

61

Phong ShadingPhong Shading• Phong shading has a

similar first step, in that vertex normals are calculated - typically as average of normals of surrounding faces

N

Page 62: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

62

Phong ShadingPhong Shading• However rather than

calculate intensity at vertices and then interpolate intensities as we do in Gouraudshading ...

• In Phong shading we interpolate normals at each pixel ...

P4

P2

P1

P3

P Q

N2

N1

N

Page 63: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

63

Phong ShadingPhong Shading• ... and apply the

reflection model at each pixel to calculate the intensity - IRED, IGREEN, IBLUE

P4

P2

P1

P3

P Q

N2

N1

N

Page 64: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

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 surface

– Phong shading: linearly interpolating the surface normal across the facet, applying the Phong lighting model at every pixel

Same input as Gouraud shadingUsually very smooth-looking results:But, considerably more expensive

Page 65: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Phong Shading

Linearly interpolate the vertex normals– Compute lighting equations at each pixel– Can use specular component

N1

N2

N3

N4

( ) ( )∑=

⋅+⋅+=

lights

i

n

sdiambientatotalshinyRVkLNkIIkI

#

1

ˆˆˆˆ

Remember: Normals used in diffuse and specular terms

Discontinuity in normal’s rate of change is harder to detect

Page 66: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

66

Phong Shading

Page 67: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

67

Phong versus Gouraud ShadingPhong versus Gouraud Shading• A major advantage of Phong shading over

Gouraud is that specular highlights tend to be much more accurate– vertex highlight is much sharper– a highlight can occur within a polygon

• Also Mach banding greatly reduced• The cost is a substantial increase in

processing time because reflection model applied per pixel

• But there are limitations to both Gouraudand Phong

Page 68: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

Shortcomings of Shading

Polygonal silhouettes remain

Gouraud Phong

Page 69: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

69

Gouraud versus Phong

Page 70: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

70

Wall Lights

Page 71: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

71

Wall Lights with Fewer Polygons

Page 72: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

72

Simple Shading -Without Taking Account of Normals

Page 73: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

73

Constant or Flat Shading -Each Polygon has Constant

Shade

Page 74: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

74

Gouraud Shading

Page 75: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

75

Phong Shading

Page 76: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

76

Phong Shading with Curved Surfaces

Page 77: Light - City University of New York– Capable of generating soft shadows (why?) zIdeal diffuse reflection – An ideal diffuse reflector, ... The Physics of Reflection. Diffuse reflection

77

Better Illumination Model


Recommended