+ All Categories
Home > Documents > CS430 Computer Graphics

CS430 Computer Graphics

Date post: 22-Feb-2016
Category:
Upload: keitha
View: 61 times
Download: 0 times
Share this document with a friend
Description:
CS430 Computer Graphics. Lighting and Shading. Topics. Introduction Geometric Model in Lighting Colored Surfaces and Lights Shading and Graphics Pipeline Flat Shading and Smooth Shading. Introduction. Lighting - PowerPoint PPT Presentation
27
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Lighting and Shading
Transcript
Page 1: CS430  Computer Graphics

Chi-Cheng Lin, Winona State University

CS430 Computer Graphics

Lighting and Shading

Page 2: CS430  Computer Graphics

2

Topics Introduction Geometric Model in Lighting Colored Surfaces and Lights Shading and Graphics Pipeline Flat Shading and Smooth Shading

Page 3: CS430  Computer Graphics

3

Introduction Lighting

Process of computing the luminous intensity reflected from a specific 3-D point

ShadingProcess of assigning colors to pixels

Shading model dictates how light is scattered or reflected from a surfaceWe will begin with achromatic light then

colored lights

Page 4: CS430  Computer Graphics

4

Introduction Two types of light sources

Point light sourceAmbient light

Light interacts surfaces in different waysAbsorbed by surfaceReflected by surfaceTransmitted into the interior

What absorbs all of the incident achromatic light?

Page 5: CS430  Computer Graphics

5

Introduction Types of reflection of incident light

Diffuse scattering Some of the incident light penetrates the surface

slightly and is re-radiated uniformly in all directions

Scattering light interacts strongly with surface color is affected by nature of surface material

Specular reflections Incident light does not penetrate the surface Reflected directly from the surface More mirror like and highly directional Highlight, shiny, plastic like

Page 6: CS430  Computer Graphics

6

Introduction Total light reflected from the

surface in a certain direction is the sum of Diffuse componentsSpecular components

We calculate the size of each component that reaches the eye for each point of interest on surfaces

Page 7: CS430  Computer Graphics

7

Geometric Model in Lighting Principle vectors to find amount of

light reaching the eye from a point Pm: normal vector of surface at Pv: from P to the eyes: from P to light sourceAngles between vectors are

calculated in the world coordinates

Is: intensity of light source

m

vsP

eye

Page 8: CS430  Computer Graphics

8

Diffuse Component Id: intensity of the diffused component

Scattering is uniform in all directionsIndependent of v

unless m v 0, where Id = 0 (why?) Lambert’s law: brightness is

proportional to the area subtended (= fraction cos()) 0: brightness varies slightly with angle 90°: brightness falls rapidly to 0m

s

Page 9: CS430  Computer Graphics

9

Diffuse Component cos() =

How do we calculate/obtain the value for d ? By experiments.

ms ˆˆ

