SlideShare une entreprise Scribd logo
1  sur  52
Lighting and Shading
Computer Graphics
Lighting & Shading
• Approximate physical reality
• Ray tracing:
– Follow light rays through a scene
– Accurate, but expensive (off-line)
• Radiosity:
– Calculate surface inter-reflection approximately
– Accurate, especially interiors, but expensive (off-line)
• Phong Illumination model :
– Approximate only interaction light, surface, viewer
– Relatively fast (on-line), supported in OpenGL
Ray Tracing
Forward Ray Tracing
• Lights emit photon
• Follow the photons
– Trace Path (Ray)
– Bounce off objects
• Reflect, refract, attenuate
– When a ray enters eye
• Calculate intersection with view plane.
• Accumulate color in the pixel
• Expensive
– Many rays will not intersect view plane
Backward Ray Tracing
• Ray-casting: one ray from center of projection
through each pixel in image plane
• Illumination
1. Phong (local as before)
2. Shadow rays
3. Specular reflection
4. Specular transmission
• (3) and (4) require recursion
Shadow Rays
• Determine if light “really” hits surface point
• Cast shadow ray from surface point to light
• If shadow ray hits opaque object, no contribution
• Improved diffuse reflection
Reflection & Transmission Rays
• Reflection Rays
– Calculate specular component of
illumination
– Compute reflection ray
– Call ray tracer recursively to determine
color
– Add contributions
Transmission ray
Analogue for transparent or translucent surface
Use Snell’s laws for refraction
Ray Casting
• Simplest case of ray tracing
– Required as first step of recursive ray tracing
• Basic ray-casting algorithm
– For each pixel (x,y) fire a ray from COP through
(x,y)
– For each ray & object calculate closest intersection
– For closest intersection point p
• Calculate surface normal
• For each light source, calculate and add contributions
• Critical operations
– Ray-surface intersections
– Illumination calculation
Radiosity Methods
Radiosity – concepts
Radiosity – concepts
Radiosity
• Radiosity:
– The rate at which energy leaves a surface
– Radiosity = (Emitted energy)+(Reflected energy)
– Light sources are not treated differently in radiosity – every
surface is a light source.
• Radiosity method:
– First determine all the light interactions in an environment in a
view-independent way
– Visible-surface determination and interpolative shading is used
to obtain view dependent image.
Classical Radiosity Method
• Divide surfaces into patches (elements)
• Model light transfer between patches as
system of linear equations
• Important assumptions:
– Reflection and emission are diffuse
• Recall: diffuse reflection is equal in all directions
• So radiance is independent of direction
– No participating media (no fog)
– No transmission (only opaque surfaces)
– Radiosity is constant across each element
– Solve for R, G, B separately
Radiosity Example
Wire-frame model Resulting Image
Radiosity Pipeline
Scene Geometry
Form Factor
Calculation
Reflectance property
Solution of
Radiosity eqn
Viewing Condition
VisualizationRadiosity Image
Radiosity Equations
• Radiosity = amount of
energy leaving a surface
per unit area, per unit time (
W / m2 ).
• Form factori–j = ratio of
energy leaving surface j
that arrives at surface i.
• The Radiosity problem :
– Estimate the form factors
– Solve for the entire scene.
ipatchtorelative
jpatchoffactorFormF
ipatchoftyReflectivi
ipatchofEmmisivityE
ipatchofsRadiositieB
A
A
FBEB
ij
i
i
i
nj i
j
ijjiii
⇒
⇒
⇒
⇒
+=
−
≤≤
−∑
ρ
ρ
1
surfacesotherfrom
surfacethisreachingEnergyFB
nj
ijj ⇒∑≤≤
−
1
surfacethisbyemmittedEnergyEi ⇒
surfacethisby
reflectedEnergyFB
nj
ijji ⇒∑≤≤
−
1
ρ
Surface patch i
Radiosity Equations












=
























−−−
−−−
−−−
=−⇒
+=
=
−−−
−−−
−−−
≤≤
−
≤≤
−
−−
∑
∑
nnnnnnnnn
n
n
nj
ijijii
nj
jijiii
jijiji
E
E
E
B
B
B
FFF
FFF
FFF
EFBB
FBEB
:haveweso
FAFA
areasurfaceandfactorsformbetweeniprelationshyreciprocittoDue





