CS5620 Illumination Models Intro to and

Illumination Models So Far … and Shading

wireframe hidden surfaces Next step…

1 2

What’s Missing ? Lighting vs. Shading

• Light ! • Lighting – Interaction between materials and light sources • Need to understand: – Physics – How lighting works Zbuffer(Scene) • Types of lights • Shading … • Types of surfaces – Determining the color of a pixel putColor(x,y,col(P)) – Computer graphics … end

– How shading works • • Shading usually determined by Shading algorithms lighting

3 4

The Physics Local vs. Model Basic Illumination Model Light rays are emitted from light sources and • Local bounce (reflect) in the scene until they reach the – only direct and local interaction eye of objects with light

• Global – all interactions and exchange of light – Can model more effects • Reflection, refraction, soft shadows

5 6

Copyright C. Gotsman, G. Elber, M. Ben-Chen Page 1 Computer Science Dept., Technion CS5620 Illumination Models Intro to Computer Graphics and Shading

Local vs. Global A Single Interaction

What determines pixel color?

Type of light

Object color Object surface material Object geometry

7 8

Light Sources Material Properties

• Point: All light originates at a point – Rays hit planar surface at different incidence • Specular angles – Smooth surface • Directional: All light rays are parallel – Rays hit a planar surface at identical – Reflects light at well-defined angle incidence angles – May be modeled as point source at infinity – Also called parallel source • • Area: Light originates at finite area in space Diffuse – In between the point and parallel sources – Rough surface – Also called distributed source – Reflects light equally in all directions • Ambient: Background light – Comes equally from all directions

9 10

Light/Reflection Types

• Local illumination model

• Looking for a value I(p) per point on the surface

• Represents the total contribution of all lights in the scene

• Takes into consideration – Position of the viewer – Position of the lights – Color of the lights – …

11 12

Copyright C. Gotsman, G. Elber, M. Ben-Chen Page 2 Computer Science Dept., Technion CS5620 Illumination Models Intro to Computer Graphics and Shading

Some Notation Ambient Reflection

• I – direction to light source • Assume non-directional light in the environment

• n – normal direction • Object illuminated with same light everywhere – Looks like a silhouette

• v – direction to COP (eye, camera) 퐼푎 = 푘푎퐿푎 푘푎 : fraction of ambient light reflected from surface • r – direction of reflected ray 퐿푎: ambient light intensity

• Defines object’s color

13 14

Diffuse Reflection Diffuse Reflection

• Dull surfaces such as solid matte plastic reflects • How does the light direction affect the illumination?

incoming light uniformly in all directions • Larger angle  with normal  less illumination density

• Called diffuse or Lambertian reflection

Fully Partially illuminated illuminated

15 16

Diffuse Reflection Specular Reflection

• Shiny objects (e.g. metallic) reflect light in 푘푑 : fraction of diffuse light preferred direction 푟 determined by surface reflected from surface 퐼푑 = 푘푑(푙 ⋅ 푛)퐿푑 normal 푛.

퐿푑: diffuse light intensity

푙 ⋅ 푛 = cos 휃

17 18

Copyright C. Gotsman, G. Elber, M. Ben-Chen Page 3 Computer Science Dept., Technion CS5620 Illumination Models Intro to Computer Graphics and Shading

Specular Reflection Specular Reflection

• Most objects are not ideal mirrors – also 퐼 = 푘 푟 ⋅ 푣 훼퐿 reflect in the immediate vicinity of 푟 푘푠 : fraction of specular light 푠 푠 푠 reflected from surface 퐿푠 • Approximate attenuation 퐿 : diffuse light intensity by cos훼  푠

(no real physical basis) 퐿푠 푟 ⋅ 푣 = cos 

훼 : shininess coefficient

19 20

Specular Reflection Total Illumination

• Exponent 훼 of cosine controls decay factor • 퐼 = 퐼푎 + 퐼푑 + 퐼푠 • Sum over all light sources • No physical basis, • May use different coefficients for RGB components but looks good • Beware of overflows

21 22

Triangle Shading Algorithms Flat Shading • Applied to piecewise linear • Given the lights and materials in the scene, polygonal models • Simple surface lighting how do we compute the color at a given point approximated over polygons on a triangle ? • Illumination value depends only on polygon normal  each polygon is colored with a uniform intensity • Three main types • Looks non-smooth (worsened by – Flat shading (per polygon) Mach band effect) – (per vertex) – (per pixel)

23 24

Copyright C. Gotsman, G. Elber, M. Ben-Chen Page 4 Computer Science Dept., Technion CS5620 Illumination Models Intro to Computer Graphics and Shading

Normal per Vertex Gouraud Shading

• Compute illumination intensity at vertices using normals • Linearly interpolate intensity over polygon interior If a polyhedron is an approximation of smooth surface: • Assign to each vertex the normal of original surface at that point • If surface is not available use estimated normal (e.g. average of neighboring faces).

25 26

Gouraud Shading Phong Shading Linearly interpolate lighting intensities at the vertices over • Interpolate (at the vertices in image space) normal vectors interior pixels of the polygon, in the image plane instead of illumination intensities

• Apply the illumination equation for each interior pixel with its c1 c12 t 12 c 1 (1  t 12 ) c 2 c13 t 13 c 1 (1  t 13 ) c 3 own (interpolated) normal n scanline Y=y 1 n12 t 12 n 1 (1  t 12 ) n 2 n13 t 13 n 1 (1  t 13 ) n 3 (,)xy scanline Y=y

c 3 c2 n3 c( x , y ) t123 c 12  (1  t 123 ) c 13 n2

Question: Can Gouraud shading support specular lighting? n(,) x y t123 n 12  (1  t 123 ) n 13 ;(,) c x y  Illum ((,)) n x y 27 28

Comparison Comparison

phong

flat

gourard

flat gourard phong

29 30

Copyright C. Gotsman, G. Elber, M. Ben-Chen Page 5 Computer Science Dept., Technion CS5620 Illumination Models Intro to Computer Graphics and Shading

Gourard

31

Copyright C. Gotsman, G. Elber, M. Ben-Chen Page 6 Computer Science Dept., Technion