tcoefficien reflection diffuse where ),),ˆˆmax((

d

dsd II 0ms

Page 10: CS430  Computer Graphics

10

Specular Reflection Isp: intensity of specular reflection Phong model is used to

approximate highlightAmount of light reflected is greatest

in the direction of perfect mirror reflection, r

Amount of light reflected diminished rapidly at the nearby angles

Beam patternm

sP

r

Page 11: CS430  Computer Graphics

11

Specular Reflection Remember ? Amount of light reflected falls off as increases

and is approximately cosf(), where f is the Phong exponent

Problem: expensive to compute as r has to be found and normalized

m

vs eye

r

mmssr ˆ)ˆ( 2

tcoefficien reflectionspecular where ,)ˆˆ(

s

fsssp II vr

Page 12: CS430  Computer Graphics

12

Specular Reflection Solution (proposed by Jim Blinn)

Calculate h = s + vLet be the angle between h and mUse to calculate the falloff of specular

intensity as has the same property as , but can be compensated by different

value of f

m

v

sh

mvs

=h=0

),)ˆˆmax(( 0fsssp II mh

Page 13: CS430  Computer Graphics

13

Ambient Light A uniform background glow in the

environmentSource is not situated at any particular placeLight spreads uniformly in all directions

Ia: intensity of light source Iaa is added to the light reaching the eye

a: ambient reflection coefficienta is often the same as d

Page 14: CS430  Computer Graphics

14

Combining Light Contributions I = Ia a + Id d lambert + Isp s phongf

lambert = phong =

Implications for different points P on a facetAmbient is not changed for different Pm is the same for all point on the facetIf the light is far far away, s will change slightly as P

changes diffuse will change slightly on different PIf the light or/and eye is/are close, s and h will

change a lot as P changes specular changes significantly over the facet

)),ˆˆmax(( 0ms)),ˆˆmax(( 0mh

Page 15: CS430  Computer Graphics

15

Colored Surfaces and Lights Colored surface

Ir = Iar ar + Idr dr lambert + Ispr sr phongf Ig = Iag ag + Idg dg lambert + Ispg sg phongf Ib = Iab ab + Idb db lambert + Ispb sb phongf

lambert and phong terms do not depends on color component

We have to define 9 reflection coefficientsAmbient and diffuse reflection are based on

the color of surface

Page 16: CS430  Computer Graphics

16

Colored Surfaces and Lights Colored light (Isr, Isg, Isb)

If the color of a surface is (r, g, b), then it is reasonable to set

(ar, ag, ab) = (dr, dg, db) = (rK, gK, bK), where K is the fraction of light reflected

The diffusion of the surface = (Isrdr, Isgdg, Isbdb) = (IsrrK, IsggK, IsbbK)

Example: white lightIsr = Isg = Isb = I, (r, g, b) = (0.3, 0.45, 0.25) then

diffusion = (0.3IK, 0.45IK, 0.25IK) the surface is seen as its color

Page 17: CS430  Computer Graphics

17

Colored Surfaces and Lights Color of specular light

Often the same as that of light source Example: sunlight

Highlight on plastic caused by sunlight is white

Set (sr, sg, sb) = (s, s, s) s = 0.5 slightly shiny s = 0.9 highly shiny

Different coefficients are selected for specific materials. (Fig 8.17)

Page 18: CS430  Computer Graphics

18

Page 19: CS430  Computer Graphics

19

Shading and Graphics Pipeline Vertices are sent down the pipeline

along with their associated normals

All shading calculations are done on vertices

VM clipprojectionmatrix

viewportmatrix

shading isapplied here

v1, m1

v2, m2

v0, m0

Page 20: CS430  Computer Graphics

20

Shading and Graphics Pipeline Lights are objects and the positions of

light sources are also transformed by the modelview matrix

After all quantities are expressed in camera coordinates, colors are attached to vertices using the formula

If an object is clipped, normals of newly generated vertices are calculated by interpolation

Page 21: CS430  Computer Graphics

21

Flat Shading and Smooth Shading

Polygonal face in 3D spaceIndividual faceUnderlying surface approximated

Shading methodsFlat shadingSmooth shading

Gouraud shading Phong shading

Page 22: CS430  Computer Graphics

22

Comparison of Shading Methods

Page 23: CS430  Computer Graphics

23

Flat Shading Entire face is drawn with the same

color Lateral inhibition

When there is a discontinuity across an object, the eye manufactures a Mach band at the discontinuity and a vivid edge is seen

Specular highlights are rendered poorlyEither no highlight at allOr highlight on the entire face

Page 24: CS430  Computer Graphics

24

Smooth Shading Smooth shading computes colors at more

points on each face to de-emphasize edges between adjacent faces

Use linear interpolation Gouraud shading

Interpolate vertex colors Phong shading

Interpolate vertex normalsInterpolate normal for each pixel

Page 25: CS430  Computer Graphics

25

Gouraud Shading Used by OpenGL Example

colora: by interpolatingcolor3 and color4

colorb: by interpolatingcolor1 and color2

Colors of pixels on the horizontal line segment is obtained by interpolating colora and colorb

Does not picture highlights well

color1

color2

color3

color4

colora colorb

Page 26: CS430  Computer Graphics

26

Phong Shading Compute normal at each pixel by

interpolating the normals at the vertices Apply the shading model to to every point to

find the color Example

ma: by interpolating m3 and m4

mb: by interpolating m1 and m2Normals of pixels on the

horizontal line segment is obtained by interpolating ma and mb

Colors of the pixels are then computedm1

m2

m3

m4

ma mb

Page 27: CS430  Computer Graphics

27

Phong Shading Very smooth appearance Highlights are approximated better Principle drawback

Heavy computation slow speed Not supported by OpenGL

Can be approximated using texture mapping

Phong shading Phong model Don’t be

confused!!


Recommended