prev

next

out of 64

View

20Download

1

Tags:

Embed Size (px)

Lighting and ShadingInstructor LE Thanh Sach, Ph.D

Chapter 05

ContactLE Thanh Sach, Ph.D. Office: Department of Computer Science, Faculty of Computer Science and Engineering, HoChiMinh City University of Technology. Office Address: 268 LyThuongKiet Str., Dist. 10, HoChiMinh City, Vietnam. E-mail: LTSACH@cse.hcmut.edu.vn E-home: http://cse.hcmut.edu.vn/~ltsach/ Tel: (+84) 83-864-7256 (Ext: 5839)Computer Graphics: Chapter 05 Lighting and Shading Slide: 2

AcknowledgmentThe slides in this PPT file are composed using the materials supplied byProf. Edward Angel: He is currently from ARTS Lab, University of New Mexico. He also the author of the book Interactive Computer Graphics: A Top-down Approach Using OpenGL Prof. Donald Hearn and Prof. M. Pauline Baker, from Indiana University and Purdue UniversityComputer Graphics: Chapter 05 Lighting and Shading Slide: 3

OutlineShading I Shading II Shading in OpenGL

Computer Graphics: Chapter 05 Lighting and Shading

Slide: 4

Shading I

ObjectivesLearn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build a simple reflection model---the Phong model--- that can be used with real time graphics hardwareComputer Graphics: Chapter 05 Lighting and Shading Slide: 6

Why we need shadingSuppose we build a model of a sphere using many polygons and color it with glColor. We get something like

But we want

Computer Graphics: Chapter 05 Lighting and Shading

Slide: 7

ShadingWhy does the image of a real sphere look like

Light-material interactions cause each point to have a different color or shade Need to considerLight sources Material properties Location of viewer Surface orientationComputer Graphics: Chapter 05 Lighting and Shading Slide: 8

ScatteringLight strikes ASome scattered Some absorbed

Some of scattered light strikes BSome scattered Some absorbed

Some of this scattered light strikes A and so onComputer Graphics: Chapter 05 Lighting and Shading Slide: 9

Rendering EquationThe infinite scattering and absorption of light can be described by the rendering equationCannot be solved in general Ray tracing is a special case for perfectly reflecting surfaces

Rendering equation is global and includesShadows Multiple scattering from object to objectComputer Graphics: Chapter 05 Lighting and Shading Slide: 10

Global Effectsshadow

multiple reflection translucent surface

Computer Graphics: Chapter 05 Lighting and Shading

Slide: 11

Local vs Global RenderingCorrect shading requires a global calculation involving all objects and light sourcesIncompatible with pipeline model which shades each polygon independently (local rendering)

However, in computer graphics, especially real time graphics, we are happy if things look rightExist many techniques for approximating global effectsComputer Graphics: Chapter 05 Lighting and Shading Slide: 12

Local vs Global RenderingLook right:Bui Tuong Phong (Phong Model):

We do not expect to be able to display the object exactly as it would appear in reality, with texture, overcast shadows, etc. We hope only to display an image that approximates the real object closely enough to provide a certain degree of realism.Computer Graphics: Chapter 05 Lighting and Shading Slide: 13

Light-Material InteractionLight that strikes an object is partially absorbed and partially scattered (reflected) The amount reflected determines the color and brightness of the objectA surface appears red under white light because the red component of the light is reflected and the rest is absorbed

The reflected light is scattered in a manner that depends on the smoothness and orientation of the surfaceComputer Graphics: Chapter 05 Lighting and Shading Slide: 14

Light SourcesGeneral light sources are difficult to work with because we must integrate light coming from all points on the source

Computer Graphics: Chapter 05 Lighting and Shading

Slide: 15

Simple Light SourcesPoint sourceModel with position and color Distant source = infinite distance away (parallel)

SpotlightRestrict light from ideal point source

Ambient lightSame amount of light everywhere in scene Can model contribution of many sources and reflecting surfacesComputer Graphics: Chapter 05 Lighting and Shading Slide: 16

Surface TypesThe smoother a surface, the more reflected light is concentrated in the direction a perfect mirror would reflected the light A very rough surface scatters light in all directions

smooth surfaceComputer Graphics: Chapter 05 Lighting and Shading

rough surfaceSlide: 17

Phong ModelA simple model that can be computed rapidly Has three componentsDiffuse Specular Ambient

Uses four vectorsTo source To viewer Normal Perfect reflectorComputer Graphics: Chapter 05 Lighting and Shading Slide: 18

