SlideShare a Scribd company logo
1 of 39
1
Computer Graphics for Scientists and Engineers
Lighting in OpenGL
2
Graphics: Conceptual Model
Real Object
Real
Object
Human Eye
Human Eye
Display
Device
Graphics System
Synthetic
Model
Synthetic
Camera
Real Light
Synthetic
Light Source
3
Lights, Surfaces, and Imaging
Proj. Plane
Viewer
Objects
4
Lights, Surfaces, and Imaging
Proj. Plane
Viewer
Light
Source
Objects
5
Modes of Interaction of Light with Materials
Specular
Surface
Diffuse
Surface Translucent
Surface
Note: Any given surface can have some of all three properties.
6
Illuminating Surfaces
z
x
y
I(θ,φ,λ)
I(x, y,z,θ,φ,λ)We can define illumination function:
To obtain total light, must integrate over total surface.
Itotal (λ) = I(x,y,z,θ,φ,λ)∫∫∫ dxdydz
7
Simplified Model
Exact model can easily get complicated!
Three simplifications help.
1. We can consider four classes of light sources
• ambient
• point
• spotlight
• distant
2. Human color perception allows us to consider illumination
function in terms of the three primary colors.
3. We can neglect (OpenGL caveats):
• multiple reflections
• obstruction of light path by objects
8
Light Sources
Ambient light
- no identifiable source or direction
- hack for replacing true global illumination
= (light bouncing off from other objects)
9
Ambient Light
Simulates situations where light sources are designed to produce
uniform lighting throughout a scene.
Characterized by a scalar intensity, Ia , that is identical at every point
in the scene.
Ia =
Iar
Iag
Iab








Although every surface receives the same illumination, each
surface can reflect the light differently.
10
Point Sources
An ideal point source radiates equally in all directions. It can
be characterized by:
I(p0
) =
Ir (p0 )
Ig
(p0
)
Ib (p0 )








Intensity of illumination from a point source is proportional
to the inverse square of the distance between the point and the
illuminated surface.
I(p,p0 ) =
1
p−p0
2 I(p0 )
11
Light Sources
Types of light sources
- glLightfv(GL_LIGHT0,GL_POSITION,light[])
- directional/parallel lights
= real-life example: sun
= infinitely far source: homogeneous co-ord. w=0
- point lights
= same intensity in all directions
- spot lights
= limited set of directions:
point+direction+cutoff angle












0
z
y
x












1
z
y
x
12
Spotlights
Spotlights are point sources for which the angle through which
light has been emitted has been limited.
θ
l
s
I = k cose
(θ) = k(l⋅s)e
13
Distant Sources
Most shading calculations require the direction from the point on
a surface to the light source. As light sources are moved to
larger distances, this direction approaches a constant.
Therefore the point source location will be replaced by a vector
indicating the direction of the source.
p0
=
x
y
z
1












will be replaced by: p0
=
x
y
z
0












14
Reflection
Rough Surface:
Light is reflected equally in
all directions.
Diffuse
Smooth Surface:
Light is reflected at an angle
near to the incident angle.Specular
15
Vectors Used by
Phong Lighting Model
p is an arbitrary point on a surface.
n is the unit normal to the surface at p.
l is a unit vector in the direction of the light source.
r is a unit vector in the direction of a perfectly (specular)
reflection
v is a unit vector in the direction of the viewer.
n
l
r
v
p
Viewer
16
Elements of the Phong Lighting Model
Ri =
Rira Riga Riba
Rird Rigd Ribd
Rirs
Rigs
Ribs










At each point p there
is a reflection matrix for
the ith light source:
I = Ia
+ Id
+ Is
= La
Ra
+ Ld
Rd
+ Ls
Rs
Assuming the calculations will be done separately for
each primary, we can sum over light sources to get:
Li
=
Lira Liga Liba
Lird
Ligd
Libd
Lirs
Ligs
Libs










