8.1 Geometric Queries for Ray Tracing Hao Li - - PowerPoint PPT Presentation

8 1 geometric queries for ray tracing
SMART_READER_LITE
LIVE PREVIEW

8.1 Geometric Queries for Ray Tracing Hao Li - - PowerPoint PPT Presentation

Fall 2017 CSCI 420: Computer Graphics 8.1 Geometric Queries for Ray Tracing Hao Li http://cs420.hao-li.com 1 Outline Ray-Surface Intersections Special cases: sphere, polygon Barycentric coordinates 2 Outline Ray-Surface


slide-1
SLIDE 1

CSCI 420: Computer Graphics

Hao Li

http://cs420.hao-li.com

Fall 2017

8.1 Geometric Queries for Ray Tracing

1

slide-2
SLIDE 2

Outline

  • Ray-Surface Intersections
  • Special cases: sphere, polygon
  • Barycentric coordinates

2

slide-3
SLIDE 3

Outline

  • Ray-Surface Intersections
  • Special cases: sphere, polygon
  • Barycentric coordinates

3

slide-4
SLIDE 4

Ray-Surface Intersections

  • Necessary in ray tracing
  • General parametric surfaces
  • General implicit surfaces
  • Specialized analysis for special surfaces
  • Spheres
  • Planes
  • Polygons
  • Quadrics

4

slide-5
SLIDE 5

Generating Rays

  • Ray in parametric form
  • Origin
  • Direction
  • Assume is normalized:
  • Ray

5

d = [xd yd zd]T xd · xd + yd · yd + zd · zd = 1 p(t) = p0 + dt for t > 0 d p0 d p(t) p0 = [x0 y0 z0]T

slide-6
SLIDE 6

Intersection of Rays and Parametric Surfaces

  • Ray in parametric form
  • Origin
  • Direction
  • Assume is normalized:
  • Ray
  • Surface in parametric form
  • Points
  • Solve
  • Three equations in three unknowns
  • Possible bounds on

6

p0 = [x0 y0 z0]T d = [xd yd zd]T xd · xd + yd · yd + zd · zd = 1 p(t) = p0 + dt for t > 0 d q = g(u, v) = [x(u, v), y(u, v), z(u, v)] p0 + dt = g(u, v) (t, u, v) u, v

slide-7
SLIDE 7

Intersection of Rays and Implicit Surfaces

  • Ray in parametric form
  • Origin
  • Direction
  • Assume is normalized:
  • Ray
  • Implicit surface
  • All points such that
  • Substitute ray equation for :
  • Solve for (univariate root finding)
  • Closed form if possible, otherwise approximation

7

d = [xd yd zd]T p(t) = p0 + dt for t > 0 f (q) = 0 q q f (p0 + dt) = 0 t xd · xd + yd · yd + zd · zd = 1 d p0 = [x0 y0 z0]T

slide-8
SLIDE 8

Outline

  • Ray-Surface Intersections
  • Special cases: sphere, polygon
  • Barycentric coordinates

8

slide-9
SLIDE 9

Ray-Sphere Intersection I

  • Define sphere by
  • Center
  • Radius
  • Implicit surface
  • Plug in ray equations for
  • Obtain a scalar equation for t

9

c = [xc yc zc]T r f (q) = (x - xc)2 + (y - yc)2 + (z - zc)2 - r2 = 0 x = x0 + xd t, y = y0 + yd t, z = z0 + zd t x, y, z (x0 + xd t - xc)2 + (y0 + yd t - yc)2 + (z0 + zd t - zc)2 - r2 = 0

slide-10
SLIDE 10

Ray-Sphere Intersection II

  • Simplify to

where

  • Solve to obtain
  • Check if . Return

10

t0, t1 > 0 min(t0, t1) t0, t1 t0,1 = −b ± √ b2 − 4ac 2

slide-11
SLIDE 11
  • For shading (e.g., Phong model), calculate unit normal
  • Negate if ray originates inside the sphere!
  • Note possible problems with roundoff errors

Ray-Sphere Intersection III

11

slide-12
SLIDE 12

Simple Optimizations

  • Factor common subexpressions
  • Compute only what is necessary
  • Calculate , abort if negative
  • Compute normal only for closest intersection
  • Other similar optimizations

12

b2 − 4ac

