Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective...

25
Shading Polygonal Geometry

Transcript of Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective...

Page 1: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

Shading Polygonal Geometry

Page 2: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

Smooth surfaces are often approximated by polygons

Shading approaches:

1. Flat2. Smooth (Gouraud)3. Phong

Page 3: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

Flat Shading

valid for light at inf and viewer at inf

and faceted surfaces

do the shading calculation once per polygon

Page 4: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

Mach Band Effect

Page 5: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

Smooth Shading

do the shading calculation once

per vertex

Page 6: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

6

Interpolating Normals

• Must renormalize

Page 7: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

7

Interpolating Normals

• Must renormalize

Page 8: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

8

Interpolating Normals

• Must renormalize

Page 9: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

We can interpolate attributes using barycentric coordinates

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

Gouraud shading (Gouraud, 1971)

Page 10: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

Phong Shading

do the shading calculation once per fragment

Page 11: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

Comparison

Flat Gouraud Phong

Page 12: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

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 13: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

Programmable Shading

Page 14: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

Fixed-Function Pipeline

CPU GPU

User Program

GeometryProcessing

PixelProcessing

primitives2D screencoordinates

Control pipeline through GL state variables

Page 15: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

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 16: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

[Shirley and Marschner]

Phong reflectance in vertex and pixel shaders using GLSL

Vertex Shader (Gouraud interpolation)

Pixel Shader (Phong interpolation)

Page 17: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

Dawn, NVIDIARusty car shader, NVIDIA

Call of Juarez DX10 Benchmark, ATI

Page 18: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

Perspective correct interpolation

Page 19: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

Perspective correct interpolation

• In minigl pipeline, we find barycentric coordinates in 2D screen space

• but not the correct object space barycentric coords

• these coordinates are okay for z-buffer test

Page 20: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

screenspace

objectspace

Page 21: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

screenspace

objectspace

Page 22: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

screenspace

objectspace

correct distorted

Interpolation with screen space weights

is incorrect

Page 23: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

Perspective correct interpolation

Using screen space weights looks wrong for textures

[Heckbert and Morton, 1990]

Page 24: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

Do we need to transform back to

object space?screenspace

objectspace

Page 25: Shading Polygonal Geometryshinar/courses/cs130-winter-2018/content/11-Pipel… · Perspective correct interpolation • In minigl pipeline, we find barycentric coordinates in 2D

NO!

Do we need to transform back to

object space?screenspace

objectspace

<whiteboard>