Top Banner
1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok [email protected]
48

1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok [email protected].

Dec 21, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

1

7M836 Animation & Rendering

Global illumination, ray tracing

Arjan Kok

[email protected]

Page 2: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

2

Local illumination models

• What is missing in local (Phong) illumination model

• (Shadows)

• Real mirrors

• Transparency

• Area light sources

• Indirect diffuse reflection

• Atmosphere

Page 3: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

3

Light paths

• Light path notation

• L: light source

• D: diffuse reflection

• S: specular reflection

• E: eye point

• Local reflection models: L(D|S)E

• Complete solution: L(D|S)*E

Page 4: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

4

Global illumination models

• Illumination for complete scene

• All illumination, also indirect illumination

• Several approaches:

• Ray tracing

• Radiosity

• …

Page 5: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

5

Brute force solutions

• Trace photons from light source into scene

• Follow paths of photons through reflections/transmissions

• At each reflection/transmission “energy” of photon is modified (part of energy absorbed by surface)

• Photons that go though image plane and reach eye contribute to image.

Page 6: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

6

Trace photons

Page 7: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

7

Trace photons

• Light paths complete solution: L(D|S)*E

• Forward ray tracing

• Problem

• Most photons will not contribute to image

Page 8: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

8

Backward ray tracing

• Only trace light that arrives at viewpoint through viewing plane

• Trace light backwards from viewpoint until light source reached

• (Backward) Ray tracing

Page 9: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

9

Ray tracing

• Basic algorithm

• for all pixels in image plane

• create ray from eye point through pixel

• trace this ray on his path(s) through scene until it reaches light source(s) and collect illumination encountered during travel

• amount of collected lightdetermines color of pixel

eye

pixel

Page 10: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

10

Ray tracing – example 1

eye

image plane

LA LB

S1S2

4

3

2

1

R1

S4

S3

V1

Object 1 diffuse & specular

Page 11: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

11

Ray tracing – example 2

eye

image plane

LA LB

S1S2

4

3

2

1 S6S5

V1

T1

Object 1 diffuse & transparent

Page 12: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

12

Ray tracing

1. Create viewing ray2. Trace ray3. At intersection point

a. Compute (local) illumination. Trace shadow rays to light sources to account for shadows.

b. If surface at intersection specularly reflecting, trace shadow ray and compute its contribution:continue at step 2

c. If surface at intersection transparent, trace transparency ray and compute its contribution: continue at step 2

d. Sum contribution of steps (a), (b) and (c)

Page 13: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

13

Ray-tracing picture (Whitted 80)

Page 14: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

14

Example using ray tracing

Page 15: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

15

Computations in ray-tracing

• Creation of viewing ray

• Intersection computation

• Find first intersected object (ray-scene intersection)

• Point of intersection

• Normal (and local coordinates) of intersection point

• Creation shadow rays

• Creation reflection rays

• Creation transparency rays

• Illumination

Page 16: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

16

Creation viewing ray

• Origin is eye point (E)

• Through pixel (P)

• R(t) = E + V * t t > 0

• PEPE

V

E

P

Page 17: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

17

Ray-scene intersection

• Compute intersection of ray R(t) with all objects in scene

• Intersection with smallest positive intersection distance t gives intersected object

t = 2

t = 5

t = 3

Page 18: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

18

Ray-object intersection

• Ray equation

R(t) = Ro + Rd * t t > 0

• Ro = ray origin

• Rd = ray direction

• ||Rd|| = 1

• Object

• Implicit surface: f(x) = 0

• Polygons

• …

Page 19: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

19

Ray-sphere intersection

• Sphere

||P – C||2 – r2 = 0

• Substitution of R(t) for P gives

t2 + 2bt + c = 0

• b = Rd • (Ro – C)

• c = ||Ro – C||2 – r2

• Solution for t gives intersection points

P’

Pr

R0

Rd

N

C

cbbt 2

2,1

Page 20: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

20

Ray-sphere intersection

• Solutions for t1 and t2:

• Normal at intersection point

N = (P – C) / r

P’

Pr

Ro

Rd

N

C

t2

t1

t1 = t2

t2

t1t2

t1

Page 21: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

21

Ray-polygon intersection

• Two steps

1. Intersect ray with plane of polygon.Compute intersection point

2. Determine if intersection point within polygon

• Normal of intersection point is plane normal

R0

Page 22: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

22

Ray-polygon intersection

• Intersection ray-plane

• Equation of plane: Ax + By + CZ + D = 0

• Substitution of R(t) for x, y, and z gives:

where N is normal of plane: {A, B, C}

z,dy,dx,d

z,oy,ox,o

