CG Lesson10 (En)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 52

Lesson 10

Illuminiation and
shading
Content
1. Overview
2. Illumination
3. Shading
1.
Overview
How lights can be seen?

■ The eye works like a camera


■ Lots of photo sensors at the back of the eye
■ Sensing the amount of light coming from
different directions
■ Similar to CMOS and CCDs

Information will be sent


to brain for processing
What colour is this
dress?
Object’s colour

■ What Affects the Color of a Point on the


Object?
□ position of the sample point
□ position of the light
□ color and intensity of the light
□ camera vector
□ normal vector of the surface at the vertex
□ physical characteristics of the object
(reflectance model, color)
Colour’s illusion
Lighting and shading

■ Lighting
□ How to compute the color of objects according to
the position of the light, normal vector and camera
position
■ Shading
□ Different methods to compute the color of the
entire surface
2.
Lighting
Factors affecting lighting

Light source

Surface properties
Light source

■ Light’s properties
□ Spectrum of light source (i.e. light colour)
□ Geometry properties
▫ Position
▫ Direction
▫ Shape
□ Decline in intensity
Surface properties

■ Surface properties
□ Spectrum (i.e. surface’s colour)
□ Geometry properties
▫ Position
▫ Direction
▫ Microscope structure
Lighting

■ Assuming we have a polygon and a point of view


in 3D space, we can specify a pixel correspondingly.
■ The task in lighting is that we have to specify the
colour of that pixel

■ If we want to make the scene look *right*, we


have to simulate the lighting process on the surfaces
inside the scene
Lighting models

■ Two types of lighting models


□ Empirical: Use simple formulas to create similar
observable result
□ Physics simulation: The lighting formulas will be
based on physics formulas in lighting
■ In most cases, experimental models will be used
in interactive computer graphics applications.
■ In modern computer graphics applications,
some physic simulation models have been more
frequently used.
Phong lighting model

■ By Bui Tuong Phong (Utah University) is a


lighting model which is a combination of both
experimental and physics simulation
■ Is the sum of 3 illumination terms
□ Ambient : 'background' illumination
□ Diffuse : non-shiny illumination and shadows
□ Specular : bright, shiny reflections
Ambient light
Ambient light

■ Light from the environment


■ Light reflected or scattered from other objects
■ Coming uniformly from all directions and then
reflected equally to all directions
■ A precise simulation of such effects requires a
lot of computation
➢Use a simple “trick” called ambient light
Ambient light

■ Simple approximation to complex 'real-world‘


process
➢Result: globally uniform color for object
Ambient light

■ For each lighting process, the ambient light


reflected from object surface only depends on
□ Surface’s properties
□ Intensity of the ambient light source (is a constant
with every point on object surface)

E.g. a sphere
Ambient light

I = ka Ia
□ I = resulting intensity
□ Ia = light intensity
□ ka = reflectance

E.g. a sphere
Example: Ambient light
What about this?
Diffuse light
Diffuse light

■ When light hits an object


□ If the object has a rough surface, it is reflected to
various directions

□ Result: Light reflected to all directions

What are the factors affecting diffuse light intensity?


Diffuse light

■ The smaller the angle between the incident


vector and the normal vector, the higher the chance
that the light is reflected back
■ When the angle is larger, the reflection light gets
weaker because the chance the light is shadowed /
masked increases
Lambert’s Cosine Law
“The radiant intensity or luminous
intensity observed from an ideal diffusely
reflecting surface or ideal diffuse radiator
is directly proportional to the cosine of the
angle θ between the direction of the
incident light and the surface normal”

l n


Example: Diffuse Light

■ Not depend on viewing direction


■ Only depend on the angle between light source
and surface normal
Diffuse light

I = kd Ip cos 
■ Ip: diffuse reflectivity
■ : the angle between the normal vector
direction towards the light
■ kd: Light Intensity

E.g. sphere
(light from the left)

Does NOT depend on


camera’s position
Specular light
Specular reflection

■ Direct reflections of light source off shiny object


□ The object has a very smooth surface
□ E.g. gloss metal, car surface

Specular
Highlight
Specular reflection

■ Reason: In microscope level, the surface of


