6
1 2IV60 Computer graphics set 11: Ray-tracing Jack van Wijk TU/e John Tsiombikas Caustic Graphics Overview Ray-tracing: Based on geometric optics; Mirroring, transparency, cast shadows; Many other effects… And very time consuming… H&B 21-1:639-647 Ray casting (reprise) x v y v z v Normalized view volume View plane pixel front = visible Algorithm: Per pixel: - Calculate intersections - Determine first z H&B 21-1:639-647 Ray-tracing principle 1 Ray-tracing: view plane projection point light source Mirroring and transparent mirroring opaque H&B 21-1:639-647

2IV60 Computer graphics set 11: Ray-tracingvanwijk/2IV60/2IV60_12_raytracing.pdf · Distributed ray tracing 1 Cook, Porter, Carpenter, 1984 Motion blur Distributed ray tracing 1 •

  • Upload
    others

  • View
    16

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 2IV60 Computer graphics set 11: Ray-tracingvanwijk/2IV60/2IV60_12_raytracing.pdf · Distributed ray tracing 1 Cook, Porter, Carpenter, 1984 Motion blur Distributed ray tracing 1 •

1

2IV60 Computer graphics

set 11: Ray-tracing

Jack van Wijk

TU/e

John Tsiombikas

Caustic Graphics

Overview

Ray-tracing:

• Based on geometric optics;

• Mirroring, transparency, cast shadows;

• Many other effects…

• And very time consuming…

H&B 21-1:639-647

Ray casting (reprise)

xv

yv

zv

Normalized view volume

View planepixel

front =

visible

Algorithm:

Per pixel:

- Calculate intersections

- Determine firstz

H&B 21-1:639-647

Ray-tracing principle 1

Ray-tracing:

view plane

projection point

light source

Mirroring and

transparent

mirroring

opaque

H&B 21-1:639-647

Page 2: 2IV60 Computer graphics set 11: Ray-tracingvanwijk/2IV60/2IV60_12_raytracing.pdf · Distributed ray tracing 1 Cook, Porter, Carpenter, 1984 Motion blur Distributed ray tracing 1 •

2

Ray-tracing principle 2

Ray-tracing:

view plane

projection point

pixel

light source

H&B 21-1:639-647

Ray-tracing algorithm 1

var fbuf: array[N,N] of color; { frame-buffer }

For all 1<= i, j <=N do { for all pixels }

fbuf [i,j] := RayTrace((0,0,0),(i,j,d), 1)

projection pointpixel

d

H&B 21-1:639-647

function RayTrace(P: point; u:vector; level: integer):

if level > MaxLevel or GetIntersections (P, u, t, N) = 0

then return BkColor;

level := level+1;

col := famb*Iamb;

Q := P + ut;

if (L− Q).N > 0 and GetIntersections (Q, L − Q) = 0

then col := col + fdif*I

+ fspec*I*power(N.H(u,N), nspec);

Ray-tracing algorithm 2

R

LPu

H

T

N

Q

H&B 21-1:639-647

function GetIntersections (P: point; u: vector; t: array of real;

N: array of vector): integer;

{ Get the intersections of a line with the scene }

For all objects do:

Calculate intersection points with surface;

Store the results in the arrays t and N,

sorted for t.

Return the number of intersection points.

Equation line:

Calculation intersections

Pu

tuPX +=

t

H&B 21-1:639-647

Line/Sphere intersections

Pu

Q

C

r

(1) tuPX +=

Equation line:

t

