Upload
primrose-franklin
View
214
Download
1
Tags:
Embed Size (px)
Citation preview
Fundamentals of Computer GraphicsPart 6
Shading
prof.ing.Václav Skala, CSc.University of West Bohemia
Plzeň, Czech Republic
©2002Prepared with Angel,E.: Interactive Computer
Graphics – A Top Down Approach with OpenGL, Addison Wesley, 2001
Fundamentals of Computer Graphics 2
Shading – Light and Matter Our perception depends on:
– light directly – intensity, spectrum (color), position
– material of objects that “reflects” or “transmit” light, roughness, color of the surface
Speed of computation – significant factor
Fundamentals of Computer Graphics 3
Shading – Light and Matter Generally we do not need to
compute all, but just those rays that contribute to the final image
Methods:
• Global – ray tracing, radiosity – very slow
• Local – constant, Gouraud, Phong etc. – relatively fast
Fundamentals of Computer Graphics 4
Shading – Light and Matter Interaction between
light and materialscan be classified as
• specular surfaces –ideal mirror
• diffuse surfaces – reflected light is ideally reflected to all directions uniformly
• translucent surfaces – allow some lights to penetrate the surface – refraction – glass, watter
• optical properties – Snell’s law
Fundamentals of Computer Graphics 5
Shading – Light sources Light source – an object with a surfaceEach point (x,y,z) on the surface can emit
light with characterization:• direction of emission (,)• intensity of energy emitted at each
wavelength illumination function I(x,y,z,,,)
Basic light sources (sufficient for rendering the most simple scenes):
• ambient lighting • point sources • spotlights• distance light
Fundamentals of Computer Graphics 6
Shading – Light sources Light - an object with a surface
Each point (x,y,z) on the surface can emit light with characterization:
• direction of emission (,)
• intensity of energy emitted at each wavelength
illumination function I(x,y,z,,,)
Usually I = [ Ir , Ig , Ib ]T
is handled as a scalar value
Basic light sources - sufficient for rendering the most simple scenes:
• ambient lighting • point sources • spotlights• distance light
Fundamentals of Computer Graphics 7
Shading – Light sources Ambient light Ia- uniform light in
the space (room etc.)
Ideal point source – emits equally in all directions I(p0)
Light received at a point p
full shadow – umbrapartial shadow – penumbra
for non-point sources (d is distance)
020
01
, pIpp
ppI
12 bdbda
Fundamentals of Computer Graphics 8
Shading – Light sources Spotlights – very narrow angles of
emission, if = 180° -> point source
distribution of light within the cone – usually cose() ; e determines how rapidly intensity drops off
cos() = sT ls – vector that points
from ps to a point s on a surface
l – vector of the light direction
Fundamentals of Computer Graphics 9
Shading – Distant light sources we replace location of light sources
with their directions
p0 = [ x , y , z , 0 ]T ( 0 is correct !)
Phong Reflection Model
I = Ia + Id + Is
disadvantages
• linear model
• superposition
Fundamentals of Computer Graphics 10
Ambient, Diffuse, Specular Reflections Ambient reflection
0 ka 1
Ia = ka La global ambient term or light
Diffuse reflection
• characterized by rough surfaces
• perfectly diffuse surfaces – Lambertian surfaces
Fundamentals of Computer Graphics 11
Ambient, Diffuse, Specular Reflections Lambert’s law:
diffuse reflection 0 kd 1
if the influence of the distance is considered
dT
dd LnlkI )(
dTd
d Lnlcdbda
kI )(2
Fundamentals of Computer Graphics 12
Ambient, Diffuse, Specular Reflections Specular Reflection: 0 ks 1
as ideal specular reflection
<100 , 500> metallic surfaces
cossss LkI
Fundamentals of Computer Graphics 13
Polygonal Shading How to display surfaces with shading?
Flat (constant) shading
glShadeModel(GL_FLAT);
Mach bands
Fundamentals of Computer Graphics 14
Polygonal Shading Interpolative and Gouraud shading
Gouraud shading
glShadeModel(GL_SMOOTH);
normal in a vertex
• average normal vector
• intensity computation for a vertex
• intensity & color interpolation for a scan-line
Fundamentals of Computer Graphics 15
Polygonal Shading Phong shading
normal in a vertex
• interpolation of a normal
• normal interpolation along the scan-line
• intensity computation
Phong shading is almost always done off-line
Fundamentals of Computer Graphics 16
Light Sources in OpenGL
Study 6.6 – 6.9 on your own
Fundamentals of Computer Graphics 17
Global Rendering – Ray tracing
global versus local lightings models
Fundamentals of Computer Graphics 18
Global Rendering – Ray tracing
Algorithm complexity:O(M2 N 2k)
M – resolution of a screenN – number of objectsk – number of levels of the tree
Typical program:POV Ray – available free