22
Shading Polygonal Geometry

Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

Shading Polygonal Geometry

Page 2: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

Phong Reflection Model[Brad Sm

ith, Wikim

edia Com

mons]

Ambient Diffuse Specular

Page 3: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

Smooth surfaces are often approximated by polygons

Shading approaches:

1. Flat2. Smooth (Gouraud)3. Phong

Page 4: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

Flat Shading

valid for light at inf and viewer at inf

and faceted surfaces

do the shading calculation once per polygon

Page 5: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

Mach Band Effect

Page 6: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

Smooth Shading

do the shading calculation once

per vertex

Page 7: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

7

Interpolating Normals

• Must renormalize

Page 8: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

8

Interpolating Normals

• Must renormalize

Page 9: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

9

Interpolating Normals

• Must renormalize

Page 10: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

We can interpolate attributes using barycentric coordinates

http://jtibble.dyndns.org/graphics/eecs487/eecs487.html

Gouraud shading (Gouraud, 1971)

Page 11: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

Phong Shading

do the shading calculation once per fragment

Page 12: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

Comparison

Flat Gouraud Phong

Page 13: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

Problems with Interpolated Shading

• Polygonal silhouette

• Perspective distortion

• Orientation dependence

• Unrepresentative surface normals

[Fol

ey, v

an D

am, F

eine

r, H

ughe

s]

Page 14: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

Programmable Shading

Page 15: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

Fixed-Function Pipeline

CPU GPU

User Program

GeometryProcessing

PixelProcessing

primitives2D screencoordinates

Control pipeline through GL state variables

Page 16: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

Programmable Pipeline

CPU GPU

User Program

GeometryProcessing

PixelProcessing

primitives2D screencoordinates

vertex shaderpixel shader

Supply shader programs to be executed on GPU as part of pipeline

Page 17: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

[Shirley and Marschner]

Phong reflectance in vertex and pixel shaders using GLSL

Vertex Shader (Gouraud interpolation)

Pixel Shader (Phong interpolation)

Page 18: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

Dawn, NVIDIARusty car shader, NVIDIA

Call of Juarez DX10 Benchmark, ATI

Page 19: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

Computing Normal Vectors

Page 20: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

Plane Normals

Page 21: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

Implicit function normals

sphere

plane

Page 22: Shading Polygonal Geometryshinar/courses/cs230-winter-2016/Lecture16.pdf · Flat Shading valid for light at inf and viewer at inf and faceted surfaces do the shading calculation once

Parametric form

tangent vectors

normal