Ray Intersections - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

Ray Intersections

Description:

Ray Intersections. CS 319. Advanced Topics in. Computer Graphics. John C. Hart ... f(x) 0 outside, f(x) 0 inside. Or vice-verse, doesn't matter ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 25
Provided by: csU70
Category:

less

Transcript and Presenter's Notes

Title: Ray Intersections


1
Ray Intersections
  • CS 319
  • Advanced Topics inComputer Graphics
  • John C. Hart

2
Intersection Computation
  • Parametric ray r(t) o t d
  • t ? 0
  • Since d 1, t is distance along ray
  • Implicit object f(x) 0
  • f(x) gt 0 outside, f(x) lt 0 inside
  • Or vice-verse, doesnt matter
  • Intersection occurs when f(r(t)) 0
  • Let F(t) f(r(t))
  • Real function of one real variable
  • Intersection ? root finding

f(x) gt 0
f(x) 0
f(x) lt 0
F(t) lt 0
F(t) lt 0
F(t) gt 0
F(t) gt 0
3
Sphere Intersection
c
r
f(x)(x - c)?(x - c) - r2 f(r(t)) (o t d -
c)?(o t d - c) - r2 d?d t2 2
(o-c)?d t (o-c)?(o-c) - r2
D gt 0
D 0
D lt 0
D BB - 4AC if (D lt 0.0) return NULL rootD
sqrt(D) t0 0.5(-B - rootD)/A t1 0.5(-B
rootD)/A if (t0 gt 0) hit-gtt t0, return
hit if (t1 gt 0) hit-gtt t1, return
hit return NULL
A d?d ( 1 if d unit length) B 2 (o-c)?d C
(o-c)?(o-c) - r2
Hit position x o t d Hit normal n (x
c)/x c
4
Ellipsoid Intersection
f(T-1x)0
  • Let T be a 4x4 transformation that distorts a
    sphere into the ellipsoid
  • Ellipsoid is implicit surface of f(T-1x)
  • f(T-1r(t)) f(T-1(o t d))
  • f(T-1o t T-1d)
  • Hit point needs to be in world coords
  • t same in both coordinates
  • x o t d

T-1
T
EllipsoidIntersect(Ray r) Ray Tir (Ti
r.o, Ti r.d) return SphereIntersect(Tir)
T-1d
f(x) 0
T-1o
5
What about the normal?
f(T-1x)0
  • Let n a b c d be a tangent plane
  • Let x x y z 1T be a point
  • Plane-point duality
  • Planes are row vectors
  • Points are column vectors
  • Point x in plane n ? n x 0
  • Need to find n such that n T x 0
  • Notice n T-1 T x 0
  • New normal n n T-1 (T-1)T nT
  • Could also use the adjoint n n T
  • n not necessarily unit length even if n is
  • But well need the inverse anyway

T
f(x) 0
6
Matrix Inverse
S-1 minors of ST
Dont need 1/S if just need directionof
transformed normal. Will have torenormalize
anyway is S not special unitary.
7
Scene Graph
  • Hierarchical representation of all objects in
    scene
  • Transformation nodes
  • Intersect kids by T-1 r
  • Returned normal (T-1)T n
  • Maintain T-1 (not T)

Scale 2,2,2Xlate 2,0,0
Xlate 2,2,0Scale .5,1,.5
Xlate -2,0,0
Xlate 2,0,0
8
Instancing
Scale 2,2,2Xlate 2,0,0
Xlate 2,2,0
  • Scene graph is a hierarchy
  • Not necessarily a tree
  • Directed acyclic graph (DAG)
  • Nodes may have multiple parents
  • Instance Appearance of each nodes geometry in
    scene

Xlate -1,0,0
Xlate 1,0,0
Scale .5,1,.5
9
Fun with Instancing
ImagecourtesyJohnAmanatides
10
Quadrics
Ray x(t) ox t dx, y(t) oy t dy z(t)
oz t dz
z
r
x
y
Paraboloidx2 y2 z
Spherex2 y2 z2 r2
Cylinderx2 y2 r2
Variations? Use the transformation trick
Hyperboloidx2 y2? z2 ? r2
Conex2 y2 z2
11
Torus
z
r
x
R
  • Product of two implicit circles
  • (x R)2 z2 r2 0
  • (x R)2 z2 r2 0
  • ((x R)2 z2 r2)((x R)2 z2 r2)
  • (x2 2Rx R2 z2 r2) (x2 2Rx R2 z2
    r2)
  • x4 2x2z2 z4 2x2r2 2z2r2 r4 2x2R2
  • 2z2R2 2r2R2 R4
  • (x2 z2 r2 R2)2 4z2R2 4r2R2
  • Surface of rotation replace x2 with x2 y2
  • f(x,y,z) (x2 y2 z2 r2 R2)2 4R2(z2
    r2)
  • Quartic!!!
  • Up to four ray torus intersections

12
Finding Roots
  • How do we find roots for degree gt 2?
  • Newtons Method
  • Converges fast
  • Might converge to wrong root
  • Root Isolation
  • Guarantees single root
  • Sturm Sequences

13
Newtons Method
14
Sturm Sequences
  • f(t) is a polynomial
  • Create a sequence
  • f1 f
  • f2 f
  • fk1 rem fk-1 /fk
  • of roots in a,b difference in of sign
    changes between fk(a) and fk(b)

