433-324 Graphics and Interaction Surface rendering and shading - - PowerPoint PPT Presentation

433 324 graphics and interaction surface rendering and
SMART_READER_LITE
LIVE PREVIEW

433-324 Graphics and Interaction Surface rendering and shading - - PowerPoint PPT Presentation

Introduction Surface rendering and shading Gouraud shading Phong shading 433-324 Graphics and Interaction Surface rendering and shading Adrian Pearce Department of Computing and Information Systems University of Melbourne The University of


slide-1
SLIDE 1

Introduction Surface rendering and shading Gouraud shading Phong shading

433-324 Graphics and Interaction Surface rendering and shading

Adrian Pearce

Department of Computing and Information Systems University of Melbourne

The University of Melbourne

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading

slide-2
SLIDE 2

Introduction Surface rendering and shading Gouraud shading Phong shading

Lecture outline

Introduction Surface rendering and shading Gouraud shading Phong shading

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading

slide-3
SLIDE 3

Introduction Surface rendering and shading Gouraud shading Phong shading

How are polygonal surfaces rendered? Aim: understand how to use illumination models to create realistic shading through surface rendering. Reading:

◮ Foley Section 14.2 Shading models for polygons. ◮ Angel Section 5.5 Polygonal Shading ◮ Akenine-Möller Section 5.Polygonal Shading ◮ Akenine-Möeller 5.5.1 Imlementing the Shading Equation

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading

slide-4
SLIDE 4

Introduction Surface rendering and shading Gouraud shading Phong shading

Shading techniques

How do we put these formulas to use? For polyhedral objects, we can use flat shading or full shading.

◮ In flat shading, compute the shading at some

representative point of each (visible) polygon face (may be a vertex, or the centroid of the face, assuming it lies within the face). Then use this computed value to fill the whole polygon.

◮ In full shading, do the complete shading calculation at

each pixel as the polygon is displayed.

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading

slide-5
SLIDE 5

Introduction Surface rendering and shading Gouraud shading Phong shading

In flat shading,

◮ the same value is used to render the entire polygon, ◮ it misses out on shading variations.

It is therefore realistic only for distant viewer and distant light source.

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading

slide-6
SLIDE 6

Introduction Surface rendering and shading Gouraud shading Phong shading

If our polyhedron is really intended as an approximation to a curved object, then either flat shading or full shading are inappropriate. The discontinuities in surface normal where the face meet will lead to artefactual discontinuities in the shading. There are two cures for this: Gouraud shading and Phong

  • shading. In both, compute an “average” surface normal at each

visible vertex, by averaging the normals of the faces that meet there.

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading

slide-7
SLIDE 7

Introduction Surface rendering and shading Gouraud shading Phong shading

◮ Because of the contrast enhancing caused by lateral

inhibition in our visual systems, these false edges are strongly perceived and are therefore even more

  • bjectionable.

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading

slide-8
SLIDE 8

Introduction Surface rendering and shading Gouraud shading Phong shading

Gouraud shading

Normalised polygon surface normals averaged to obtain vertex normals in Gouraud shading (Foley Figure 14.18).

Nv N1 N3 N2 N4

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading

slide-9
SLIDE 9

Introduction Surface rendering and shading Gouraud shading Phong shading

Calculating surface normals

Assuming all polygons store vertices in same walking order, the sign for surface normals should be correct and obtained simply calculating the cross products of the vectors (p2 − p1) and (p3 − p2).

N p2 p3 p1 p4 p5

— N = (p2 − p1) × (p3 − p2)

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading

slide-10
SLIDE 10

Introduction Surface rendering and shading Gouraud shading Phong shading

In Gouraud shading, compute the shading at each vertex. When filling a polygon in a scan-line fashion, interpolate the shading linearly along each edge, and then interpolate linearly along each scan-line segment (Foley Figure 14.19).

y y1 l3 lb l1 lp la l2 y3 y2 ys Scan line

y1 – ys

y1 – y3 lb = l1 – (l1 – l3)

xb – xp

xb – xa lp = lb – (lb – la)

y1 – ys

y1 – y2 la = l1 – (l1 – l2)

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading

slide-11
SLIDE 11

Introduction Surface rendering and shading Gouraud shading Phong shading

◮ Gouraud shading is also called intensity interpolated

shading.

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading

slide-12
SLIDE 12

Introduction Surface rendering and shading Gouraud shading Phong shading

Orientation dependence

The results of interpolated-shading is not independent of the projected polygons position (Foley Figure 14.22).

(a) (b) B P C D A A B C D P

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading

slide-13
SLIDE 13

Introduction Surface rendering and shading Gouraud shading Phong shading

Perspective distortion

Imagine you have a polygon with vertex 1 more distant than vertex 2. In this case you get perspective distortion, since perspective foreshortening means that the difference from one scan line to another increases in the direction of the further coordinate. Under these conditions you can get polygonal silhouettes and edges can look weird.

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading

slide-14
SLIDE 14

Introduction Surface rendering and shading Gouraud shading Phong shading

Phong shading

Phong shading is similar to Gouraud, except interpolate the surface normals, and do full shading calculation at every pixel using these interpolated normals (Foley Figure 14.20).

Na Nb Nc N1 N0 Pa Pb Pc P1 P0

Normal vector interpolation used in Phong shading. What is the computational cost of Phong versus Gouraud?

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading

slide-15
SLIDE 15

Introduction Surface rendering and shading Gouraud shading Phong shading

Gouraud shading (left) Phong shading (right) with highlight falling at left vertex (Foley Figure 14.21).

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading

slide-16
SLIDE 16

Introduction Surface rendering and shading Gouraud shading Phong shading

Highlight falling in centre of polygon face (Foley Figure 14.21).

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading

slide-17
SLIDE 17

Introduction Surface rendering and shading Gouraud shading Phong shading

Gouraud shading with specular reflection

Intensity interpolation (Gouraud shading) can be used with specular reflection but get less pronounced highlights (according to specular reflection coefficient).

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading

slide-18
SLIDE 18

Introduction Surface rendering and shading Gouraud shading Phong shading

Unrepresentative vertex normals

Averaged vertex normals may not represent surface geometry adequately (Foley Figure 14.24).

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading

slide-19
SLIDE 19

Introduction Surface rendering and shading Gouraud shading Phong shading

If interpolation is used, this example should appear like corrugated iron!

◮ In this example, there will be little or no variation in the

shade, if the light source is distant.

◮ This is because we interpolate between the normals,

therefore the actual surface normal information inbetween is lost!

◮ Particularly true for objects represented by with lots of

small polygons.

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading

slide-20
SLIDE 20

Introduction Surface rendering and shading Gouraud shading Phong shading

Summary

◮ Polygons can be rendered to produce curved surfaces by

calculating surface normals at vertices and performing either

◮ interpolation over intensity (Gouraud shading), or ◮ interpolation over surfaces normals (Phong shading).

◮ Phong shading requires calculation of the illumination

model at each pixel, whereas

◮ Gouraud shading only requires calculating the illumination

model at each vertex.

Adrian Pearce University of Melbourne 433-324 Graphics and InteractionSurface rendering and shading