specular surface is very smooth, therefore the
specular reflection is similar to reflection on mirror
■ The smoother the surface, the more it looks like
a mirror
■ Following Snell’s law

l = r
Specular reflection

■ For *less than ideal* surface


□ Instead of having to model the microscopic level of
the surface to handle conventional reflection
□ When the light touches the surface, some of the
light will be reflected in a slightly different direction
than the ideal ray.
□ Higher the angle of deviation from the ideal
reflector, the less light reflected
Specular highlight

I = ksIp (cos  )
nshiny

■ specular intensity n = shiny reflectance of object


■ Result: specular highlight on object
□ This is an empirical calculation and isn’t based on
any physics formula

E.g. a sphere

Does NOT depend on


surface’s colour
Changing the n-shiny

■ Reflection with different nshiny value


Phong lighting
model
Phong lighting model

■ By Bui Tuong Phong (Utah University) is a


lighting model which is a combination of both
experimental and physics simulation
■ Is the sum of 3 illumination terms
□ Ambient : 'background' illumination
□ Diffuse : non-shiny illumination and shadows
□ Specular : bright, shiny reflections
Phong lighting model

■ Resulting intensity will be calculated by the


sum of all terms
𝐼 = 𝐼𝑎 𝑘𝑎 + 𝐼𝑝 𝑘𝑑 cos 𝜃 + 𝑘𝑠 cos 𝑛 𝜑
■ If there are many light sources
□ Calculate the sum of all light intensity
𝑙𝑖𝑔ℎ𝑡𝑠

𝐼 = 𝐼𝑎 𝑘𝑎 + ෍ 𝐼𝑝 𝑘𝑑 cos 𝜃 + 𝑘𝑠 cos 𝑛 𝜑
𝑝
Phong lighting model

■ We can also use dot product

( ) ( )
lights
I = k a I a +  I p  k d Nˆ  Lˆ + k s Vˆ  Rˆ 
nshiny

i =1  
□ V: Vector from the surface to the viewer
□ N: Normal vector at the colored point
□ R: Normalized reflection vector
□ L: Normalized vector from the colored
point towards the light source
3.
Shading
Overview

■ The illumination model computes the color of


sample points
■ How do we color of the entire object?
➢This is done at the rasterization level
■ The procedure to color the entire surface is
called shading
Flat shading

■ Compute the color at the middle of the polygon


■ All points in the same polygon are colored by
the same color
■ Works well for objects really made of flat faces
Example scene: Flat shading
Flat shading: Problem

■ Suffers from Mach band effect


□ Humans are very sensitive to the sudden change of
the brightness
■ The artefact remains although the polygon
number is increased
Goraud shading

■ by Henri Gouraud
■ Computing the color per vertex by local
illumination model
■ Then, interpolating the colors within the
polygons
□ We can interpolate the color by barycentric
coordinates
Example scene: Goraud shading
Goraud shading: Problem

■ For specular
reflection, highlight falls
off with cosnα
■ Gouraud shading
linear interpolates –
makes highlight too
big.
■ Gouraud shading
may well miss a
highlight that occurs in
the middle of the face.
Phong shading

■ by Bui Tuong Phong


■ Doing the lighting computation at every pixel
during rasterization
■ Interpolating the normal vectors at the vertices
(again using barycentric coordinates)
Phong shading process

1. For every vertex of the object, compute its


normal vector
2. Project the vertices onto the screen
3. When rasterizing the pixels, interpolate the
normal vector, position of the point (and the
light and camera vector if necessary) using
barycentric coordinates, and do the lighting
computation.
Example scene: Goraud shading
Comparison between shading techniques
Thanks!
Any questions?
Credits

Lecture notes provided by School of Information and


Communication Technology, Hanoi University of Science and
Technology.
Composed by Huynh Quyet Thang, Le Tan Hung, Trinh Thanh
Trung and others
Edited by Trinh Thanh Trung

Special thanks to all the people who made and released these
awesome resources for free:
■ Presentation template by SlidesCarnival
■ Photographs by Death to the Stock Photo (license)
■ Diverse device hand photos by Facebook Design
Resources

You might also like