At each point p there
is an illumination matrix
from the ith light source:
red green blue
ambient
diffuse
specular
17
Elements of the Phong Lighting Model
Ambient Reflection
Ia
= ka
La
0 ≤ ka ≤1
The intensity of ambient light is the same at every point
on the surface. The percentage of light reflected is given
by: Ra
= ka
Note that the ambient reflection terms can be different
for red, green and blue.
18
Elements of the Phong Lighting Model
Diffuse Reflection
Intensity of illumination is dependent upon the incidence angle
of light from the source:
Adding a term for attenuation
with distance from source:
Id =
k d
a + bd + cd 2
( l ⋅ n ) L d
θ
l
n
Rd
∝ cosθ = l⋅n
Id
= kd
(l⋅n)Ld
19
Elements of the Phong Lighting Model
Specular Reflection
For a shiny surface, most light is reflected around vector r,
corresponding to a reflected angle equal to the angle of incidence.
If θ is the angle between v and r,
Is
= ks
Ls
cosα
θ
Adding a distance term, and expressing the cosine in terms of
a dot product:
Is =
1
a + bd + cd 2
k s L s (r ⋅ v )α
n
l
r
v
p
Viewer
20
The Complete Lighting Model
globalambglobalambm
aassdd
n
i
LkE
LkLkLk
cdbda
I
++
+⋅+⋅
++
= ∑
−
=
)])()((
1
[ 2
1
0
α
vrnl
Distance
(Attenuation)
Ambient
Diffuse Specular
Emission
Global
Ambient
n
l
r
v
p
Viewer





()
()
()
glMaterial
glLight
elglLightMod
k
L
E
21
Calculation of Normals
Normal exists at every point for mathematically defined smooth
surfaces.
Exists for each polygon in surface defined by flat polygons.
What about the shared lines/points?
Polygonal Case:
p0
p1
p2
n
n = (p1
− p0
) × (p2
− p0
)
22
Calculation of Normals
Mathematically Defined Surface: Sphere
Sphere is defined implicitly by equation:
f ( x, y, z) = x2
+ y2
+ z2
− 1 = 0
n =
∂f
∂x
∂f
∂y
∂f
∂z














=
2x
2y
2z








= 2p
23
Specification of the Normal in OpenGL
Specification of the current normal is modal and associated with
vertices.
glNormal3f(nx,ny,nz);
glNormal3fv(pointer_to_normal_vector);
You have to calculate the normals yourself.
24
Shading in OpenGL:
Flat Shading
OpenGL uses the normal of the first vertex of a single
polygon to determine the color.
Requested by: glShadeModel(GL_FLAT);
Flat shading exaggerates the visual effect of the
boundaries between polygons due to the Mach band
effect.
25
Mach Band Effect
(Mach, 1865)
Color Science, Concepts and Methods
Wyszecki, Stiles
26
Mach Band Effect
27
Mach Band Effect
28
Shading in OpenGL:
Smooth Shading
Requested by: glShadeModel(GL_SMOOTH);
Lighting calculations will be done at each vertex using the
material properties, and the vectors v and l calculated for that
vertex.
Bilinear interpolation is used to determine color values in the
interior of the polygon.
Gouraud Shading:
Normal at a vertex is the normalized average of the normals of
the polygons that share that vertex.
29
Gouraud Shading
30
Lighting Implementation in OpenGL
31
Lighted Sphere Demo and Source Code
32
Enable Depth Buffer
For Hidden Surface Removal
//before enabling
while (1) {
get_viewing_point_from_mouse_position();
glClear(GL_COLOR_BUFFER_BIT);
draw_3d_object_A();
draw_3d_object_B();
}
//after enabling
glutInitDisplayMode (GLUT_DEPTH | .... );
glEnable(GL_DEPTH_TEST); ...
while (1) {
glClear(GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT);
get_viewing_point_from_mouse_position();
draw_3d_object_A();
draw_3d_object_B();
}
33
Specifying Light Sources in OpenGL
General form: glLightf(source, parameter, value);
glLightfv(source, parameter, *array);
source is one of at least eight lights: GL_LIGHTi
Parameters:
GL_AMBIENT contains four values that specify the ambient RGBA
intensity of the light. Default is (0.0, 0.0, 0.0, 1.0).
GL_DIFFUSE contains four values that specify the diffuse RGBA
intensity of the light. Default is (1.0, 1.0, 1.0, 1.0).
GL_SPECULAR contains four values that specify the secular RGBA
intensity of the light. Default is (1.0, 1.0, 1.0, 1.0).
34
Specifying Light Sources in OpenGL
General form: glLightf(source, parameter, value);
glLightfv(source, parameter, *array);
GL_POSITION specifies the position of the light in homogeneous
object coordinates. If the w component is zero, the light
is treated as a directional source.
GL_SPOT_DIRECTION specifies the direction of the light in
homogeneous object coordinates. Default is (0.0, 0.0, -1.0)
GL_SPOT_EXPONENT spotlight exponent, default 0.0
GL_SPOT_CUTOFF spot cutoff angle in [0,90] or (default) 180.
θ
l
s
I = kcose
(θ) = k(l⋅s)e
35
Specifying Light Sources in OpenGL
General form: glLightf(source, parameter, value);
glLightfv(source, parameter, *array);
GL_CONSTANT_ATTENUATION constant atten. factor, default 1.0
GL_LINEAR_ATTENUATION linear atten. factor, default 0.0
GL_QUADRATIC_ATTENUATION quadratic atten. factor, default 0.0
Id =
k d
a + b d + c d 2
( l ⋅ n ) L d
n
l r
v
p
Viewer
36
Enabling the Lights and Lighting
Enabling a specific light source: glEnable(GL_LIGHTi );
Enabling the lighting model: glEnable (GL_LIGHTING);
37
Specifying Materials in OpenGL
General form: glMaterialf(face, parameter,value);
glMaterialfv(face, parameter,*array);
face is GL_FRONT, GL_BACK, GL_FRONT_AND_BACK
parameter is:
GL_AMBIENT four values that specify the ambient RGBA
reflectance of the material. (0.2,0.2,0.2,1.0)
GL_DIFFUSE four values that specify the diffuse RGBA
reflectance of the material. (0.8,0.8,0.8,1.0)
GL_SPECULAR four values that specify the ambient RGBA
reflectance of the material. (0.0,0.0,0.0,1.0)
GL_SHININESS specifies the specular reflectance
exponent of the material. 0.0
38
1. Ambient light in a
scene with 3 spheres.
2. Diffuse light
hitting the surface of
3 spheres. Notice,
the spheres look
matte and almost
plastic like.
3. The three
spheres illuminated
by specular light.
Imagine an
extremely shiny
billiard ball and the
sheen it creates
Types Of Light And Its Effects
39
By S.Vanitha, Chennai

More Related Content

What's hot

Image segmentation 3 morphology
Image segmentation 3 morphologyImage segmentation 3 morphology
Image segmentation 3 morphologyRumah Belajar
 
Green Custard Friday Talk 17: Ray Tracing
Green Custard Friday Talk 17: Ray TracingGreen Custard Friday Talk 17: Ray Tracing
Green Custard Friday Talk 17: Ray TracingGreen Custard
 
Note on Coupled Line Cameras for Rectangle Reconstruction (ACDDE 2012)
Note on Coupled Line Cameras for Rectangle Reconstruction (ACDDE 2012)Note on Coupled Line Cameras for Rectangle Reconstruction (ACDDE 2012)
Note on Coupled Line Cameras for Rectangle Reconstruction (ACDDE 2012)Joo-Haeng Lee
 
A Novel Methodology for Designing Linear Phase IIR Filters
A Novel Methodology for Designing Linear Phase IIR FiltersA Novel Methodology for Designing Linear Phase IIR Filters
A Novel Methodology for Designing Linear Phase IIR FiltersIDES Editor
 
Scale Invariant Feature Tranform
Scale Invariant Feature TranformScale Invariant Feature Tranform
Scale Invariant Feature TranformShanker Naik
 
Hidden Surface Removal using Z-buffer
Hidden Surface Removal using Z-bufferHidden Surface Removal using Z-buffer
Hidden Surface Removal using Z-bufferRaj Sikarwar
 
Beginning direct3d gameprogramming07_lightsandmaterials_20161117_jintaeks
Beginning direct3d gameprogramming07_lightsandmaterials_20161117_jintaeksBeginning direct3d gameprogramming07_lightsandmaterials_20161117_jintaeks
Beginning direct3d gameprogramming07_lightsandmaterials_20161117_jintaeksJinTaek Seo
 
Chapter 1 introduction (Image Processing)
Chapter 1 introduction (Image Processing)Chapter 1 introduction (Image Processing)
Chapter 1 introduction (Image Processing)Varun Ojha
 
Scale Invariant feature transform
Scale Invariant feature transformScale Invariant feature transform
Scale Invariant feature transformShanker Naik
 
A Comparative Study of Histogram Equalization Based Image Enhancement Techniq...
A Comparative Study of Histogram Equalization Based Image Enhancement Techniq...A Comparative Study of Histogram Equalization Based Image Enhancement Techniq...
A Comparative Study of Histogram Equalization Based Image Enhancement Techniq...Shahbaz Alam
 
3.point operation and histogram based image enhancement
3.point operation and histogram based image enhancement3.point operation and histogram based image enhancement
3.point operation and histogram based image enhancementmukesh bhardwaj
 
Chapter 9 morphological image processing
Chapter 9 morphological image processingChapter 9 morphological image processing
Chapter 9 morphological image processingasodariyabhavesh
 
Image enhancement using alpha rooting based hybrid technique
Image enhancement using alpha rooting based hybrid techniqueImage enhancement using alpha rooting based hybrid technique
Image enhancement using alpha rooting based hybrid techniqueRahul Yadav
 

What's hot (20)

Image segmentation
Image segmentationImage segmentation
Image segmentation
 
Lec14 eigenface and fisherface
Lec14 eigenface and fisherfaceLec14 eigenface and fisherface
Lec14 eigenface and fisherface
 
Image segmentation 3 morphology
Image segmentation 3 morphologyImage segmentation 3 morphology
Image segmentation 3 morphology
 
Green Custard Friday Talk 17: Ray Tracing
Green Custard Friday Talk 17: Ray TracingGreen Custard Friday Talk 17: Ray Tracing
Green Custard Friday Talk 17: Ray Tracing
 
Note on Coupled Line Cameras for Rectangle Reconstruction (ACDDE 2012)
Note on Coupled Line Cameras for Rectangle Reconstruction (ACDDE 2012)Note on Coupled Line Cameras for Rectangle Reconstruction (ACDDE 2012)
Note on Coupled Line Cameras for Rectangle Reconstruction (ACDDE 2012)
 
A Novel Methodology for Designing Linear Phase IIR Filters
A Novel Methodology for Designing Linear Phase IIR FiltersA Novel Methodology for Designing Linear Phase IIR Filters
A Novel Methodology for Designing Linear Phase IIR Filters
 
Dip3
Dip3Dip3
Dip3
 
Scale Invariant Feature Tranform
Scale Invariant Feature TranformScale Invariant Feature Tranform
Scale Invariant Feature Tranform
 
Feature Extraction
Feature ExtractionFeature Extraction
Feature Extraction
 
Hidden Surface Removal using Z-buffer
Hidden Surface Removal using Z-bufferHidden Surface Removal using Z-buffer
Hidden Surface Removal using Z-buffer
 
Beginning direct3d gameprogramming07_lightsandmaterials_20161117_jintaeks
Beginning direct3d gameprogramming07_lightsandmaterials_20161117_jintaeksBeginning direct3d gameprogramming07_lightsandmaterials_20161117_jintaeks
Beginning direct3d gameprogramming07_lightsandmaterials_20161117_jintaeks
 
Chapter 1 introduction (Image Processing)
Chapter 1 introduction (Image Processing)Chapter 1 introduction (Image Processing)
Chapter 1 introduction (Image Processing)
 
Scale Invariant feature transform
Scale Invariant feature transformScale Invariant feature transform
Scale Invariant feature transform
 
Point Processing
Point ProcessingPoint Processing
Point Processing
 
point operations in image processing
point operations in image processingpoint operations in image processing
point operations in image processing
 
A Comparative Study of Histogram Equalization Based Image Enhancement Techniq...
A Comparative Study of Histogram Equalization Based Image Enhancement Techniq...A Comparative Study of Histogram Equalization Based Image Enhancement Techniq...
A Comparative Study of Histogram Equalization Based Image Enhancement Techniq...
 
point processing
point processingpoint processing
point processing
 
3.point operation and histogram based image enhancement
3.point operation and histogram based image enhancement3.point operation and histogram based image enhancement
3.point operation and histogram based image enhancement
 
Chapter 9 morphological image processing
Chapter 9 morphological image processingChapter 9 morphological image processing
Chapter 9 morphological image processing
 
Image enhancement using alpha rooting based hybrid technique
Image enhancement using alpha rooting based hybrid techniqueImage enhancement using alpha rooting based hybrid technique
Image enhancement using alpha rooting based hybrid technique
 

Similar to Light effect

Phong Shading over any Polygonal Surface
Phong Shading over any Polygonal Surface Phong Shading over any Polygonal Surface
Phong Shading over any Polygonal Surface Bhuvnesh Pratap
 
Illumination model
Illumination modelIllumination model
Illumination modelAnkur Kumar
 
illumination model in Computer Graphics by irru pychukar
illumination model in Computer Graphics by irru pychukarillumination model in Computer Graphics by irru pychukar
illumination model in Computer Graphics by irru pychukarsyedArr
 
Computer Vision: Shape from Specularities and Motion
Computer Vision: Shape from Specularities and MotionComputer Vision: Shape from Specularities and Motion
Computer Vision: Shape from Specularities and MotionDamian T. Gordon
 
UNIT-6-Illumination-Models-and-Surface-Rendering-Methods.pdf
UNIT-6-Illumination-Models-and-Surface-Rendering-Methods.pdfUNIT-6-Illumination-Models-and-Surface-Rendering-Methods.pdf
UNIT-6-Illumination-Models-and-Surface-Rendering-Methods.pdfSayantanMajhi2
 
7 illumination and-shading computer graphics
7 illumination and-shading computer graphics7 illumination and-shading computer graphics
7 illumination and-shading computer graphicscairo university
 
APPLICATIONS OF MULTIPLE INTEGRALS.pdf
APPLICATIONS OF MULTIPLE INTEGRALS.pdfAPPLICATIONS OF MULTIPLE INTEGRALS.pdf
APPLICATIONS OF MULTIPLE INTEGRALS.pdfnissyjessilyn
 
Calibrating Lighting and Materials in Far Cry 3
Calibrating Lighting and Materials in Far Cry 3Calibrating Lighting and Materials in Far Cry 3
Calibrating Lighting and Materials in Far Cry 3stevemcauley
 
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeksBeginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeksJinTaek Seo
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyappasami
 
Interactive Volumetric Lighting Simulating Scattering and Shadowing
Interactive Volumetric Lighting Simulating Scattering and ShadowingInteractive Volumetric Lighting Simulating Scattering and Shadowing
Interactive Volumetric Lighting Simulating Scattering and ShadowingMarc Sunet
 
Lighting and shading
Lighting and shadingLighting and shading
Lighting and shadingeshveeen
 
Lec_2_Digital Image Fundamentals.pdf
Lec_2_Digital Image Fundamentals.pdfLec_2_Digital Image Fundamentals.pdf
Lec_2_Digital Image Fundamentals.pdfnagwaAboElenein
 

Similar to Light effect (20)

Phong Shading over any Polygonal Surface
Phong Shading over any Polygonal Surface Phong Shading over any Polygonal Surface
Phong Shading over any Polygonal Surface
 
graphics notes
graphics notesgraphics notes
graphics notes
 
Illumination model
Illumination modelIllumination model
Illumination model
 
illumination model in Computer Graphics by irru pychukar
illumination model in Computer Graphics by irru pychukarillumination model in Computer Graphics by irru pychukar
illumination model in Computer Graphics by irru pychukar
 
Shading methods
Shading methodsShading methods
Shading methods
 
Computer Vision: Shape from Specularities and Motion
Computer Vision: Shape from Specularities and MotionComputer Vision: Shape from Specularities and Motion
Computer Vision: Shape from Specularities and Motion
 
Pycon openlcdfdm
Pycon openlcdfdmPycon openlcdfdm
Pycon openlcdfdm
 
UNIT-6-Illumination-Models-and-Surface-Rendering-Methods.pdf
UNIT-6-Illumination-Models-and-Surface-Rendering-Methods.pdfUNIT-6-Illumination-Models-and-Surface-Rendering-Methods.pdf
UNIT-6-Illumination-Models-and-Surface-Rendering-Methods.pdf
 
7 illumination and-shading computer graphics
7 illumination and-shading computer graphics7 illumination and-shading computer graphics
7 illumination and-shading computer graphics
 
Lighting and shading
Lighting and shadingLighting and shading
Lighting and shading
 
APPLICATIONS OF MULTIPLE INTEGRALS.pdf
APPLICATIONS OF MULTIPLE INTEGRALS.pdfAPPLICATIONS OF MULTIPLE INTEGRALS.pdf
APPLICATIONS OF MULTIPLE INTEGRALS.pdf
 
Calibrating Lighting and Materials in Far Cry 3
Calibrating Lighting and Materials in Far Cry 3Calibrating Lighting and Materials in Far Cry 3
Calibrating Lighting and Materials in Far Cry 3
 
Shading
ShadingShading
Shading
 
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeksBeginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
 
10illumination
10illumination10illumination
10illumination
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer key
 
Interactive Volumetric Lighting Simulating Scattering and Shadowing
Interactive Volumetric Lighting Simulating Scattering and ShadowingInteractive Volumetric Lighting Simulating Scattering and Shadowing
Interactive Volumetric Lighting Simulating Scattering and Shadowing
 
PolygonalAreaLights_09081016
PolygonalAreaLights_09081016PolygonalAreaLights_09081016
PolygonalAreaLights_09081016
 
Lighting and shading
Lighting and shadingLighting and shading
Lighting and shading
 
Lec_2_Digital Image Fundamentals.pdf
Lec_2_Digital Image Fundamentals.pdfLec_2_Digital Image Fundamentals.pdf
Lec_2_Digital Image Fundamentals.pdf
 

More from Vanitha Chandru

Computer Oragnization Flipflops
Computer Oragnization FlipflopsComputer Oragnization Flipflops
Computer Oragnization FlipflopsVanitha Chandru
 
COMPUTER ORGANIZATION -Multiplexer,Demultiplexer, Encoder
COMPUTER ORGANIZATION -Multiplexer,Demultiplexer, EncoderCOMPUTER ORGANIZATION -Multiplexer,Demultiplexer, Encoder
COMPUTER ORGANIZATION -Multiplexer,Demultiplexer, EncoderVanitha Chandru
 
COMPUTER ORGANIZATION - Logic gates, Boolean Algebra, Combinational Circuits
COMPUTER ORGANIZATION - Logic gates, Boolean Algebra, Combinational CircuitsCOMPUTER ORGANIZATION - Logic gates, Boolean Algebra, Combinational Circuits
COMPUTER ORGANIZATION - Logic gates, Boolean Algebra, Combinational CircuitsVanitha Chandru
 
Text-Elements of multimedia
Text-Elements of multimediaText-Elements of multimedia
Text-Elements of multimediaVanitha Chandru
 
Swami Vivekananda's Quotes
Swami Vivekananda's QuotesSwami Vivekananda's Quotes
Swami Vivekananda's QuotesVanitha Chandru
 

More from Vanitha Chandru (10)

Karnaugh map
Karnaugh mapKarnaugh map
Karnaugh map
 
Binary tree
Binary  treeBinary  tree
Binary tree
 
Shift Register
Shift RegisterShift Register
Shift Register
 
Computer Oragnization Flipflops
Computer Oragnization FlipflopsComputer Oragnization Flipflops
Computer Oragnization Flipflops
 
COMPUTER ORGANIZATION -Multiplexer,Demultiplexer, Encoder
COMPUTER ORGANIZATION -Multiplexer,Demultiplexer, EncoderCOMPUTER ORGANIZATION -Multiplexer,Demultiplexer, Encoder
COMPUTER ORGANIZATION -Multiplexer,Demultiplexer, Encoder
 
COMPUTER ORGANIZATION - Logic gates, Boolean Algebra, Combinational Circuits
COMPUTER ORGANIZATION - Logic gates, Boolean Algebra, Combinational CircuitsCOMPUTER ORGANIZATION - Logic gates, Boolean Algebra, Combinational Circuits
COMPUTER ORGANIZATION - Logic gates, Boolean Algebra, Combinational Circuits
 
Text-Elements of multimedia
Text-Elements of multimediaText-Elements of multimedia
Text-Elements of multimedia
 
Alexander the Great
Alexander the GreatAlexander the Great
Alexander the Great
 
Swami Vivekananda's Quotes
Swami Vivekananda's QuotesSwami Vivekananda's Quotes
Swami Vivekananda's Quotes
 
Customers
CustomersCustomers
Customers
 

Recently uploaded

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Recently uploaded (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 

Light effect

  • 1. 1 Computer Graphics for Scientists and Engineers Lighting in OpenGL
  • 2. 2 Graphics: Conceptual Model Real Object Real Object Human Eye Human Eye Display Device Graphics System Synthetic Model Synthetic Camera Real Light Synthetic Light Source
  • 3. 3 Lights, Surfaces, and Imaging Proj. Plane Viewer Objects
  • 4. 4 Lights, Surfaces, and Imaging Proj. Plane Viewer Light Source Objects
  • 5. 5 Modes of Interaction of Light with Materials Specular Surface Diffuse Surface Translucent Surface Note: Any given surface can have some of all three properties.
  • 6. 6 Illuminating Surfaces z x y I(θ,φ,λ) I(x, y,z,θ,φ,λ)We can define illumination function: To obtain total light, must integrate over total surface. Itotal (λ) = I(x,y,z,θ,φ,λ)∫∫∫ dxdydz
  • 7. 7 Simplified Model Exact model can easily get complicated! Three simplifications help. 1. We can consider four classes of light sources • ambient • point • spotlight • distant 2. Human color perception allows us to consider illumination function in terms of the three primary colors. 3. We can neglect (OpenGL caveats): • multiple reflections • obstruction of light path by objects
  • 8. 8 Light Sources Ambient light - no identifiable source or direction - hack for replacing true global illumination = (light bouncing off from other objects)
  • 9. 9 Ambient Light Simulates situations where light sources are designed to produce uniform lighting throughout a scene. Characterized by a scalar intensity, Ia , that is identical at every point in the scene. Ia = Iar Iag Iab         Although every surface receives the same illumination, each surface can reflect the light differently.
  • 10. 10 Point Sources An ideal point source radiates equally in all directions. It can be characterized by: I(p0 ) = Ir (p0 ) Ig (p0 ) Ib (p0 )         Intensity of illumination from a point source is proportional to the inverse square of the distance between the point and the illuminated surface. I(p,p0 ) = 1 p−p0 2 I(p0 )
  • 11. 11 Light Sources Types of light sources - glLightfv(GL_LIGHT0,GL_POSITION,light[]) - directional/parallel lights = real-life example: sun = infinitely far source: homogeneous co-ord. w=0 - point lights = same intensity in all directions - spot lights = limited set of directions: point+direction+cutoff angle             0 z y x             1 z y x
  • 12. 12 Spotlights Spotlights are point sources for which the angle through which light has been emitted has been limited. θ l s I = k cose (θ) = k(l⋅s)e
  • 13. 13 Distant Sources Most shading calculations require the direction from the point on a surface to the light source. As light sources are moved to larger distances, this direction approaches a constant. Therefore the point source location will be replaced by a vector indicating the direction of the source. p0 = x y z 1             will be replaced by: p0 = x y z 0            
  • 14. 14 Reflection Rough Surface: Light is reflected equally in all directions. Diffuse Smooth Surface: Light is reflected at an angle near to the incident angle.Specular
  • 15. 15 Vectors Used by Phong Lighting Model p is an arbitrary point on a surface. n is the unit normal to the surface at p. l is a unit vector in the direction of the light source. r is a unit vector in the direction of a perfectly (specular) reflection v is a unit vector in the direction of the viewer. n l r v p Viewer
  • 16. 16 Elements of the Phong Lighting Model Ri = Rira Riga Riba Rird Rigd Ribd Rirs Rigs Ribs           At each point p there is a reflection matrix for the ith light source: I = Ia + Id + Is = La Ra + Ld Rd + Ls Rs Assuming the calculations will be done separately for each primary, we can sum over light sources to get: Li = Lira Liga Liba Lird Ligd Libd Lirs Ligs Libs           At each point p there is an illumination matrix from the ith light source: red green blue ambient diffuse specular
  • 17. 17 Elements of the Phong Lighting Model Ambient Reflection Ia = ka La 0 ≤ ka ≤1 The intensity of ambient light is the same at every point on the surface. The percentage of light reflected is given by: Ra = ka Note that the ambient reflection terms can be different for red, green and blue.
  • 18. 18 Elements of the Phong Lighting Model Diffuse Reflection Intensity of illumination is dependent upon the incidence angle of light from the source: Adding a term for attenuation with distance from source: Id = k d a + bd + cd 2 ( l ⋅ n ) L d θ l n Rd ∝ cosθ = l⋅n Id = kd (l⋅n)Ld
  • 19. 19 Elements of the Phong Lighting Model Specular Reflection For a shiny surface, most light is reflected around vector r, corresponding to a reflected angle equal to the angle of incidence. If θ is the angle between v and r, Is = ks Ls cosα θ Adding a distance term, and expressing the cosine in terms of a dot product: Is = 1 a + bd + cd 2 k s L s (r ⋅ v )α n l r v p Viewer
  • 20. 20 The Complete Lighting Model globalambglobalambm aassdd n i LkE LkLkLk cdbda I ++ +⋅+⋅ ++ = ∑ − = )])()(( 1 [ 2 1 0 α vrnl Distance (Attenuation) Ambient Diffuse Specular Emission Global Ambient n l r v p Viewer      () () () glMaterial glLight elglLightMod k L E
  • 21. 21 Calculation of Normals Normal exists at every point for mathematically defined smooth surfaces. Exists for each polygon in surface defined by flat polygons. What about the shared lines/points? Polygonal Case: p0 p1 p2 n n = (p1 − p0 ) × (p2 − p0 )
  • 22. 22 Calculation of Normals Mathematically Defined Surface: Sphere Sphere is defined implicitly by equation: f ( x, y, z) = x2 + y2 + z2 − 1 = 0 n = ∂f ∂x ∂f ∂y ∂f ∂z               = 2x 2y 2z         = 2p
  • 23. 23 Specification of the Normal in OpenGL Specification of the current normal is modal and associated with vertices. glNormal3f(nx,ny,nz); glNormal3fv(pointer_to_normal_vector); You have to calculate the normals yourself.
  • 24. 24 Shading in OpenGL: Flat Shading OpenGL uses the normal of the first vertex of a single polygon to determine the color. Requested by: glShadeModel(GL_FLAT); Flat shading exaggerates the visual effect of the boundaries between polygons due to the Mach band effect.
  • 25. 25 Mach Band Effect (Mach, 1865) Color Science, Concepts and Methods Wyszecki, Stiles
  • 28. 28 Shading in OpenGL: Smooth Shading Requested by: glShadeModel(GL_SMOOTH); Lighting calculations will be done at each vertex using the material properties, and the vectors v and l calculated for that vertex. Bilinear interpolation is used to determine color values in the interior of the polygon. Gouraud Shading: Normal at a vertex is the normalized average of the normals of the polygons that share that vertex.
  • 31. 31 Lighted Sphere Demo and Source Code
  • 32. 32 Enable Depth Buffer For Hidden Surface Removal //before enabling while (1) { get_viewing_point_from_mouse_position(); glClear(GL_COLOR_BUFFER_BIT); draw_3d_object_A(); draw_3d_object_B(); } //after enabling glutInitDisplayMode (GLUT_DEPTH | .... ); glEnable(GL_DEPTH_TEST); ... while (1) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); get_viewing_point_from_mouse_position(); draw_3d_object_A(); draw_3d_object_B(); }
  • 33. 33 Specifying Light Sources in OpenGL General form: glLightf(source, parameter, value); glLightfv(source, parameter, *array); source is one of at least eight lights: GL_LIGHTi Parameters: GL_AMBIENT contains four values that specify the ambient RGBA intensity of the light. Default is (0.0, 0.0, 0.0, 1.0). GL_DIFFUSE contains four values that specify the diffuse RGBA intensity of the light. Default is (1.0, 1.0, 1.0, 1.0). GL_SPECULAR contains four values that specify the secular RGBA intensity of the light. Default is (1.0, 1.0, 1.0, 1.0).
  • 34. 34 Specifying Light Sources in OpenGL General form: glLightf(source, parameter, value); glLightfv(source, parameter, *array); GL_POSITION specifies the position of the light in homogeneous object coordinates. If the w component is zero, the light is treated as a directional source. GL_SPOT_DIRECTION specifies the direction of the light in homogeneous object coordinates. Default is (0.0, 0.0, -1.0) GL_SPOT_EXPONENT spotlight exponent, default 0.0 GL_SPOT_CUTOFF spot cutoff angle in [0,90] or (default) 180. θ l s I = kcose (θ) = k(l⋅s)e
  • 35. 35 Specifying Light Sources in OpenGL General form: glLightf(source, parameter, value); glLightfv(source, parameter, *array); GL_CONSTANT_ATTENUATION constant atten. factor, default 1.0 GL_LINEAR_ATTENUATION linear atten. factor, default 0.0 GL_QUADRATIC_ATTENUATION quadratic atten. factor, default 0.0 Id = k d a + b d + c d 2 ( l ⋅ n ) L d n l r v p Viewer
  • 36. 36 Enabling the Lights and Lighting Enabling a specific light source: glEnable(GL_LIGHTi ); Enabling the lighting model: glEnable (GL_LIGHTING);
  • 37. 37 Specifying Materials in OpenGL General form: glMaterialf(face, parameter,value); glMaterialfv(face, parameter,*array); face is GL_FRONT, GL_BACK, GL_FRONT_AND_BACK parameter is: GL_AMBIENT four values that specify the ambient RGBA reflectance of the material. (0.2,0.2,0.2,1.0) GL_DIFFUSE four values that specify the diffuse RGBA reflectance of the material. (0.8,0.8,0.8,1.0) GL_SPECULAR four values that specify the ambient RGBA reflectance of the material. (0.0,0.0,0.0,1.0) GL_SHININESS specifies the specular reflectance exponent of the material. 0.0
  • 38. 38 1. Ambient light in a scene with 3 spheres. 2. Diffuse light hitting the surface of 3 spheres. Notice, the spheres look matte and almost plastic like. 3. The three spheres illuminated by specular light. Imagine an extremely shiny billiard ball and the sheen it creates Types Of Light And Its Effects