SlideShare a Scribd company logo
1 of 44
CAP4730: Computational
Structures in Computer Graphics
Lighting and Shading
Outline
•Lighting
•Lighting models
•Ambient
•Diffuse
•Specular
•Surface Rendering Methods
•Ray-Tracing
What we know
• We already know how to render the world
from a viewpoint.
“Lighting”
• Two components:
– Lighting Model or
Shading Model - how
we calculate the intensity
at a point on the surface
– Surface Rendering
Method - How we
calculate the intensity at
each pixel
Jargon
• Illumination - the transport of light from a
source to a point via direct and indirect paths
• Lighting - computing the luminous intensity
for a specified 3D point, given a viewpoint
• Shading - assigning colors to pixels
• Illumination Models:
– Empirical - approximations to observed
light properties
– Physically based - applying physics
properties of light and its interactions with
matter
The lighting problem…
• What are we trying to
solve?
• Global illumination – the
transport of light within a
scene.
• What factors play a part in
how an object is “lit”?
• Let’s examine different
items here…
Two components
• Light Source Properties
– Color (Wavelength(s) of light)
– Shape
– Direction
• Object Properties
– Material
– Geometry
– Absorption
Light Source Properties
• Color
– We usually assume the light has
one wavelength
• Shape
– point light source - approximate
the light source as a 3D point in
space. Light rays emanate in all
directions.
• good for small light sources
(compared to the scene)
• far away light sources
Distributed Lights
• Light Source Shape continued
– distributed light source - approximating the light source
as a 3D object. Light rays usually emanate in specific
directions
• good for larger light sources
• area light sources
Light Source Direction
• In computer graphics, we usually treat
lights as rays emanating from a source. The
direction of these rays can either be:
– Omni-directional (point light source)
– Directional (spotlights)
Light Position
• We can specify the position of a light one of
two ways, with an x, y, and z coordinate.
– What are some examples?
– These lights are called positional lights
• Q: Are there types of lights that we can
simplify?
A: Yep! Think about the sun. If a light is significantly far
away, we can represent the light with only a direction vector.
These are called directional lights. How does this help?
Contributions from lights
• We will breakdown what a light does to an
object into three different components.
This APPROXIMATES what a light does.
To actually compute the rays is too
expensive to do in real-time.
– Light at a pixel from a light = Ambient +
Diffuse + Specular contributions.
– Ilight= Iambient + Idiffuse + Ispecular
Ambient Term - Background Light
• The ambient term is a HACK!
• It represents the approximate
contribution of the light to the
general scene, regardless of
location of light and object
• Indirect reflections that are too
complex to completely and
accurately compute
• Iambient = color
Diffuse Term
• Contribution that a light has on the
surface, regardless of viewing
direction.
• Diffuse surfaces, on a microscopic
level, are very rough. This means
that a ray of light coming in has an
equal chance of being reflected in
any direction.
• What are some ideal diffuse
surfaces?
Lambert’s Cosine Law
• Diffuse surfaces follow Lambert’s Cosine Law
• Lambert’s Cosine Law - reflected energy from a small
surface area in a particular direction is proportional to
the cosine of the angle between that direction and the
surface normal.
• Think about surface area and # of rays
Diffuse Term
• To determine how much of a diffuse contribution
a light supplies to the surface, we need the surface
normal and the direction on the incoming ray
• What is the angle between these two vectors?
• Idiffuse = kdIlightcosθ = kdIlight(N . L)
• Ilight = diffuse (intensity) of light
• kd [0..1] = surface diffuse reflectivity
• What CS are L and N in?
• How expensive is it?
Example
• What are the possible values for theta (and
thus the dot product?)
http://graphics.lcs.mit.edu/classes/6.837/F98/
Lecture18/Slide11.html
Specular Reflection
• Specular contribution can be thought of as
the “shiny highlight” of a plastic object.
• On a microscopic level, the surface is very
smooth. Almost all light is reflected.
• What is an ideal purely specular reflector?
• What does this term depend on?
Viewing Direction
Normal of the Surface
Snell’s Law
• Specular reflection applies Snell’s Law.
• The incoming ray, the surface normal, and
the reflected ray all lie in a common
plane.
• The angle that the reflected ray forms
with the surface normal is determined by
the angle that the incoming ray forms with
the surface normal, and the relative speeds
of light of the mediums in which the
incident and reflected rays propagate
according to:
• We assume θl = θr
Snell’s Law is for IDEAL surfaces
• Think about the amount of light reflected at
different angles.
N
L
R
Vθ
Different for shiny vs. dull objects
Snell’s Law is for IDEAL surfaces
• Think about the amount of light reflected at
different angles.
N
L
R
Vθ θ
φ
Phong Model
Phong Reflection Model
• An approximation is sets the intensity of specular
reflection proportional to (cos φ)shininess
• What are the possible values of cos φ?
• What does the value of shininess mean?
• How do we represent shinny or dull surfaces using
the Phong model?
• What is the real thing we probably SHOULD do?
• Ispecular = ksIlight(cos φ)shininess
= ksIlight(V.R)shininess
Effect of the shininess value
How do we compute R?
• N*(N.L)
• R+L=2N(N.L)
• R = 2N(N.L)-L N
L
R
Vθ
N(N.L)
φ
L
Simplify this
• Instead of R, we
compute halfway
between L and V.
• We call this vector the
halfway vector, H. N
L
R
Vθ
φ
( )shininess
yspecularitlightsspecular HNIkI
VL
VL
H
⋅=
+
+
=
_
H
Let’s compare the two
( )
( )shininess
yspecularitlightsspecular
shininess
yspecularitlightsspecular
HNIkI
VL
VL
H
RVIkI
LLNNR
⋅=
+
+
=
⋅=
−⋅=
_
_
)(2
N
L
R
Vθ
φ
H
Q: Which vectors stay
constant when viewpoint
is far away?
A: V and L vectors -> H
Q: What does this buy us?
Combining the terms
• Ambient - the combination of light reflections
from various surfaces to produce a uniform
illumination. Background light.
• Diffuse - uniform light scattering of light rays on a
surface. Proportional to the “amount of light” that
hits the surface. Depends on the surface normal
and light vector.
• Sepecular - light that gets reflected. Depends on
the light ray, the viewing angle, and the surface
normal.
Ambient + Diffuse + Specular
Lighting Equation
Ilambient = light source l’s ambient component
Ildiffuse = light source l’s diffuse component
Ilspecular = light source l’s specular component
kambient = surface material ambient reflectivity
kdiffuse = surface material diffuse reflectivity
kspecular = surface material specular reflectivity
shininess = specular reflection parameter (1 -> dull, 100+ -> very shiny)
( ) ( )
( ) ( )∑
−
=
⋅+⋅+=
⋅+⋅+=
1
0
lights
l
shininess
specularldiffuselambientlfinal
shininess
specularspeculardiffusediffuseambientambientfinal
HNkILNkIkII
HNkILNkIkII
speculardiffuseambient
N
L
R
Vθ
Clamping & Spotlights
• What does the value Ifinal mean?
• How do we make sure it doesn’t
get too high?
• Spotlights? How do them?
( ) ( )
( ) ( )∑
−
=
⋅+⋅+=
⋅+⋅+=
1
0
lights
l
shininess
specularldiffuselambientlfinal
shininess
specularspeculardiffusediffuseambientambientfinal
HNkILNkIkII
HNkILNkIkII
speculardiffuseambient
N
L
R
Vθ
How would we light a green
cube?
( ) ( )
( ) ( )∑
−
=
⋅+⋅+=
⋅+⋅+=
1
0
lights
l
shininess
specularldiffuselambientlfinal
shininess
specularspeculardiffusediffuseambientambientfinal
HNkILNkIkII
HNkILNkIkII
speculardiffuseambient
N
L
R
Vθ
Attenuation
• One factor we have yet to take into account
is that a light source contributes a higher
incident intensity to closer surfaces.
• The energy from a point light source falls
off proportional to 1/d2
.
• What happens if we don’t do this?
What would attenuation do for:
• Actually, using only 1/d2
, makes it
difficult to correctly light things.
Think if d=1 and d=2. Why?
• Remember, we are approximating
things. Lighting model is too
simple AND most lights are not
point sources.
• We use:
( ) 2
210
1
dadaa
df
++
=
Subtleties
• What’s wrong with:
( ) 2
210
1
dadaa
df
++
=
What’s a good fix?
( ) 





++
= 2
210
1
,1min
dadaa
df
Full Illumination Model
( ) 





++
= 2
210
1
,1min
dadaa
df
( ) ( ) ( )[ ]∑
−
=
⋅+⋅+=
1
0
lights
l
shininess
specularldiffusellambientlfinal HNkILNkIdfkII speculardiffuseambient
Run demo
Putting Lights in OpenGL
• 1. glEnable(GL_LIGHTING);
• 2. Set up Light properties
– glLightf(…)
• 3. Set up Material properties
– glMaterial(…)
Shading
• When do we do the lighting equation?
• What is the cost to compute the lighting for
a 3D point?
( ) ( ) ( )[ ]∑
−
=
⋅+⋅+=
1
0
lights
l
shininess
specularldiffusellambientlfinal HNkILNkIdfkII speculardiffuseambient
Shading
• Shading is how we “color” a triangle.
• Constant Shading
• Gouraud Shading
• Phong Shading
Constant Shading
• Constant Intensity or Flat Shading
• One color for the entire triangle
• Fast
• Good for some objects
• What happens if triangles are small?
• Sudden intensity changes at borders
Gouraud Shading
• Intensity Interpolation Shading
• Calculate lighting at the vertices. Then interpolate
the colors as you scan convert
Gouraud Shading
• Relatively fast, only do three calculations
• No sudden intensity changes
• What can it not do?
• What are some approaches to fix this?
• Question, what is the normal at a vertex?
Phong Shading
• Interpolate the normal, since that is the
information that represents the
“curvature”
• Linearly interpolate the vertex
normals. For each pixel, as you scan
convert, calculate the lighting per
pixel.
• True “per pixel” lighting
• Not done by most
hardware/libraries/etc
Shading Techniques
• Constant Shading
– Calculate one lighting calculation (pick a vertex) per triangle
– Color the entire triangle the same color
• Gouraud Shading
– Calculate three lighting calculations (the vertices) per triangle
– Linearly interpolate the colors as you scan convert
• Phong Shading
– While you scan convert, linearly interpolate the normals.
– With the interpolated normal at each pixel, calculate the lighting at
each pixel

More Related Content

What's hot (20)

Image segmentation
Image segmentationImage segmentation
Image segmentation
 
Ray Tracing in Computer Graphics
Ray Tracing in Computer GraphicsRay Tracing in Computer Graphics
Ray Tracing in Computer Graphics
 
Texture mapping
Texture mapping Texture mapping
Texture mapping
 
IMAGE SEGMENTATION.
IMAGE SEGMENTATION.IMAGE SEGMENTATION.
IMAGE SEGMENTATION.
 
hidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithmhidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithm
 
fractals
fractalsfractals
fractals
 
3D Display Method
3D Display Method3D Display Method
3D Display Method
 
Illumination Models & Shading
Illumination Models & ShadingIllumination Models & Shading
Illumination Models & Shading
 
Hit and-miss transform
Hit and-miss transformHit and-miss transform
Hit and-miss transform
 
Image Filtering in the Frequency Domain
Image Filtering in the Frequency DomainImage Filtering in the Frequency Domain
Image Filtering in the Frequency Domain
 
Ray tracing
Ray tracingRay tracing
Ray tracing
 
Depth Buffer Method
Depth Buffer MethodDepth Buffer Method
Depth Buffer Method
 
Chapter 5 Image Processing: Fourier Transformation
Chapter 5 Image Processing: Fourier TransformationChapter 5 Image Processing: Fourier Transformation
Chapter 5 Image Processing: Fourier Transformation
 
Illumination Model
Illumination ModelIllumination Model
Illumination Model
 
Ray tracing
 Ray tracing Ray tracing
Ray tracing
 
Content Based Image Retrieval
Content Based Image Retrieval Content Based Image Retrieval
Content Based Image Retrieval
 
3 d display methods
3 d display methods3 d display methods
3 d display methods
 
Polygons - Computer Graphics - Notes
Polygons - Computer Graphics - NotesPolygons - Computer Graphics - Notes
Polygons - Computer Graphics - Notes
 
Image enhancement
Image enhancementImage enhancement
Image enhancement
 
Image Enhancement in Spatial Domain
Image Enhancement in Spatial DomainImage Enhancement in Spatial Domain
Image Enhancement in Spatial Domain
 

Viewers also liked

Lighting and shading
Lighting and shadingLighting and shading
Lighting and shadingeshveeen
 
03 Shading
03 Shading03 Shading
03 Shadingnjoubert
 
computer graphics
computer graphicscomputer graphics
computer graphicsashpri156
 
Future Trends - Lecture 12 - Web Information Systems (4011474FNR)
Future Trends - Lecture 12 - Web Information Systems (4011474FNR)Future Trends - Lecture 12 - Web Information Systems (4011474FNR)
Future Trends - Lecture 12 - Web Information Systems (4011474FNR)Beat Signer
 
Ten Worst Insurance Companies
Ten Worst Insurance CompaniesTen Worst Insurance Companies
Ten Worst Insurance CompaniesTom Gartner
 
Shading for Computer Topics in Burapha University
Shading for Computer Topics in Burapha UniversityShading for Computer Topics in Burapha University
Shading for Computer Topics in Burapha UniversityMao Sararith
 
GRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and RadiosityGRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and RadiosityMichael Heron
 
Halftone QR Codes
Halftone QR CodesHalftone QR Codes
Halftone QR Codes小蜜 許
 
Southwest Airlines Portfolio
Southwest Airlines PortfolioSouthwest Airlines Portfolio
Southwest Airlines PortfolioAmber Berlin
 
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
 
Shading and two type of shading flat shading and gauraud shading with coding ...
Shading and two type of shading flat shading and gauraud shading with coding ...Shading and two type of shading flat shading and gauraud shading with coding ...
Shading and two type of shading flat shading and gauraud shading with coding ...Adil Mehmoood
 
Hidden Surface Removal using Z-buffer
Hidden Surface Removal using Z-bufferHidden Surface Removal using Z-buffer
Hidden Surface Removal using Z-bufferRaj Sikarwar
 
Hidden lines & surfaces
Hidden lines & surfacesHidden lines & surfaces
Hidden lines & surfacesAnkur Kumar
 

Viewers also liked (20)

Shading
ShadingShading
Shading
 
Lighting and shading
Lighting and shadingLighting and shading
Lighting and shading
 
Ray tracing
Ray tracingRay tracing
Ray tracing
 
03 Shading
03 Shading03 Shading
03 Shading
 
Texture Synthesis
Texture SynthesisTexture Synthesis
Texture Synthesis
 
computer graphics
computer graphicscomputer graphics
computer graphics
 
Future Trends - Lecture 12 - Web Information Systems (4011474FNR)
Future Trends - Lecture 12 - Web Information Systems (4011474FNR)Future Trends - Lecture 12 - Web Information Systems (4011474FNR)
Future Trends - Lecture 12 - Web Information Systems (4011474FNR)
 
CS 354 Lighting
CS 354 LightingCS 354 Lighting
CS 354 Lighting
 
Ten Worst Insurance Companies
Ten Worst Insurance CompaniesTen Worst Insurance Companies
Ten Worst Insurance Companies
 
Ray tracing
Ray tracingRay tracing
Ray tracing
 
Shading for Computer Topics in Burapha University
Shading for Computer Topics in Burapha UniversityShading for Computer Topics in Burapha University
Shading for Computer Topics in Burapha University
 
GRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and RadiosityGRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and Radiosity
 
Halftone QR Codes
Halftone QR CodesHalftone QR Codes
Halftone QR Codes
 
Southwest Airlines Portfolio
Southwest Airlines PortfolioSouthwest Airlines Portfolio
Southwest Airlines Portfolio
 
Phong Shading over any Polygonal Surface
Phong Shading over any Polygonal Surface Phong Shading over any Polygonal Surface
Phong Shading over any Polygonal Surface
 
Shading and two type of shading flat shading and gauraud shading with coding ...
Shading and two type of shading flat shading and gauraud shading with coding ...Shading and two type of shading flat shading and gauraud shading with coding ...
Shading and two type of shading flat shading and gauraud shading with coding ...
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Hidden Surface Removal using Z-buffer
Hidden Surface Removal using Z-bufferHidden Surface Removal using Z-buffer
Hidden Surface Removal using Z-buffer
 
Halftone
HalftoneHalftone
Halftone
 
Hidden lines & surfaces
Hidden lines & surfacesHidden lines & surfaces
Hidden lines & surfaces
 

Similar to Lighting and shading

illuminationmodelsshading-200501081735 (1).pdf
illuminationmodelsshading-200501081735 (1).pdfilluminationmodelsshading-200501081735 (1).pdf
illuminationmodelsshading-200501081735 (1).pdfSayantanMajhi2
 
Use of Specularities and Motion in the Extraction of Surface Shape
Use of Specularities and Motion in the Extraction of Surface ShapeUse of Specularities and Motion in the Extraction of Surface Shape
Use of Specularities and Motion in the Extraction of Surface ShapeDamian T. Gordon
 
Computer vision - light
Computer vision - lightComputer vision - light
Computer vision - lightWael Badawy
 
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
 
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
 
Lecture 1. Lighting Design.pptx
Lecture 1. Lighting Design.pptxLecture 1. Lighting Design.pptx
Lecture 1. Lighting Design.pptxNisthaPathak2
 
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
 
One day short course on Green Building Assessment Methods - Daylight Simulation
One day short course on Green Building Assessment Methods - Daylight SimulationOne day short course on Green Building Assessment Methods - Daylight Simulation
One day short course on Green Building Assessment Methods - Daylight Simulationekwtsang
 
Light the photonic storm
Light   the photonic stormLight   the photonic storm
Light the photonic stormSandeep Kar
 
Reflection and refraction at home & curved surfaces
Reflection and refraction at home & curved surfacesReflection and refraction at home & curved surfaces
Reflection and refraction at home & curved surfacesMohammad Arman Bin Aziz
 
smallpt: Global Illumination in 99 lines of C++
smallpt:  Global Illumination in 99 lines of C++smallpt:  Global Illumination in 99 lines of C++
smallpt: Global Illumination in 99 lines of C++鍾誠 陳鍾誠
 
7 illumination and-shading computer graphics
7 illumination and-shading computer graphics7 illumination and-shading computer graphics
7 illumination and-shading computer graphicscairo university
 

Similar to Lighting and shading (20)

illuminationmodelsshading-200501081735 (1).pdf
illuminationmodelsshading-200501081735 (1).pdfilluminationmodelsshading-200501081735 (1).pdf
illuminationmodelsshading-200501081735 (1).pdf
 
3 D texturing
 3 D texturing 3 D texturing
3 D texturing
 
Use of Specularities and Motion in the Extraction of Surface Shape
Use of Specularities and Motion in the Extraction of Surface ShapeUse of Specularities and Motion in the Extraction of Surface Shape
Use of Specularities and Motion in the Extraction of Surface Shape
 
Computer vision - light
Computer vision - lightComputer vision - light
Computer vision - light
 
Visual realism
Visual realismVisual realism
Visual realism
 
Lec03 light
Lec03 lightLec03 light
Lec03 light
 
Lecture 33 reflection and refraction
Lecture 33   reflection and refractionLecture 33   reflection and refraction
Lecture 33 reflection and refraction
 
graphics notes
graphics notesgraphics notes
graphics notes
 
Visual realism
Visual realismVisual realism
Visual realism
 
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
 
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
 
Lecture 1. Lighting Design.pptx
Lecture 1. Lighting Design.pptxLecture 1. Lighting Design.pptx
Lecture 1. Lighting Design.pptx
 
november6.ppt
november6.pptnovember6.ppt
november6.ppt
 
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
 
One day short course on Green Building Assessment Methods - Daylight Simulation
One day short course on Green Building Assessment Methods - Daylight SimulationOne day short course on Green Building Assessment Methods - Daylight Simulation
One day short course on Green Building Assessment Methods - Daylight Simulation
 
Light the photonic storm
Light   the photonic stormLight   the photonic storm
Light the photonic storm
 
Reflection and refraction at home & curved surfaces
Reflection and refraction at home & curved surfacesReflection and refraction at home & curved surfaces
Reflection and refraction at home & curved surfaces
 
Day lighting final
Day lighting   finalDay lighting   final
Day lighting final
 
smallpt: Global Illumination in 99 lines of C++
smallpt:  Global Illumination in 99 lines of C++smallpt:  Global Illumination in 99 lines of C++
smallpt: Global Illumination in 99 lines of C++
 
7 illumination and-shading computer graphics
7 illumination and-shading computer graphics7 illumination and-shading computer graphics
7 illumination and-shading computer graphics
 

Recently uploaded

Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086anil_gaur
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...soginsider
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoordharasingh5698
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf203318pmpc
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projectssmsksolar
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfRagavanV2
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 

Recently uploaded (20)

Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 

Lighting and shading

  • 1. CAP4730: Computational Structures in Computer Graphics Lighting and Shading
  • 3. What we know • We already know how to render the world from a viewpoint.
  • 4. “Lighting” • Two components: – Lighting Model or Shading Model - how we calculate the intensity at a point on the surface – Surface Rendering Method - How we calculate the intensity at each pixel
  • 5. Jargon • Illumination - the transport of light from a source to a point via direct and indirect paths • Lighting - computing the luminous intensity for a specified 3D point, given a viewpoint • Shading - assigning colors to pixels • Illumination Models: – Empirical - approximations to observed light properties – Physically based - applying physics properties of light and its interactions with matter
  • 6. The lighting problem… • What are we trying to solve? • Global illumination – the transport of light within a scene. • What factors play a part in how an object is “lit”? • Let’s examine different items here…
  • 7. Two components • Light Source Properties – Color (Wavelength(s) of light) – Shape – Direction • Object Properties – Material – Geometry – Absorption
  • 8. Light Source Properties • Color – We usually assume the light has one wavelength • Shape – point light source - approximate the light source as a 3D point in space. Light rays emanate in all directions. • good for small light sources (compared to the scene) • far away light sources
  • 9. Distributed Lights • Light Source Shape continued – distributed light source - approximating the light source as a 3D object. Light rays usually emanate in specific directions • good for larger light sources • area light sources
  • 10. Light Source Direction • In computer graphics, we usually treat lights as rays emanating from a source. The direction of these rays can either be: – Omni-directional (point light source) – Directional (spotlights)
  • 11. Light Position • We can specify the position of a light one of two ways, with an x, y, and z coordinate. – What are some examples? – These lights are called positional lights • Q: Are there types of lights that we can simplify? A: Yep! Think about the sun. If a light is significantly far away, we can represent the light with only a direction vector. These are called directional lights. How does this help?
  • 12. Contributions from lights • We will breakdown what a light does to an object into three different components. This APPROXIMATES what a light does. To actually compute the rays is too expensive to do in real-time. – Light at a pixel from a light = Ambient + Diffuse + Specular contributions. – Ilight= Iambient + Idiffuse + Ispecular
  • 13. Ambient Term - Background Light • The ambient term is a HACK! • It represents the approximate contribution of the light to the general scene, regardless of location of light and object • Indirect reflections that are too complex to completely and accurately compute • Iambient = color
  • 14. Diffuse Term • Contribution that a light has on the surface, regardless of viewing direction. • Diffuse surfaces, on a microscopic level, are very rough. This means that a ray of light coming in has an equal chance of being reflected in any direction. • What are some ideal diffuse surfaces?
  • 15. Lambert’s Cosine Law • Diffuse surfaces follow Lambert’s Cosine Law • Lambert’s Cosine Law - reflected energy from a small surface area in a particular direction is proportional to the cosine of the angle between that direction and the surface normal. • Think about surface area and # of rays
  • 16. Diffuse Term • To determine how much of a diffuse contribution a light supplies to the surface, we need the surface normal and the direction on the incoming ray • What is the angle between these two vectors? • Idiffuse = kdIlightcosθ = kdIlight(N . L) • Ilight = diffuse (intensity) of light • kd [0..1] = surface diffuse reflectivity • What CS are L and N in? • How expensive is it?
  • 17. Example • What are the possible values for theta (and thus the dot product?) http://graphics.lcs.mit.edu/classes/6.837/F98/ Lecture18/Slide11.html
  • 18. Specular Reflection • Specular contribution can be thought of as the “shiny highlight” of a plastic object. • On a microscopic level, the surface is very smooth. Almost all light is reflected. • What is an ideal purely specular reflector? • What does this term depend on? Viewing Direction Normal of the Surface
  • 19. Snell’s Law • Specular reflection applies Snell’s Law. • The incoming ray, the surface normal, and the reflected ray all lie in a common plane. • The angle that the reflected ray forms with the surface normal is determined by the angle that the incoming ray forms with the surface normal, and the relative speeds of light of the mediums in which the incident and reflected rays propagate according to: • We assume θl = θr
  • 20. Snell’s Law is for IDEAL surfaces • Think about the amount of light reflected at different angles. N L R Vθ
  • 21. Different for shiny vs. dull objects
  • 22. Snell’s Law is for IDEAL surfaces • Think about the amount of light reflected at different angles. N L R Vθ θ φ
  • 23. Phong Model Phong Reflection Model • An approximation is sets the intensity of specular reflection proportional to (cos φ)shininess • What are the possible values of cos φ? • What does the value of shininess mean? • How do we represent shinny or dull surfaces using the Phong model? • What is the real thing we probably SHOULD do? • Ispecular = ksIlight(cos φ)shininess = ksIlight(V.R)shininess
  • 24. Effect of the shininess value
  • 25. How do we compute R? • N*(N.L) • R+L=2N(N.L) • R = 2N(N.L)-L N L R Vθ N(N.L) φ L
  • 26. Simplify this • Instead of R, we compute halfway between L and V. • We call this vector the halfway vector, H. N L R Vθ φ ( )shininess yspecularitlightsspecular HNIkI VL VL H ⋅= + + = _ H
  • 27. Let’s compare the two ( ) ( )shininess yspecularitlightsspecular shininess yspecularitlightsspecular HNIkI VL VL H RVIkI LLNNR ⋅= + + = ⋅= −⋅= _ _ )(2 N L R Vθ φ H Q: Which vectors stay constant when viewpoint is far away? A: V and L vectors -> H Q: What does this buy us?
  • 28. Combining the terms • Ambient - the combination of light reflections from various surfaces to produce a uniform illumination. Background light. • Diffuse - uniform light scattering of light rays on a surface. Proportional to the “amount of light” that hits the surface. Depends on the surface normal and light vector. • Sepecular - light that gets reflected. Depends on the light ray, the viewing angle, and the surface normal.
  • 29. Ambient + Diffuse + Specular
  • 30. Lighting Equation Ilambient = light source l’s ambient component Ildiffuse = light source l’s diffuse component Ilspecular = light source l’s specular component kambient = surface material ambient reflectivity kdiffuse = surface material diffuse reflectivity kspecular = surface material specular reflectivity shininess = specular reflection parameter (1 -> dull, 100+ -> very shiny) ( ) ( ) ( ) ( )∑ − = ⋅+⋅+= ⋅+⋅+= 1 0 lights l shininess specularldiffuselambientlfinal shininess specularspeculardiffusediffuseambientambientfinal HNkILNkIkII HNkILNkIkII speculardiffuseambient N L R Vθ
  • 31. Clamping & Spotlights • What does the value Ifinal mean? • How do we make sure it doesn’t get too high? • Spotlights? How do them? ( ) ( ) ( ) ( )∑ − = ⋅+⋅+= ⋅+⋅+= 1 0 lights l shininess specularldiffuselambientlfinal shininess specularspeculardiffusediffuseambientambientfinal HNkILNkIkII HNkILNkIkII speculardiffuseambient N L R Vθ
  • 32. How would we light a green cube? ( ) ( ) ( ) ( )∑ − = ⋅+⋅+= ⋅+⋅+= 1 0 lights l shininess specularldiffuselambientlfinal shininess specularspeculardiffusediffuseambientambientfinal HNkILNkIkII HNkILNkIkII speculardiffuseambient N L R Vθ
  • 33. Attenuation • One factor we have yet to take into account is that a light source contributes a higher incident intensity to closer surfaces. • The energy from a point light source falls off proportional to 1/d2 . • What happens if we don’t do this?
  • 34. What would attenuation do for: • Actually, using only 1/d2 , makes it difficult to correctly light things. Think if d=1 and d=2. Why? • Remember, we are approximating things. Lighting model is too simple AND most lights are not point sources. • We use: ( ) 2 210 1 dadaa df ++ =
  • 35. Subtleties • What’s wrong with: ( ) 2 210 1 dadaa df ++ = What’s a good fix? ( )       ++ = 2 210 1 ,1min dadaa df
  • 36. Full Illumination Model ( )       ++ = 2 210 1 ,1min dadaa df ( ) ( ) ( )[ ]∑ − = ⋅+⋅+= 1 0 lights l shininess specularldiffusellambientlfinal HNkILNkIdfkII speculardiffuseambient Run demo
  • 37. Putting Lights in OpenGL • 1. glEnable(GL_LIGHTING); • 2. Set up Light properties – glLightf(…) • 3. Set up Material properties – glMaterial(…)
  • 38. Shading • When do we do the lighting equation? • What is the cost to compute the lighting for a 3D point? ( ) ( ) ( )[ ]∑ − = ⋅+⋅+= 1 0 lights l shininess specularldiffusellambientlfinal HNkILNkIdfkII speculardiffuseambient
  • 39. Shading • Shading is how we “color” a triangle. • Constant Shading • Gouraud Shading • Phong Shading
  • 40. Constant Shading • Constant Intensity or Flat Shading • One color for the entire triangle • Fast • Good for some objects • What happens if triangles are small? • Sudden intensity changes at borders
  • 41. Gouraud Shading • Intensity Interpolation Shading • Calculate lighting at the vertices. Then interpolate the colors as you scan convert
  • 42. Gouraud Shading • Relatively fast, only do three calculations • No sudden intensity changes • What can it not do? • What are some approaches to fix this? • Question, what is the normal at a vertex?
  • 43. Phong Shading • Interpolate the normal, since that is the information that represents the “curvature” • Linearly interpolate the vertex normals. For each pixel, as you scan convert, calculate the lighting per pixel. • True “per pixel” lighting • Not done by most hardware/libraries/etc
  • 44. Shading Techniques • Constant Shading – Calculate one lighting calculation (pick a vertex) per triangle – Color the entire triangle the same color • Gouraud Shading – Calculate three lighting calculations (the vertices) per triangle – Linearly interpolate the colors as you scan convert • Phong Shading – While you scan convert, linearly interpolate the normals. – With the interpolated normal at each pixel, calculate the lighting at each pixel