21
CAP 4703 CAP 4703 Computer Graphic Computer Graphic Methods Methods Prof. Roy Levow Prof. Roy Levow Chapter 6 Chapter 6

CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

Embed Size (px)

Citation preview

Page 1: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

CAP 4703CAP 4703Computer Graphic Computer Graphic

MethodsMethodsProf. Roy LevowProf. Roy Levow

Chapter 6Chapter 6

Page 2: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

Light and MatterLight and Matter

Surface maySurface may– emit lightemit light– reflect lightreflect light

Rendering equationRendering equation– Recusrively applying the effect from a Recusrively applying the effect from a

source to the viewer yields thesource to the viewer yields the Equation cannot be solved in generalEquation cannot be solved in general Approximate approaches can be Approximate approaches can be

computationally intensivecomputationally intensive

Page 3: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

ApproximationsApproximations

Ray tracingRay tracing– trace light from source to eyetrace light from source to eye

most rays don’t reach the eyemost rays don’t reach the eye

RadiosityRadiosity– Treat surfaces as small regions each emitting Treat surfaces as small regions each emitting

fixed lightfixed light Calculate emission independent of viewerCalculate emission independent of viewer

Simplified ray tracingSimplified ray tracing– Single interaction between light source and Single interaction between light source and

each surfaceeach surface

Page 4: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

Light and SurfacesLight and Surfaces

Page 5: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

Interaction with SurfacesInteraction with Surfaces

Specular surfaceSpecular surface– Similar to mirrorSimilar to mirror– Light leaves atLight leaves at

same angle as same angle as entryentry

Page 6: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

Interaction with Surfaces (cont)Interaction with Surfaces (cont)

Diffuse SurfaceDiffuse Surface– Light leaves inLight leaves in

all directionsall directions

Page 7: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

Interaction with Surfaces (cont)Interaction with Surfaces (cont)

Translucent Translucent SurfaceSurface– some light some light

penetrates surfacepenetrates surface– leaves at modified leaves at modified

angle – refractionangle – refraction– some reflectedsome reflected

Page 8: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

Light SourcesLight Sources

Six variable illumination Six variable illumination functionfunction

I(x,y,x,theta, phi, lambda)I(x,y,x,theta, phi, lambda)– Generally too complex to Generally too complex to

compute for all pointscompute for all points

Page 9: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

Light SourcesLight Sources

Consider four simpler light sourcesConsider four simpler light sources– Ambient lightingAmbient lighting

Omnidirectional; constant everywhereOmnidirectional; constant everywhere

– Point sourcePoint sourceRadiates in all directionsRadiates in all directions

– Spot lightsSpot lightsSmall cone of constant lightSmall cone of constant light

– Distant lightDistant lightrays are parallelrays are parallel

Page 10: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

Color SourcesColor Sources

Describe color with 3-dimensional Describe color with 3-dimensional RGB vectorRGB vector– (Ir, Ig, Ib)(Ir, Ig, Ib)TT

Page 11: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

Characteristics of Light SourcesCharacteristics of Light Sources

Ambient light Ambient light – every point in scene receives same light every point in scene receives same light

in every directionin every direction Point sourcePoint source

– Intensity decreases with inverse square Intensity decreases with inverse square of distanceof distance

– Often approximate with formOften approximate with form

(a + bd +cd(a + bd +cd22))-1-1 where d is distance to soften effectwhere d is distance to soften effect

Page 12: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

Characteristics of Light SourcesCharacteristics of Light Sources

Spot lightSpot light– Light limited to cone of angleLight limited to cone of angle– diminishes toward edges of cone asdiminishes toward edges of cone as

coscosee(theta) for some value of e(theta) for some value of e

– intensity as for point sourceintensity as for point source Distant sourceDistant source

– constant intensityconstant intensity– fixed directionfixed direction

Page 13: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

Phong Reflection ModelPhong Reflection Model

Described by 4 Described by 4 vectorsvectors

n – normal to pn – normal to p

v – to viewerv – to viewer

l – to sourcel – to source

r – reflected rayr – reflected ray

Page 14: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

Phong Reflection ModelPhong Reflection Model

SupportsSupports– ambientambient– diffusediffuse– specularspecularor combination of theseor combination of these

Uses 3 x 3 matrixUses 3 x 3 matrix– columns for r – g – bcolumns for r – g – b– rows for ambient, diffuse, specularrows for ambient, diffuse, specular

Color source and reflection matricesColor source and reflection matrices

Page 15: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

Phong Reflection ModelPhong Reflection Model

resulting intensity is sum or products resulting intensity is sum or products of corresponding termsof corresponding termsIIirir = R = RirairaLLiraira+R+RirdirdLLirdird+R+RirsirsLLirsirs

= I= Iiraira+I+Iirdird+I+Iirsirs

for red, etcfor red, etc Sum over all points for complete Sum over all points for complete

effecteffect

Page 16: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

Ambient ReflectionAmbient Reflection

Ra = kRa = kaa, 0 <= k, 0 <= kaa <= 1 <= 1– a fraction of light is reflecteda fraction of light is reflected– one coefficient for each colorone coefficient for each color

Page 17: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

Diffuse reflectionDiffuse reflection

Lambertian surfacesLambertian surfaces– reflect only vertical reflect only vertical

componentcomponent

– RRdd proportional to proportional to cos(theta)cos(theta)

– IIdd = k = kdd (l . n) L (l . n) Ldd / (a + bd +cd/ (a + bd +cd22))

Page 18: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

Specular ReflectionSpecular Reflection

Phong model equationPhong model equationIIss = k = kss L Lss (R . v) (R . v)aa

kkss is shininess coefficient is shininess coefficient

Page 19: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

OpenGL ShadingOpenGL Shading

Polygonal shadingPolygonal shading– Generate shading on individual polygonsGenerate shading on individual polygons

Flat shadingFlat shading glShadeModel(GL_FLAT);glShadeModel(GL_FLAT);– select one vertex of polygon for normalselect one vertex of polygon for normal– same color throughout polygonsame color throughout polygon– tends to produce artificial looking surfaces with tends to produce artificial looking surfaces with

distinctly colored regionsdistinctly colored regions– eye is very sensitive to changeeye is very sensitive to change

Mach BandsMach Bands

Page 20: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

Flat ShadingFlat Shading

Page 21: CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6

Interpolative and Gourand ShadingInterpolative and Gourand Shading

GL_SMOOTHGL_SMOOTH– average normalsaverage normals– example: plates 4 & 5example: plates 4 & 5