0% found this document useful (0 votes)
45 views48 pages

04b Lighting Full

The document describes the process of ray casting and modeling lighting and surfaces for 3D rendering. It explains how to trace primary rays from the camera and calculate direct illumination, and also discusses modeling light sources, surface reflectance, shadows, and the basics of recursive ray tracing for global illumination effects.

Uploaded by

nidharshan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views48 pages

04b Lighting Full

The document describes the process of ray casting and modeling lighting and surfaces for 3D rendering. It explains how to trace primary rays from the camera and calculate direct illumination, and also discusses modeling light sources, surface reflectance, shadows, and the basics of recursive ray tracing for global illumination effects.

Uploaded by

nidharshan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

T

h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0

( )
Thomas Funkhouser
Princeton University
C0S 426, Fall 2000

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Ray Casting
Image RayCast(Camera camera, Scene scene, int width, int height)
{
Image image = new Image(width, height);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
Ray ray = ConstructRayThroughPixel(camera, i, j);
Intersection hit = FindIntersection(ray, scene);
image[i][j] = GetColor(scene, ray, hit);
}
}
return image;
}
Wireframe

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Ray Casting
Image RayCast(Camera camera, Scene scene, int width, int height)
{
Image image = new Image(width, height);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
Ray ray = ConstructRayThroughPixel(camera, i, j);
Intersection hit = FindIntersection(ray, scene);
image[i][j] = GetColor(scene, ray, hit);
}
}
return image;
}
Without Illumination

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Ray Casting
Image RayCast(Camera camera, Scene scene, int width, int height)
{
Image image = new Image(width, height);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
Ray ray = ConstructRayThroughPixel(camera, i, j);
Intersection hit = FindIntersection(ray, scene);
image[i][j] = GetColor(scene, ray, hit);
}
}
return image;
}
With Illumination

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Illumination
How do we compute radiance for a sample ray?
Angel Figure 6.2
image[i][j] = GetColor(scene, ray, hit);

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Goal
Must derive computer models for ...
Emission at light sources
Scattering at surfaces
Reception at the camera
Desirable features
Concise
Efficient to compute
Accurate

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Overview
Direct Illumination
Emission at light sources
Scattering at surfaces
Global illumination
Shadows
Refractions
Inter-object reflections
Direct Illumination
Shadows

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Modeling Light Sources
I
L
(x,y,z,u,|,) ...
describes the intensity of energy,
leaving a light source,
arriving at location(x,y,z), ...
from direction (u,|), ...
with wavelength
(x,y,z)
Light

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Empirical Models
Ideally measure irradiant energy for all situations
Too much storage
Difficult in practice

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
OpenGL Light Source Models
Simple mathematical models:
Point light
Directional light
Spot light

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Point Light Source
Models omni-directional point source (e.g., bulb)
intensity (I
0
),
position (px, py, pz),
factors (k
c
, k
l
, k
q
) for attenuation with distance (d)
2
q l c
0
k k k
I
d d
I
L
+ +
=
d
Light
(px, py, pz)

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Directional Light Source
Models point light source at infinity (e.g., sun)
intensity (I
0
),
direction (dx,dy,dz)
0
I I
L
=
(dx, dy, dz)
No attenuation
with distance

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Spot Light Source
Models point light source with direction (e.g., Luxo)
intensity (I
0
),
position (px, py, pz),
direction D=(dx, dy, dz)
attenuation
2
q l c
0
k k k
) ( I
d d
L D
I
L
+ +
-
=
d
Light
(px, py, pz)
D
L

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Overview
Direct Illumination
Emission at light sources
Scattering at surfaces
Global illumination
Shadows
Refractions
Inter-object reflections
Direct Illumination

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Modeling Surface Reflectance
R
s
(u,|,,,) ...
describes the amount of incident energy,
arriving from direction (u,|), ...
leaving in direction (,),
with wavelength
Surface

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Empirical Models
Ideally measure radiant energy for
all combinations of incident
angles
Too much storage
Difficult in practice
Example
BRDF (Bidirectional reflectance
distribution function)
Surface
(u,|)
(,)

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
OpenGL Reflectance Model
Simple analytic model:
diffuse reflection +
specular reflection +
emission +
ambient
Surface
Based on model
proposed by Phong in
his PhD dissertation
1973

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Diffuse Reflection
Diffuse: Spread Out / To pass by
spreading every way / To extend
in all directions
Assume surface reflects equally
in all directions
Examples: chalk, clay
Surface

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Diffuse Reflection
How much light is reflected?
Depends on angle of incident light
Surface
dL
O = cos dA dL
dA
u

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Diffuse Reflection
Lambertian model
cosine law (dot product)
Surface
N
L
u
cos

cos

( )
D D L
N L N L
N L
I K N L I
= O
= O
=

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
OpenGL Reflectance Model
Simple analytic model:
diffuse reflection +
specular reflection +
emission +
ambient
Surface

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Specular Reflection
Reflection is strongest near mirror angle
Examples: mirrors, metals
N
L
R
u u

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Specular Reflection
How much light is seen?
Depends on angle of incident light and angle to viewer
N
L
R
V
Viewer
o
u u

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Specular Reflection
Phong Model
cos(o)
n
L
n
S S
I R V K I ) ( - =
N
L
R
V
Viewer
o
u u
Phong exponent: apparent
smoothness of the surface

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Specular Reflection
Phong Examples
Direction of light source and shininess exponent is varied

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
OpenGL Reflectance Model
Simple analytic model:
diffuse reflection +
specular reflection +
emission +
ambient
Surface

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Emission
Emission = 0
Represents light eminating directly from polygon

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
OpenGL Reflectance Model
Simple analytic model:
diffuse reflection +
specular reflection +
emission +
ambient
Surface

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Ambient Term
This is a total hack (avoids complexity of global illumination)!
Represents reflection of all indirect illumination

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
OpenGL Reflectance Model
Simple analytic model:
diffuse reflection +
specular reflection +
emission +
ambient
Surface

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
OpenGL Reflectance Model
Simple analytic model:
diffuse reflection +
specular reflection +
emission +
ambient
Surface

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Surface Illumination Calculation
Single light source:
L
n
S L D AL A E
I R V K I L N K I K I I ) ( ) ( - + - + + =
N
L
R
V
Viewer
o
u u

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Surface Illumination Calculation
Multiple light sources:
) ) ( ) ( (

- + - + + =
i
i
n
i S i i D AL A E
I R V K I L N K I K I I
N
L
2
V
Viewer
L
1

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Overview
Direct Illumination
Emission at light sources
Scattering at surfaces
Global illumination
Shadows
Transmissions
Inter-object reflections
Global Illumination

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Global Illumination
Greg Larson

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Shadows
Shadow terms tell which light sources are blocked
Cast ray towards each light source L
i
S
i
= 0 if ray is blocked, S
i
= 1 otherwise
Angel Figure 6.44

- + - + + =
L
L L
n
S D A A E
I S R V K L N K I K I I ) ) ( ) ( (
Shadow
Term

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Ray Casting
Trace primary rays from camera
Direct illumination from unblocked lights only

- + - + + =
L
L L
n
S D A A E
I S R V K L N K I K I I ) ) ( ) ( (

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
T T R S
L
L L
n
S D A A E
I K I K I S R V K L N K I K I I + + - + - + + =

) ) ( ) ( (
Recursive Ray Tracing
Also trace secondary rays from hit surfaces
Global illumination from mirror reflection and
transparency

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Mirror reflections
Trace secondary ray in direction of mirror reflection
Evaluate radiance along secondary ray and
include it into illumination model
T T R S
L
L L
n
S D A A E
I K I K I S R V K L N K I K I I + + - + - + + =

) ) ( ) ( (
Radiance
for mirror
reflection ray
I
R

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Transparency
Trace secondary ray in direction of refraction
Evaluate radiance along secondary ray and
include it into illumination model
T T R S
L
L L
n
S D A A E
I K I K I S R V K L N K I K I I + + - + - + + =

) ) ( ) ( (
Radiance for
refraction ray
I
T

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
T T R S
L
L L
n
S D A A E
I K I K I S R V K L N K I K I I + + - + - + + =

) ) ( ) ( (
Transparency
Transparency coefficient is fraction transmitted
K
T
= 1 if object is translucent, K
T
= 0 if object is opaque
0 < K
T
< 1if object is semi-translucent
Transparency
Coefficient
K
T

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Refractive Transparency
For thin surfaces, can ignore change in direction
Assume light travels straight through surface
N
L
O
i
T
O
r
q
r
q
i
O
i
T
L T ~

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Refractive Transparency
N
L
O
i
T
O
r
q
r
q
i
L N T
r
i
r i
r
i
q
q
q
q
O O = ) cos cos (
For solid objects, apply Snells law:
i i r r
O = O sin sin q q

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Recursive Ray Tracing
Ray tree represents illumination computation
Ray traced through scene Ray tree
T T R S
L
L L
n
S D A A E
I K I K I S R V K L N K I K I I + + - + - + + =

) ) ( ) ( (

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Recursive Ray Tracing
Ray tree represents illumination computation
Ray traced through scene Ray tree
T T R S
L
L L
n
S D A A E
I K I K I S R V K L N K I K I I + + - + - + + =

) ) ( ) ( (

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Recursive Ray Tracing
Image RayTrace(Camera camera, Scene scene, int width, int height)
{
Image image = new Image(width, height);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
Ray ray = ConstructRayThroughPixel(camera, i, j);
Intersection hit = FindIntersection(ray, scene);
image[i][j] = GetColor(scene, ray, hit);
}
}
return image;
}
GetColor calls RayTrace recursively

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Summary
Ray casting (direct Illumination)
Usually use simple analytic approximations for
light source emission and surface reflectance
Recursive ray tracing (global illumination)
Incorporate shadows, mirror reflections,
and pure refractions
More on global illumination later!
All of this is an approximation
so that it is practical to compute

T
h
o
m
a
s

F
u
n
k
h
o
u
s
e
r

2
0
0
0
Illumination Terminology
Radiant power [flux] (u)
Rate at which light energy is transmitted (in Watts).
Radiant Intensity (I)
Power radiated onto a unit solid angle in direction (in Watts/sr)
e.g.: energy distribution of a light source (inverse square law)
Radiance (L)
Radiant intensity per unit projected surface area (in Watts/m
2
sr)
e.g.: light carried by a single ray (no inverse square law)
Irradiance (E)
Incident flux density on a locally planar area (in Watts/m
2
)
e.g.: light hitting a surface along a
Radiosity (B)
Exitant flux density from a locally planar area (in Watts/ m
2
)

You might also like