Ideal ReflectorNormal is determined by local orientation Angle of incidence = angle of reflection The three vectors must be coplanarr = 2 (l n ) n - l

Computer Graphics: Chapter 05 Lighting and Shading

Slide: 19

Lambertian SurfacePerfectly diffuse reflector Light scattered equally in all directions Amount of light reflected is proportional to the vertical component of incoming lightreflected light ~ cos i cos i = l n :if vectors normalized There are also three coefficients, kr, kb, kg that show how much of each color component is reflectedComputer Graphics: Chapter 05 Lighting and Shading Slide: 20

Specular SurfacesMost surfaces are neither ideal diffusers nor perfectly specular (ideal reflectors) Smooth surfaces show specular highlights due to incoming light being reflected in directions concentrated close to the direction of a perfect reflection

specular highlightComputer Graphics: Chapter 05 Lighting and Shading Slide: 21

Modeling Specular RelectionsPhong proposed using a term that dropped off as the angle between the viewer and the ideal reflection increasedIr ~ ks I cos

reflected intensity

shininess coef

incoming intensity absorption coefComputer Graphics: Chapter 05 Lighting and Shading Slide: 22

The Shininess CoefficientValues of between 100 and 200 correspond to metals Values between 5 and 10 give surface that look like plasticcos

-90Computer Graphics: Chapter 05 Lighting and Shading

90Slide: 23

Shading II

Computer Graphics: Chapter 05 Lighting and Shading

Slide: 24

ObjectivesContinue discussion of shading Introduce modified Phong model Consider computation of required vectors

Computer Graphics: Chapter 05 Lighting and Shading

Slide: 25

Ambient LightAmbient light is the result of multiple interactions between (large) light sources and the objects in the environment Amount and color depend on both the color of the light(s) and the material properties of the object Add ka Ia to diffuse and specular termsreflection coef intensity of ambient lightSlide: 26 Computer Graphics: Chapter 05 Lighting and Shading

Distance TermsThe light from a point source that reaches a surface is inversely proportional to the square of the distance between them We can add a factor of the form 1/(ad + bd +cd2) to the diffuse and specular terms The constant and linear terms soften the effect of the point sourceComputer Graphics: Chapter 05 Lighting and Shading Slide: 27

Light SourcesIn the Phong Model, we add the results from each light source Each light source has separate diffuse, specular, and ambient terms to allow for maximum flexibility even though this form does not have a physical justification Separate red, green and blue components Hence, 9 coefficients for each point sourceIdr, Idg, Idb, Isr, Isg, Isb, Iar, Iag, IabComputer Graphics: Chapter 05 Lighting and Shading Slide: 28

Material PropertiesMaterial properties match light source propertiesNine absorbtion coefficients Shininess coefficient

kdr, kdg, kdb, ksr, ksg, ksb, kar, kag, kab

Computer Graphics: Chapter 05 Lighting and Shading

Slide: 29

Adding up the ComponentsFor each light source and each color component, the Phong model can be written (without the distance terms) as

I =kd Id l n + ks Is (v r ) + ka IaFor each color component we add contributions from all sourcesComputer Graphics: Chapter 05 Lighting and Shading Slide: 30

Phong Lighting ModelCompute light at a point by:r r r kd I d max(l.n, 0) + ksr I sr (max(r.v, 0)) + kar I a Ir I = k g I g max(l.n, 0) + k g I g (max(r.v, 0)) + k g I g I = g d d s s a a I b k b I b max(l.n, 0) + k b I b (max(r.v, 0)) + k b I b d d s s a a

Where:

kdr g kd b kd

k k k

r s g s b s

k - are materials properties k - In Opengl: specified by glMaterialfv(.) k r a g a b aSlide: 31

Computer Graphics: Chapter 05 Lighting and Shading

Phong Lighting ModelCompute light at a point by:r r r kd I d max(l.n, 0) + ksr I sr (max(r.v, 0)) + kar I a Ir I = k g I g max(l.n, 0) + k g I g (max(r.v, 0)) + k g I g I = g d d s s a a I b k b I b max(l.n, 0) + k b I b (max(r.v, 0)) + k b I b d d s s a a

Where:r Id g Id b Id

I I I

r s g s b s

I - are light intensities I - In Opengl: specified by glLightfv(.) I r a g a b aSlide: 32

Computer Graphics: Chapter 05 Lighting and Shading

Modified Phong ModelThe specular term in the Phong model is problematic because it requires the calculation of a new reflection vector and view vector for each vertex Blinn suggested an approximation using the halfway vector that is more efficienthalfway angle is half of angle between n and h if vecto