Upload
pierce-nelson
View
215
Download
0
Embed Size (px)
Citation preview
Shading 1/17
Komputer Grafik 2 (AK045206)
Realisme : Shading
Shading 2/17
Komputer Grafik 2 (AK045206)
Outline
• Shading Models : Direct Line– Flat Shading– Gouraud Shading– Phong Shading
• Shading Models : Indirect Line
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
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
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
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))
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!
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
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
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
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
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
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
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
Shading 15/17
Komputer Grafik 2 (AK045206)
• Polygonal silhouettes remain
Shortcomings of Shading
Gouraud Phong
Shading 16/17
Komputer Grafik 2 (AK045206)
Shading Models (Indirect lighting)
Ray Tracing
Radiosity
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