2
1
2
1
21
22222122
11211111
1
1
1
1
1
ρρρ
ρρρ
ρρρ
ρ
ρ
Calculating Form Factor
The form factor from differential surface dAi to dAj
is:
∫ ∫
∫
=
=
=
i j
j
A A
ijij
ji
i
j-i
A
jij
ji
j-di
jij
ji
dj-di
dAdAH
rA
F
dAH
r
F
dAH
r
dF
2
2
2
coscos1
coscos
coscos
π
θθ
π
θθ
π
θθ
otherwise0,dAfromvisibleisdAifH
AtoAfromfactorformF
AtodAfromfactorformF
dAtodAfromfactorformdF
jiij
jij-i
jij-di
jidj-di
,1=
=
=
=
Geometric Ingredients
• Three ingredients
– Normal vector m at point P of the surface
– Vector v from P to the viewers eye
– Vector s from P to the light source
m
s
v
P
Types of Light Sources
• Ambient light: no identifiable source or direction
• Diffuse light - Point: given only by point
• Diffuse light - Direction: given only by direction
• Spot light: from source in direction
– Cut-off angle defines a cone of light
– Attenuation function (brighter in center)
• Light source described by a luminance
– Each color is described separately
– I = [I r I g I b ] T (I for intensity)
– Sometimes calculate generically (applies to r, g, b)
Ambient Light
• Global ambient light
– Independent of light source
– Lights entire scene
• Local ambient light
– Contributed by additional light sources
– Can be different for each light and primary color
• Computationally inexpensive
Diffuse Light
• Point Source
– Given by a point
– Light emitted equally in all directions
– Intensity decreases with square of distance
– Point source [x y z 1]T
• Directional Source
– Given by a direction
– Simplifies some calculations
– Intensity dependents on angle between surface
normal and direction of light
– Distant source [x y z 0]T
Spot Lights
• Spotlights are point sources whose intensity falls off
directionally.
– Requires color, point
direction, falloff
parameters
d
P
α
β
Intensity at P = I cosε
(β)
Based on modeling surface reflection as aBased on modeling surface reflection as a
combination of the following components:combination of the following components:
Used to model objects that glowUsed to model objects that glow
A simple way to model indirect reflectionA simple way to model indirect reflection
The illumination produced by dull smooth surfacesThe illumination produced by dull smooth surfaces
The bright spots appearing on smooth shinyThe bright spots appearing on smooth shiny
surfacessurfaces
Phong illumination model
• Ideal diffuse reflection
– An ideal diffuse reflector, at the microscopic level, is a very
rough surface (real-world example: chalk)
– Because of these microscopic variations, an incoming ray of
light is equally likely to be reflected in any direction over the
hemisphere
– What does the reflected intensity depend on?
Diffuse Reflection
Computing Diffuse Reflection
• Independent of the angle between m and v
• Does depend on the direction s (Lambertian
surface)
ms
ms•
= diffusesourcediffuse II ρ
)0,max(
ms
ms•
= diffusesourcediffuse II ρ
Diffuse Reflection Coefficient
Adjustment for ‘inside’ face
)cos(θρdiffusesourcediffuse II =
Therefore, the diffuse component is:
Specular Reflection
• Shiny surfaces exhibit specular reflection
– Polished metal
– Glossy car finish
• A light shining on a specular surface causes a bright spot
known as a specular highlight
• Where these highlights appear is a function of the viewer’s
position, so specular reflectance is view dependent
Specular Reflection
• Perfect specular reflection (perfect mirror)
– Snell’s law
• The smoother the surface, the closer it becomes to a
perfect mirror
• Non-perfect specular reflection: Phong Model
– most light reflects according to Snell’s Law
– as we move from the ideal reflected ray, some light is still
reflected
Non-Ideal Specular Reflectance: Phong Model
An illustration of this angular falloff
θ
m
s
r
Phong Lighting
θ
m
s
r
vφ
The Specular Intensity, according to Phong model:
)(cos ϕρ f
specularsourcespecular II =
Specular Reflection Coefficient
Shininess factor
f
specularsourcespecular II







 •
=
vr
vr
ρ
Phong Lighting Examples
•These spheres illustrate the Phong model as s and f are
varied:
Blinn and Torrence Variation
• In Phong Model, r need to be found
– computationally expensive
• Instead, halfway vector h = s + v is used
– angle between m and h measures the falloff of intensity
β
m
s h
v
f
specularsourcespecular II







 •
=
mh
mh
ρ
Combining Everything
• Simple analytic model:
– diffuse reflection +
– specular reflection +
– ambient
Surface
The Final Combined Equation
• Single light source: m
s
r
v
Viewer
φ
θθ
f
sspddaa phongIlambertIII )(×+×+= ρρρ







 •
=
ms
ms
,0maxlambert







 •
=
mh
mh
,0maxphong
Adding Color
• Consider R, G, B components individually
• Add the components to get the final color of reflected
light
f
srsprdrdrarar phongIlambertIII )(×+×+= ρρρ
f
sgspgdgdgagag phongIlambertIII )(×+×+= ρρρ
f
sbspbdbdbabab phongIlambertIII )(×+×+= ρρρ
Shading Models
Applying Illumination
• We have an illumination model for a point on a surface
• Assuming that our surface is defined as a mesh of
polygonal facets, which points should we use?
Polygon Shading
Flat Shading
Gouraud Shading Phong Shading
Smooth Shading
Types of Shading Model
Flat Shading
• For each polygon
– Determines a single intensity value
– Uses that value to shade the entire
polygon
• Assumptions
– Light source at infinity
– Viewer at infinity
– The polygon represents the actual surface
being modeled
Wire-frameWire-frame ModelModel
Flat Shading
Flat ShadingFlat Shading
Smooth Shading
• Introduce vertex normals at each
vertex
– Usually different from facet normal
– Used only for shading
– Think of as a better approximation of the real surface that
the polygons approximate
• Two types
– Gouraud Shading
– Phong Shading (do not confuse with Phong Lighting Model)
Gouraud Shading
• This is the most common approach
– Perform Phong lighting at the vertices
– Linearly interpolate the resulting colors over faces
• Along edges
• Along scanlines
Gouraud Shading
xright
ys
ytop
ybott
xleft
color1
color2
color3
color4y4
( )
bott
botts
left
yy
yy
colorcolorcolorcolor
−
−
−+=
4
141
( )
bott
botts
right
yy
yy
colorcolorcolorcolor
−
−
−+=
2
121
( )
rightleft
left
leftrightleftx
xx
xx
colorcolorcolorcolor
−
−
−+=
Wire-frame ModelWire-frame Model
Gouraud Shading
Flat ShadingFlat ShadingGouraud ShadingGouraud Shading
Gouraud Shading
• Artifacts
– Often appears dull
– Lacks accurate specular component
• If included, will be averaged over entire polygon
C1
C2
C3
Can’t shade the spot light
Phong Shading
ys
x
m1
m2
m3
m4 mleft
mright
m
Interpolate normal vectors at each pixel
Wire-frame ModelWire-frame Model
Phong Shading
Flat ShadingFlat ShadingGouraud ShadingGouraud ShadingPhong ShadingPhong Shading
If a highlight does not fall on a vertex
Gouraud shading may miss it completely,
but Phong shading does not.
Phong vs Gouraud Shading
Shading Models (Direct lighting)
• Flat Shading
– Compute Phong lighting once for entire polygon
• Gouraud Shading
– Compute Phong lighting at the vertices and interpolate lighting
values across polygon
• Phong Shading
– Interpolate normals across polygon and perform Phong
lighting across polygon
Lighting in OpenGL
Lighting in OpenGL [1/2]
• Enabling shading
– glShadeModel(GL_FLAT)
– glShadeModel(GL_SMOOTH); // Gouraud Shading only
• Using light sources
– Up to 8 light sources
– To create a light
• GLfloat light0_position[] = { 600, 40, 600, 1.0};
• glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
• glEnable(GL_LIGHT0);
• glEnable(GL_LIGHTING);
Lighting in OpenGL [2/2]
– Changing light properties
• GLfloat light0_ambient[] = { 0.4, 0.1, 0.0, 1.0 };
• GLfloat light0_diffuse[] = { 0.9, 0.3, 0.3, 1.0 };
• GLfloat light0_specular[] = { 0.0, 1.0, 1.0, 1.0 };
• glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
• glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
• glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular);

