ray tracing
play

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


  1. ray tracing 1

  2. image formation 2

  3. image formation 3

  4. rendering computational simulation of image formation 4

  5. rendering given viewer, geometry, materials, lights determine visibility and compute colors 5

  6. raytracing a specific rendering algorithm 6

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

  8. vector math review point: location in 3D space P = ( P x P y P z , , ) vector: direction and magnitude v = ( v x v y v z , , ) 8

  9. vector math review dot product a ⋅ b = | a || b |cos θ cross product | a × b | = | a || b |sin θ is orthogonal to and a × b a b 9

  10. vector math review segment: set of points (line) between two points with P ( t ) = A + t ( B − A ) t ∈ [0,1] 10

  11. vector math review ray: infinite line from point in a given direction with P ( t ) = E + t d t ∈ [0,∞] 11

  12. vector math review coordinate system aka frame frame : position and orthonormal f = { f O f x f y f z , , , } axes default (or world ) frame: origin and three major axes 12

  13. vector math review point coords are defined wrt a frame wrt ( world if not P = ( P x P y P z , , ) { f O f x f y f z , , , } specified) P = ( ( P − f O ) ⋅ f x ,( P − f O ) ⋅ f y ,( P − f O ) ⋅ f z ) 13

  14. vector math review change of coordinate system f → f ′ is w.r.t P ′ P ′ x P ′ y P ′ f ′ O f ′ x f ′ y f ′ = ( , , ) P { , , , } z z f ′ f ′ f ′ f ′ f ′ f ′ P ′ = ( ( P − ) ⋅ ,( P − ) ⋅ ,( P − ) ⋅ ) O x O y O z 14

  15. vector math review change of coordinate system f ′ → f is w.r.t P ′ P ′ x P ′ y P ′ f ′ O f ′ x f ′ y f ′ = ( , , ) P { , , , } z z f ′ x f ′ y f ′ z f ′ P ′ P ′ P ′ P = + + + O x y z 15

  16. vector math review vector coords are defined wrt a frame to change coord system, ignore origin x f ′ y f ′ z f ′ v ′ v ′ v ′ v = + + x y z f ′ f ′ f ′ v ′ = ( v ⋅ , v ⋅ , v ⋅ ) x y z 16

  17. vector math review construct a frame from two non-orthonormal vectors , z ′ y ′ assume that is not parallel to z ′ y ′ z ′ z ′ z = /| | y ′ y ′ x = × z /| × z | y = z × x construct a frame from a vector z ′ pick arbitrary and continue as above y ′ 17

  18. vector math review infinite plane P ∈ plane ; ( P − C ) ⋅ n = 0 ; P ⋅ n = d with ( u , v ) ∈ (−∞,∞) 2 P ( u , v ) = C + u ⋅ u + v ⋅ v normal: n = u × v 18

  19. vector math review triangle baricentric coordinates with P ( α , β , γ ) = α A + β B + γ C α + β + γ = 1 P ( α , β ) = α ( A − C ) + β ( B − C ) + C , ... α = area ( BCP )/ area ( ABC ) 19

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

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

  22. viewer model a painter tracing objects on a canvas in front 22 [Marschner 2004 – original unknown]

  23. viewer model equivalent to pinhole photography [Marschner 2004 – original unknown] 23

  24. viewer model -- parameters camera frame: position and orientation , , O x y z image plane: distance and size , d w h 24

  25. view frustum all visible points within a truncated pyramid 25

  26. generating view rays for each pixel, ray from camera center to the pixel center 26

  27. generating view rays ray: r = O + t ( Q − O )/| Q − O | point on image plane Q 27

  28. generating view rays Q ( u , v ) = ( u − 0.5) w x + ( v − 0.5) h y − d z image plane params: , origin at bottom ( u , v ) ∈ [0,1] 2 28

  29. geometry model simple shapes spheres, quads, traingles complex shapes handled as collections of simple shapes later in the course 29

  30. ray-shape intersection determine visible surface by finding closest intersection along a ray ray with r : E + t d t ∈ ( t min t max , ) keep explicit bounds on t e.g. used in shadows and to improve numerical precision if not specified otherwise: , t min = ϵ t max = ∞ mitigate numerical precision issues ("shadow acne") ϵ value is scene depedent: start with 10 −5 30

  31. ray-sphere intersection point on a ray: P ( t ) = E + t d point on a sphere: | P ( t ) − C | = R by substitution: | E + t d − C | = R 31

  32. ray-sphere intersection algebraic equation: t 2 a + bt + c = 0 with: , , a = | d | 2 b = 2 d ⋅ ( E − C ) c = | E − C | 2 R 2 − determinant: b 2 d = − 4 ac no solution for d < 0 32

  33. ray-sphere intersection two solutions: √ t ± = ( − b ± d ) /(2 a ) pick smallest such that t t ∈ ( t min t max , ) 33

  34. ray-sphere intersection shading frame at with normal with P = f O n = f z and P l P = E + t d = ( P − C )/ R and θ = arccos P l P l y P l ϕ = arctan( , ) z x , where , P l f = { P , x , y , } x = (sin ϕ ,cos ϕ ,0) y = (cos θ cos ϕ ,cos θ sin ϕ ,sin θ ) 34

  35. ray-plane intersection point on a ray: P ( t ) = E + t d point on a plane: ( P ( t ) − C ) ⋅ n = 0 by substitution: ( E + t d − C ) ⋅ n = 0 35

  36. ray-plane intersection one solution for , no/infinite solutions otherwise d ⋅ n ≠ 0 t = ( C − E ) ⋅ n d ⋅ n check that t ∈ ( t min t max , ) 36

  37. ray-plane intersection shading frame: f = { e + t d , u , v , n } 37

  38. ray-triangle intersection point on ray: P ( t ) = E + t d point on triangle: P ( α , β ) = α ( A − C ) + β ( B − C ) + C by substitution: E + t d = α ( A − C ) + β ( B − C ) + C 38

  39. ray-triangle intersection E + t d = α ( A − C ) + β ( B − C ) + C → α ( A − C ) + β ( B − C ) − t d = E − C → α a + β b − t d = e → t ⎡ ⎤ [ ] = e −d a b α ⎣ ⎦ β 39

  40. ray-triangle intersection use Cramer's rule | | ( e × a ) ⋅ b e a b t = = | | ( d × b ) ⋅ a −d a b | | ( d × b ) ⋅ e −d e b α = = | | ( d × b ) ⋅ a −d a b | | ( e × a ) ⋅ d −d a e β = = | | ( d × b ) ⋅ a −d a b test for 40 t ∈ ( t min t max , ), α ≥ 0, β ≥ 0, α + β ≤ 1

  41. ray-triangle intersection shading frame: f = { e + t d , u , v , n } create frame by orthonomalization with , z ′ x ′ = ( B − A ) × ( C − A ) = ( B − A ) 41

  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

  43. intersection and coord systems ray wrt (e.g. world ) r = { E , d } f object defined wrt (in turn defined wrt ) f ′ o ′ f transform rays E ′ d ′ r ′ = { , } transform origin/direction as point/vector intersect object with transformed ray o ′ r ′ use standard intersection tests transform intersection frame back to f transform origin/axes as point/vectors 43

  44. image so far 44

  45. intersecting many shapes intersect each primitive pick closest intersection essentially a line search 45

  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

  47. image so far 47

  48. shading for each pixel { determine viewing direction intersect ray with scene -> compute illumination store result in pixel } 48

  49. shading variation in observed color across a surface 49

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

  51. real-world materials Metals Dielectric 51 [Marschner 2004] [Marschner 2004]

  52. real-world materials Metals Dielectric 52 [Marschner 2004] [Marschner 2004]

  53. shading models empirical models produce believable images simple and efficient only for simple materials physically-based shading models can reproduce accurate effects more complex and expensive will concentrate on empirical models first 53

  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

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

  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 ρ ( l , v ; f ) is the direction from the point to the light l is the direction from the point to the viewer v is the local shading frame that describes surface f orientation (normal and tangent) 56

Recommend


More recommend