Presentation is loading. Please wait.

Presentation is loading. Please wait.

Written by: Itzik Ben Shabat Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab.

Similar presentations


Presentation on theme: "Written by: Itzik Ben Shabat Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab."— Presentation transcript:

1 Written by: Itzik Ben Shabat Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab 12 : Lighting Basics

2 Written by: Itzik Ben Shabat Tutorial Contents Introduction to Lighting Lighting model Ambient Diffusive Specular Phong model summary Blins correction Calculation example – sphere MATLAB Lighting shading Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

3 Written by: Itzik Ben Shabat Introduction to lighting Lighting plays an important role in rendering realistic scenes Lighting models can simulate shading, reflections etc. Local illumination is based on the interaction of a light source and a point on a surface The main local illumination model in this coure is Phong which is composed of 3 components Ambient Diffusive Specular At each surface point we calculate the contribution od every component Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

4 Written by: Itzik Ben Shabat Ambient Component Global effect of light (source at infinity) I out = k ambient · I ambient_source I – Light intensity / Illumination K – reflection constant Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

5 Written by: Itzik Ben Shabat Diffusive Component Correlates to surface roughness (at microscopic level) I out =k diffusive · I in cos(θ i ) or I out =k diffusive · I in n ·l Θ i - angle between normal and light ray L – light ray vector (unit size from surface to light source) N – normal at surface point (unit size) Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

6 Written by: Itzik Ben Shabat Specular Component Shiny materials show highlights from light sources The highlight depends on our position (in relation to the surface the light is reflected from) Surfaces are not perfectly smooth, therefore there will be variations Phong modeled the variation empirically I out =k specular ·I light ·cos s (φ) or I out =k specular ·I light ·(v·r) s S – shininess factor V – unit vector from surface point to observer eye r - unit vector of reflection direction r=2(LN)N-L Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

7 Written by: Itzik Ben Shabat Phong model summary In reality we can have more than one light source Therefore Phong model transforms to I out = k ambient ·I ambient + ΣI light ·(k diffuse ·(n·l)+ k specular ·(v·r) s ) Note – k and i can have 3 RGB components. The multiplication results in a vector (multiply each component seperately i.e (Kr,Kg,Kb) · (Ir,Ig,Ib) = (Ir · Kr, Ig · Kg, Ib · Kb) Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

8 Written by: Itzik Ben Shabat Phong model summary Below is a graphical illustration of the contribution of each component Image taken from wikipedia - linklink Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

9 Written by: Itzik Ben Shabat Blins Correction Blin introduced a correction for the specular component H=Normalized(L+V) Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering I out = K specular ·I light ·(H·n) s Ф=2α

10 Written by: Itzik Ben Shabat Calculation example – Sphere Sphere equation (centered in [0,0,0]) R 2 =x 2 +y 2 +z 2 Normal Given that R=1 The surface color is blue [ka kd ks s]=[[0 0 0.3] [0 0 0.6] [0.9 0.9 0.9] 20] – rgb format Observer at [0 2 0] Assuming we have a white light source at y axis infinity (rays are parallel and in direction ([0 -1 0])) Calculate the light intensity (I) using phong model at [x y z]=[0 1 0] [x y z]=[0 0 1] Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

11 Written by: Itzik Ben Shabat Calculate normals: N 1 =[0,1,0] N 2 =[0,0,1] L=[0 1 0] Calculate V: V 1 = Normalized([0 2 0]-[0 1 0])=[0 1 0] V 2 = Normalized( [0 2 0]-[0 0 1]) = Normalized([0 2 -1]) = Calculate r: r1 = [0 1 0] r2 = [0 -1 0] Calculation example – Sphere Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

12 Written by: Itzik Ben Shabat Calculation example – Sphere Ambient - I out = k ambient · I ambient_source I a1 = [0 0 0.3] * [1 1 1] = [0 0 0.3] I a2 = [0 0 0.3] * [ 1 1 1]=[0 0 0.3] Diffusive - I out =k diffusive · I in n ·l I d1 = [0 0 0.6] * [1 1 1] · [0 1 0] · [0 1 0] = [0 0 0.6] I d2 = [0 0 0.6] * [1 1 1] · [0 0 1] · [0 1 0] = [0 0 0] Specular – I out =k specular ·I light ·(v·r) s I s1 = [0.9 0.9 0.9] *[1 1 1] ·([0 1 0] ·[0 1 0] ) 20 = [0.9 0.9 0.9] I s2 = [0.9 0.9 0.9] *[1 1 1] ·([0 2/5 -1/5] ·[0 -1 0] ) 20 =~ [0 0 0] I1= [0 0 0.3]+[0 0 0.6] + [0.9 0.9 0.9] = [ 0.9 0.9 1.8] I2 = [0 0 0.3] It can be seen in the image that in the center of the sphere the intensity is high (due to the specular highlights) and at the top its much darker since there is only ambient component * marks an element by element multiplication Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

13 Written by: Itzik Ben Shabat Shading Gouraud shading – interpolation of vertex intensities Phong shading – interpulation of normal vectors Note: in advanced Matlab versions phong does not work Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering phongGouraudflatnoneType Result

14 Written by: Itzik Ben Shabat Sources and Refrences Mathworks Documentation Center - http://www.mathworks.com/help/documentation-center.html http://www.mathworks.com/help/documentation-center.html Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering


Download ppt "Written by: Itzik Ben Shabat Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab."

Similar presentations


Ads by Google