Contenu connexe

Tendances

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 algorithmrajivagarwal23dei
 
Computer Graphics Notes
Computer Graphics NotesComputer Graphics Notes
Computer Graphics NotesGurpreet singh
 
Raster Scan and Raster Scan Displays
Raster Scan and Raster Scan DisplaysRaster Scan and Raster Scan Displays
Raster Scan and Raster Scan DisplaysSaravana Priya
 
Ray casting algorithm by mhm
Ray casting algorithm by mhmRay casting algorithm by mhm
Ray casting algorithm by mhmMd Mosharof Hosen
 
Bezier and Spline Curves and Surfaces
Bezier and Spline Curves and SurfacesBezier and Spline Curves and Surfaces
Bezier and Spline Curves and SurfacesSyed Zaid Irshad
 
Window to viewport transformation&matrix representation of homogeneous co...
Window to viewport transformation&matrix representation of homogeneous co...Window to viewport transformation&matrix representation of homogeneous co...
Window to viewport transformation&matrix representation of homogeneous co...Mani Kanth
 
2 d geometric transformations
2 d geometric transformations2 d geometric transformations
2 d geometric transformationsMohd Arif
 
3 d transformation
3 d transformation3 d transformation
3 d transformationPooja Dixit
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer GraphicsAnkur Soni
 
Unit 3
Unit 3Unit 3
Unit 3ypnrao
 
Raster Scan Display
Raster Scan DisplayRaster Scan Display
Raster Scan DisplayAnkur Soni
 
Two dimensional geometric transformations
Two dimensional geometric transformationsTwo dimensional geometric transformations
Two dimensional geometric transformationsMohammad Sadiq
 
Reflection transformation
Reflection transformationReflection transformation
Reflection transformationMani Kanth
 
Color Models Computer Graphics
Color Models Computer GraphicsColor Models Computer Graphics
Color Models Computer Graphicsdhruv141293
 
Cohen sutherland line clipping
Cohen sutherland line clippingCohen sutherland line clipping
Cohen sutherland line clippingMani Kanth
 

Tendances (20)

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
 
Computer Graphics Notes
Computer Graphics NotesComputer Graphics Notes
Computer Graphics Notes
 
3 d viewing
3 d viewing3 d viewing
3 d viewing
 
Spline representations
Spline representationsSpline representations
Spline representations
 
Raster Scan and Raster Scan Displays
Raster Scan and Raster Scan DisplaysRaster Scan and Raster Scan Displays
Raster Scan and Raster Scan Displays
 
Ray casting algorithm by mhm
Ray casting algorithm by mhmRay casting algorithm by mhm
Ray casting algorithm by mhm
 
Illumination Models & Shading
Illumination Models & ShadingIllumination Models & Shading
Illumination Models & Shading
 
Depth Buffer Method
Depth Buffer MethodDepth Buffer Method
Depth Buffer Method
 