slide-13
SLIDE 13

Ray-Quadric Intersection

13

  • Quadric , where is polynomial of order 2
  • Sphere, ellipsoid, paraboloid, hyperboloid, cone, cylinder
  • Closed form solution as for sphere
  • Combine with CSG

f (p) = f (x, y, z) = 0 f

slide-14
SLIDE 14

Ray-Polygon Intersection I

14

  • Assume planar polygon in 3D
  • 1. Intersect ray with plane containing polygon
  • 2. Check if intersection point is inside polygon
  • Plane
  • Implicit form:
  • Unit normal:

n = [a b c]T with a2 + b2 + c2 = 1 a · x + b · y + c · z + d = 0

slide-15
SLIDE 15

Ray-Polygon Intersection II

15

  • Substitute to obtain intersection point in plane
  • Solve and rewrite using dot product
  • If , no intersection (ray parallel to plane)
  • If , the intersection is behind ray origin

t n · d = 0 t ≤ 0

slide-16
SLIDE 16

Test if point inside polygon

16

  • Use even-odd rule or winding rule
  • Easier if polygon is in 2D (project from 3D to 2D)
  • Easier for triangles (tessellate polygons)
slide-17
SLIDE 17

Point-in-triangle testing

  • 1. Project the point and triangle onto a plane
  • Pick a plane not perpendicular to triangle (such

a choice always exists)

  • x = 0, y = 0, or z = 0
  • 2. Then, do the 2D test in the plane, by computing

barycentric coordinates (follows next)

17

slide-18
SLIDE 18

Outline

  • Ray-Surface Intersections
  • Special cases: sphere, polygon
  • Barycentric coordinates

18

slide-19
SLIDE 19

Interpolated Shading for Ray Tracing

19

  • Assume we know normals at vertices
  • How do we compute normal of interior point?
  • Need linear interpolation between 3 points
  • Barycentric coordinates

p1 p2 p p3

slide-20
SLIDE 20

Barycentric Coordinates in 1D

20

  • Linear interpolation
  • Geometric intuition
  • Weigh each vertex by ratio of distances from ends
  • α, β are called barycentric coordinates

p(t) = (1 - t) p1 + t p2 , 0 ≤ t ≤ 1 p = α p1 + β p2 , α + β = 1 p is between p1 and p2 iff 0 ≤ α, β ≤ 1 p1 p2 p

slide-21
SLIDE 21

Barycentric Coordinates in 2D

  • Now we have 3 points instead of 2
  • Define 3 barycentric coordinates α, β, γ
  • p = α p1 + β p2 + γ p3
  • p inside triangle iff 0 ≤ α, β, γ ≤ 1, α + β + γ = 1
  • How do we calculate α, β, γ?

21

p1 p2 p p3

slide-22
SLIDE 22
  • Coordinates are ratios of triangle areas
  • Areas in these formulas should be signed
  • Clockwise (-) or anti-clockwise (+) orientation of the triangle
  • Important for point-in-triangle test

Barycentric Coordinates for Triangle

22

p1 p2 p p3 α = Area(pp2p3) / Area(p1p2p3) β = Area(p1pp3) / Area(p1p2p3) γ = Area(p1p2p) / Area(p1p2p3) = 1 - α - β

slide-23
SLIDE 23

Compute Triangle Area in 3D

23

  • Use cross product
  • Parallelogram formula
  • Area(ABC) = (1/2) |(B - A) × (C - A)|
  • How to get correct sign for barycentric coordinates?
  • Compare directions of cross product (B - A) × (C - A)

for triangles pp2p3 vs p1p2p3, etc. (either 0 (sign+) or 180 deg (sign-) angle)

  • Easier alternative: project to 2D, use 2D formula

(projection to 2D preserves barycentric coordinates) A B C

slide-24
SLIDE 24

Compute Triangle Area in 2D

24

  • Suppose we project the triangle ABC to x-y plane
  • Area of the projected triangle in 2D with the

correct sign: (1/2)((bx - ax)(cy - ay) - (cx - ax)(by - ay))

slide-25
SLIDE 25

Outline

  • Ray-Surface Intersections
  • Special cases: sphere, polygon
  • Barycentric coordinates

25

slide-26
SLIDE 26

http://cs420.hao-li.com

Thanks!

26