72
TURNER WHITTED’S RAY - TRACING ALGORITHM: PRACTICE PROGRAMAÇÃO 3D MEIC/IST

TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Embed Size (px)

Citation preview

Page 1: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE

PROGRAMAÇÃO 3D

MEIC/IST

Page 2: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Ray Tracing History

Page 3: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Ray Tracing History

Page 4: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Whitted ray tracing

It combines in a single model:

Hidden surface removal

Shading due to direct illumination

Shading due to indirect illumination (reflection and refraction effects due to reflective/translucid objects)

Shadow computation (hard shadows)

Page 5: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb
Page 6: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Image Rendering

xo

zo

Objects

Pixel(RGB)

Light

Illumination

yo

Camera

xe

ye

ze eye

Page 7: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Ray Casting

For each pixel in the viewport;

shoot a ray;

for each object in the scene

compute intersection ray-object;

store the closest intersection;

if there is an intersection

shade the pixel using color, lights, materials;

else /* ray misses all objects */

shade the pixel with background color

Page 8: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Shadows Only shades the intersection if not in shadow

Page 9: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Ray Casting

Page 10: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

How does RT differ fromRasterization (slide from CS348b: image synthesis by Matt Pharr)

Page 11: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Global Illumination

Page 12: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Global Illumination or Light Transport

Page 13: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Light Transport and Shading The appearance of objects, only depends on

the way light interacts with matter and travels trough space.

Shading: Interaction light-matter

Light transport: determine and follow pathlight rays due to inter-reflections

Page 14: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Forward tracing aka Light Tracing

Page 15: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Backward Tracing

Page 16: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Backward Tracing

Page 17: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Ray-Tracing de Turner Whitted

Define the viewpoint, the view window and the viewport resolutionfor each pixel in the viewport{

compute a ray in World space from the eye towards the pixel;pixel_color = trace ( scene, eye, primary ray direction, 1);

}

• Backward Ray Tracer

• We trace light rays from the eye through a pixel in the viewport - primary rays

• ie we follow light beams in the reverse direction of the light propagation

• Find the intersection with the first object during the backwards trace of the ray

• The color of the ray (hence at the required pixel) is made up of 3 contributions:

-local color due to direct illumination (it can be in shadow) and ambient light ;

-color from a ray coming from the reflection direction – reflected ray;

- color from a ray coming from the refraction direction – transmitted or refratced ray;

• Shadow feelers, reflected and refracted rays are called secondary rays

Page 18: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Recursive nature

Page 19: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Algorithm’s recursive nature

R1

T1

R2

T2

R3

L1

L3

L2

R1

R2

L1

L3L2

T1

T2R3

Page 20: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Result

Page 21: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Mirror Maze

Page 22: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Mirror Maze