Bezier and Spline Curves and Surfaces
Bezier and Spline Curves and SurfacesBezier and Spline Curves and Surfaces
Bezier and Spline Curves and Surfaces
 
Window to viewport transformation&matrix representation of homogeneous co...
Window to viewport transformation&matrix representation of homogeneous co...Window to viewport transformation&matrix representation of homogeneous co...
Window to viewport transformation&matrix representation of homogeneous co...
 
2 d geometric transformations
2 d geometric transformations2 d geometric transformations
2 d geometric transformations
 
3 d transformation
3 d transformation3 d transformation
3 d transformation
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
Unit 3
Unit 3Unit 3
Unit 3
 
Raster Scan Display
Raster Scan DisplayRaster Scan Display
Raster Scan Display
 
Two dimensional geometric transformations
Two dimensional geometric transformationsTwo dimensional geometric transformations
Two dimensional geometric transformations
 
Reflection transformation
Reflection transformationReflection transformation
Reflection transformation
 
Color Models Computer Graphics
Color Models Computer GraphicsColor Models Computer Graphics
Color Models Computer Graphics
 
Cohen sutherland line clipping
Cohen sutherland line clippingCohen sutherland line clipping
Cohen sutherland line clipping
 

En vedette

Lighting and shading
Lighting and shadingLighting and shading
Lighting and shadingeshveeen
 
MVisio: A Computer Graphics Platform for Virtual Reality, Science and Education
MVisio: A Computer Graphics Platform for Virtual Reality, Science and EducationMVisio: A Computer Graphics Platform for Virtual Reality, Science and Education
MVisio: A Computer Graphics Platform for Virtual Reality, Science and EducationAchille Peternier
 
03 Shading
03 Shading03 Shading
03 Shadingnjoubert
 
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
 
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
 
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
 
Computer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methodsComputer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methodsJoseph Charles
 
computer graphics
computer graphicscomputer graphics
computer graphicsashpri156
 

En vedette (14)

Lighting and shading
Lighting and shadingLighting and shading
Lighting and shading
 
Lighting and shading
Lighting and shadingLighting and shading
Lighting and shading
 
Ray tracing
Ray tracingRay tracing
Ray tracing
 
MVisio: A Computer Graphics Platform for Virtual Reality, Science and Education
MVisio: A Computer Graphics Platform for Virtual Reality, Science and EducationMVisio: A Computer Graphics Platform for Virtual Reality, Science and Education
MVisio: A Computer Graphics Platform for Virtual Reality, Science and Education
 
03 Shading
03 Shading03 Shading
03 Shading
 
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
 
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
 
Illumination Model
Illumination ModelIllumination Model
Illumination Model
 
Ray tracing
 Ray tracing Ray tracing
Ray tracing
 
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: Visible surface detection methods
Computer Graphics: Visible surface detection methodsComputer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methods
 
computer graphics
computer graphicscomputer graphics
computer graphics
 

Similaire à Graphics Lecture 7

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
 
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
 
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
 
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
 
Compututer Graphics - Color Modeling And Rendering
Compututer Graphics - Color Modeling And RenderingCompututer Graphics - Color Modeling And Rendering
Compututer Graphics - Color Modeling And RenderingPrince Soni
 
Lighting terminlologyand their units
Lighting terminlologyand their unitsLighting terminlologyand their units
Lighting terminlologyand their unitsSafdar Ali
 
Lecture 1. Lighting Design.pptx
Lecture 1. Lighting Design.pptxLecture 1. Lighting Design.pptx
Lecture 1. Lighting Design.pptxNisthaPathak2
 
Concept of basic illumination model
Concept of basic illumination modelConcept of basic illumination model
Concept of basic illumination modelAnkit Garg
 
Paris Master Class 2011 - 07 Dynamic Global Illumination
Paris Master Class 2011 - 07 Dynamic Global IlluminationParis Master Class 2011 - 07 Dynamic Global Illumination
Paris Master Class 2011 - 07 Dynamic Global IlluminationWolfgang Engel
 

Similaire à Graphics Lecture 7 (20)

illuminationmodelsshading-200501081735 (1).pdf
illuminationmodelsshading-200501081735 (1).pdfilluminationmodelsshading-200501081735 (1).pdf
illuminationmodelsshading-200501081735 (1).pdf
 
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
 
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
 
Lec03 light
Lec03 lightLec03 light
Lec03 light
 
Light (1)
Light (1)Light (1)
Light (1)
 
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
 
3 D texturing
 3 D texturing 3 D texturing
3 D texturing
 
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
 
Ray Tracing.pdf
Ray Tracing.pdfRay Tracing.pdf
Ray Tracing.pdf
 
Compututer Graphics - Color Modeling And Rendering
Compututer Graphics - Color Modeling And RenderingCompututer Graphics - Color Modeling And Rendering
Compututer Graphics - Color Modeling And Rendering
 
Lighting terminlologyand their units
Lighting terminlologyand their unitsLighting terminlologyand their units
Lighting terminlologyand their units
 
Lecture 1. Lighting Design.pptx
Lecture 1. Lighting Design.pptxLecture 1. Lighting Design.pptx
Lecture 1. Lighting Design.pptx
 
