Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray,...

53
Lighting and Reflectance COS 426, Spring 2020 Felix Heide Princeton University

Transcript of Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray,...

Page 1: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Lighting and Reflectance

COS 426, Spring 2020

Felix Heide

Princeton University

Page 2: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

R2Image *RayCast(R3Scene *scene, int width, int height)

{

R2Image *image = new R2Image(width, height);

for (int i = 0; i < width; i++) {

for (int j = 0; j < height; j++) {

R3Ray ray = ConstructRayThroughPixel(scene->camera, i, j);

R3Rgb radiance = ComputeRadiance(scene, &ray);

image->SetPixel(i, j, radiance);

}

}

return image;

}

Ray Casting

Without Illumination

Page 3: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Ray Casting

R3Rgb ComputeRadiance(R3Scene *scene, R3Ray *ray)

{

R3Intersection intersection = ComputeIntersection(scene, ray);

return ComputeRadiance(scene, ray, intersection);

}

With Illumination

Page 4: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Illumination

• How do we compute radiance for a sample ray

once we know what it hits?

Angel Figure 6.2

ComputeRadiance(scene, ray, intersection)

Page 5: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Goal

• Must derive computer models for ... Emission at light sources

Scattering at surfaces

Reception at the camera

• Desirable features … Concise

Efficient to compute

“Accurate”

Page 6: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Overview

• Direct Illumination Emission at light sources

Scattering at surfaces

• Global illumination Shadows

Refractions

Inter-object reflections

Direct Illumination

Page 7: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Emission at Light Sources

• IL(x,y,z,q,f,l) ... describes the intensity of energy,

leaving a light source, …

arriving at location(x,y,z), ...

from direction (q,f), ...

with wavelength l (x,y,z)

Light

Page 8: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Empirical Models

• Ideally measure irradiant energy for “all” situations Too much storage

Difficult in practice

x,y,z,q,f,l

Page 9: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

OpenGL Light Source Models

• Simple mathematical models: Point light

Directional light

Spot light

Page 10: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Point Light Source

• Models omni-directional point source intensity (I0),

position (px, py, pz),

coefficients (ca, la, qa) for attenuation with distance (d)

2

0I

dqdlcI

aaa

L++

=

d

Light

(px, py, pz)

Page 11: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Point Light Source

• Physically-based: “inverse square law” ca = la = 0

• Use ca and la 0 for non-physical effects Better control of the look (artistic)

2

0I

dqdlcI

aaa

L++

=

Page 12: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Directional Light Source

• Models point light source at infinity intensity (I0),

direction (dx,dy,dz)

0IIL =

(dx, dy, dz)

No attenuation

with distance

Page 13: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Spot Light Source

• Models point light source with direction intensity (I0),

position (px, py, pz),

direction (dx, dy, dz)

attenuation with distance

falloff (sd), and cutoff (sc)

++

=

otherwise0

