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 11 : Lighting Basics

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

3 Written by: Itzik Ben Shabat Why Lighting is Important https://youtu.be/mt1eG1g9vNY?t=1m11s Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

4 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

5 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

6 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

7 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

8 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

9 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

10 Written by: Itzik Ben Shabat MATLAB Lighting In order to display the scene we need to calculate the color value at each vertex. MATLAB has routines and functions that does this automatically We use the following steps Define light object – position and properties Define material Define shading method Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

11 Written by: Itzik Ben Shabat MATLAB Lighting light('PropertyName',propertyvalue,...) For full property list visit linklink Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering What does it do?Property values Property Name Location of light object – Sets light origin if ‘ style ’ is ‘ infinite ‘ or sets light position if ‘ style ’ is ‘ local ’ [x,y,z] values in data units Position Sets lighting style‘infinite’ | ‘local’ style Set light colorcolorspec Color

12 Written by: Itzik Ben Shabat MATLAB Material material([ka kd ks s]) sets the ambient/diffuse/specular strength and specular exponent of the objects You can use predefined values material shiny material dull Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering skskdkaType 200.90.60.3Shiny 1000.60.3dull

13 Written by: Itzik Ben Shabat MATLAB Material surf(...,'PropertyName',PropertyValue) patch(...,'PropertyName',Propertyvalue,...) Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering What does it do? Prop. value Property Name Strength of ambient light. Ambient light is a nondirectional light that illuminates the entire scene. [0..1] (0.3) AmbientStrength Strength of diffuse light. Diffuse light is the nonspecular reflectance from light objects in the axes. [0..1] (0.6) DiffuseStrength Color of specular reflections. A value of 1 sets the color using only the color of the light source. A value of 0 sets the color using both the color of the object from which it reflects and the color of the light source. [0..1] (1) SpecularColorReflectance Size of specular spot, specified as a scalar value greater than or equal to 1. Most materials have exponents in the range [5 20]. Scalar (10) SpecularExponent Strength of specular reflection, specified as a scalar value in the range [0,1]. Specular reflections are the bright spots on the surface from light objects in the axes. [0..1] (0.9) SpecularStrength

14 Written by: Itzik Ben Shabat Shading set(axis_handle,'FaceLighting',type); 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

15 Written by: Itzik Ben Shabat Exercise Goals Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Todays goals: Create Tetris Object. Create Sphere object. Allow camera movement on Ellipsoid. Lighting, Shading and Material definitions.

16 Written by: Itzik Ben Shabat Exercise Definition Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Shapes definition: Define material for each graphic primitive. Make sure you have only one handle for each shape. Camera Allow camera movement by arrows. The ellipsoid should be in ratio 1:1:2. All of the scene needs to be on screen all the time.

17 Written by: Itzik Ben Shabat Exercise Definition Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lighting Define the light position at upper, front righter corner of the scene. Define color of the light to be green. Allow the light being turn on and off by “l” letter Shading Allow the to change shading by “n” letter. Define shading types of: None Flat Gouraund

18 Written by: Itzik Ben Shabat Guidelines Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Develop the Ellipsoid surface on a piece of paper based on lectures and tutorials. Create a new.m file and call it “yourname_3D_Lighting” Create main functions: yourname_3D_Lighting() DrawingCB() KeyboardCB() SceneLighting([object handles]) DuckGraphicPrimitive() SphereGraphicPrimitive()

19 Written by: Itzik Ben Shabat Guidelines Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Recommended working order Define your “world”. Create the 3D Duck Primitive. Describe Ellipsoid movement of the camera. Create Sphere Primitive. Transform sphere to the needed position. Define materials of primitives. Add lightening. Allow different shadings.

20 Written by: Itzik Ben Shabat Your final Result Should Look Like This Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering

21 Written by: Itzik Ben Shabat Tips, Sources and References Don’t Forget to add in your program: Comments Name Don’t forget to indent (align) your code. 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