Shading
ShadingShading
Shading
 
Concept of basic illumination model
Concept of basic illumination modelConcept of basic illumination model
Concept of basic illumination model
 
Paris Master Class 2011 - 07 Dynamic Global Illumination
Paris Master Class 2011 - 07 Dynamic Global IlluminationParis Master Class 2011 - 07 Dynamic Global Illumination
Paris Master Class 2011 - 07 Dynamic Global Illumination
 
Visual realism
Visual realismVisual realism
Visual realism
 
Ray Tracing
Ray TracingRay Tracing
Ray Tracing
 
graphics notes
graphics notesgraphics notes
graphics notes
 
Visual realism
Visual realismVisual realism
Visual realism
 

Dernier

CREATING A POSITIVE SCHOOL CULTURE CHAPTER 10
CREATING A POSITIVE SCHOOL CULTURE CHAPTER 10CREATING A POSITIVE SCHOOL CULTURE CHAPTER 10
CREATING A POSITIVE SCHOOL CULTURE CHAPTER 10uasjlagroup
 
FiveHypotheses_UIDMasterclass_18April2024.pdf
FiveHypotheses_UIDMasterclass_18April2024.pdfFiveHypotheses_UIDMasterclass_18April2024.pdf
FiveHypotheses_UIDMasterclass_18April2024.pdfShivakumar Viswanathan
 
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书zdzoqco
 
Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025Rndexperts
 
办理学位证(SFU证书)西蒙弗雷泽大学毕业证成绩单原版一比一
办理学位证(SFU证书)西蒙弗雷泽大学毕业证成绩单原版一比一办理学位证(SFU证书)西蒙弗雷泽大学毕业证成绩单原版一比一
办理学位证(SFU证书)西蒙弗雷泽大学毕业证成绩单原版一比一F dds
 
cda.pptx critical discourse analysis ppt
cda.pptx critical discourse analysis pptcda.pptx critical discourse analysis ppt
cda.pptx critical discourse analysis pptMaryamAfzal41
 
1比1办理美国北卡罗莱纳州立大学毕业证成绩单pdf电子版制作修改
1比1办理美国北卡罗莱纳州立大学毕业证成绩单pdf电子版制作修改1比1办理美国北卡罗莱纳州立大学毕业证成绩单pdf电子版制作修改
1比1办理美国北卡罗莱纳州立大学毕业证成绩单pdf电子版制作修改yuu sss
 
办理(麻省罗威尔毕业证书)美国麻省大学罗威尔校区毕业证成绩单原版一比一
办理(麻省罗威尔毕业证书)美国麻省大学罗威尔校区毕业证成绩单原版一比一办理(麻省罗威尔毕业证书)美国麻省大学罗威尔校区毕业证成绩单原版一比一
办理(麻省罗威尔毕业证书)美国麻省大学罗威尔校区毕业证成绩单原版一比一diploma 1
 
办理(UC毕业证书)查尔斯顿大学毕业证成绩单原版一比一
办理(UC毕业证书)查尔斯顿大学毕业证成绩单原版一比一办理(UC毕业证书)查尔斯顿大学毕业证成绩单原版一比一
办理(UC毕业证书)查尔斯顿大学毕业证成绩单原版一比一z xss
 
西北大学毕业证学位证成绩单-怎么样办伪造
西北大学毕业证学位证成绩单-怎么样办伪造西北大学毕业证学位证成绩单-怎么样办伪造
西北大学毕业证学位证成绩单-怎么样办伪造kbdhl05e
 
Iconic Global Solution - web design, Digital Marketing services
Iconic Global Solution - web design, Digital Marketing servicesIconic Global Solution - web design, Digital Marketing services
Iconic Global Solution - web design, Digital Marketing servicesIconic global solution
 
Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025Rndexperts
 
Pharmaceutical Packaging for the elderly.pdf
Pharmaceutical Packaging for the elderly.pdfPharmaceutical Packaging for the elderly.pdf
Pharmaceutical Packaging for the elderly.pdfAayushChavan5
 
办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一
办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一
办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一F dds
 
Passbook project document_april_21__.pdf
Passbook project document_april_21__.pdfPassbook project document_april_21__.pdf
Passbook project document_april_21__.pdfvaibhavkanaujia
 
Apresentação Clamo Cristo -letra música Matheus Rizzo
Apresentação Clamo Cristo -letra música Matheus RizzoApresentação Clamo Cristo -letra música Matheus Rizzo
Apresentação Clamo Cristo -letra música Matheus RizzoCarolTelles6
 
Chapter 6(1)system devolopment life .ppt
Chapter 6(1)system devolopment life .pptChapter 6(1)system devolopment life .ppt
Chapter 6(1)system devolopment life .pptDoaaRezk5
 
Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...
Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...
Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...Yantram Animation Studio Corporation
 
Call Girls Aslali 7397865700 Ridhima Hire Me Full Night
Call Girls Aslali 7397865700 Ridhima Hire Me Full NightCall Girls Aslali 7397865700 Ridhima Hire Me Full Night
Call Girls Aslali 7397865700 Ridhima Hire Me Full Nightssuser7cb4ff
 

Dernier (20)

