17
Shading 1/17 Komputer Grafik 2 (AK045206) Realisme : Shading

Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading

Embed Size (px)

Citation preview

Page 1: Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading

Shading 1/17

Komputer Grafik 2 (AK045206)

Realisme : Shading

Page 2: Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading

Shading 2/17

Komputer Grafik 2 (AK045206)

Outline

• Shading Models : Direct Line– Flat Shading– Gouraud Shading– Phong Shading

• Shading Models : Indirect Line

Page 3: Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading

Shading 3/17

Komputer Grafik 2 (AK045206)

Shading Models (Direct lighting)

• Flat Shading– Compute Phong lighting once for

entire polygon

• Gouraud Shading– Compute Phong lighting at the

vertices and interpolate lighting values across polygon

• Phong Shading– Compute averaged vertex normals– Interpolate normals across polygon

and perform Phong lighting across polygon

Page 4: Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading

Shading 4/17

Komputer Grafik 2 (AK045206)

• The simplest approach, flat shading, calculates illumination at a single point for each polygon.

• We can refine it a bit by evaluating the Phong lighting model at each pixel of each polygon, but the result is still clearly faceted:

• To get smoother-looking surfaceswe introduce vertex normals at eachvertex– Usually different from facet normal– Used only for shading– Think of as a better approximation of the real

surface that the polygons approximate

Flat Shading

Page 5: Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading

Shading 5/17

Komputer Grafik 2 (AK045206)

• Vertex normals may be – Provided with the model– Computed from first principles – Approximated by averaging the normals

of the facets that share the vertex

Flat Shading :Vertex Normal

Page 6: Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading

Shading 6/17

Komputer Grafik 2 (AK045206)

• This is the most common approach– Perform Phong lighting at the vertices– Linearly interpolate the resulting colors

over faces• Along edges• Along scanlines

– This is what OpenGL does

Gouraud Shading

C1

C2

C3

c1 + t1(c2-c1)

c1 + t2(c3-c1)

c1 + t1(c2-c1) + t3(c1 + t2(c3-c1)- c1 + t1(c2-c1))

Page 7: Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading

Shading 7/17

Komputer Grafik 2 (AK045206)

• Artifacts– Often appears dull, chalky– Lacks accurate specular

component• If included, will be averaged over

entire polygon

Gouraud Shading

C1

C2

C3

Can’t shade that effect!

Page 8: Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading

Shading 8/17

Komputer Grafik 2 (AK045206)

• Artifacts– Mach Banding

• Artifact at discontinuities in intensity or intensity slope

Gouraud Shading

C1

C2

C3

C4

Discontinuity in rateof color change

occurs here

Page 9: Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading

Shading 9/17

Komputer Grafik 2 (AK045206)

• Phong shading is not the same as Phong lighting, though they are sometimes mixed up– Phong lighting: the empirical model we’ve

been discussing to calculate illumination at a point on a surface

– Phong shading: linearly interpolating the surface normal across the facet, applying the Phong lighting model at every pixel

• Same input as Gouraud shading

• Usually very smooth-looking results:

• But, considerably more expensive

Phong Shading

Page 10: Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading

Shading 10/17

Komputer Grafik 2 (AK045206)

Phong Shading

• Linearly interpolate the vertex normals– Compute lighting equations at each pixel– Can use specular component

lights

i

n

isidiambientatotal

shinyRVkLNkIIkI

#

1

ˆˆˆˆ

N

2

N

3

N

4

Remember: Normals used in diffuse and specular terms

Discontinuity in normal’s rate of change is harder to detect

Page 11: Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading

Shading 11/17

Komputer Grafik 2 (AK045206)

Perspective Distortion

Z – into the scene

Imageplane

Break up large polygonswith many smaller ones

Notice that linear interpolation in screen spacedoes not align with linear interpolation in world space

Page 12: Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading

Shading 12/17

Komputer Grafik 2 (AK045206)

Z – into the scene

Imageplane Break up large polygons

with many smaller ones

Notice that linear interpolation in screen spacedoes not align with linear interpolation in world space

Perspective Distortion

Page 13: Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading

Shading 13/17

Komputer Grafik 2 (AK045206)

Interpolation dependent on polygon orientation

• Interpolation dependent on polygon orientation

A

D

C

B

Interpolate betweenAB and AD

B

A

D

C

Interpolate betweenCD and AD

Rotate -90o

and colorsame point

Page 14: Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading

Shading 14/17

Komputer Grafik 2 (AK045206)

Problems at Shared Vertices

Vertex B is shared by the two rectangles on the right, but not by the one on the left

The first portion of the scanline is interpolated between DE and AC

The second portion of the scanline is interpolated between BC and GH

A large discontinuity could arise

B

A

C

E

D

F

H

G

Page 15: Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading

Shading 15/17

Komputer Grafik 2 (AK045206)

• Polygonal silhouettes remain

Shortcomings of Shading

Gouraud Phong

Page 16: Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading

Shading 16/17

Komputer Grafik 2 (AK045206)

Shading Models (Indirect lighting)

Ray Tracing

Radiosity

Page 17: Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading

Shading 17/17

Komputer Grafik 2 (AK045206)

Referensi

• F.S.Hill, Jr., COMPUTER GRAPHICS – Using Open GL, Second Edition, Prentice Hall, 2001

• CS 445/645 : Introduction to Computer Graphics, Slide-Presentation, Virginia University