f1(t) t3 3t2 1 f2(t) 3t2 6t f3(t) 2t
1 f4(t) 9/4 t f1 f2 f3 f4
-? - - 3 -3 - -
3 -2 0 - 2 -1 - -
2 0 - 0 1 1
0 2 0
15
Ray-Object Intersection
in
out
  • Returns intersection in a hit record
  • Next field enables hit record to hold a list of
    intersections
  • List only non-negative intersection parameters
  • Ray always originates outside
  • If first t 0 then ray originated inside
  • Parity classifies ray segments
  • Odd segments in
  • Even segments out

in
out
in
in
out
out
16
Constructive Solid Geometry
B
  • Construct shapes from primitives using boolean
    set operations
  • Union A?B, A B, A or B
  • Intersection A?B, AB, A and B
  • Difference A\B, AB, A and not B

A
BA
A?B
A?B
AB
17
CSG Intersections
A
B

A.t0
B.t0
A.t1
B.t1
  • List of t-values for A, B w/in-out classification
  • A.t_list 0.9, 3.1 0.9in, 3.1out
  • B.t_list 2.5, 4.5 2.5in, 4.5out
  • Use dot(r.d,n) to determine in,out
  • Merge both lists into a single t-ordered list
  • 0.9 Ain Bout, 2.5 Ain Bin, 3.1 Aout Bin
    , 4.5 Aout Bout
  • Keep track of A and B in/out classification
  • Use Roth table to classify t-values
  • AB 0.9in, 2.5in, 3.1in, 4.5out 0.9, 4.5
  • AB 0.9out, 2.5in, 3.1out, 4.5out 2.5,
    3.1
  • A-B 0.9in, 2.5out,3.1out, 4.5out 0.9, 2.5
  • Remove redundant t-values

0.9
2.5
3.1
4.5
Roth Table Op A B Res in in in in out in out
in in out out out in in in in out out out in
out out out out in in out in out in out in o
ut out out out
18
Accelerating Ray Intersections
  • Q Why is basic ray tracing so slow?
  • A It intersects every ray with every primitive
    in every object
  • Q How can we make ray tracing faster?
  • A Coherence
  • Image coherence neighboring pixels probably
    display same object
  • Spatial coherence neighboring points probably
    exhibit same appearance
  • Temporal coherence Pixels in neighboring frames
    probably display same object

Stanford Bunny70K triangles Do we need 70K
ray-triangleintersections for each ray?
19
Shadow Caching
s
  • Any interloper between surface point x and the
    light source s will cast a shadow
  • Doesnt matter how many
  • Doesnt matter which is closest
  • Stop ray intersections once any intersection
    found
  • Neighboring shadowed surface points x and x
    probably shadowed by the same object
  • Start shadow ray intersection search with object
    intersected in last shadow search

C
A
B
x
x
20
Bounding Volume
  • Ray-bunny intersection takes 70K ray-triangle
    intersections even if ray misses the bunny
  • Place a sphere around bunny
  • Ray A misses sphere so ray A misses bunny without
    checking 70K ray-triangle intersections
  • Ray B intersects sphere but still misses bunny
    after checking 70K intersections
  • Ray C intersects sphere and intersects bunny
  • Can also use axis-aligned bounding box
  • Easier to create for triangle mesh

A
B
C
21
Bounding Volume Hierarchy
A
B
C
  • Associate bounding volume with each node of scene
    graph
  • If ray misses a nodes bounding volume, then no
    need to check any node beneath it
  • If ray hits a nodes BV, then replace it with its
    childrens BVs (or geometry)
  • Breadth first search of tree
  • Maintain heap ordered by ray-BV intersection
    t-values
  • Explore children of nodew/least pos. ray-BV
    t-value

Bunny
BV
Body
BV
Head
BV
L.Ear
Face
R.Ear
BV
BV
BV
22
Grids
  • Encase object in a 3-D array of cubic cells
  • Each cell contains list of all triangles it
    contains or intersects
  • Rasterize ray to find which cells it intersects
  • 3D Bresenham algorithm
  • All cells that contain any part of ray
  • Working from first ray-cell to last
  • Find least positive intersect of ray with
    triangles in cells list
  • If no intersection, move on to next cell

23
Tagging
  • Ray-object intersection test valid for ray with
    entire object
  • not just portion of object inside current cell
  • Need only intersect object once for each ray
  • In cell A list 1
  • Intersect r with 1? Yes
  • Miss ? Tag 1 with no-intersection
  • In cell B list 2
  • Intersect r with 2? Yes
  • ray r hits object 2 but later in cell C
  • Tag object 2 with intersection-at-C
  • In cell C list 1,2
  • Intersect r with 1? No (no-intersection)
  • Intersect r with 2? No (intersection-at-D)
  • In cell D list 2
  • Intersect r with 2? No (intersection-at-D)

A
B
2
C
D
1
r
24
Other Partitioning Structures
  • Octree
  • Ray can parse through large empty areas
  • Requires less space than grid
  • Subdivision takes time
  • Binary Space Partition (BSP) Tree
  • Planes can divide models nearly in half
  • Trees better balanced, shallower
  • Added ray-plane intersections
Write a Comment
User Comments (0)
About PowerShow.com