CREATING A POSITIVE SCHOOL CULTURE CHAPTER 10
CREATING A POSITIVE SCHOOL CULTURE CHAPTER 10CREATING A POSITIVE SCHOOL CULTURE CHAPTER 10
CREATING A POSITIVE SCHOOL CULTURE CHAPTER 10
 
Call Girls in Pratap Nagar, 9953056974 Escort Service
Call Girls in Pratap Nagar,  9953056974 Escort ServiceCall Girls in Pratap Nagar,  9953056974 Escort Service
Call Girls in Pratap Nagar, 9953056974 Escort Service
 
FiveHypotheses_UIDMasterclass_18April2024.pdf
FiveHypotheses_UIDMasterclass_18April2024.pdfFiveHypotheses_UIDMasterclass_18April2024.pdf
FiveHypotheses_UIDMasterclass_18April2024.pdf
 
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
 
Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025
 
办理学位证(SFU证书)西蒙弗雷泽大学毕业证成绩单原版一比一
办理学位证(SFU证书)西蒙弗雷泽大学毕业证成绩单原版一比一办理学位证(SFU证书)西蒙弗雷泽大学毕业证成绩单原版一比一
办理学位证(SFU证书)西蒙弗雷泽大学毕业证成绩单原版一比一
 
cda.pptx critical discourse analysis ppt
cda.pptx critical discourse analysis pptcda.pptx critical discourse analysis ppt
cda.pptx critical discourse analysis ppt
 
1比1办理美国北卡罗莱纳州立大学毕业证成绩单pdf电子版制作修改
1比1办理美国北卡罗莱纳州立大学毕业证成绩单pdf电子版制作修改1比1办理美国北卡罗莱纳州立大学毕业证成绩单pdf电子版制作修改
1比1办理美国北卡罗莱纳州立大学毕业证成绩单pdf电子版制作修改
 
办理(麻省罗威尔毕业证书)美国麻省大学罗威尔校区毕业证成绩单原版一比一
办理(麻省罗威尔毕业证书)美国麻省大学罗威尔校区毕业证成绩单原版一比一办理(麻省罗威尔毕业证书)美国麻省大学罗威尔校区毕业证成绩单原版一比一
办理(麻省罗威尔毕业证书)美国麻省大学罗威尔校区毕业证成绩单原版一比一
 
办理(UC毕业证书)查尔斯顿大学毕业证成绩单原版一比一
办理(UC毕业证书)查尔斯顿大学毕业证成绩单原版一比一办理(UC毕业证书)查尔斯顿大学毕业证成绩单原版一比一
办理(UC毕业证书)查尔斯顿大学毕业证成绩单原版一比一
 
西北大学毕业证学位证成绩单-怎么样办伪造
西北大学毕业证学位证成绩单-怎么样办伪造西北大学毕业证学位证成绩单-怎么样办伪造
西北大学毕业证学位证成绩单-怎么样办伪造
 
Iconic Global Solution - web design, Digital Marketing services
Iconic Global Solution - web design, Digital Marketing servicesIconic Global Solution - web design, Digital Marketing services
Iconic Global Solution - web design, Digital Marketing services
 
Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025
 
Pharmaceutical Packaging for the elderly.pdf
Pharmaceutical Packaging for the elderly.pdfPharmaceutical Packaging for the elderly.pdf
Pharmaceutical Packaging for the elderly.pdf
 
办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一
办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一
办理学位证(SFU证书)西蒙菲莎大学毕业证成绩单原版一比一
 
Passbook project document_april_21__.pdf
Passbook project document_april_21__.pdfPassbook project document_april_21__.pdf
Passbook project document_april_21__.pdf
 
Apresentação Clamo Cristo -letra música Matheus Rizzo
Apresentação Clamo Cristo -letra música Matheus RizzoApresentação Clamo Cristo -letra música Matheus Rizzo
Apresentação Clamo Cristo -letra música Matheus Rizzo
 
Chapter 6(1)system devolopment life .ppt
Chapter 6(1)system devolopment life .pptChapter 6(1)system devolopment life .ppt
Chapter 6(1)system devolopment life .ppt
 
Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...
Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...
Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...
 
Call Girls Aslali 7397865700 Ridhima Hire Me Full Night
Call Girls Aslali 7397865700 Ridhima Hire Me Full NightCall Girls Aslali 7397865700 Ridhima Hire Me Full Night
Call Girls Aslali 7397865700 Ridhima Hire Me Full Night
 

