ray tracing 1 image formation 2 image formation 3 rendering - - PowerPoint PPT Presentation

ray tracing
SMART_READER_LITE
LIVE PREVIEW

ray tracing 1 image formation 2 image formation 3 rendering - - PowerPoint PPT Presentation

ray tracing 1 image formation 2 image formation 3 rendering computational simulation of image formation 4 rendering given viewer, geometry, materials, lights determine visibility and compute colors 5 raytracing a specific rendering


slide-1
SLIDE 1

ray tracing

1

slide-2
SLIDE 2

image formation

2

slide-3
SLIDE 3

image formation

3

slide-4
SLIDE 4

rendering

computational simulation of image formation

4

slide-5
SLIDE 5

rendering

given viewer, geometry, materials, lights determine visibility and compute colors

5

slide-6
SLIDE 6

raytracing

a specific rendering algorithm

6

slide-7
SLIDE 7

raytracing algorithm

for each pixel { determine viewing direction intersect ray with scene compute illumination store result in pixel }

7

slide-8
SLIDE 8

vector math review

point: location in 3D space vector: direction and magnitude

P = ( , , ) Px Py Pz v = ( , , ) vx vy vz

8

slide-9
SLIDE 9

vector math review

dot product cross product is orthogonal to and

a ⋅ b = |a||b|cos θ |a × b| = |a||b|sinθ a × b a b

9

slide-10
SLIDE 10

vector math review

segment: set of points (line) between two points with

P(t) = A + t(B − A) t ∈ [0,1]

10

slide-11
SLIDE 11

vector math review

ray: infinite line from point in a given direction with

P(t) = E + td t ∈ [0,∞]

11

slide-12
SLIDE 12

vector math review

coordinate system aka frame frame : position and orthonormal axes default (or world) frame: origin and three major axes

f = { , , , } fO fx fy fz

12

slide-13
SLIDE 13

vector math review

point coords are defined wrt a frame wrt (world if not specified)

P = ( , , ) Px Py Pz { , , , } fO fx fy fz P = ((P − ) ⋅ ,(P − ) ⋅ ,(P − ) ⋅ ) fO fx fO fy fO fz

13

slide-14
SLIDE 14

vector math review

change of coordinate system is w.r.t

f → f ′ = ( , , ) P′ P ′

x P ′ y P ′ z

P { , , , } f ′

O f ′ x f ′ y f ′ z

= ((P − ) ⋅ ,(P − ) ⋅ ,(P − ) ⋅ ) P′ f ′

O

f ′

x

f ′

O

f ′

y

f ′

O

f ′

z

14

slide-15
SLIDE 15

vector math review

change of coordinate system is w.r.t

→ f f ′ = ( , , ) P′ P ′

x P ′ y P ′ z

P { , , , } f ′

O f ′ x f ′ y f ′ z

P = + + + f ′

O

P ′

xf ′ x

P ′

yf ′ y

P ′

zf ′ z

15

slide-16
SLIDE 16

vector math review

vector coords are defined wrt a frame to change coord system, ignore origin

v = + + v′

xf ′ x

v′

yf ′ y

v′

zf ′ z

= (v ⋅ ,v ⋅ ,v ⋅ ) v′ f ′

x

f ′

y

f ′

z

16

slide-17
SLIDE 17

vector math review

construct a frame from two non-orthonormal vectors , assume that is not parallel to construct a frame from a vector pick arbitrary and continue as above

z′ y′ z′ y′ z = /| | z′ z′ x = × z/| × z| y′ y′ y = z × x z′ y′

17

slide-18
SLIDE 18

vector math review

infinite plane with normal:

P ∈ plane ; (P − C) ⋅ n = 0 ; P ⋅ n = d P(u,v) = C + u ⋅ u + v ⋅ v (u,v) ∈ (−∞,∞)2 n = u × v

18

slide-19
SLIDE 19

vector math review

triangle baricentric coordinates with , ...

P(α,β,γ) = αA + βB + γC α + β + γ = 1 P(α,β) = α(A − C) + β(B − C) + C α = area(BCP)/area(ABC)

19

slide-20
SLIDE 20

vector math review

sphere

P ∈ sphere ; |P − C| = R P(u,v) = C + R ⋅ (cos ϕ sinθ,sinϕ sinθ,cos θ)

20

slide-21
SLIDE 21

viewing

for each pixel {

  • > determine viewing direction

intersect ray with scene compute illumination store result in pixel }

21

slide-22
SLIDE 22

viewer model

a painter tracing objects on a canvas in front

[Marschner 2004 – original unknown]

22

slide-23
SLIDE 23

viewer model

