bounding_volume_hierarchy.html 16.8 KB
Newer Older
allai5's avatar
allai5 committed
1
<!DOCTYPE html> <html lang="en-US"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=Edge"> <title>(Task 3) BVH - </title> <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"> <link rel="stylesheet" href="/assets/css/just-the-docs-default.css"> <script type="text/javascript" src="/assets/js/vendor/lunr.min.js"></script> <script type="text/javascript" src="/assets/js/just-the-docs.js"></script> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Begin Jekyll SEO tag v2.7.1 --> <title>(Task 3) BVH</title> <meta name="generator" content="Jekyll v4.2.0" /> <meta property="og:title" content="(Task 3) BVH" /> <meta property="og:locale" content="en_US" /> <meta name="twitter:card" content="summary" /> <meta property="twitter:title" content="(Task 3) BVH" /> <script type="application/ld+json"> {"headline":"(Task 3) BVH","@type":"WebPage","url":"/pathtracer/bounding_volume_hierarchy","@context":"https://schema.org"}</script> <!-- End Jekyll SEO tag --> </head> <body> <svg xmlns="http://www.w3.org/2000/svg" style="display: none;"> <symbol id="svg-link" viewBox="0 0 24 24"> <title>Link</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-link"> <path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path> </svg> </symbol> <symbol id="svg-search" viewBox="0 0 24 24"> <title>Search</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"> <circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line> </svg> </symbol> <symbol id="svg-menu" viewBox="0 0 24 24"> <title>Menu</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-menu"> <line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line> </svg> </symbol> <symbol id="svg-arrow-right" viewBox="0 0 24 24"> <title>Expand</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-right"> <polyline points="9 18 15 12 9 6"></polyline> </svg> </symbol> <symbol id="svg-doc" viewBox="0 0 24 24"> <title>Document</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-file"> <path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"></path><polyline points="13 2 13 9 20 9"></polyline> </svg> </symbol> </svg> <div class="side-bar"> <div class="site-header"> <a href="/" class="site-title lh-tight"> </a> <a href="#" id="menu-button" class="site-button"> <svg viewBox="0 0 24 24" class="icon"><use xlink:href="#svg-menu"></use></svg> </a> </div> <nav role="navigation" aria-label="Main" id="site-nav" class="site-nav"> <ul class="nav-list"><li class="nav-list-item"><a href="/" class="nav-list-link">Home</a></li><li class="nav-list-item"><a href="/git/" class="nav-list-link">GitHub Setup</a></li><li class="nav-list-item"><a href="/build/" class="nav-list-link">Building Scotty3D</a></li><li class="nav-list-item"><a href="#" class="nav-list-expander"><svg viewBox="0 0 24 24"><use xlink:href="#svg-arrow-right"></use></svg></a><a href="/guide/" class="nav-list-link">User Guide</a><ul class="nav-list "><li class="nav-list-item "><a href="/guide/animate_mode/" class="nav-list-link">Animate</a></li><li class="nav-list-item "><a href="/guide/layout_mode/" class="nav-list-link">Layout</a></li><li class="nav-list-item "><a href="/guide/model_mode/" class="nav-list-link">Model</a></li><li class="nav-list-item "><a href="/guide/render_mode/" class="nav-list-link">Render</a></li><li class="nav-list-item "><a href="/guide/rigging_mode/" class="nav-list-link">Rig</a></li><li class="nav-list-item "><a href="/guide/simulate_mode/" class="nav-list-link">Simulate</a></li></ul></li><li class="nav-list-item"><a href="#" class="nav-list-expander"><svg viewBox="0 0 24 24"><use xlink:href="#svg-arrow-right"></use></svg></a><a href="/meshedit/" class="nav-list-link">A2: MeshEdit</a><ul class="nav-list "><li class="nav-list-item "><a href="/meshedit/halfedge" class="nav-list-link">Halfedge Mesh</a></li><li class="nav-list-item "><a href="#" class="nav-list-expander"><svg viewBox="0 0 24 24"><use xlink:href="#svg-arrow-right"></use></svg></a><a href="/meshedit/local/" class="nav-list-link">Local Operations</a><ul class="nav-list"><li class="nav-list-item "> <a href="/meshedit/local/edge_flip" class="nav-list-link">Edge Flip Tutorial</a> </li><li class="nav-list-item "> <a href="/meshedit/local/bevel/" class="nav-list-link">Bevelling</a> </li></ul></li><li class="nav-list-item "><a href="#" class="nav-list-expander"><svg viewBox="0 0 24 24"><use xlink:href="#svg-arrow-right"></use></svg></a><a href="/meshedit/global/" class="nav-list-link">Global Operations</a><ul class="nav-list"><li class="nav-list-item "> <a href="/meshedit/global/catmull/" class="nav-list-link">Catmull-Clark Subdivision</a> </li><li class="nav-list-item "> <a href="/meshedit/global/remesh/" class="nav-list-link">Isotropic Remeshing</a> </li><li class="nav-list-item "> <a href="/meshedit/global/linear/" class="nav-list-link">Linear Subdivision</a> </li><li class="nav-list-item "> <a href="/meshedit/global/loop/" class="nav-list-link">Loop Subdivision</a> </li><li class="nav-list-item "> <a href="/meshedit/global/simplify/" class="nav-list-link">Simplification</a> </li><li class="nav-list-item "> <a href="/meshedit/global/triangulate/" class="nav-list-link">Triangulation</a> </li></ul></li></ul></li><li class="nav-list-item active"><a href="#" class="nav-list-expander"><svg viewBox="0 0 24 24"><use xlink:href="#svg-arrow-right"></use></svg></a><a href="/pathtracer/" class="nav-list-link">A3: Pathtracer</a><ul class="nav-list "><li class="nav-list-item "><a href="/pathtracer/camera_rays" class="nav-list-link">(Task 1) Camera Rays</a></li><li class="nav-list-item "><a href="#" class="nav-list-expander"><svg viewBox="0 0 24 24"><use xlink:href="#svg-arrow-right"></use></svg></a><a href="/pathtracer/intersecting_objects" class="nav-list-link">(Task 2) Intersections</a><ul class="nav-list"><li class="nav-list-item "> <a href="/pathtracer/ray_triangle_intersection" class="nav-list-link">Ray Triangle Intersection</a> </li><li class="nav-list-item "> <a href="/pathtracer/ray_sphere_intersection" class="nav-list-link">Ray Sphere Intersection</a> </li></ul></li><li class="nav-list-item active"><a href="/pathtracer/bounding_volume_hierarchy" class="nav-list-link active">(Task 3) BVH</a></li><li class="nav-list-item "><a href="/pathtracer/shadow_rays" class="nav-list-link">(Task 4) Shadow Rays</a></li><li class="nav-list-item "><a href="/pathtracer/path_tracing" class="nav-list-link">(Task 5) Path Tracing</a></li><li class="nav-list-item "><a href="#" class="nav-list-expander"><svg viewBox="0 0 24 24"><use xlink:href="#svg-arrow-right"></use></svg></a><a href="/pathtracer/materials" class="nav-list-link">(Task 6) Materials</a><ul class="nav-list"><li class="nav-list-item "> <a href="/pathtracer/dielectrics_and_transmission" class="nav-list-link">Dielectrics and Transmission</a> </li></ul></li><li class="nav-list-item "><a href="#" class="nav-list-expander"><svg viewBox="0 0 24 24"><use xlink:href="#svg-arrow-right"></use></svg></a><a href="/pathtracer/environment_lighting" class="nav-list-link">(Task 7) Environment Lighting</a><ul class="nav-list"><li class="nav-list-item "> <a href="/pathtracer/importance_sampling" class="nav-list-link">Environment Light Importance Sampling</a> </li></ul></li><li class="nav-list-item "><a href="/pathtracer/visualization_of_normals" class="nav-list-link">Visualization of normals</a></li></ul></li><li class="nav-list-item"><a href="#" class="nav-list-expander"><svg viewBox="0 0 24 24"><use xlink:href="#svg-arrow-right"></use></svg></a><a href="/animation/" class="nav-list-link">A4: Animation</a><ul class="nav-list "><li class="nav-list-item "><a href="/animation/splines" class="nav-list-link">Splines</a></li><li class="nav-list-item "><a href="/animation/skeleton_kinematics" class="nav-list-link">Skeleton Kinematics</a></li><li class="nav-list-item "><a href="/animation/skinning" class="nav-list-link">Skinning</a></li><li class="nav-list-item "><a href="/animation/particles" class="nav-list-link">Particles</a></li></ul></li></ul> </nav> <footer class="site-footer"> This site uses <a href="https://github.com/pmarsceill/just-the-docs">Just the Docs</a>, a documentation theme for Jekyll. </footer> </div> <div class="main" id="top"> <div id="main-header" class="main-header"> <div class="search"> <div class="search-input-wrap"> <input type="text" id="search-input" class="search-input" tabindex="0" placeholder="Search " aria-label="Search " autocomplete="off"> <label for="search-input" class="search-label"><svg viewBox="0 0 24 24" class="search-icon"><use xlink:href="#svg-search"></use></svg></label> </div> <div id="search-results" class="search-results"></div> </div> </div> <div id="main-content-wrap" class="main-content-wrap"> <nav aria-label="Breadcrumb" class="breadcrumb-nav"> <ol class="breadcrumb-nav-list"> <li class="breadcrumb-nav-list-item"><a href="/pathtracer/">A3: Pathtracer</a></li> <li class="breadcrumb-nav-list-item"><span>(Task 3) BVH</span></li> </ol> </nav> <div id="main-content" class="main-content" role="main"> <h1 id="task-3-bounding-volume-hierarchy"> <a href="#task-3-bounding-volume-hierarchy" class="anchor-heading" aria-labelledby="task-3-bounding-volume-hierarchy"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> (Task 3) Bounding Volume Hierarchy </h1> <p>In this task you will implement a bounding volume hierarchy that accelerates ray-scene intersection. Most of this work will be in <code class="language-plaintext highlighter-rouge">student/bvh.inl</code>. Note that this file has an unusual extension (<code class="language-plaintext highlighter-rouge">.inl</code> = inline) because it is an implementation file for a template class. This means <code class="language-plaintext highlighter-rouge">bvh.h</code> must <code class="language-plaintext highlighter-rouge">#include</code> it, so all code that sees <code class="language-plaintext highlighter-rouge">bvh.h</code> will also see <code class="language-plaintext highlighter-rouge">bvh.inl</code>.</p> <p>First, take a look at the definition for our <code class="language-plaintext highlighter-rouge">BVH</code> in <code class="language-plaintext highlighter-rouge">rays/bvh.h</code>. We represent our BVH using a vector of <code class="language-plaintext highlighter-rouge">Node</code>s, <code class="language-plaintext highlighter-rouge">nodes</code>, as an implicit tree data structure in the same fashion as heaps that you probably have seen in some other courses. A <code class="language-plaintext highlighter-rouge">Node</code> has the following fields:</p> <ul> <li><code class="language-plaintext highlighter-rouge">BBox bbox</code>: the bounding box of the node (bounds all primitives in the subtree rooted by this node)</li> <li><code class="language-plaintext highlighter-rouge">size_t start</code>: start index of primitives in the <code class="language-plaintext highlighter-rouge">BVH</code>’s primitive array</li> <li><code class="language-plaintext highlighter-rouge">size_t size</code>: range of index in the primitive list (number of primitives in the subtree rooted by the node)</li> <li><code class="language-plaintext highlighter-rouge">size_t l</code>: the index of the left child node</li> <li><code class="language-plaintext highlighter-rouge">size_t r</code>: the index of the right child node</li> </ul> <p>The BVH class also maintains a vector of all primitives in the BVH. The fields start and size in the BVH <code class="language-plaintext highlighter-rouge">Node</code> refer the range of contained primitives in this array. The primitives in this array are not initially in any particular order, and you will need to <em>rearrange the order</em> as you build the BVH so that your BVH can accurately represent the spacial hierarchy.</p> <p>The starter code constructs a valid BVH, but it is a trivial BVH with a single node containing all scene primitives. Once you are done with this task, you can check the box for BVH in the left bar under “Visualize” when you start render to visualize your BVH and see each levels.</p> <p>Finally, note that the BVH visualizer will start drawing from <code class="language-plaintext highlighter-rouge">BVH::root_idx</code>, so be sure to set this to the proper index (probably 0 or <code class="language-plaintext highlighter-rouge">nodes.size() - 1</code>, depending on your implementation) when you build the BVH.</p> <h2 id="step-0-bounding-box-calculation"> <a href="#step-0-bounding-box-calculation" class="anchor-heading" aria-labelledby="step-0-bounding-box-calculation"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Step 0: Bounding Box Calculation </h2> <p>Implement <code class="language-plaintext highlighter-rouge">BBox::hit</code> in <code class="language-plaintext highlighter-rouge">student/bbox.cpp</code>. Also if you haven’t already, implement <code class="language-plaintext highlighter-rouge">Triangle::bbox</code> in <code class="language-plaintext highlighter-rouge">student/tri_mesh.cpp</code> (<code class="language-plaintext highlighter-rouge">Triangle::bbox</code> should be fairly straightforward). We recommend checking out this <a href="https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-box-intersection">Scratchapixel article</a>.</p> <h2 id="step-1-bvh-construction"> <a href="#step-1-bvh-construction" class="anchor-heading" aria-labelledby="step-1-bvh-construction"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Step 1: BVH Construction </h2> <p>Your job is to construct a <code class="language-plaintext highlighter-rouge">BVH</code> using the <a href="http://15462.courses.cs.cmu.edu/fall2017/lecture/acceleratingqueries/slide_025">Surface Area Heuristic</a> discussed in class. Tree construction would occur when the BVH object is constructed. Below is the pseudocode by which your BVH construction procedure should generally follow (copied from lecture slides).</p> <center><img src="BVH_construction_pseudocode.png" /></center> <h2 id="step-2-ray-bvh-intersection"> <a href="#step-2-ray-bvh-intersection" class="anchor-heading" aria-labelledby="step-2-ray-bvh-intersection"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Step 2: Ray-BVH Intersection </h2> <p>Implement the ray-BVH intersection routine <code class="language-plaintext highlighter-rouge">Trace BVH&lt;Primitive&gt;::hit(const Ray&amp; ray)</code>. You may wish to consider the node visit order optimizations we discussed in class. Once complete, your renderer should be able to render all of the test scenes in a reasonable amount of time. <a href="visualization_of_normals.md">Visualization of normals</a> may help with debugging.</p> <center><img src="ray_bvh_pseudocode.png" /></center> <h2 id="visualization"> <a href="#visualization" class="anchor-heading" aria-labelledby="visualization"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Visualization </h2> <p>In Render mode, simply check the box for “BVH”, and you would be able to see the BVH you generated in task 3 when you <strong>start rendering</strong>. You can click on the horizontal bar to see each level of your BVH.</p> <center><img src="new_results/bvh_button.png" style="height:120px" /></center> <h2 id="sample-bvhs"> <a href="#sample-bvhs" class="anchor-heading" aria-labelledby="sample-bvhs"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Sample BVHs </h2> <p>The BVH constructed for Spot the Cow on the 10th level.</p> <center><img src="new_results/bvh.png" style="height:320px" /></center> <p>The BVH constructed for a scene composed of several cubes and spheres on the 0th and 1st levels.</p> <center><img src="new_results/l0.png" style="height:220px" /><img src="new_results/l2.png" style="height:220px" /></center> <p>The BVH constructed for the Stanford Bunny on the 10th level.</p> <center><img src="new_results/bvh_bunny_10.png" style="height:320px" /></center> </div> </div> <div class="search-overlay"></div> </div> </body> </html>