Graphics Lecture 7

  • 2. Lighting & Shading • Approximate physical reality • Ray tracing: – Follow light rays through a scene – Accurate, but expensive (off-line) • Radiosity: – Calculate surface inter-reflection approximately – Accurate, especially interiors, but expensive (off-line) • Phong Illumination model : – Approximate only interaction light, surface, viewer – Relatively fast (on-line), supported in OpenGL
  • 4. Forward Ray Tracing • Lights emit photon • Follow the photons – Trace Path (Ray) – Bounce off objects • Reflect, refract, attenuate – When a ray enters eye • Calculate intersection with view plane. • Accumulate color in the pixel • Expensive – Many rays will not intersect view plane
  • 5. Backward Ray Tracing • Ray-casting: one ray from center of projection through each pixel in image plane • Illumination 1. Phong (local as before) 2. Shadow rays 3. Specular reflection 4. Specular transmission • (3) and (4) require recursion
  • 6. Shadow Rays • Determine if light “really” hits surface point • Cast shadow ray from surface point to light • If shadow ray hits opaque object, no contribution • Improved diffuse reflection
  • 7. Reflection & Transmission Rays • Reflection Rays – Calculate specular component of illumination – Compute reflection ray – Call ray tracer recursively to determine color – Add contributions Transmission ray Analogue for transparent or translucent surface Use Snell’s laws for refraction
  • 8. Ray Casting • Simplest case of ray tracing – Required as first step of recursive ray tracing • Basic ray-casting algorithm – For each pixel (x,y) fire a ray from COP through (x,y) – For each ray & object calculate closest intersection – For closest intersection point p • Calculate surface normal • For each light source, calculate and add contributions • Critical operations – Ray-surface intersections – Illumination calculation
  • 12. Radiosity • Radiosity: – The rate at which energy leaves a surface – Radiosity = (Emitted energy)+(Reflected energy) – Light sources are not treated differently in radiosity – every surface is a light source. • Radiosity method: – First determine all the light interactions in an environment in a view-independent way – Visible-surface determination and interpolative shading is used to obtain view dependent image.
  • 13. Classical Radiosity Method • Divide surfaces into patches (elements) • Model light transfer between patches as system of linear equations • Important assumptions: – Reflection and emission are diffuse • Recall: diffuse reflection is equal in all directions • So radiance is independent of direction – No participating media (no fog) – No transmission (only opaque surfaces) – Radiosity is constant across each element – Solve for R, G, B separately
  • 15. Radiosity Pipeline Scene Geometry Form Factor Calculation Reflectance property Solution of Radiosity eqn Viewing Condition VisualizationRadiosity Image
  • 16. Radiosity Equations • Radiosity = amount of energy leaving a surface per unit area, per unit time ( W / m2 ). • Form factori–j = ratio of energy leaving surface j that arrives at surface i. • The Radiosity problem : – Estimate the form factors – Solve for the entire scene. ipatchtorelative jpatchoffactorFormF ipatchoftyReflectivi ipatchofEmmisivityE ipatchofsRadiositieB A A FBEB ij i i i nj i j ijjiii ⇒ ⇒ ⇒ ⇒ += − ≤≤ −∑ ρ ρ 1 surfacesotherfrom surfacethisreachingEnergyFB nj ijj ⇒∑≤≤ − 1 surfacethisbyemmittedEnergyEi ⇒ surfacethisby reflectedEnergyFB nj ijji ⇒∑≤≤ − 1 ρ Surface patch i
  • 18. Calculating Form Factor The form factor from differential surface dAi to dAj is: ∫ ∫ ∫ = = = i j j A A ijij ji i j-i A jij ji j-di jij ji dj-di dAdAH rA F dAH r F dAH r dF 2 2 2 coscos1 coscos coscos π θθ π θθ π θθ otherwise0,dAfromvisibleisdAifH AtoAfromfactorformF AtodAfromfactorformF dAtodAfromfactorformdF jiij jij-i jij-di jidj-di ,1= = = =
  • 19. Geometric Ingredients • Three ingredients – Normal vector m at point P of the surface – Vector v from P to the viewers eye – Vector s from P to the light source m s v P
  • 20. Types of Light Sources • Ambient light: no identifiable source or direction • Diffuse light - Point: given only by point • Diffuse light - Direction: given only by direction • Spot light: from source in direction – Cut-off angle defines a cone of light – Attenuation function (brighter in center) • Light source described by a luminance – Each color is described separately – I = [I r I g I b ] T (I for intensity) – Sometimes calculate generically (applies to r, g, b)
  • 21. Ambient Light • Global ambient light – Independent of light source – Lights entire scene • Local ambient light – Contributed by additional light sources – Can be different for each light and primary color • Computationally inexpensive
  • 22. Diffuse Light • Point Source – Given by a point – Light emitted equally in all directions – Intensity decreases with square of distance – Point source [x y z 1]T • Directional Source – Given by a direction – Simplifies some calculations – Intensity dependents on angle between surface normal and direction of light – Distant source [x y z 0]T
  • 23. Spot Lights • Spotlights are point sources whose intensity falls off directionally. – Requires color, point direction, falloff parameters d P α β Intensity at P = I cosε (β)
  • 24. Based on modeling surface reflection as aBased on modeling surface reflection as a combination of the following components:combination of the following components: Used to model objects that glowUsed to model objects that glow A simple way to model indirect reflectionA simple way to model indirect reflection The illumination produced by dull smooth surfacesThe illumination produced by dull smooth surfaces The bright spots appearing on smooth shinyThe bright spots appearing on smooth shiny surfacessurfaces Phong illumination model
  • 25. • Ideal diffuse reflection – An ideal diffuse reflector, at the microscopic level, is a very rough surface (real-world example: chalk) – Because of these microscopic variations, an incoming ray of light is equally likely to be reflected in any direction over the hemisphere – What does the reflected intensity depend on? Diffuse Reflection
  • 26. Computing Diffuse Reflection • Independent of the angle between m and v • Does depend on the direction s (Lambertian surface) ms ms• = diffusesourcediffuse II ρ )0,max( ms ms• = diffusesourcediffuse II ρ Diffuse Reflection Coefficient Adjustment for ‘inside’ face )cos(θρdiffusesourcediffuse II = Therefore, the diffuse component is:
  • 27. Specular Reflection • Shiny surfaces exhibit specular reflection – Polished metal – Glossy car finish • A light shining on a specular surface causes a bright spot known as a specular highlight • Where these highlights appear is a function of the viewer’s position, so specular reflectance is view dependent
  • 28. Specular Reflection • Perfect specular reflection (perfect mirror) – Snell’s law • The smoother the surface, the closer it becomes to a perfect mirror • Non-perfect specular reflection: Phong Model – most light reflects according to Snell’s Law – as we move from the ideal reflected ray, some light is still reflected
  • 29. Non-Ideal Specular Reflectance: Phong Model An illustration of this angular falloff θ m s r
  • 30. Phong Lighting θ m s r vφ The Specular Intensity, according to Phong model: )(cos ϕρ f specularsourcespecular II = Specular Reflection Coefficient Shininess factor f specularsourcespecular II         • = vr vr ρ
  • 31. Phong Lighting Examples •These spheres illustrate the Phong model as s and f are varied:
  • 32. Blinn and Torrence Variation • In Phong Model, r need to be found – computationally expensive • Instead, halfway vector h = s + v is used – angle between m and h measures the falloff of intensity β m s h v f specularsourcespecular II         • = mh mh ρ
  • 33. Combining Everything • Simple analytic model: – diffuse reflection + – specular reflection + – ambient Surface
  • 34. The Final Combined Equation • Single light source: m s r v Viewer φ θθ f sspddaa phongIlambertIII )(×+×+= ρρρ         • = ms ms ,0maxlambert         • = mh mh ,0maxphong
  • 35. Adding Color • Consider R, G, B components individually • Add the components to get the final color of reflected light f srsprdrdrarar phongIlambertIII )(×+×+= ρρρ f sgspgdgdgagag phongIlambertIII )(×+×+= ρρρ f sbspbdbdbabab phongIlambertIII )(×+×+= ρρρ
  • 37. Applying Illumination • We have an illumination model for a point on a surface • Assuming that our surface is defined as a mesh of polygonal facets, which points should we use?
  • 38. Polygon Shading Flat Shading Gouraud Shading Phong Shading Smooth Shading Types of Shading Model
  • 39. Flat Shading • For each polygon – Determines a single intensity value – Uses that value to shade the entire polygon • Assumptions – Light source at infinity – Viewer at infinity – The polygon represents the actual surface being modeled
  • 41. Smooth Shading • Introduce vertex normals at each vertex – Usually different from facet normal – Used only for shading – Think of as a better approximation of the real surface that the polygons approximate • Two types – Gouraud Shading – Phong Shading (do not confuse with Phong Lighting Model)
  • 42. Gouraud Shading • This is the most common approach – Perform Phong lighting at the vertices – Linearly interpolate the resulting colors over faces • Along edges • Along scanlines
  • 43. Gouraud Shading xright ys ytop ybott xleft color1 color2 color3 color4y4 ( ) bott botts left yy yy colorcolorcolorcolor − − −+= 4 141 ( ) bott botts right yy yy colorcolorcolorcolor − − −+= 2 121 ( ) rightleft left leftrightleftx xx xx colorcolorcolorcolor − − −+=
  • 44. Wire-frame ModelWire-frame Model Gouraud Shading Flat ShadingFlat ShadingGouraud ShadingGouraud Shading
  • 45. Gouraud Shading • Artifacts – Often appears dull – Lacks accurate specular component • If included, will be averaged over entire polygon C1 C2 C3 Can’t shade the spot light
  • 47. Wire-frame ModelWire-frame Model Phong Shading Flat ShadingFlat ShadingGouraud ShadingGouraud ShadingPhong ShadingPhong Shading
  • 48. If a highlight does not fall on a vertex Gouraud shading may miss it completely, but Phong shading does not. Phong vs Gouraud Shading
  • 49. Shading Models (Direct lighting) • Flat Shading – Compute Phong lighting once for entire polygon • Gouraud Shading – Compute Phong lighting at the vertices and interpolate lighting values across polygon • Phong Shading – Interpolate normals across polygon and perform Phong lighting across polygon
  • 51. Lighting in OpenGL [1/2] • Enabling shading – glShadeModel(GL_FLAT) – glShadeModel(GL_SMOOTH); // Gouraud Shading only • Using light sources – Up to 8 light sources – To create a light • GLfloat light0_position[] = { 600, 40, 600, 1.0}; • glLightfv(GL_LIGHT0, GL_POSITION, light0_position); • glEnable(GL_LIGHT0); • glEnable(GL_LIGHTING);
  • 52. Lighting in OpenGL [2/2] – Changing light properties • GLfloat light0_ambient[] = { 0.4, 0.1, 0.0, 1.0 }; • GLfloat light0_diffuse[] = { 0.9, 0.3, 0.3, 1.0 }; • GLfloat light0_specular[] = { 0.0, 1.0, 1.0, 1.0 }; • glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient); • glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse); • glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular);