TNM046: Global Lighting Models

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

TNM046: Global lighting models

Mark Eric Dieckmann, VITA, ITN Linkpings universitet o Campus Norrkping o SE-60174 Norrkping o

May 19, 2010

Content of lecture

Revise the rendering equation. Ray-tracing is discussed as a method that is good for specular reection. The fundamental mechanisms (refraction, reection) are presented. The concept of importance is introduced as a complementary quantity to intensity.

A brief outlook about further techniques is presented.

Rendering equation for opaque objects


We had previously introduced the rendering equation as: I (x, x ) = g (x, x ) (x, x ) + s (x, x , x ) I (x , x ) dx

The intensity I (x, x ) tells us how much light arrives at the point x from the direction of the point x . The point x can be the eye or another object point.

The point x can be seen from x, if the visibility function g (x, x ) = 1. Light sources can be introduced by setting (x, x ) = 0. The surface reection is specied by (x, x , x ). The intensity I (x , x ) determines how much light arrives at x from x .

The approximations

We have computed the intensity using information about:


1. The light source. 2. The surface normal. 3. The observer (for specular light reection).

No reections between two object points are taken into account. Thus we can not model any shadows. Such illumination models are called local lighting models.

Global lighting models compute the intensity by considering also reections between two object points.

Ray-tracing
The rendering equation considers the interplay of the light with the objects in the scene: A point light source emits rays.
Obj 2 Eye Light

Each light beam is (perfectly) reected once. We neglect for now transmission through the object. The light beams can encounter several objects.

Obj 4 Obj 1

Obj 3

Problem: We emit three light beams, we get in total 6 reections, but only one beam hits the eye. The others just leave the scene.

Ray-tracing
If we follow the light from the light source into the scene, many rays do not contribute to the intensity calculation at the camera.
Light

Obj 2 Eye

We launch rays from the camera instead Back-tracing. Now every ray we consider contributes to the intensity calculation at the camera.

Obj 4 Obj 1

Obj 3

Problem: Only light rays that hit a light source will carry an intensity dierent from zero. Most rays miss the light source They will not contribute to the intensity calculation due to a zero intensity.

From ray-tracing to Whitted ray-tracing

In true ray-tracing we follow many rays from the light source to the camera and let them bounce o the objects. Many computations do not contribute to the visual result: If we launch rays at the light source (forward-tracing), most rays miss the camera. If we launch rays at the camera (back-tracing), most rays miss the light source.

Back-tracing allows us to cheat: Whitted-ray tracing (1980). We can add to the ray at each ray-object intersection an intensity contribution calculated with a local lighting model.

Whitted ray-tracing
Consider a ray that is traced backwards from the eye through a pixel into the scene.
Light

The eye position is x.


L Incoming ray

Screen N Eye X Pixels Refl. ray

The ray direction is given by the vector from the pixel to x. The rst intersection of the ray with an object gives the x in the rendering equation.

X Obj 1

The incoming ray that is reected to the eye does not hit the light source No intensity if we use the global model. We use the light source direction L and the object normal N to add diuse light Id = N L if Id 0 to the ray.

Reection laws
Perfect reection will make the object look like a mirror. We can make it look like glass too.
Light Incom. ray N

Reflected ray

We have an incoming light beam and a (perfectly) reected one. The angle between the normal N and each ray is . If the material is transparent (glass), then some of the light can enter the object.

Surface Refracted ray

The angle between the surface normal and the refracted ray is .

Reection laws
Perfect reection and perfect refraction are now considered. The surface normal is N. The following rays are relevant: 1. The incoming ray is I . 2. The reected ray is R. 3. The refracted (transmitted) ray is T . It can be shown that all rays and N lie in the same plane. We can determine the angle between I , N and between N, R. We must calculate R. No trick is possible, like for the computation of the intensity due to the specular reection.

Reection laws
The angle between N and T is given by Snells law :
I N R

n2 sin = . sin n1
n1

The refractive indices of material 1 and 2 are n1 and n2 . The sketch assumes n2 > n1 . The refractive indices of air 1 and glass 1.5.

n2

As long as the ray hits a medium with a higher refractive index (air to glass), nothing special happens. We nd one and thus one T for every 0 90 .

Reection laws
The situation is dierent if n1 > n2 (ray goes from glass into air). Snells law: sin / sin = n2 /n1 For , 90 we can approximate sin and sin and Snells law: n1 /n2 = . The angle grows faster than .
I1 I2 I3 I4 N R4 R3 R2 R1

If m = 90 then sin m = 1. Thus sin m = n2 /n1 .

n1
T2

If n1 /n2 = 1.5 then m 42 . Rays with > m are totally reected and no T exists.

n2

T4

T3

If we implement transparency in Whitted ray tracing, we must be careful with the refracted beam.

Reection laws

We have determined the direction vectors R and T of the reected and transmitted rays. These are uniquely set by the surface normal N and the incoming light direction I .

The intensity moving along I must be split and distributed over R and T . In principle we should use the computationally expensive Fresnel equations to determine the intensity IT along T and the intensity IR along R. It is simpler and faster to use its small-angle approximation:

Reection laws
We normalize all intensities at this intersection point such, that the intensity of the incoming light is II = 1. The rays I and R move through the material with the refractive index n1 . The transmitted ray T moves through the material with the refractive index n2 . The small-angle expansion ( 90 ) predicts the intensities IT (transmitted ray) and IR (reected ray). IR = n1 n2 n1 + n2
2

, IT = 1 IR =

4n1 n2 (n1 + n2 )2

We assume II = 1. If II = 1, then we multiply II to IR and IT .

Whitted ray-tracing
We can use the reection / refraction laws to compute the intensity in the global model. Careful: Forward tracing: The vector I is the incoming ray. Backward tracing: The vector I is anti-parallel to the reected ray.
Incoming ray N
Ray refracted to camera

Forward (light) tracing: We compute with the refraction law the refracted incoming ray. Backward (ray) tracing: We compute the ray refracted to the camera.

Reflected ray towards camera

Refracted incoming ray

The relation between the intensities I (incoming I ), IR (reected R) and IT (refracted T ) is the same in both cases.

Whitted ray-tracing

The laws for perfect reection and perfect refraction work for forward (light) tracing and backward (ray) tracing. We obtain (between the normal and the incoming or reected ray) and between the normal and the refracted ray. An intensity II along the incoming ray I is subdivided into IR along R (reected ray) and IT along T (refracted ray) with II = IR + IT (loss-free material). The term intensity is dened only for light and is used for forward tracing. The importances WI , WT and WR replace the intensities II , IT and IR in backward tracing.

Importance
The blue arrows show the ow direction of (light) intensity towards the camera. The ray I collects intensity from R and from T . The brown arrows show the ow direction of importance: We call them importance rays to distinguish them from light rays. The parent (importance) ray splits up into a reected ray R and a refracted ray T .
Ray I to camera N Reflected ray R
Branch point

WT

WI

WR
Parent ray: Level j Rays: Level j+1

Importance W
WT Refracted ray T

WR
R

Importance rays for backward tracing behave like light rays for forward tracing.

Importance
Implementation: An importance ray is launched at the eye and traced through the scene as it intersects objects. We compute the intersection points importance ray-object. We store the coordinates in a list.
R R T R L0 T R T T R

A blue circle denotes a ray-object intersection. A reected ray R and a refracted ray T are launched. A tree structure is built up.

R R R T L1 L2 T L3 T L4

Each recursion level Li corresponds to a branch point.

Whitted ray-tracing

The tree structure reveals why we only use perfect reection and perfect refraction. We must follow even in this case 2N rays after N ray-surface intersections.

Representing a reection lobe for specular or diuse reection with many rays is too costly. 10 reected rays: We have 10N rays after N intersections. Even for the case of perfect reection / refraction, we must stop the iteration. 10 Iterations already give 210 = 1024 rays. Just for one pixel.

Whitted ray-tracing
Stopping conditions for ray-tracing are:

The importance ray hits the light source (unlikely). The importance ray hits an object that is not a perfect reector / refractor. Often the walls in ray-traced scenes are diuse reectors.

The contributions of the two new importance rays to the pixel intensity are less than that of the initial ray. After several iterations, further iterations may not improve the image quality any more and we stop it.

We set a maximum number of iterations: The ray is not followed any more after this number of iterations is reached.

Whitted ray-tracing

We know how much importance (WR and WT ) the two rays at the level Lj+1 contribute to their parent ray at the level Lj . The importance tells us how much each ray at the level Lj+1 contributes to the intensity at Lj . Example: II = WR IR + WT IT , if 0 II , IR , IT 1. The ray-surface intersection points Sj are known. A shadow ray goes from Sj to the light source with position L. If the ray does not intersect any object, then the surface point sees the light source. The normal N at Sj and the light direction L Sj gives the intensity Id using a local lighting model.

Whitted ray-tracing
We calculate the ray intensity at level Lj using the intensities at level Lj+1 and that due to our local model:
D

Ray surface inter section

WR WT

We can consider the system as three canals, which can, but may not carry intensity. The widths of the canals are D + WR + WT = 1.

Branching point in tree

Intensity ow along the canals: ID (local model), IR (reected importance ray) and IT (refracted importance ray). The intensity Ij in the left canal (level Lj ) is, for 0 ID , IR , IT 1: Ij = WR IR + WT IT + D Id . The constant 0 D 1 determines how important the diuse reection component is.

Whitted ray-tracing
We have all components for ray-tracing. This is what we do:

Dene the scene (light sources, objects, walls and their material properties) Make a loop over all pixels. Shoot an importance ray from the eye through a pixel into the scene. Calculate reected and refracted importance rays. We carve out the light canals corresponding to this pixel. Stop the method at a certain iteration level or when the ray hits a diuse object: You get a tree. Calculate the intensity and colour at the tips of the twigs (e.g. that at the walls. Follow the light through the canals: At each branch point you combine colour and intensity of the contributions: Diuse light and reected / refracted light. Give the colour/intensity you get at iteration L0 to the pixel.

Brief overview over further visualization methods

Whitted ray-tracing is an elegant scheme for perfectly reecting / refracting objects. It is view dependent. You can already implement a Whitted ray-tracer.

Ray-tracing can be expanded to include also diuse reectors: Monte-Carlo ray tracing. Diuse reection is captured by Radiosity. Transparent objects are dealt with by Volume Rendering. Some schemes combine forward and backward tracing: Bi-directional schemes.

You might also like