KD Tree BSP Tree Octree (3D) Uniform Grid Uniform Grid

KD Tree BSP Tree Octree (3D) Uniform Grid Uniform Grid

Acceleration techniques Acceleration Digggyital Image Synthesis Yung-Yu Chuang with slides by Mario Costa Sousa, Gordon Stoll and Pat Hanrahan Bounding volume hierarchy Bounding volume hierarchy 1) Find bounding box of objects Bounding volume hierarchy Bounding volume hierarchy 1) Find bounding box of objects 1) Find bounding box of objects 2) SliSplit objects into two groups 2) SliSplit objects into two groups 3) Recurse Bounding volume hierarchy Bounding volume hierarchy 1) Find bounding box of objects 1) Find bounding box of objects 2) SliSplit objects into two groups 2) SliSplit objects into two groups 3) Recurse 3) Recurse Bounding volume hierarchy Where to split? 1) Find bounding box of objects • At midpoint 2) SliSplit objects into two groups • Sort, and put half of the objects on each side 3) Recurse • Use modeling hierarchy BVH traversal BVH traversal • If hit parent, then check all children • Don't return intersection immediately because the other subvolumes may have a closer intersection Bounding volume hierarchy Bounding volume hierarchy Space subdivision approaches Space subdivision approaches Unifrom grid Quadtree (2D) KD tree BSP tree Octree (3D) Uniform grid Uniform grid Preprocess scene 1. Find bounding box Uniform grid Uniform grid Preprocess scene Preprocess scene 1. Find bounding box 1. Find bounding box 2. Determine grid resolution 2. Determine grid resolution 3. Place object in cell if its bounding box overlaps the cell Uniform grid Uniform grid traversal Preprocess scene Preprocess scene 1. Find bounding box Traverse grid 2. Determine grid resolution 3D line = 3D-DDA 3. Place object in cell if its (Digital Differential bounding box overlaps the cell Analyzer) 4. Check that object overlaps cell (expensive!) y y y mx b m 2 1 x2 x1 xi1 xi 1 yi1 mxi1 b naive yi1 yi m DDA octree Octree K-d tree A A Leaf nodes correspond to unique regions in space K-d tree K-d tree A A B B B A A Leaf nodes correspond to unique regions in space Leaf nodes correspond to unique regions in space K-d tree K-d tree C A C A B B C B B A A K-d tree K-d tree C A C A D B D B C C B B D A A K-d tree K-d tree traversal A A D B D B B C C B C C D D A A Leaf nodes correspond to unique regions in space Leaf nodes correspond to unique regions in space BSP tree BSP tree 6 6 5 5 1 9 9 inside outside ones ones 7 7 10 8 10 8 1 1 11 11 2 2 4 4 3 3 BSP tree BSP tree 6 6 5 1 5 1 2 5 5 9 9b 9 3 6 4 7 7 6 8 7 10 10 11b 8 8 8 9a 7 9b 1 9 1 9a 11b 11 10 11 10 11a 2 11 2 11a 4 4 3 3 BSP tree BSP tree traversal 6 5 6 5 1 1 9b 9b 9 2 5 9 2 5 7 7 10 11b 8 8 10 11b11b 8 9a 3 6 9a9a 3 6 8 1 1 11 9b 11 9b 11a 4 7 11a 4 7 2 2 4 9a 11b 4 9a 11b poitint 3 3 10 10 11a 11a BSP tree traversal BSP tree traversal 6 5 6 5 1 1 9b 9b 9 2 5 9 2 5 7 11b 7 10 11b11b 10 11b 8 8 3 8 9a9a 3 6 8 9a9a 6 1 1 11 9b 11 9b 11a 4 7 11a 4 7 2 2 4 9a 11b 4 9a 11b poitint point 3 3 10 10 11a 11a Classes Hierarchy • Primitive (in core/primitive.*) Primitive – Geome tiPiititricPrimitive – InstancePrimitive – AtAggregate • Three types of accelerators are provided (in Geometric Transformed Aggregate accelerators/*.cpp) PiPrimiti ve PiPrimiti ve – GridAccel T – BVHAccel – KdTreeAccel Material Shape Support both Store intersectable Instancing and primitives, call animation Refine If necessary Primitive Interface class Primitive : public ReferenceCounted { BBox WorldBound(); geometry <Primitive interface> bool CanIntersect(); const int primitiveId; bool Intersect(const Ray &r, // update maxt static int nextprimitiveId; Intersection *in); } bool IntersectP(const Ray &r); void Refine(vector<ReferencRefine(vector<Reference<Primitive>>e<Primitive>> &refined); class TransformedPrimitive: public Primitive void FullyRefine(vector<Reference<Primitive>> &refined); { AreaLight *GetAreaLight(); material … BSDF *GetBSDF((yg,const DifferentialGeometry &dg, Re ference< Pr im itive> itinstance; Transform &WorldToObject); } BSSRDF *GetBSSRDF(DifferentialGeometry &dg, Transform &WorldToObject); Intersection GeometricPrimitive struct Intersection { • represents a single shape <Intersection interface> • hldholds a reference to a Shape and its Materilial, DifferentialGeometry dg; and a pointer to an AreaLight const Primitive *primitive; Reference<Shape> shape; Transform WorldToObject, ObjectToWorld; Reference<Material> material; // BRDF int shapeId, primitiveId; AreaLight *areaLight; // emittance float rayEpsilon; • Most operations are forwarded to shape }; adaptiv ely estimated primitive stores the actual intersecting primitive, hence Primitive->GetAreaLight and GetBSDF can only be called for GeometricPrimitive GeometricPrimitive Object instancing bool Intersect(Ray &r,Intersection *isect) { float thit, rayEpsilon; if (!shape->Intersect(r, &thit, &rayypEpsilon , &isect->dg)) return false; isect->primitive = this; isect->WorldToObject = *shape->WorldToObject; isect->ObjectToWorld = *shape->ObjectToWorld; isect->shapeId = shape->shapeId; isect->primitiveId = primitiveId; isect->rayEpsilon = rayEpsilon; r.maxt = thit; 61 uniqqpue plants , 4000 individual plants, 19.5M trian gles return true; With instancing, store only 1.1M triangles, 11GB->600MB } TransformedPrimitive TransformedPrimitive bool Intersect(Ray &r, Intersection *isect){ Re ference <Pr im itive > pr im itive; Transform w2p; AnimatedTransform WorldToPrimitive; WorldToPrimitive.Interpolate(r.time,&w2p); for instancing and animation Ray ray = w2p(r); if (!primitive->Intersect(ray, isect)) Ray ray = WorldToPrimitive(r); return false; if (!instance->Intersect(ray, isect)) r.maxt = ray.maxt; return false; itisect->iitiId>primitiveId = pr iitiIdimitiveId; r.maxt = ray.maxt; if (!w2p.IsIdentity()) { // Compute world-to-object transformation for instance isect->WorldToObject = isect->WorldToObject isect->WorldToObject=isect->WorldToObject*w2p; *WorldToInstance; isect->ObjectToWorld=Inverse( isect->WorldToObject); TransformedPrimitive Aggregates // Transform instance's differential geometry to world space • Acceleration is a heart component of a ray Transform PrimitiveToWorld = Inverse((p);w2p); tracer because ray/scene intersection accounts isect->dg.p = PrimitiveToWorld(isect->dg.p); for the majority of execution time isect->dg.nn = Normalize( PrimitiveToWorld(isect- >dg.nn)); • GlGoal: reduce the number of ray/iiti/primitive isect->dg.dpdu=PrimitiveToWorld(isect->dg.dpdu); intersections by quick simultaneous rejection of isect->dg.dpdv=PrimitiveToWorld(isect->dg.dpdv); groups of prim itives and the fact tha t nearby isect->dg.dndu=PrimitiveToWorld(isect->dg.dndu); intersections are likely to be found first isect->dg.dndv=PrimitiveToWorld(isect->dg.dndv); • Two main approaches: spatial subdivision, } object subdivision return true; • No clear winner } Ray-Box intersections Ray-Box intersections • Almost all acclerators require it 1 • QikQuick rejecti on, use enter and exit point to traverse the hierarchy Dx • AABB is the intersection of three slabs t1 x1 Ox t1 Dx x1 Ox x=x0 x=x1 Ray-Box intersections Grid accelerator bool BBox::IntersectP(const Ray &ray, • Uniform grid float *hitt0, float *hitt1) { float t0 = ray.mint, t1 = ray.maxt; for (int i = 0; i < 3; ++i) { float invRayDir = 1.f / ray.d[i]; float tNear = (pMin[i] - ray.o[i]) * invRayDir; float tFar = (pMax[ i] -rayy[]).o[i]) * invRay Dir; if (tNear > tFar) swap(tNear, tFar); t0 = tNear > t0 ? tNear : t0; segment iiintersection t1 = tFar < t1 ? tFar : t1; if (t0 > t1) return false; intersection is empty } if (hitt0) *hitt0 = t0; if (hitt1) *hitt1 = t1; return true; } Teapot in a stadium problem GridAccel • Not adaptive to distribution of primitives. Class GridAccel:public Aggregate { • Have to determine the number of voxels. <GridAccel methods> (problem with too many or too few) u_int nMailboxes; MailboxPrim *mailboxes; vector<Reference<Primitive>> primitives; int nVoxels[3]; BBox bounds; VtVector WidthIWidthWidth, InvWidth; Voxel **voxels; MAMemoryArena voxe lArena; RWMutex *rwMutex; } mailbox GridAccel struct MailboxPrim { GridAccel(vector<Reference<Primitive> > &p, Reference<Primitive> primitive; bool forRefined, bool refineImmediately) Int lastMailboxId; : gridForRefined(forRefined) { } // Initialize with primitives for grid if (refineImmediately) for (int i = 0; i < p. size(); ++i) p[i]->FullyRefine(primitives); else primitives = p; for (iti(int i = 0 ; i < pri iitimitives.s ize (); ++ i) bounds = Union(bounds, primitives[i]->WorldBound()); Determine number of voxels Calculate voxel size and allocate voxels • Too many voxels → slow traverse, large for (int axis=0; axis<3; ++axis) { memory consumption (bad cache performance) nVoxels[axis]=Round2Int(delta[axis]*voxelsPerUnitDist); nVoxels[axis]=Clamp(nVoxels[axis], 1, 64); • Too few voxels → too many primitives in a } voxel • Let the axis with the largest extent have 3 3 N for (int axis=0; axis<3; ++axis) { width[axis]=delta[axis]/nVoxels[axis]; partitions (N:number of primitives) invWidth[axis]= (width[axis]==0.f)?0.f:1.f/width[axis]; Vector delta = bounds.pMax - bounds.pMin; } int maxAxis=bounds.MaximumExtent(); float invMaxWidth=1.f/delta[maxAxis]; int nv = nVoxels[0] * nVoxels[1] * nVoxels[2]; float cubeRoot=3.f*powf(float(prims.size()),1.f/3.f); voxels=AllocAligned<Voxel *>(nv); float voxelsPerUnitDist=cubeRoot * invMaxWidth; memset(voxels, 0, nv * sizeof(Voxel *)); Conversion between voxel and position Add primitives into voxels int posToVoxel(const Point &P, int axis) { for (u_int i=0; i<prims.size(); ++i) { int v=Float2Int( (P[axis]-bounds.pMin[axis])*InvWidth[axis]); <Find voxel extent of primitive> return Clamp(v, 0, NVoxels[axis]-1);

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    33 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