equivalent to pinhole photography

[Marschner 2004 – original unknown]

23

slide-24
SLIDE 24

viewer model -- parameters

camera frame: position and orientation , , image plane: distance and size ,

O x y z d w h

24

slide-25
SLIDE 25

view frustum

all visible points within a truncated pyramid

25

slide-26
SLIDE 26

generating view rays

for each pixel, ray from camera center to the pixel center

26

slide-27
SLIDE 27

generating view rays

ray: point on image plane

r = O + t(Q − O)/|Q − O| Q

27

slide-28
SLIDE 28

generating view rays

image plane params: , origin at bottom

Q(u,v) = (u − 0.5)wx + (v − 0.5)hy − dz (u,v) ∈ [0,1]2

28

slide-29
SLIDE 29

geometry model

simple shapes spheres, quads, traingles complex shapes handled as collections of simple shapes later in the course

29

slide-30
SLIDE 30

ray-shape intersection

determine visible surface by finding closest intersection along a ray ray with keep explicit bounds on e.g. used in shadows and to improve numerical precision if not specified otherwise: , mitigate numerical precision issues ("shadow acne") value is scene depedent: start with

r : E + td t ∈ ( , ) tmin tmax t = ϵ tmin = ∞ tmax ϵ 10−5

30

slide-31
SLIDE 31

ray-sphere intersection

point on a ray: point on a sphere: by substitution:

P(t) = E + td |P(t) − C| = R |E + td − C| = R

31

slide-32
SLIDE 32

ray-sphere intersection

algebraic equation: with: , , determinant: no solution for

a + bt + c = 0 t2 a = |d|2 b = 2d ⋅ (E − C) c = |E − C − |2 R2 d = − 4ac b2 d < 0

32

slide-33
SLIDE 33

ray-sphere intersection

two solutions: pick smallest such that

= (−b ± )/(2a) t± d √ t t ∈ ( , ) tmin tmax

33

slide-34
SLIDE 34

ray-sphere intersection

shading frame at with normal with and and , where ,

P = fO n = fz P = E + td = (P − C)/R Pl θ = arccos P l

z

ϕ = arctan( , ) P l

y P l x

f = {P,x,y, } Pl x = (sinϕ,cos ϕ,0) y = (cos θcos ϕ,cos θsinϕ,sinθ)

34

slide-35
SLIDE 35

ray-plane intersection

point on a ray: point on a plane: by substitution:

P(t) = E + td (P(t) − C) ⋅ n = 0 (E + td − C) ⋅ n = 0

35

slide-36
SLIDE 36

ray-plane intersection

  • ne solution for

, no/infinite solutions otherwise check that

d ⋅ n ≠ 0 t = (C − E) ⋅ n d ⋅ n t ∈ ( , ) tmin tmax

36

slide-37
SLIDE 37

ray-plane intersection

shading frame: f = {e + td,u,v,n}

37

slide-38
SLIDE 38

ray-triangle intersection

point on ray: point on triangle: by substitution:

P(t) = E + td P(α,β) = α(A − C) + β(B − C) + C E + td = α(A − C) + β(B − C) + C

38

slide-39
SLIDE 39

ray-triangle intersection

E + td = α(A − C) + β(B − C) + C → α(A − C) + β(B − C) − td = E − C → αa + βb − td = e → [ ] = e −d a b ⎡ ⎣ t α β ⎤ ⎦

39

slide-40
SLIDE 40

ray-triangle intersection

use Cramer's rule test for

t = = | | e a b | | −d a b (e × a) ⋅ b (d × b) ⋅ a α = = | | −d e b | | −d a b (d × b) ⋅ e (d × b) ⋅ a β = = | | −d a e | | −d a b (e × a) ⋅ d (d × b) ⋅ a t ∈ ( , ),α ≥ 0,β ≥ 0,α + β ≤ 1 tmin tmax

40

slide-41
SLIDE 41

ray-triangle intersection

shading frame: create frame by orthonomalization with ,

f = {e + td,u,v,n} = (B − A) × (C − A) z′ = (B − A) x′

41

slide-42
SLIDE 42

intersection and coord systems

transform the object simple for triangles, since they transforms to triangles but objects may require more complex intersection tests transform the ray much more elegant works on any surface allow for much simpler intersection tests

42

slide-43
SLIDE 43

intersection and coord systems

ray wrt (e.g. world)

  • bject

defined wrt (in turn defined wrt ) transform rays transform origin/direction as point/vector intersect object with transformed ray use standard intersection tests transform intersection frame back to transform origin/axes as point/vectors

r = {E,d} f

f ′ f = { , } r′ E′ d′

r′ f

43