Page 23: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Color trace (Scene scene, Vector3d origin, Vector3d ray direction, int depth){

intersect ray with all objects and find a hit point (if any) closest to the start of the rayif (!intersection point) return BACKGROUND;else {

color = object material’s ambient color;compute normal at the hit point;for (each source light) {

L = unit light vector from hit point to light source;if (L • normal>0)

if (!point in shadow); //trace shadow raycolor += diffuse color + specular color;

}if (depth >= maxDepth) return color;

if (reflective object) {rRay = calculate ray in the reflected direction;rColor = trace(scene, point, rRay direction, depth+1);reduce rColor by the specular reflection coefficient and add to color; }

if (translucid object) {tRay = calculate ray in the refracted direction;tColor = trace(scene, point, tRay direction, depth+1);reduce tColor by the transmittance coefficient and add to color; }

return color;}

Page 24: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Rays

Parametric formulation: p = o + td

p: a point on the ray

o: origin of the ray

t: scalar parameter

d: unit vector giving the direction of the ray

Page 25: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

The axes in the Camera Frame

Viewing direction

v

u

eyexe

ye

ze

ResX (pixels)width

Res

Y(p

ixel

s)h

eig

ht

viewing window-viewporttransformation

o xe

ye

t (top)

b (bottom)

l (le

ft)

r (r

igh

t)

Page 26: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Camera Position and Orientation

eye = viewerat = target point in the center of viewing window (near plane in OpenGL), up = up direction

World Coordinates

eyeat

fovy

upeye

at

up

x0

z0

y0

near

far

view = at - eye

Page 27: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Camera Frame - xe ye ze (uvn)

at

zeeye

up

z0

y0

x0

view

up

at

eye

z0

y0

x0

data:eye, at, up

view = at - eye

ze 1

eye ateye at

Page 28: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Camera Frame - xe ye ze (u v -n)

at

eye

up

z0

y0

x0

view

zexe

at

eye

up

z0

y0

x0

view

zexe

ye

e

e

e zupzup

x

1

eee xzy eye

up ze

xeye

at

Page 29: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Primary Rays

zw

xw eyeo

d pxy eye

yw

dop ttraio )(:

d

Page 30: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Computing Primary Rays

vuop ˆ)(ˆ)(1 yvxuxy

wsX

xxu

Re)(

hsY

yyv

Re)(

v

h

eexysY

yh

sX

xw yxop ˆ

Reˆ

Re1

(w/2, h/2)

uResX-1o1

pxy

10 2 x3

ResY-1

1

2

y

w

(-w/2, -h/2)

Ray at the left-bottom corner of the unit square pixel

Page 31: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Ray at the center of the square pixel

eexysY

yh

sX

xw yxop ˆ

Re

5.0ˆ

Re

5.01

for unit square pixels, ie. s=1;

Page 32: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Computing Primary Rays

zo

xo

eyeo yo

dop ttray )(:

d

eeefsX

xw

sY

yhd xyzd ˆ

2

1

Reˆ

2

1

Reˆ

d f eye at

Ray at the left-bottom corner of the square pixel

Page 33: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Camera Data in C

struct _Camera {

/* Camera definition*/

Vector eye, at, up;

float fovy;

float near,far; //hither and yon planes

int ResX,ResY;

float w,h;

Vector xe,ye,ze; //uvn frame

};

typedef struct _Camera Camera;

Camera* camCreate( Vector eye, Vector at, Vector up,

double fovy, double near, double far, int ResX, int ResY );

Ray camGetPrimaryRay( Camera camera, double x, double y );

Page 34: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

The Camera object

ze 1

eye ateye at e

e

e zupzup

x

1

eee xzy

Initialization:

Ray in parametic form : o + td (normalize d; why?)

eyeo

d f eye at

h 2d f tanfov

2

w ResX

ResYh

Data input: fov, ResX, ResY, near, far, eye, at, up

Given: x, y

eeefsX

xw

sY

yhd xyzd ˆ

2

1

Reˆ

2

1

Reˆ

Ray at the left-bottom corner of the square pixel

Page 35: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Shadow Feeleers

No light at that point

ip

sr̂

sitt rpp ˆ)(:ray Shadow

Page 36: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Intersections computation

• Read the slides “Geometry Intersections”• Self-intersections problem due to floating-point precision (secondary rays and shadow-feelers) •Solution: Slightly offset intersections • Read the article : Andrew Woo et al., “It’s Really Not a Rendering Bug, You See…”, IEEE CG&A, September 1996, vol. 21

Page 37: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Reflection Model for Lambert Surfaces

luz incidente luz

incidenteluz incidente

1. Reflete igualmente em todas as direções2. Diffuse Intensity: linear variation with angle cos

Page 38: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Diffuse Reflection Component

cos

cos

cos

dbb

dgg

drr

b

g

r

kl

kl

kl

I

I

I

- /2 0 /2

cos

1

ip

Page 39: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Diffuse Reflection Component

I, l, k [0 ,1 ]

Eq. 1

LnLn

Ln

Ln

Ln

ˆˆˆˆ

ˆˆ

ˆˆ

ˆˆ

db

dg

dr

b

g

r

dbb

dgg

drr

dbb

dgg

drr

b

g

r

k

k

k

l

l

l

kl

kl

kl

kl

kl

kl

I

I

I

cos

cos

cos

dbb

dgg

drr

b

g

r

kl

kl

kl

I

I

I

Page 40: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Ambient plus Diffuse:

Ln ˆˆ

db

dg

dr

b

g

r

db

dg

dr

ab

ag

ar

b

g

r

k

k

k

l

l

l

k

k

k

I

I

I

I

I

I

Page 41: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Local Specular Reflection Component

I, l, k [0 ,1 ]

Eq.2

-1 -0,5 0 0,5 1

n=4

n=1

n=8

nvr ˆˆ

n

sbb

n

sgg

n

srr

especularb

g

r

kl

kl

kl

I

I

I

cos

cos

cos

Specular area

Page 42: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Local Specular Reflection Component

n

sb

sg

sr

b

g

r

db

dg

dr

b

g

r

db

dg

dr

ab

ag

ar

b

g

r

k

k

k

l

l

l

k

k

k

l

l

l

k

k

k

I

I

I

I

I

I

vrLn ˆˆˆˆ

Page 43: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Local Specular Reflection Component

r̂ v̂

ip

luzrefletida

Page 44: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Mirror Reflection Vector

LnnLr ˆˆˆˆ2ˆ

LLh n

h h

Ln

nnLL ˆ)ˆˆ( n

hLr nˆ

L̂ r̂

Page 45: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Phong Model: Local Reflection Distribution

nsluzdifluzamb kCkCCC vrLn ˆˆˆˆ

r̂v̂

ip

Ambient Diffuse Specular

Page 46: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Multiple Light Sources

luzes

n

sb

sg

sr

b

g

r

db

dg

dr

b

g

r

db

dg

dr

ab

ag

ar

b

g

r

k

k

k

l

l

l

k

k

k

l

l

l

k

k

k

I

I

I

I

I

I

vrLn ˆˆˆˆ

vnnvr ˆˆ)ˆˆ(2ˆ r

luzes

n

r

sb

sg

sr

b

g

r

db

dg

dr

b

g

r

db

dg

dr

ab

ag

ar

b

g

r

k

k

k

l

l

l

k

k

k

l

l

l

k

k

k

I

I

I

I

I

I

LrLn ˆˆˆˆ

LnnLr ˆˆ)ˆˆ(2ˆ

Page 47: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

First Lab Exercise

Page 48: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Model with multiple lights and shadow

otherwise1

shadowin if0s

f

luzes

n

r

sb

sg

sr

b

g

r

db

dg

dr

b

g

r

s

db

dg

dr

ab

ag

ar

b

g

r

k

k

k

l

l

l

k

k

k

l

l

l

f

k

k

k

I

I

I

I

I

I

LrLn ˆˆˆˆ

Page 49: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Indirect Illumination: Mirror reflectionsfrom other objects

Reflective surface

iprr̂

ritt rpp ˆ)(:ray reflected

Page 50: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Indirect illumination: Mirror Reflection Vector

VVr nnr ˆˆ2ˆ

VVn h

h h

Vn

nn ˆ)ˆ( VVn

hr nVrˆ

Vrr̂

Page 51: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Translucid objects

1

2

h1

h2

ip

tr̂

ti ttrefratadoRaio rpp ˆ)(:

1

2

2

1

sin

sin

h

h

Snell law

Page 52: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

t

t

vv

t1ˆ

Indirect Illumination: Refracted Ray

i

n̂ vnnvv ˆˆ)ˆˆ( t

ip

tr̂

nv

tvti vsin

i

t

it

h

h sinsin

tt 2sin1cos

)ˆ(cosˆsin ntr ttt

titt rpp ˆ)(:ray refracted

t

Page 53: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Advertência: Refração não é simples!

Page 54: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Objectos refletores e transparentes

redução da

transparência

redução da

reflexão

)(

)(

)(

)1(

)(

)(

)(

ˆˆˆˆ

tb

tg

tr

rb

rg

rr

luzes

n

r

sb

sg

sr

b

g

r

db

dg

dr

b

g

r

s

db

dg

dr

ab

ag

ar

b

g

r

I

I

I

o

I

I

I

k

k

k

k

l

l

l

k

k

k

l

l

l

f

k

k

k

I

I

I

I

I

I

r

r

r

r

r

r

LrLn

Page 55: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Texturas

u

v

1.0

1.0

0 u1.0

1.0

0

v

u1.0

1.0

0

v

Texturas 2D = Imagens onde o domínio é u, v [0,1]×[0,1] R2

Page 56: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Sistemas de coordenada de textura na caixa

u

v

u

v

x

y

z

u

v

(1,1)(0,0)

(0,0)

(0,0)

face x=xmax

minmax

min

yy

yyu

minmax

min

zz

zzv

Page 57: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Sistema de coordenadas de textura na esfera

x

y

z

sinsin

cossin

cos

y

x

z

z

yx

xy

22

tan

/tan

1

1

v

u

)1(

)1(

wuj

hvi

i

j

Page 58: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Sistema de coordenadas de textura no triângulo

u

v

(u1,v1)

(u2,v2)

(u3,v3)

u1= u3 u2

v1= v2

v3

1

2

3

Page 59: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Textura no triângulo e coordenadas baricêntricas

p1

v12

v23

v31

2/)(ˆ

2/)(ˆ

2/)(ˆ

1123

3312

2231

ppvn

ppvn

ppvn

i

i

i

A

A

A

A3

A1A2

321 AAAAT

T

T

T

AAL

AAL

AAL

/

/

/

33

22

11

p2

p3

int

ip

3

3

3

2

2

2

1

1

1v

uL

v

uL

v

uL

v

u

i

i

)(1 213 LLL

Page 60: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Textura

Page 61: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Texturas de rugosidade (bump textures) eTexturas de deslocamentos (displacement mapping)

Pertubar aleatoriamente

as normais dos objetos

),(ˆ'ˆ nn

Pertubar aleatoriamente

as posições dos pontos

Page 62: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Textura ambiente(environment maps)

xy

z

u

v

(0,0)

(1,1)

face dos raios x>y e x>z

x

xyu

2

x

xzv

2

y=-x

y=x

z=-x

z=x

Page 63: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Processamento anti-aliasing

•Lance um raio para cada sub-pixel•Faça uma média dos valores obtidos

dx, dy = variáveis aleatórias

dxdya sub-pixels

pixel

Page 64: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Anti-aliasing

(a) original (b) uniforme (c) “jittered”

pixel pixel pixel

Page 65: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Refinamento Progresivo

subdivisão finalsegunda subdivisão

primeira subdivisãoamostragem inicial

pixels sendo visitados pixels já visitados

Page 66: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Radiosidade e Ray Tracing

Klaus Mueller, Stony Brook University, Computer Science (CSE 564)

global illuminationstandard raytracing

Page 67: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

Todays State of the Art- Some Snapshots

Page 68: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb
Page 69: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb
Page 70: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb
Page 71: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb
Page 72: TURNER WHITTED’S RAY-TRACING ALGORITHM: PRACTICE · PROGRAMAÇÃO 3D MEIC/IST. Ray Tracing History. Ray Tracing History. Whitted ray tracing It combines in a single model: ... sb

RT Acceleration

More efficient computations

Hierarchical data structures: Kd-Tree, BVH o Grids