Top Banner
© Machiraju/Zhang/Möller Shading CMPT 361 Introduction to Computer Graphics Torsten Möller
18

Shading - Computing Science · Shading CMPT 361 Introduction to Computer Graphics ... small flat polygons in graphics ... Flat vs. Gouraud Shading Flat Shading Gouraud Shading

Jul 07, 2018

Download

Documents

phungthu
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Shading - Computing Science · Shading CMPT 361 Introduction to Computer Graphics ... small flat polygons in graphics ... Flat vs. Gouraud Shading Flat Shading Gouraud Shading

© Machiraju/Zhang/Möller

Shading

CMPT 361Introduction to Computer Graphics

Torsten Möller

Page 2: Shading - Computing Science · Shading CMPT 361 Introduction to Computer Graphics ... small flat polygons in graphics ... Flat vs. Gouraud Shading Flat Shading Gouraud Shading

© Machiraju/Zhang/Möller2

Reading• Chapter 5.5 - Angel• Chapter 16 - Foley, van Dam, et al

Page 3: Shading - Computing Science · Shading CMPT 361 Introduction to Computer Graphics ... small flat polygons in graphics ... Flat vs. Gouraud Shading Flat Shading Gouraud Shading

© Machiraju/Zhang/Möller3

Shading• Illumination Model: determine the color of a

surface (data) point by simulating some light attributes.– Local IM: deals only with isolated surface

(data) point and direct light sources.– Global IM: takes into account the

relationships between all surfaces (points) in the environment.

• Shading Model: applies the illumination models at a set of points and colors the whole scene.

Page 4: Shading - Computing Science · Shading CMPT 361 Introduction to Computer Graphics ... small flat polygons in graphics ... Flat vs. Gouraud Shading Flat Shading Gouraud Shading

© Machiraju/Zhang/Möller4

Shading of surfaces• We can shade a point on a surface using a

local IM• How about surfaces?

– Flat (planar) polygons are computationally attractive

• Normals, intersections, visibility, projections, etc., are all easy to compute

• hardware acceleration available– Curved surfaces are often tessellated into many

small flat polygons in graphics – polygonal meshes

Page 5: Shading - Computing Science · Shading CMPT 361 Introduction to Computer Graphics ... small flat polygons in graphics ... Flat vs. Gouraud Shading Flat Shading Gouraud Shading

© Machiraju/Zhang/Möller5

Polygonal meshes• Composed of a set of polygons (often

quadrilaterals or triangles) pasted along their edges

• The dominant surface model for 3D shapes (esp. free-form shapes), e.g., in games

• Well, now there are points

Page 6: Shading - Computing Science · Shading CMPT 361 Introduction to Computer Graphics ... small flat polygons in graphics ... Flat vs. Gouraud Shading Flat Shading Gouraud Shading

© Machiraju/Zhang/Möller6

Shading of flat polygons• Flat (constant, faceted) shading

– compute illumination once per polygon and apply it to whole polygon:glShadeModel(GL_FLAT)

• Interpolated/smooth/Gouraud shading– compute illumination at borders (e.g. vertices)

and interpolate: glShadeModel(GL_SMOOTH)• Accurate shading – e.g., Phong shading

– compute illumination at every point of the polygon

Page 7: Shading - Computing Science · Shading CMPT 361 Introduction to Computer Graphics ... small flat polygons in graphics ... Flat vs. Gouraud Shading Flat Shading Gouraud Shading

© Machiraju/Zhang/Möller7

Flat shading

N1 N2

• A single color across the polygon – efficient• Intensity discontinuity across edges• Flat shading would be correct if

– Light source is at infinity, i.e., light vector l is constant, so n⋅l is constant across polygon, and

– viewer is at infinity, so r⋅v is constant across polygon, and

– polygons represent actual surface, not an approximation

• Also, if there are a very large number of very small polygons, the faceting effects is less obvious – spatial integration of our eyes

Page 8: Shading - Computing Science · Shading CMPT 361 Introduction to Computer Graphics ... small flat polygons in graphics ... Flat vs. Gouraud Shading Flat Shading Gouraud Shading