slide-44
SLIDE 44

image so far

44

slide-45
SLIDE 45

intersecting many shapes

intersect each primitive pick closest intersection essentially a line search

45

slide-46
SLIDE 46

intersecting many shapes -- pseudocode

minDistance = infinity hit = false foreach surface s { if(s.intersect(ray,intersection)) { if(intersection.distance < minDistance) { hit = true; minDistance = intersection.distance; } } }

46

slide-47
SLIDE 47

image so far

47

slide-48
SLIDE 48

shading

for each pixel { determine viewing direction intersect ray with scene

  • > compute illumination

store result in pixel }

48

slide-49
SLIDE 49

shading

variation in observed color across a surface

49

slide-50
SLIDE 50

shading

compute reflected light depends on: view position incoming light, i.e. lighting surface geometry surface material

50

slide-51
SLIDE 51

real-world materials

Metals Dielectric

[Marschner 2004] [Marschner 2004]

51

slide-52
SLIDE 52

real-world materials

Metals Dielectric

[Marschner 2004] [Marschner 2004]

52

slide-53
SLIDE 53

shading models

empirical models produce believable images simple and efficient

  • nly for simple materials

physically-based shading models can reproduce accurate effects more complex and expensive will concentrate on empirical models first

53

slide-54
SLIDE 54

shading model

shading model: diffuse + specular reflection diffuse reflection light is reflected in every direction equally colored by surface color specular reflection light is reflected only around the mirror direction white for plastic-like surfaces (glossy paints) colored for metals (brass, copper, gold)

54

slide-55
SLIDE 55

incident light

beam of light is more spread on oblique surfaces incident light depends on angle light fraction: f = |n ⋅ l|

55

slide-56
SLIDE 56

surface reflectance

surface reflectance is described by the BRDF, bidirectional surface distribution functions BRDF is simple for simple shading models in general, the BRDF is a function of incoming and outgoing angles is the direction from the point to the light is the direction from the point to the viewer is the local shading frame that describes surface

  • rientation (normal and tangent)

ρ(l,v;f) l v f

56

slide-57
SLIDE 57

lambert diffuse model

simple and efficient diffuse model light is scattered uniformly in all directions brdf: surface color:

(l,v;f) = ρd kd = (l,v;f) ⋅ |n ⋅ l| = |n ⋅ l| Cd ρd kd

57

slide-58
SLIDE 58

lambert diffuse model

produce matte appearance

left-to-right: increasing kd

58

slide-59
SLIDE 59

image so far

59

slide-60
SLIDE 60

phong specular model

empirical, used to look good enough cosine of mirror and view direction reflected direction: brdf:

r v r = −l + 2(n ⋅ l)n (l,v;f) = max(0,v ⋅ r ρs ks )n = (l,v;f) ⋅ |n ⋅ l| = max(0,v ⋅ r ⋅ |n ⋅ l| Cs ρs ks )n

60

slide-61
SLIDE 61

phong specular model

produces highlight, shiny appearance

left-to-right: increasing , top-to-bottom: increasing

n ks

61

slide-62
SLIDE 62

blinn specular model

slightly better than Phong cosine of bisector and normal bisector: brdf:

h n h = (l + v)/|l + v| (l,v;f) = max(0,n ⋅ h ρs ks )n = (l,v;f) ⋅ |n ⋅ l| = max(0,n ⋅ h ⋅ |n ⋅ l| Cs ρs ks )n

62

slide-63
SLIDE 63

image so far

63

slide-64
SLIDE 64

lighting

patterns of illumination in the environment

64

slide-65
SLIDE 65

lighting

determines how much light reaches a point depends on: light geometry light emission scene geometry

65

slide-66
SLIDE 66

light source models

describe how light is emitted from light sources empirical light source models point, directional, spot physically-based light source models area light, sky model

66

slide-67
SLIDE 67

point lights

light is emitted equally from a point in all directions simulate local lighting, different at each surface point light direction: light color:

S P l = (S − P)/|S − P| L = /|S − P kl |2

67

slide-68
SLIDE 68

directional lights

light is emitted from infinity in one direction simulate distant lighting, e.g. sun, same at all surface points light direction: light color:

d P l = d L = kl

68

slide-69
SLIDE 69

spot lights

same as points lights, but only emits in a cone around simulate theatrical lights cone falloff model arbitrary light direction: light color:

d l = (S − P)/|S − P| L = ⋅ attenutation/|S − P kl |2

69

slide-70
SLIDE 70

shading model with multiple lights

add contribution of all lights for diffuse and specular for Lambert and Phong for Lambert and Blinn