,if)(cosI

2

0 scdqdlcI

aaa

sd

L

d

(px, py, pz) D

L Θ = cos-1(L D)

sc

Page 14: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Overview

• Direct Illumination Emission at light sources

Scattering at surfaces

• Global illumination Shadows

Refractions

Inter-object reflections

Direct Illumination

Page 15: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Scattering at Surfaces

Bidirectional Reflectance Distribution Function

fr(qi,fi,qo,fo,l) ... describes the aggregate fraction of incident energy,

arriving from direction (qi,fi), ...

leaving in direction (qo,fo), …

with wavelength l

Surface

(qi,fi)

l

(qo,fo)

Page 16: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Empirical Models

Ideally measure BRDF for “all” combinations of

angles: qi,fi,qo,fo

Difficult in practice

Too much storage

Page 17: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Parametric Models

Approximate BRDF with simple parametric function

that is fast to compute. Phong [75]

Blinn-Phong [77]

Cook-Torrance [81]

He et al. [91]

Ward [92]

Lafortune et al. [97]

Ashikhmin et al. [00]

etc.

Lafortune [97]

Cook-Torrance [81]

Page 18: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

OpenGL Reflectance Model

• Simple analytic model: diffuse reflection +

specular reflection +

emission +

“ambient”

Surface

Based on model

proposed by Phong

Page 19: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

OpenGL Reflectance Model

• Simple analytic model: diffuse reflection +

specular reflection +

emission +

“ambient”

Surface

Based on Phong

illumination model

Based on model

proposed by Phong

Page 20: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Diffuse Reflection

• Assume surface reflects equally in all directions Examples: chalk, clay

Surface

Page 21: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Diffuse Reflection

• What is brightness of surface? Depends on angle of incident light

Surface

q

Page 22: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Diffuse Reflection

• What is brightness of surface? Depends on angle of incident light

Surface

dL

= cosdAdL

dA

q

Page 23: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Diffuse Reflection

• Lambertian model cosine law (dot product)

LDD ILNKI )( =

Surface

N

Lq

Page 24: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

OpenGL Reflectance Model

• Simple analytic model: diffuse reflection +

specular reflection +

emission +

“ambient”

Surface

Page 25: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Specular Reflection

• Reflection is strongest near mirror angle Examples: mirrors, metals

N

LR qq

Page 26: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Specular Reflection

How much light is seen?

Depends on: angle of incident light

angle to viewerN

LR

V

Viewer

a

qq

Page 27: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Specular Reflection

• Phong Model (cos a)n

L

n

SS IRVKI )( =

N

LR

V

Viewer

a

qq

This is a (vaguely physically-motivated) hack!

Page 28: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

OpenGL Reflectance Model

• Simple analytic model: diffuse reflection +

specular reflection +

emission +

“ambient”

Surface

Page 29: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Emission

Represents light emanating directly from surface Note: does not automatically act as light source!

Does not affect other surfaces in scene!

Emission 0

Page 30: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

OpenGL Reflectance Model

• Simple analytic model: diffuse reflection +

specular reflection +

emission +

“ambient”

Surface

Page 31: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Ambient Term

This is a hack (avoids complexity of global illumination)!

Represents reflection of all indirect illumination

Page 32: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

OpenGL Reflectance Model

• Simple analytic model: diffuse reflection +

specular reflection +

emission +

“ambient”

Surface

Page 33: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

OpenGL Reflectance Model

• Simple analytic model: diffuse reflection +

specular reflection +

emission +

“ambient”

Surface

Page 34: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

OpenGL Reflectance Model

Sum diffuse, specular, emission, and ambient

Leonard McMillan, MIT

Page 35: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

OpenGL Reflectance Model

Good model for plastic surfaces, …

Page 36: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Direct Illumination Calculation

Single light source:

L

n

SLDALAE IRVKILNKIKII )()( +++=

N

LR

V

Viewer

a

qq

Page 37: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Direct Illumination Calculation

Multiple light sources:

( ) L

L

n

iSiDALAE IRVKLNKIKII +++= )()(

N

L2

V

Viewer L1 Note:

all of the

K and I

are RGB

colors

Page 38: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Example from production

This scene had 400 virtual lights (~100 params)

Pixar

Page 39: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Overview

• Direct Illumination Emission at light sources

Scattering at surfaces

• Global illumination Shadows

Transmissions

Inter-object reflections

Global Illumination

Page 40: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Global Illumination

Greg Ward

Page 41: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Ray Casting (last lecture)

Trace primary rays from camera Direct illumination from unblocked lights only

( ) L

L

n

iSiDALAE IRVKLNKIKII +++= )()(

Page 42: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Shadows

Shadow term tells if light sources are blocked Cast ray towards each light source

SL = 0 if ray is blocked, SL = 1 otherwise

Shadow

Term

( ) LL

L

n

iSiDALAE ISRVKLNKIKII +++= )()(

Page 43: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Recursive Ray Tracing

Also trace secondary rays from hit surfaces Mirror reflection and transparency

( ) TTRSLL

L

n

iSiDALAE IKIKISRVKLNKIKII +++++= )()(

Page 44: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

( ) TTRSLL

L

n

iSiDALAE IKIKISRVKLNKIKII +++++= )()(

Mirror reflections

Trace secondary ray in mirror direction Evaluate radiance along secondary ray and

include it into illumination model

Radiance for mirror

reflection ray

Page 45: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

( ) TTRSLL

L

n

iSiDALAE IKIKISRVKLNKIKII +++++= )()(

Transparency

Trace secondary ray in direction of refraction Evaluate radiance along secondary ray and

include it into illumination model

Radiance for refraction ray

Page 46: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

( ) TTRSLL

L

n

iSiDALAE IKIKISRVKLNKIKII +++++= )()(

Transparency

Transparency coefficient is fraction transmitted KT = 1 for translucent object, KT = 0 for opaque

0 < KT < 1 for object that is semi-translucent

Transparency

Coefficient

Page 47: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Refractive Transparency

For thin surfaces, can ignore change in direction Assume light travels straight through surface

N

L

i

Tr

hr

hi

i

T LT −

Page 48: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Refractive Transparency

N

L

i

Tr

hr

hi

LNTr

iri

r

i

h

h

h

h−−= )coscos(

For solid objects, apply Snell’s law:

iirr = sinsin hh

Page 49: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Recursive Ray Tracing

Ray tree represents illumination computation

Ray traced through scene Ray tree

( ) TTRSLL

L

n

iSiDALAE IKIKISRVKLNKIKII +++++= )()(

Page 50: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Recursive Ray Tracing

Ray tree represents illumination computation

Ray traced through scene Ray tree

( ) TTRSLL

L

n

iSiDALAE IKIKISRVKLNKIKII +++++= )()(

Page 51: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Recursive Ray Tracing

ComputeRadiance is called recursively

R3Rgb ComputeRadiance(R3Scene *scene, R3Ray *ray, R3Intersection& hit)

{

R3Ray specular_ray = SpecularRay(ray, hit);

R3Ray refractive_ray = RefractiveRay(ray, hit);

R3Rgb radiance = Phong(scene, ray, hit) +

Ks * ComputeRadiance(scene, specular_ray) +

Kt * ComputeRadiance(scene, refractive_ray);

return radiance;

}

Page 52: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

Example

Turner Whitted, 1980

Page 53: Lighting and Reflectance › ... › Lecture-12.pdfAngel Figure 6.2 ComputeRadiance(scene, ray, intersection) Goal ... angles: q i,f i,q o,f o Difficult in practice Too much storage.

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 after next week!

All of this is an approximation

so that it is practical to compute