![Page 1: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/1.jpg)
ILLUMINATION
Class 5
![Page 2: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/2.jpg)
Shading models
� Simulate physical interaction of light and matter.
� Physically correct shading models are complex and expensive
� Light properties� Light properties
� Material properties
� Inter-object relations
� Good approximations are possible
� Approximations of physical laws
� Heuristics that look good
![Page 3: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/3.jpg)
Light Sources
� Point light source (A)
� Parallel light source (B)
� Area light source (C)
AB
C
![Page 4: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/4.jpg)
Point Light Source
� Light originates from a point
� Represented by position and color
� The point may be at infinity
� Approximate light sources whose dimensions � Approximate light sources whose dimensions are small relative to the objects
AB
C
![Page 5: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/5.jpg)
Parallel Light Source
� Light rays are parallel
� Represented by direction and color
� Can be modeled as a point light source at infinity
� Approximate far and large light sources� Approximate far and large light sources
AB
C
![Page 6: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/6.jpg)
Area Light Source
� Light originates at a finite area
� Window
� Fluorescent
� Sometimes called distributed source � Sometimes called distributed source
AB
C
![Page 7: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/7.jpg)
Parallel Vs. Point Source
� Parallel light source
� Point light source
![Page 8: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/8.jpg)
Intensity Attenuation
� Radial intensity attenuation:
� Angular intensity attenuation:
� How can we represent a spotlight?
![Page 9: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/9.jpg)
Illumination models
� Object illumination is affected by the following:
� Ambient light
� Diffuse reflection
� Specular reflection� Specular reflection
![Page 10: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/10.jpg)
Ambient Light
� Assumes non directional light in the background
� Object illuminated with same light everywhere
� The illumination equation:
I = I K ,Iamb = IaKa ,
Ia – ambient light intensity
Ka – fraction of ambient light reflected from surface
![Page 11: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/11.jpg)
Diffuse Reflection
� Reflects incoming light uniformly in all directions
� Known as Lambert reflection
� Represents matte (non shining) surfaces
� Reflected light is proportional to � Reflected light is proportional to
N
L
![Page 12: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/12.jpg)
Diffuse Reflection
� Illumination due to point light source:
Ip – point light intensity
Ka – diffuse-reflection coefficientKa – diffuse-reflection coefficient
� Total illumination:
![Page 13: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/13.jpg)
� Shiny (metallic) surfaces reflect light in a preferred direction R and its vicinity
� Ideal shiny surface (mirror) reflects only in the direction R
Specular Reflection
direction R
� Phong model: attenuation is relative to (no physical basis):
co s α co s8
α co s1 2 8
α
θ αNL R
Vθ
![Page 14: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/14.jpg)
Specular Reflection
� Illumination due to point light source:
Ip – point light intensity
Ks – specular-reflection coefficientKs – specular-reflection coefficient
n – specularity exponent
� Calculation of R:
θ αNL R
Vθ
![Page 15: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/15.jpg)
Illumination Equation
� N – point normal
� V – viewing direction
L – lighting direction� L – lighting direction
� R – reflection direction
� d – diffuse, a – ambient, s – specular
� I – intensity
� K – surface coefficient,
� θ – angle between N and L
� α – angle between V and R
θ α
NL R
Vθ
![Page 16: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/16.jpg)
Illumination comparison
Ambient
Diffuse
Specular, n = 100
Specular, n = 8
![Page 17: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/17.jpg)
Surface Rendering Methods
� Constant (Flat)
� Gouraud
� Phong
� Also named ‘Shading’
![Page 18: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/18.jpg)
Constant Surface Rendering
� Color each polygon according to its normal
� Piecewise linear polygonal models
� Light source is far from the object
� Viewer is far from the object� Viewer is far from the object
![Page 19: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/19.jpg)
Gouraud Surface Rendering
� Gouraud’s method:
� Compute average normal on each vertex
� Compute light intensity on each vertex
� Use linear interpolation to compute light intensity � Use linear interpolation to compute light intensity on a point on the polygon
� Interpolation is done on image plane using scan-conversion
� Can it support specular highlights?
![Page 20: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/20.jpg)
Phong Surface Rendering
� Phong’s method:
� Compute average normal on each vertex
� Use linear interpolation to compute normal on a point on the polygon
� Interpolation is done on image plane using scan-conversion
� Compute light intensity on each point
� Expensive but more accurate
![Page 21: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/21.jpg)
Rendering Quiz
![Page 22: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/22.jpg)
LIGHTING IN OSGLIGHTING IN OSG
![Page 23: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/23.jpg)
Lights in the graph
Root
The graphLight
Source
Light
Light
Source
Light
The graph
![Page 24: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/24.jpg)
TODO
� Specify normals with your geometry
� Enable lighting and set other lighting state
� Specify the light source properties
� attach it to your scene graph� attach it to your scene graph
� Specify surface material properties
![Page 25: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/25.jpg)
Normals
� Enable normal rescaling� uniform scaling
osg::StateSet* state = geode->getOrCreateStateSet();
state->setMode( GL_RESCALE_NORMAL, osg::StateAttribute::ON );state->setMode( GL_RESCALE_NORMAL, osg::StateAttribute::ON );
� Enable normalization� non-uniform scaling
osg::StateSet* state = geode->getOrCreateStateSet();
state->setMode( GL_NORMALIZE, osg::StateAttribute::ON );
![Page 26: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/26.jpg)
Lighting State
� Enable lighting
� Enable at least one light source
osg::StateSet* state = root->getOrCreateStateSet();osg::StateSet* state = root->getOrCreateStateSet();
state->setMode( GL_LIGHTING, osg::StateAttribute::ON );
state->setMode( GL_LIGHT0, osg::StateAttribute::ON );
state->setMode( GL_LIGHT1, osg::StateAttribute::ON );
![Page 27: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/27.jpg)
Light Sources
� Create an osg::Light
� GL_LIGHT0, …, GL_LIGHT7
� Add the Light to an osg::LightSource node
� Add the LightSource node to your scene graph� Add the LightSource node to your scene graph
LightSource is effectively a leaf node containing a single Light definition.
![Page 28: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/28.jpg)
Adding light to graph
// Light Source node…
osg::ref_ptr<osg::LightSource> ls = new osg::LightSource;
//... is added to the root
root->addChild( ls.get() );
// Light Source holds Light
osg::ref_ptr<osg::Light> light = new osg::Light;
light->setLightNum(2); // Indicate which light (Default – 0)
ls->setLight( light.get() );
![Page 29: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/29.jpg)
Light Properties
// Create a white spot light source
osg::ref_ptr<osg::Light> light = new osg::Light;
light->setAmbient( osg::Vec4( .1f, .1f, .1f, 1.f )); // (r,g,b,1)
light->setDiffuse( osg::Vec4( .8f, .8f, .8f, 1.f )); // (r,g,b,1)
light->setSpecular( osg::Vec4( .8f, .8f, .8f, 1.f )); // (r,g,b,1)light->setSpecular( osg::Vec4( .8f, .8f, .8f, 1.f )); // (r,g,b,1)
light->setPosition( osg::Vec4( 0.f, 0.f, 0.f, 1.f )); //(x,y,z,w)
light->setDirection( osg::Vec3( 1.f, 0.f, 0.f )); //(x,y,z)
light->setSpotCutoff(25.f );
light-> setConstantAttenuation(0.5f);
![Page 30: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/30.jpg)
Light Position
� By current transformation of LightSource� Default
� Absolute value� Absolute value
osg::ref_ptr<osg::LightSource> ls = new osg::LightSource;
ls->setReferenceFrame( osg::LightSource::ABSOLUTE_RF );
![Page 31: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/31.jpg)
Material Properties
� Create a Material object
� Set colors and other parameters
� attach it to a StateSet in your scene graph
![Page 32: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/32.jpg)
Material
osg::StateSet* state = node->getOrCreateStateSet();
osg::ref_ptr<osg::Material> mat = new osg::Material;
…
state->setAttribute( mat.get() );
� Faces:
� osg::Material::FRONT
� osg::Material::BACK
� osg::Material::FRONT_AND_BACK
� When do we need back faces?
![Page 33: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/33.jpg)
Material Properties
mat->setDiffuse( osg::Material::FRONT, osg::Vec4( .2f, .9f, .9f, 1.f ) );
// (r,g,b,1)
mat->setSpecular( osg::Material::FRONT, osg::Vec4( 1.f, 1.f, 1.f, 1.f ) );
// (r,g,b,1)
mat->setShininess( osg::Material::FRONT, 96.f ); // 1-128mat->setShininess( osg::Material::FRONT, 96.f ); // 1-128
mat->setAlpha ( osg::Material::FRONT, 0.5f ); // 0-1
mat->setEmission(Face,osg::Vec4(1.f, 1.f, 1.f, 1.f )); // 0-1
![Page 34: ILLUMINATION - Technionwebee.technion.ac.il/~cgcourse/classes/class5.pdf · Add the Light to an osg::LightSource node Add the LightSource node to your scene graph LightSource is effectively](https://reader031.vdocument.in/reader031/viewer/2022022421/5a80725a7f8b9a0c748c61ed/html5/thumbnails/34.jpg)
Shade model
osg::ShadeModel* sm = new osg::ShadeModel();
sm->setMode( osg::ShadeModel::FLAT);
state->setAttribute( sm );
� Shade Models:� Shade Models:� FLAT
� SMOOTH