i C = ⋅ ( ( ,v;f) + ( ,v;f)) ⋅ |n ⋅ | ∑i Li ρd li ρs li li C = ⋅ ( + max(0,v ⋅ ) ⋅ |n ⋅ | ∑i Li kd ks ri)n li C = ⋅ ( + max(0,n ⋅ ) ⋅ |n ⋅ | ∑i Li kd ks hi)n li

70

slide-71
SLIDE 71

image so far

71

slide-72
SLIDE 72

illumination models

describe how light spreads in the environment direct illumination incoming light comes directly from light sources shadows indirect illumination incoming light comes from other objects specular reflections (mirrors) diffuse inter-reflections

72

slide-73
SLIDE 73

illumination models

[PCG]

73

slide-74
SLIDE 74

ray tracing lighting model

point/directional/spot light sources sharp shadows sharp reflection/refractions hacked diffuse inter-reflection: ambient term

74

slide-75
SLIDE 75

ray traced shadows

light contributes only if visible at surface point no shadow shadow

75

slide-76
SLIDE 76

ray traced shadows

send a shadow ray to check if light is visible visible if no hits or if more than light distance

t

76

slide-77
SLIDE 77

ray traced shadows

shadow ray with spot/point lights at : directional lights: scale lighting by visibility term which is 0 or 1 implementation detail: numerical precision shadow acne: ray hits the visible point solution: only intersect if , i.e.

r = P + tl t ∈ ( , ) tmin tmax S = length(S − P) tmax = ∞ tmax (P) Vi C = ⋅ (P)( + )|n ⋅ | ∑i Li Vi ρd ρs li t > ϵ = ϵ tmin

77

slide-78
SLIDE 78

image so far

78

slide-79
SLIDE 79

ambient term hack

light bounces even in diffuse environment ceiling are not black shadows are not perfectly black very expensive to compute approximate (poorly) with a constant term

C = + ⋅ (P)( + )|n ⋅ | kdLa ∑i Li Vi ρd ρs li

79

slide-80
SLIDE 80

ray traced reflections and refractions

perfectly shiny surfaces reflects objects recursively trace a ray if material is reflective or refractive

80

slide-81
SLIDE 81

ray traced reflections and refractions

reflections: along mirror direction , scaled by refractions: along refraction direction scaled by implementation detail: recursion avoid hitting visible point: make sure you do not recurse indefinitely

r = −l + 2(l ⋅ n)n kr kt C = + ⋅ (P)( + )|n ⋅ | + kdLa ∑i Li Vi ρd ρs li + raytrace(P,r) + raytrace(P,t) kr kt > ϵ tmin

81

slide-82
SLIDE 82

image so far

82

slide-83
SLIDE 83

antialiasing

83

slide-84
SLIDE 84

antialiasing: removing jaggies

1 sample/pixel

84

slide-85
SLIDE 85

antialiasing: removing jaggies

1 sample/pixel

85

slide-86
SLIDE 86

antialiasing: removing jaggies

1 sample/pixel

86

slide-87
SLIDE 87

antialiasing: removing jaggies

1 sample/pixel

87

slide-88
SLIDE 88

antialiasing: removing jaggies

1 sample/pixel 9 sample/pixel

88

slide-89
SLIDE 89

antialiasing: removing jaggies

1 sample/pixel 9 sample/pixel

89

slide-90
SLIDE 90

antialiasing: removing jaggies

1 sample/pixel 9 sample/pixel

90

slide-91
SLIDE 91

antialiasing: removing jaggies

1 sample/pixel 9 sample/pixel

91

slide-92
SLIDE 92

antialiasing: removing jaggies

poor-man antialiasing: for each pixel take multiple samples compute average

92

slide-93
SLIDE 93

ray tracing pseudocode

for(i = 0; i < imageWidth; i ++) { for(j = 0; j < imageHeight; j ++) { u = (i + 0.5)/imageWidth; v = (j + 0.5)/imageHeight; ray = camera.generateRay(u,v); c = computeColor(ray); image[i][j] = c; } }

93

slide-94
SLIDE 94

anti-aliased ray tracing pseudocode

for(i = 0; i < imageWidth; i ++) { for(j = 0; j < imageHeight; j ++) { color c = 0; for(ii = 0; ii < numberOfSamples; ii ++) { for(jj = 0; jj < numberofSamples; jj ++) { u = (i+(ii+0.5)/numberOfSamples)/imageWidth; v = (j+(jj+0.5)/numberofSamples)/imageHeight; ray = camera.generateRay(u,v); c += computeColor(ray); } } image[i][j] = c / (numberOfSamples^2); } }

94

slide-95
SLIDE 95

image so far

95