© Machiraju/Zhang/Möller8

Results of flat shading

Page 9: Shading - Computing Science · Shading CMPT 361 Introduction to Computer Graphics ... small flat polygons in graphics ... Flat vs. Gouraud Shading Flat Shading Gouraud Shading

© Machiraju/Zhang/Möller9

Mach Banding• Creates discontinuities in colour

– easily visible– hence we can see the distinct surface patches

easily• Machbands!

– caused by “lateralinhibition” of thereceptors in the eye

Page 10: Shading - Computing Science · Shading CMPT 361 Introduction to Computer Graphics ... small flat polygons in graphics ... Flat vs. Gouraud Shading Flat Shading Gouraud Shading

© Machiraju/Zhang/Möller10

Mach Banding (2)• Problems - Machbands!

Page 11: Shading - Computing Science · Shading CMPT 361 Introduction to Computer Graphics ... small flat polygons in graphics ... Flat vs. Gouraud Shading Flat Shading Gouraud Shading

© Machiraju/Zhang/Möller11

Gouraud shading• This shading model is interpolative:

– Given colors of the polygon vertices, interior points are colored through bilinear interpolation

• How to compute the normal at a mesh vertex?– E.g., take the (normalized) average of the

normals of adjacent faces

– Also, area weighted normals

Page 12: Shading - Computing Science · Shading CMPT 361 Introduction to Computer Graphics ... small flat polygons in graphics ... Flat vs. Gouraud Shading Flat Shading Gouraud Shading

© Machiraju/Zhang/Möller12

Color interpolation• Interpolate colors along edges and scan-

lines• Can be done incrementally, i.e., via scan-

lines

Page 13: Shading - Computing Science · Shading CMPT 361 Introduction to Computer Graphics ... small flat polygons in graphics ... Flat vs. Gouraud Shading Flat Shading Gouraud Shading

© Machiraju/Zhang/Möller13

Flat vs. Gouraud Shading

Gouraud ShadingFlat Shading

Page 14: Shading - Computing Science · Shading CMPT 361 Introduction to Computer Graphics ... small flat polygons in graphics ... Flat vs. Gouraud Shading Flat Shading Gouraud Shading

© Machiraju/Zhang/Möller14

Phong shading• Gouraud shading does not properly handle

specular highlights because of color interpolation

• Phong shading – accurate shading – Interpolates normals at each point instead of colors– Apply LIM at each point according to approximated

normal

Page 15: Shading - Computing Science · Shading CMPT 361 Introduction to Computer Graphics ... small flat polygons in graphics ... Flat vs. Gouraud Shading Flat Shading Gouraud Shading

© Machiraju/Zhang/Möller15

Phong vs. Gouraud shading • Phong shading:

– Handles specular highlights much better– Does a better job in handling Mach bands– But much more expensive than Gouraud

shading

Page 16: Shading - Computing Science · Shading CMPT 361 Introduction to Computer Graphics ... small flat polygons in graphics ... Flat vs. Gouraud Shading Flat Shading Gouraud Shading

© Machiraju/Zhang/Möller16

Further problems with shading models so far (1)

• Polygonal silhouette – we are quite sensitive in picking these up

• Solution: subdivide further• Exercise: How to determine

whether an edge in a mesh is a silhouette edge?

Page 17: Shading - Computing Science · Shading CMPT 361 Introduction to Computer Graphics ... small flat polygons in graphics ... Flat vs. Gouraud Shading Flat Shading Gouraud Shading

• Orientation dependence– Note first that interpolation is done along

horizontal scanlines– When the orientation of the same polygon

changes, the same point p may be colored differently

• Solution: triangulate

© Machiraju/Zhang/Möller17

Further problems with shading models so far (2)

Page 18: Shading - Computing Science · Shading CMPT 361 Introduction to Computer Graphics ... small flat polygons in graphics ... Flat vs. Gouraud Shading Flat Shading Gouraud Shading

© Machiraju/Zhang/Möller18

Further problems with shading models so far (3)

• Unrepresentative normals– As shown, all vertex and interpolated normals

are the same• Solution: subdivide further