R*CR*BR*A

DR*CR*BR*At

d

o

RN

DRNt

Page 23: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

23

Ray-polygon intersection

• Determine if intersection point within polygon (2D)

• Draw line from intersection point in a direction

• Count number of intersection with edges of polygon

• If count even, than point outside polygon, otherwise inside

Page 24: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

24

Shadow ray

• Determine if point is illuminated by light source• Shadow ray:

• R(t) = P + S * t t > 0

• Point P is illuminated by light source L if there is no intersection of shadow ray with scene for 0 < t < ||L – P||

PLPL

S S

P

L

Page 25: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

25

Reflection ray

• Physical laws:

• R, N, and I are in same plane: R = αI + βN

• Angle of incidence = angle of reflection: θr = θi

• Reflection ray direction θi I

N

θrR

N)IN(2I

N)cos(2IR i

Page 26: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

26

Reflection

Page 27: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

27

Transparency ray

• Snell’s law:

• ηi = index of refraction medium i with respect to vacuum

• ηit = index of refraction medium I with respect to medium t

• Transparency ray direction

1

221

2

1

)sin()sin(

N))1)((cos1)cos((IT i

22

itiitit

θi

I

N

θt

medium imedium t

T

Page 28: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

28

Transparency

Page 29: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

29

Transparency

Page 30: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

30

Illumination

• Phong illumination model for local illumination

i

i

n

ssiDDiAAAE cosCkcosCkIICkII

αi

θiRi Li

V

N

Page 31: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

31

Illumination for ray tracing

• Extension of local model with shadow information, mirroring and transparency

• Si = shadow factor (0, 1)• IR = intensity of reflection ray• IT = intensity of transmission ray

TttRss

ii

n

ssiDDii

AAAE

ICkICk

cosCkcosCkIS

ICkII

Page 32: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

32

Ray tracing

Page 33: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

33

Ray tracing

• Light paths ray tracing: LS*E and LDS*E

• Allows for transparency with refraction

• Easy shadow computation

• Easy to program

• Inefficient

Page 34: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

34

Ray tracing

modelleertransformatie

ray tracing display

Page 35: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

35

Ray tracing extensions

• More effects

• Caustics

• Area light sources, soft shadows

• Depth of field

• Motion blur

Page 36: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

36

Two-pass ray tracing

• Two-pass method

• First pass: forward tracing (from lights into scene).

• Limited to rays from light to reflective and transparent objects

• When transparency ray hits surface, energy is stored at surface

• Second pass: backward ray tracing

• When local illumination applied, also check for stored intensity. Add this intensity to illumination

• Light paths ray tracing with caustics: LS*E and LS*DS*E

Page 37: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

37

Area light sources

• Area light sources generate soft shadows (penumbrae)

umbra

penumbra

penumbra

entirely illuminated

entirely illuminated

Page 38: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

38

Area light source

Page 39: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

39

Area light source

• Subdivide area light source in number of point light sources

• Use regular grid of points

Page 40: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

40

Area light source

• How many point light sources must be used to simulate area source?

• Number depends on distance from point to light source

• Regular pattern of point sources generates shadow bands

Page 41: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

41

Area source: adaptive subdivision

Page 42: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

42

Shadow bands

Page 43: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

43

Area source: irregular pattern

• Trace shadow ray to random point on sub light source

• Degree of randomness often indicated with “jitter”

• Regular shadow patterns replaced by noise

Page 44: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

44

Area source: jittered subdivision

Page 45: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

45

Ray tracing - efficiency

• Ray tracing inefficient

• Need for methods to improve performance

• Efficiency ray tracing determined by

• Number of rays

• Number of light sources

• Number of specular and transparent objects

• Recursion depth

• Efficiency ray-object intersections

• Number of intersections to be computed

Page 46: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

46

• Reduce number of complex ray-object intersection computations by providing complex objects with a simple geometry around complex geometry

• Sphere

• Cube

• Do intersection with simple geometry

• Only if intersection found, do intersection with complex geometry

• Hierarchy of bounding volumes

Ray tracing – bounding volume

Page 47: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

47

Ray tracing – space subdivision

• Partition scene into small cells

• Store in each cell pointers to objects it contains

• Trace ray through cells and only compute intersections with objects in visited cell

• When intersection found, stop tracing rays through cells

Page 48: 1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok a.j.f.kok@tue.nl.

48

Ray tracing: conclusion

• Spectacular effects:• Shadows• Mirrors• Transparency, refraction

• Simple implementation

• Limitations• Not all light paths possible, missing diffuse

interreflection• Area light sources possible, but at high price

• => Radiosity method solves (parts of) limitations