Acceleration Structures for Ray Casting

Acceleration Structures for Ray Casting

Acceleration Structures for Ray Casting MIT EECS 6.837 Computer Graphics Wojciech Matusik, MIT EECS © ACM. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/. Hašan et al. 2007 1 Recap: Ray Tracing trace ray Intersect all objects color = ambient term For every light cast shadow ray Stopping criteria: color += local shading term If mirror • Recursion depth color += colorrefl * – Stop after a trace reflected ray number If transparent of bounces color += colortrans * trace transmitted ray • Ray contribution – Stop if reflected / transmitted • Does it ever end? contribution becomes too small 2 Recursion For Reflection: None 0 recursion 3 Recursion For Reflection: 1 0 recursion 4 Recursion For Reflection: 2 0 recursion 5 Ray tree • Visualizing the ray tree for single image pixel incoming reflected ray shadow ray transmitted (refracted) ray 6 Ray tree This gets pretty complicated pretty fast! • Visualizing the ray tree for single image pixel incoming reflected ray shadow ray transmitted (refracted) ray 7 Questions? 8 Ray Tracing Algorithm Analysis • Lots of primitives cost ≈ height * width * • Recursive num primitives * intersection cost * • Distributed Ray size of recursive ray tree * Tracing num shadow rays * num supersamples * – Means using many num glossy rays * rays for non- num temporal samples * ideal/non-pointlike num aperture samples * phenomena . • Soft shadows Can we reduce this? • Anti-aliasing • Glossy reflection • Motion blur • Depth of field 9 Today • Motivation – You need LOTS of rays to generate nice pictures – Intersecting every ray with every primitive becomes the bottleneck • Bounding volumes • Bounding Volume Hierarchies, Kd-trees For every pixel Construct a ray from the eye For every object in the scene Find intersection with the ray Keep if closest Shade 10 Accelerating Ray Casting • Goal: Reduce the number of ray/primitive intersections 11 Conservative Bounding Volume • First check for an intersection with a conservative bounding volume • Early reject: If ray doesn’t hit volume, it doesn’t hit the triangles! 12 Conservative Bounding Volume • What does “conservative” mean? – Volume must be big enough to contain all geometry within 13 Conservative Bounding Regions • Desiderata – Tight → avoid false positives – Fast to intersect 14 Ray-Box Intersection • Axis-aligned box • Box: (X1, Y1, Z1) → (X2, Y2, Z2) • Ray: P(t) = Ro + tRd y=Y2 y=Y1 Rd x=X1 x=X2 Ro 15 Naïve Ray-Box Intersection • 6 plane equations: Compute all intersections • Return closest intersection inside the box – Verify intersections are on the correct side of each plane: Ax+By+Cz+D < 0 y=Y2 y=Y1 Rd x=X1 x=X2 Ro 16 Reducing Total Computation • Pairs of planes have the same normal • Normals have only one non-zero component • Do computations one dimension at a time y=Y2 y=Y1 Rd x=X1 x=X2 Ro 17 Test if Parallel • If Rdx = 0 (ray is parallel) AND Rox < X1 or Rox > X2 → no intersection y=Y2 y=Y1 Rd (The same for Y and Z, x=X1 x=X2 of course) Ro 18 Find Intersections Per Dimension • Basic idea – Determine an interval along the ray for each dimension – The intersect these 1D intervals (remember CSG!) – Done! y=Y2 Ro y=Y1 x=X1 x=X2 19 Find Intersections Per Dimension • Basic idea – Determine an interval along the ray for each dimension – The intersect these 1D intervals (remember CSG!) – Done! Interval between X1 y=Y 2 and X2 Ro y=Y1 x=X1 x=X2 20 Find Intersections Per Dimension • Basic idea – Determine an interval along the ray for each dimension – The intersect these 1D intervals (remember CSG!) – Done! Interval between X1 y=Y 2 and X2 Interval between Y1 R o and Y2 y=Y1 x=X1 x=X2 21 Find Intersections Per Dimension • Basic idea – Determine an interval along the ray for each dimension – The intersect these 1D intervals (remember CSG!) – Done! Interval between X1 y=Y 2 and X2 Interval between Y1 R o and Y2 y=Y1 Intersection x=X1 x=X2 22 Intersecting 1D Intervals 23 Intersecting 1D Intervals Start= max of mins 24 Intersecting 1D Intervals Start= max of mins End= min of maxs 25 Intersecting 1D Intervals If Start > End, the intersection is empty! Start= max of mins End= min of maxs 26 Find Intersections Per Dimension • Calculate intersection distance t1 and t2 t2 y=Y2 t1 Rd Ro y=Y1 x=X1 x=X2 27 Find Intersections Per Dimension • Calculate intersection distance t1 and t2 – t1 = (X1 - Rox) / Rdx – t2 = (X2 - Rox) / Rdx – [t1, t2] is the X interval t2 y=Y2 t1 Rd Ro y=Y1 x=X1 x=X2 28 Then Intersect Intervals • Init tstart & tend with X interval • Update tstart & tend for each subsequent dimension tend y=Y2 tstart y=Y1 x=X1 x=X2 29 Then Intersect Intervals • Compute t1 and t2 for Y... t2 y=Y2 t1 y=Y1 x=X1 x=X2 30 Then Intersect Intervals • Update tstart & tend for each subsequent dimension – If t1 > tstart, tstart = t1 – If t2 < tend, tend = t2 t2 tend y=Y2 tstart t1 y=Y1 x=X1 x=X2 31 Then Intersect Intervals • Update tstart & tend for each subsequent dimension – If t1 > tstart, tstart = t1 – If t2 < tend, tend = t2 t2 tend y=Y2 tstart t1 y=Y1 x=X1 x=X2 32 Then Intersect Intervals • Update tstart & tend for each subsequent dimension – If t1 > tstart, tstart = t1 – If t2 < tend, tend = t2 tend y=Y2 tstart :-) y=Y1 x=X1 x=X2 33 Is there an Intersection? • If tstart > tend → box is missed tstart tend y=Y2 y=Y1 x=X1 x=X2 34 Is the Box Behind the Eyepoint? • If tend < tmin → box is behind tend y=Y2 tstart y=Y1 x=X1 x=X2 35 Return the Correct Intersection • If tstart > tmin → closest intersection at tstart • Else → closest intersection at tend – Eye is inside box tend y=Y2 tstart y=Y1 x=X1 x=X2 36 Ray-Box Intersection Summary • For each dimension, – If Rdx = 0 (ray is parallel) AND Rox < X1 or Rox > X2 → no intersection • For each dimension, calculate intersection distances t1 and t2 – t1 = (X1 - Rox) / Rdx t2 = (X2 - Rox) / Rdx – If t1 > t2, swap – Maintain an interval [tstart, tend], intersect with current dimension – If t1 > tstart, tstart = t1 If t2 < tend, tend = t2 • If tstart > tend → box is missed • If tend < tmin → box is behind • If tstart > tmin → closest intersection at tstart • Else → closest intersection at tend 37 Efficiency Issues • 1/Rdx, 1/Rdy and 1/Rdz can be pre-computed and shared for many boxes 38 Bounding Box of a Triangle (xmax, ymax, zmax) (x0, y0, z0) = (max(x0,x1,x2), max(y0,y1,y2), max(z0,z1,z2)) (x1, y1, z1) (x2, y2, z2) (xmin, ymin, zmin) = (min(x0,x1,x2), min(y0,y1,y2), min(z0,z1,z2)) 39 Bounding Box of a Sphere (xmax, ymax, zmax) = (x+r, y+r, z+r) r (x, y, z) (xmin, ymin, zmin) = (x-r, y-r, z-r) 40 Bounding Box of a Plane (xmax, ymax, zmax) = (+∞, +∞, +∞)* n = (a, b, c) ax + by + cz = d (xmin, ymin, zmin) = (-∞, -∞, -∞)* * unless n is exactly perpendicular to an axis 41 Bounding Box of a Group (xmax, ymax, zmax) (xmax_a, ymax_a, zmax_a) = (max(xmax_a,xmax_b), (xmax_b, ymax_b, zmax_b) max(ymax_a,ymax_b), max(zmax_a,zmax_b)) (xmin_b, ymin_b, zmin_b) (xmin_a, ymin_a, zmin_a) (x , y , z ) min min min = (min(xmin_a,xmin_b), min(ymin_a,ymin_b), min(zmin_a,zmin_b)) 42 Bounding Box of a Transform Bounding box of transformed object IS NOT (x'max, y'max, z'max) the transformation of the bounding box! = (max(x0,x1,x2,x3,x4,x5,x6,x7), max(y0,y1,y2,y3,y4,x5,x6,x7), (xmax, ymax, zmax) max(z0,z1,z2,z3,z4,x5,x6,x7)) M (x3,y3,z3) = M (xmax,ymax,zmin) (x2,y2,z2) = (x1,y1,z1) = M (xmin,ymax,zmin) M (xmax,ymin,zmin) (x0,y0,z0) = (x'min, y'min, z'min) (xmin, ymin, zmin) M (xmin,ymin,zmin) = (min(x0,x1,x2,x3,x4,x5,x6,x7), min(y0,y1,y2,y3,y4,x5,x6,x7), min(z0,z1,z2,z3,z4,x5,x6,x7)) 43 Bounding Box of a Transform Bounding box of transformed object IS NOT (x'max, y'max, z'max) the transformation of the bounding box! = (max(x0,x1,x2,x3,x4,x5,x6,x7), max(y0,y1,y2,y3,y4,x5,x6,x7), (xmax, ymax, zmax) max(z0,z1,z2,z3,z4,x5,x6,x7)) M (x3,y3,z3) = M (xmax,ymax,zmin) (x2,y2,z2) = (x1,y1,z1) = M (xmin,ymax,zmin) M (xmax,ymin,zmin) (x0,y0,z0) = (x'min, y'min, z'min) (xmin, ymin, zmin) M (xmin,ymin,zmin) = (min(x0,x1,x2,x3,x4,x5,x6,x7), min(y0,y1,y2,y3,y4,x5,x6,x7), min(z0,z1,z2,z3,z4,x5,x6,x7)) Questions? 44 Are Bounding Volumes Enough? • If ray hits bounding volume, must we test all primitives inside it? – Lots of work, think of a 1M-triangle mesh bounding sphere 45 Bounding Volume Hierarchies • If ray hits bounding volume, must we test all primitives inside it? – Lots of work, think of a 1M-triangle mesh • You guessed it already, we’ll split the primitives in groups and build recursive bounding volumes – Like collision detection, bounding remember? sphere hierarchy 46 Bounding Volume Hierarchy (BVH) • Find bounding box of objects/primitives • Split objects/primitives into two, compute child BVs • Recurse, build a binary tree 47 Bounding Volume Hierarchy (BVH) • Find bounding box of objects/primitives • Split objects/primitives into two, compute child BVs • Recurse, build a binary tree 48 Bounding Volume Hierarchy (BVH) • Find bounding box of objects/primitives • Split objects/primitives into two, compute child BVs • Recurse, build a binary tree 49 Bounding Volume Hierarchy (BVH) • Find bounding box of objects/primitives • Split objects/primitives into two, compute child BVs • Recurse, build a binary tree 50 Bounding Volume Hierarchy (BVH) • Find bounding box of objects/primitives • Split objects/primitives into two, compute child BVs • Recurse, build a binary tree 51 Where to Split Objects? • At midpoint of current volume OR • Sort, and put half of the objects on each side OR • Use modeling hierarchy 52 Where to Split Objects? • At midpoint of current volume OR • Sort,

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    93 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us