Sei sulla pagina 1di 3

3/19/2012

Outline
Polygon shading algorithms:
Constant shading Gouraud shading Phong shading

Polygon Shading

Limitations of polygon shading:


Orientation dependency Jaggy silhouettes

Result comparison.

Monday, March 19, 2012

Minglun Gong

Polygon Shading Problem

Constant Shading
Also called faceted shading or flat shading. A single color is used for the entire polygon. Valid for:

Objective:
Calculate the color for all visible polygons under the given lighting condition

Question:
How to efficiently compute the color for different pixels covered by a given polygon
Monday, March 19, 2012 Minglun Gong 3

Directional light source: NL is constant. Parallel projection: V is constant.

N I

In other cases, it is a poor approximation.


Monday, March 19, 2012 Minglun Gong 4

Problem of Constant Shading


When multiple polygon patches are used to approximate smooth surfaces, the shading results are not smooth.
Due to the mach band visual effect, using smaller & more patches may not help.

Gouraud Shading
Also called intensity/color interpolation shading.
Proposed by Gouraud in 1971.
IA I1 IB ID I I2

Calculate color for each vertex of the polygon.


Interpolate the color for points inside the polygon.

IC

Monday, March 19, 2012

Minglun Gong

Monday, March 19, 2012

Minglun Gong

3/19/2012

Gouraud Shading Algorithm


for ( each vertex T in the polygon ) { Calculate NT; IT = illuminationModel(T, NT); } for ( each scan-line ) { Interpolate the color of the edges: I1 & I2; for ( each pixel p in current scan-line ) I = linearlyIterpolate(I1, I2); }

Problems of Gouraud Shading


In real world, the intensity does not change linearly across the polygon.
Especially for the specular reflection.

Artifacts:
Missing highlights. Irregular shaped highlights. Highlight appears around the edges.
7 Monday, March 19, 2012 Minglun Gong 8

Monday, March 19, 2012

Minglun Gong

Phong Shading
Also known as normalvector interpolation shading.
Proposed by Phong in 1975. Different from Phong illumination.
N1 NB NC NA

Phong Shading Algorithm


for ( each vertex T in the polygon ) Calculate NT; for ( each scan-line ) { Interpolate the normals of the edges: N1 & N2; for ( each pixel P in current scan-line ) { N = linearlyInterpolate(N1, N2); I = illuminationModel(P, N); } }

ND N2

Interpolate normals instead of colors.


Calculate color for every pixel using the interpolated normal.
Monday, March 19, 2012

Minglun Gong

Monday, March 19, 2012

Minglun Gong

10

Result of Phong Shading


Since the shading for all pixels are calculated using illumination model, the result is more photo realistic.
Highlights caused by varying normal can be generated.

Is Phong Shading Correct?


In real world, there exists no surface that has a linearly changing normal.
No surface will give the illumination distribution generated by the Phong shading.

In some cases, interpolating normal will eliminate surface details.


Minglun Gong 11 Monday, March 19, 2012 Minglun Gong 12

Monday, March 19, 2012

3/19/2012

Limitations of Polygon Shading


Using polygons to approximate smooth surfaces, such as spheres, has its limitations:
Orientation dependency. Jaggy silhouettes.

Orientation Dependency
When rotating camera, the color on the surface may change. Orientation 1:
I=((IA+IB)+(IC+ID)) = (IA+IB+IC+ID) I = (IB + ID) Use orientation independent interpolation approach.
IB I ID IA I IB IA IC ID

Both Gouraud shading and Phong shading algorithms have these limitations.

Orientation 2: Solution:

IC
Minglun Gong 14

Monday, March 19, 2012

Minglun Gong

13

Monday, March 19, 2012

Orientation Independent Interpolation


Use triangles instead of polygons to model the objects. Use Areal coordinates to interpolate either the color (in Gouraud shading) or the normal (in Phong shading).
N = *NA + *NB + *NC
NC NB

Jaggy Silhouettes
The shading inside the object looks smooth, but the silhouette edges may look jaggy. Interpolation in image space also ignores perspective distortion. Solution:
Use more facets to approximate the object
32 triangles

N NA

512 triangles

Monday, March 19, 2012

Minglun Gong

15

Monday, March 19, 2012

Minglun Gong

16

Potrebbero piacerti anche