(2) )()( 2r=−⋅− CXCX

Equation sphere:

uu

PPuuuPuP

PPuPuu

uPuP

CPPCuPCuP

−∆⋅∆⋅−⋅∆±⋅∆−=

=−∆⋅∆+⋅∆+⋅

=−+∆⋅+∆

−=∆=−+⋅−+

))(()(

or ,0)()2()(

or ,0)()(

:with ,)()(

22

1,2

22

2

2

rt

rtt

rtt

rtt

Substitute (1) in (2):

H&B 21-1:639-647

Line/polygon intersection

Pu

N

(1) tuPX +=

Equation line:

t

(2) D−=⋅ XN

Equation plane polygon:

uN

PN

uNPN

uPN

⋅−−=

−=⋅+⋅

−=+⋅

Dt

Dt

Dt

hence ,

or ,)(

Substitute (1) in (2):

Check if Q is inside polygon

Q

H&B 21-1:639-647

Page 3: 2IV60 Computer graphics set 11: Ray-tracingvanwijk/2IV60/2IV60_12_raytracing.pdf · Distributed ray tracing 1 Cook, Porter, Carpenter, 1984 Motion blur Distributed ray tracing 1 •

3

Ray-tracing acceleration 1

Limit intersection calculations:

Hierarchy of Bounding Volumes

Bounding SpheresBounding Boxes

H&B 21-1:639-647

Ray-tracing acceleration 2

Limit intersection calculations:

Space-subdivision

Regular Adaptive (Octtree, quadtree)

H&B 21-1:639-647

Aliasing 1• Generic problem of raster graphics

• Shapes are continuous, pixels are discrete

• Jagged edges, Moiré patterns, flickering textures, …

• Especially annoying during animation

• More pixels?

• More samples!

H&B 21-1:639-647Aliased Anti-aliased

Aliasing 2

pixelray

1 ray/pixel: blocky patterns

H&B 21-1:639-647

Anti-aliasing 1

pixelray

average 5 rays/pixel:

smoother transitions

H&B 21-1:639-647

Anti-aliasing 2

pixelray

adaptive sampling:

more efficient, not fail save

H&B 21-1:639-647

Page 4: 2IV60 Computer graphics set 11: Ray-tracingvanwijk/2IV60/2IV60_12_raytracing.pdf · Distributed ray tracing 1 Cook, Porter, Carpenter, 1984 Motion blur Distributed ray tracing 1 •

4

Anti-aliasing 3

pixelray

dense patterns

give problems

H&B 21-1:639-647

Anti-aliasing 3

pixelray

dense patterns

give problems

H&B 21-1:639-647

Anti-aliasing 3

pixelray

dense patterns

give problems

H&B 21-1:639-647

Anti-aliasing 4

pixelray

random sampling gives

a better result

H&B 21-1:639-647

Anti-aliasing 4

pixelray

random sampling gives

a better result

H&B 21-1:639-647

Anti-aliasing 4

pixelray

random sampling gives

a better result

H&B 21-1:639-647

Page 5: 2IV60 Computer graphics set 11: Ray-tracingvanwijk/2IV60/2IV60_12_raytracing.pdf · Distributed ray tracing 1 Cook, Porter, Carpenter, 1984 Motion blur Distributed ray tracing 1 •

5

More optical effects…

Cook, Porter, Carpenter, 1984

Imperfect reflection

Non-point light source

Distributed ray tracing 1

Cook, Porter, Carpenter, 1984

Motion blur

Distributed ray tracing 1

• Monte Carlo sampling

• Typically 16 rays/pixel;

• Each ray is shifted along a small

random vector (jitter)

• rough reflecting surfaces, non-

point light sources, depth of field,

motion blur

pixelray

H&B 21-1:651-653

Distributed ray tracing 2

• rough reflecting surfaces, non-

point light sources, depth of

field, motion blur

R

Pu

T

L

H&B 21-1:651-653

Radiosity

• Surface-surface

interreflection

• Physically based simulation

• Calculate for each polygon

the balance between incoming

and outgoing light

• Important for architecture

and indoor scenes

Cornell box

Page 6: 2IV60 Computer graphics set 11: Ray-tracingvanwijk/2IV60/2IV60_12_raytracing.pdf · Distributed ray tracing 1 Cook, Porter, Carpenter, 1984 Motion blur Distributed ray tracing 1 •

6

Cohen et al., 1988

Finally

• That concludes our tour through the world

of 2D and 3D graphics