Commit fb20ee76 authored by allai5's avatar allai5
Browse files

add data and site info

parent 20d39ee3
<!DOCTYPE html> <html lang="en-US"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=Edge"> <title>(Task 7) Environment Lighting - </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 7) Environment Lighting</title> <meta name="generator" content="Jekyll v4.2.0" /> <meta property="og:title" content="(Task 7) Environment Lighting" /> <meta property="og:locale" content="en_US" /> <meta name="twitter:card" content="summary" /> <meta property="twitter:title" content="(Task 7) Environment Lighting" /> <script type="application/ld+json"> {"headline":"(Task 7) Environment Lighting","@type":"WebPage","url":"/pathtracer/environment_lighting","@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 "><a href="/pathtracer/bounding_volume_hierarchy" class="nav-list-link">(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 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/environment_lighting" class="nav-list-link active">(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 7) Environment Lighting</span></li> </ol> </nav> <div id="main-content" class="main-content" role="main"> <h1 id="task-7-environment-lighting"> <a href="#task-7-environment-lighting" class="anchor-heading" aria-labelledby="task-7-environment-lighting"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> (Task 7) Environment Lighting </h1> <p>The final task of this assignment will be to implement a new type of light source: an infinite environment light. An environment light is a light that supplies incident radiance (really, the light intensity dPhi/dOmega) from all directions on the sphere. Rather than using a predefined collection of explicit lights, an environment light is a capture of the actual incoming light from some real-world scene; rendering using environment lighting can be quite striking.</p> <p>The intensity of incoming light from each direction is defined by a texture map parameterized by phi and theta, as shown below.</p> <p><img src="envmap_figure.jpg" alt="envmap_figure" /></p> <p>In this task you need to implement the <code class="language-plaintext highlighter-rouge">Env_Map::sample</code> and <code class="language-plaintext highlighter-rouge">Env_Map::sample_direction</code> method in <code class="language-plaintext highlighter-rouge">student/env_light.cpp</code>. You’ll start with uniform direction sampling to get things working, and then move to a more advanced implementation that uses <strong>importance sampling</strong> to significantly reduce variance in rendered images.</p> <h2 id="step-1-uniform-sampling"> <a href="#step-1-uniform-sampling" class="anchor-heading" aria-labelledby="step-1-uniform-sampling"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Step 1: Uniform sampling </h2> <p>To get things working, your first implementation of <code class="language-plaintext highlighter-rouge">Env_Map::sample</code> will be quite simple. You should generate a random direction on the sphere (<strong>with uniform (1/4pi) probability with respect to solid angle</strong>), convert this direction to coordinates (phi, theta) and then look up the appropriate radiance value in the texture map using <strong>bilinear interpolation</strong> (note: we recommend you begin with bilinear interpolation to keep things simple.)</p> <p>Since high dynamic range environment maps can be large files, we have not included them in the starter code repo. You can download a set of environment maps from this <a href="http://15462.courses.cs.cmu.edu/fall2015content/misc/asst3_images/asst3_exr_archive.zip">link</a>. You can designate rendering to use a particular environment map from the GUI: go to <code class="language-plaintext highlighter-rouge">layout</code> -&gt; <code class="language-plaintext highlighter-rouge">new light</code> -&gt; <code class="language-plaintext highlighter-rouge">environment map</code>-&gt; <code class="language-plaintext highlighter-rouge">add</code>, and then select one of the environment maps that you have just downloaded.</p> <p><img src="envmap_gui.png" alt="envmap_gui" /></p> <p>For more HDRIs for creative environment maps, check out <a href="https://hdrihaven.com/">HDRIHAVEN</a></p> <p><strong>Tips:</strong></p> <ul> <li>You must write your own code to uniformly sample the sphere.</li> <li>check out the interface of <code class="language-plaintext highlighter-rouge">Env_Map</code> in <code class="language-plaintext highlighter-rouge">rays/env_light.h</code>. For <code class="language-plaintext highlighter-rouge">Env_Map</code>, the <code class="language-plaintext highlighter-rouge">image</code> field is the actual map being represented as a <code class="language-plaintext highlighter-rouge">HDR_Image</code>, which contains the pixels of the environment map and size of the environment texture. The interface for <code class="language-plaintext highlighter-rouge">HDR_Image</code> is in <code class="language-plaintext highlighter-rouge">util/hdr_image.h</code>.</li> </ul> <h2 id="step-2-importance-sampling-the-environment-map"> <a href="#step-2-importance-sampling-the-environment-map" class="anchor-heading" aria-labelledby="step-2-importance-sampling-the-environment-map"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Step 2: Importance sampling the environment map </h2> <p>Much like light in the real world, most of the energy provided by an environment light source is concentrated in the directions toward bright light sources. <strong>Therefore, it makes sense to bias selection of sampled directions towards the directions for which incoming radiance is the greatest.</strong> In this final task you will implement an importance sampling scheme for environment lights. For environment lights with large variation in incoming light intensities, good importance sampling will significantly improve the quality of renderings.</p> <p>The basic idea is that you will assign a probability to each pixel in the environment map based on the total flux passing through the solid angle it represents.</p> <p>A pixel with coordinate <img src="environment_eq1.png" width="45" /> subtends an area <img src="environment_eq2.png" width="80" /> on the unit sphere (where <img src="environment_eq3.png" width="20" /> and <img src="environment_eq4.png" width="20" /> the angles subtended by each pixel – as determined by the resolution of the texture). Thus, the flux through a pixel is proportional to <img src="environment_eq5.png" width="45" />. (We only care about the relative flux through each pixel to create a distribution.)</p> <p><strong>Summing the fluxes for all pixels, then normalizing the values so that they sum to one, yields a discrete probability distribution for picking a pixel based on flux through its corresponding solid angle on the sphere.</strong></p> <p>The question is now how to sample from this 2D discrete probability distribution. We recommend the following process which reduces the problem to drawing samples from two 1D distributions, each time using the inversion method discussed in class:</p> <ul> <li> <p>Given <img src="environment_eq6.png" width="45" /> the probability distribution for all pixels, compute the marginal probability distribution <img src="environment_eq7.png" width="100" /> for selecting a value from each row of pixels.</p> </li> <li> <p>Given for any pixel, compute the conditional probability <img src="environment_eq8.png" width="100" />.</p> </li> </ul> <p>Given the marginal distribution for <img src="environment_eq9.png" width="10" /> and the conditional distributions <img src="environment_eq10.png" width="45" /> for environment map rows, it is easy to select a pixel as follows:</p> <ol> <li>Use the inversion method to first select a “row” of the environment map according to <img src="environment_eq11.png" width="35" />.</li> <li>Given this row, use the inversion method to select a pixel in the row according to <img src="environment_eq12.png" width="45" />.</li> </ol> <p><strong>Here are a few tips:</strong></p> <ul> <li>When computing areas corresponding to a pixel, use the value of theta at the pixel centers.</li> <li>We recommend precomputing the joint distributions p(phi, theta) and marginal distributions p(theta) in the constructor of <code class="language-plaintext highlighter-rouge">Sampler::Sphere::Image</code> and storing the resulting values in fields <code class="language-plaintext highlighter-rouge">pdf</code>. See <code class="language-plaintext highlighter-rouge">rays/sampler.h</code>.</li> <li><code class="language-plaintext highlighter-rouge">Spectrum::luma()</code> returns the luminance (brightness) of a Spectrum. The probability of a pixel should be proportional to the product of its luminance and the solid angle it subtends.</li> <li><code class="language-plaintext highlighter-rouge">std::lower_bound</code> is your friend. Documentation is <a href="https://en.cppreference.com/w/cpp/algorithm/lower_bound">here</a>.</li> </ul> <h2 id="sample-results-for-importance-sampling"> <a href="#sample-results-for-importance-sampling" class="anchor-heading" aria-labelledby="sample-results-for-importance-sampling"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Sample results for importance sampling: </h2> <p>ennis.exr with 32 spp</p> <p><img src="new_results/ennis32importance.png" alt="ennis" /></p> <p>uffiz.exr with 32 spp</p> <p><img src="new_results/uffiz32importance.png" alt="uffiz" /></p> <p>field.exr with 1024 spp</p> <p><img src="new_results/field1024importance.png" alt="ennis" /></p> </div> </div> <div class="search-overlay"></div> </div> </body> </html>
<!DOCTYPE html> <html lang="en-US"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=Edge"> <title>Environment Light Importance Sampling - </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>Environment Light Importance Sampling</title> <meta name="generator" content="Jekyll v4.2.0" /> <meta property="og:title" content="Environment Light Importance Sampling" /> <meta property="og:locale" content="en_US" /> <meta name="twitter:card" content="summary" /> <meta property="twitter:title" content="Environment Light Importance Sampling" /> <script type="application/ld+json"> {"headline":"Environment Light Importance Sampling","@type":"WebPage","url":"/pathtracer/importance_sampling","@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 "><a href="/pathtracer/bounding_volume_hierarchy" class="nav-list-link">(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 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/environment_lighting" class="nav-list-link">(Task 7) Environment Lighting</a><ul class="nav-list"><li class="nav-list-item active"> <a href="/pathtracer/importance_sampling" class="nav-list-link active">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"><a href="/pathtracer/environment_lighting">(Task 7) Environment Lighting</a></li> <li class="breadcrumb-nav-list-item"><span>Environment Light Importance Sampling</span></li> </ol> </nav> <div id="main-content" class="main-content" role="main"> <h1 id="environment-light-importance-sampling"> <a href="#environment-light-importance-sampling" class="anchor-heading" aria-labelledby="environment-light-importance-sampling"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Environment Light Importance Sampling </h1> <p>A pixel with coordinate <img src="environment_eq1.png" style="height:18px" /> subtends an area <img src="environment_eq2.png" style="height:18px" /> on the unit sphere (where <img src="environment_eq3.png" style="height:16px" /> and <img src="environment_eq4.png" style="height:18px" /> the angles subtended by each pixel – as determined by the resolution of the texture). Thus, the flux through a pixel is proportional to <img src="environment_eq5.png" style="height:14px" />. (We only care about the relative flux through each pixel to create a distribution.)</p> <p><strong>Summing the fluxes for all pixels, then normalizing the values so that they sum to one, yields a discrete probability distribution for picking a pixel based on flux through its corresponding solid angle on the sphere.</strong></p> <p>The question is now how to sample from this 2D discrete probability distribution. We recommend the following process which reduces the problem to drawing samples from two 1D distributions, each time using the inversion method discussed in class:</p> <ul> <li> <p>Given <img src="environment_eq6.png" style="height:18px" /> the probability distribution for all pixels, compute the marginal probability distribution <img src="environment_eq7.png" style="height:32px" /> for selecting a value from each row of pixels.</p> </li> <li> <p>Given for any pixel, compute the conditional probability <img src="environment_eq8.png" style="height:40px" />.</p> </li> </ul> <p>Given the marginal distribution for <img src="environment_eq9.png" style="height:14px" /> and the conditional distributions <img src="environment_eq10.png" style="height:18px" /> for environment map rows, it is easy to select a pixel as follows:</p> <ol> <li>Use the inversion method to first select a “row” of the environment map according to <img src="environment_eq11.png" style="height:18px" />.</li> <li>Given this row, use the inversion method to select a pixel in the row according to <img src="environment_eq12.png" style="height:18px" />.</li> </ol> </div> </div> <div class="search-overlay"></div> </div> </body> </html>
<!DOCTYPE html> <html lang="en-US"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=Edge"> <title>A3: Pathtracer - </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>A3: Pathtracer</title> <meta name="generator" content="Jekyll v4.2.0" /> <meta property="og:title" content="A3: Pathtracer" /> <meta property="og:locale" content="en_US" /> <meta name="twitter:card" content="summary" /> <meta property="twitter:title" content="A3: Pathtracer" /> <script type="application/ld+json"> {"headline":"A3: Pathtracer","@type":"WebPage","url":"/pathtracer/","@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 active">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 "><a href="/pathtracer/bounding_volume_hierarchy" class="nav-list-link">(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"> <div id="main-content" class="main-content" role="main"> <h1 id="pathtracer-overview"> <a href="#pathtracer-overview" class="anchor-heading" aria-labelledby="pathtracer-overview"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> PathTracer Overview </h1> <p>PathTracer is (as the name suggests) a simple path tracer that can render scenes with global illumination. The first part of the assignment will focus on providing an efficient implementation of <strong>ray-scene geometry queries</strong>. In the second half of the assignment you will <strong>add the ability to simulate how light bounces around the scene</strong>, which will allow your renderer to synthesize much higher-quality images. Much like in MeshEdit, input scenes are defined in COLLADA files, so you can create your own scenes to render using Scotty3D or other free software like <a href="https://www.blender.org/">Blender</a>.</p> <center><img src="raytracing_diagram.png" style="height:240px" /></center> <p>Implementing the functionality of PathTracer is split in to 7 tasks, and here are the instructions for each of them:</p> <ul> <li><a href="camera_rays">(Task 1) Generating Camera Rays</a></li> <li><a href="intersecting_objects">(Task 2) Intersecting Objects</a></li> <li><a href="bounding_volume_hierarchy">(Task 3) Bounding Volume Hierarchy</a></li> <li><a href="shadow_rays">(Task 4) Shadow Rays</a></li> <li><a href="path_tracing">(Task 5) Path Tracing</a></li> <li><a href="materials">(Task 6) Materials</a></li> <li><a href="environment_lighting">(Task 7) Environment Lighting</a></li> </ul> <p>The files that you will work with for PathTracer are all under <code class="language-plaintext highlighter-rouge">src/student</code> directory. Some of the particularly important ones are outlined below. Methods that we expect you to implement are marked with “TODO (PathTracer)”, which you may search for.</p> <p>You are also provided with some very useful debugging tool in <code class="language-plaintext highlighter-rouge">src/student/debug.h</code> and <code class="language-plaintext highlighter-rouge">src/student/debug.cpp</code>. Please read the comments in those two files to learn how to use them effectively.</p> <div class="table-wrapper"><table> <thead> <tr> <th>File(s)</th> <th>Purpose</th> <th>Need to modify?</th> </tr> </thead> <tbody> <tr> <td><code class="language-plaintext highlighter-rouge">student/pathtracer.cpp</code></td> <td>This is the main workhorse class. Inside the ray tracer class everything begins with the method <code class="language-plaintext highlighter-rouge">Pathtracer::trace_pixel</code> in pathtracer.cpp. This method computes the value of the specified pixel in the output image.</td> <td>Yes</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">student/camera.cpp</code></td> <td>You will need to modify <code class="language-plaintext highlighter-rouge">Camera::generate_ray</code> in Part 1 of the assignment to generate the camera rays that are sent out into the scene.</td> <td>Yes</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">student/tri_mesh.cpp</code>, <code class="language-plaintext highlighter-rouge">student/shapes.cpp</code></td> <td>Scene objects (e.g., triangles and spheres) are instances of the <code class="language-plaintext highlighter-rouge">Object</code> class interface defined in <code class="language-plaintext highlighter-rouge">rays/object.h</code>. You will need to implement the <code class="language-plaintext highlighter-rouge">bbox</code> and intersect routine <code class="language-plaintext highlighter-rouge">hit</code> for both triangles and spheres.</td> <td>Yes</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">student/bvh.inl</code></td> <td>A major portion of the first half of the assignment concerns implementing a bounding volume hierarchy (BVH) that accelerates ray-scene intersection queries. Note that a BVH is also an instance of the Object interface (A BVH is a scene object that itself contains other primitives.)</td> <td>Yes</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">rays/light.h</code></td> <td>Describes lights in the scene. The initial starter code has working implementations of directional lights and constant hemispherical lights.</td> <td>No</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">lib/spectrum.h</code></td> <td>Light energy is represented by instances of the Spectrum class. While it’s tempting, we encourage you to avoid thinking of spectrums as colors – think of them as a measurement of energy over many wavelengths. Although our current implementation only represents spectrums by red, green, and blue components (much like the RGB representations of color you’ve used previously in this class), this abstraction makes it possible to consider other implementations of spectrum in the future. Spectrums can be converted into a vector using the <code class="language-plaintext highlighter-rouge">Spectrum::to_vec</code> method.</td> <td>No</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">student/bsdf.cpp</code></td> <td>Contains implementations of several BSDFs (diffuse, mirror, glass). For each, you will define the distribution of the BSDF and write a method to sample from that distribution.</td> <td>Yes</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">student/samplers.cpp</code></td> <td>When implementing raytracing and environment light, we often want to sample randomly from a hemisphere, uniform grid, or shphere. This file contains various functions that simulate such random sampling.</td> <td>Yes</td> </tr> </tbody> </table></div> </div> </div> <div class="search-overlay"></div> </div> </body> </html>
<!DOCTYPE html> <html lang="en-US"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=Edge"> <title>(Task 2) Intersections - </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 2) Intersections</title> <meta name="generator" content="Jekyll v4.2.0" /> <meta property="og:title" content="(Task 2) Intersections" /> <meta property="og:locale" content="en_US" /> <meta name="twitter:card" content="summary" /> <meta property="twitter:title" content="(Task 2) Intersections" /> <script type="application/ld+json"> {"headline":"(Task 2) Intersections","@type":"WebPage","url":"/pathtracer/intersecting_objects","@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 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/intersecting_objects" class="nav-list-link active">(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 "><a href="/pathtracer/bounding_volume_hierarchy" class="nav-list-link">(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 2) Intersections</span></li> </ol> </nav> <div id="main-content" class="main-content" role="main"> <h1 id="task-2-intersecting-objects"> <a href="#task-2-intersecting-objects" class="anchor-heading" aria-labelledby="task-2-intersecting-objects"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> (Task 2) Intersecting Objects </h1> <p>Now that your ray tracer generates camera rays, we need to be able to answer the core query in ray tracing: “does this ray hit this object?” Here, you will start by implementing ray-object intersection routines against the two types of objects in the starter code: triangles and spheres. Later, we will use a BVH to accelerate these queries, but for now we consider an intersection test against a single object.</p> <p>First, take a look at the <code class="language-plaintext highlighter-rouge">rays/object.h</code> for the interface of <code class="language-plaintext highlighter-rouge">Object</code> class. An <code class="language-plaintext highlighter-rouge">Object</code> can be <strong>either</strong> a <code class="language-plaintext highlighter-rouge">Tri_Mesh</code>, a <code class="language-plaintext highlighter-rouge">Shape</code>, a BVH(which you will implement in Task 3), or a list of <code class="language-plaintext highlighter-rouge">Objects</code>. Right now, we are only dealing with <code class="language-plaintext highlighter-rouge">Tri_Mesh</code>’s case and <code class="language-plaintext highlighter-rouge">Shape</code>’s case, and their interfaces are in <code class="language-plaintext highlighter-rouge">rays/tri_mesh.h</code> and <code class="language-plaintext highlighter-rouge">rays/shapes.h</code>, respectively. <code class="language-plaintext highlighter-rouge">Tri_Mesh</code> contains a BVH of <code class="language-plaintext highlighter-rouge">Triangle</code>, and in this task you will be working with the <code class="language-plaintext highlighter-rouge">Triangle</code> class. For <code class="language-plaintext highlighter-rouge">Shape</code>, you are going to work with <code class="language-plaintext highlighter-rouge">Sphere</code>s, which is the major type of <code class="language-plaintext highlighter-rouge">Shape</code> in Scotty 3D.</p> <p>Now, you need to implement the <code class="language-plaintext highlighter-rouge">hit</code> routine for both <code class="language-plaintext highlighter-rouge">Triangle</code> and <code class="language-plaintext highlighter-rouge">Sphere</code>. <code class="language-plaintext highlighter-rouge">hit</code> takes in a ray, and returns a <code class="language-plaintext highlighter-rouge">Trace</code> structure, which contains information on whether the ray hits the object and if hits, the information describing the surface at the point of the hit. See <code class="language-plaintext highlighter-rouge">rays/trace.h</code> for the definition of <code class="language-plaintext highlighter-rouge">Trace</code>.</p> <p>In order to correctly implement <code class="language-plaintext highlighter-rouge">hit</code> you need to understand some of the fields in the Ray structure defined in <code class="language-plaintext highlighter-rouge">lib/ray.h</code>.</p> <ul> <li><code class="language-plaintext highlighter-rouge">point</code>: represents the 3D point of origin of the ray</li> <li><code class="language-plaintext highlighter-rouge">dir</code>: represents the 3D direction of the ray (this direction will be normalized)</li> <li><code class="language-plaintext highlighter-rouge">time_bounds</code>: correspond to the minimum and maximum points on the ray with its x-component as the lower bound and y-component as the upper bound. That is, intersections that lie outside the [<code class="language-plaintext highlighter-rouge">ray.time_bounds.x</code>, <code class="language-plaintext highlighter-rouge">ray.time_bounds.y</code>] range should not be considered valid intersections with the primitive.</li> </ul> <p>One important detail of the Ray structure is that <code class="language-plaintext highlighter-rouge">time_bounds</code> is a mutable field of the Ray. This means that this fields can be modified by constant member functions such as <code class="language-plaintext highlighter-rouge">Triangle::hit</code>. When finding the first intersection of a ray and the scene, you almost certainly want to update the ray’s <code class="language-plaintext highlighter-rouge">time_bounds</code> value after finding each hit with scene geometry. By bounding the ray as tightly as possible, your ray tracer will be able to avoid unnecessary tests with scene geometry that is known to not be able to result in a closest hit, resulting in higher performance.</p><hr /> <h3 id="step-1-intersecting-triangles"> <a href="#step-1-intersecting-triangles" class="anchor-heading" aria-labelledby="step-1-intersecting-triangles"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> <strong>Step 1: Intersecting Triangles</strong> </h3> <p>The first intersect routine that the <code class="language-plaintext highlighter-rouge">hit</code> routines for the triangle mesh in <code class="language-plaintext highlighter-rouge">student/tri_mesh.cpp</code>.</p> <p>While faster implementations are possible, we recommend you implement ray-triangle intersection using the method described in the <a href="http://15462.courses.cs.cmu.edu/fall2017/lecture/acceleratingqueries">lecture slides</a>. Further details of implementing this method efficiently are given in <a href="ray_triangle_intersection.md">these notes</a>.</p> <p>There are two important details you should be aware of about intersection:</p> <ul> <li> <p>When finding the first-hit intersection with a triangle, you need to fill in the <code class="language-plaintext highlighter-rouge">Trace</code> structure with details of the hit. The structure should be initialized with:</p> <ul> <li><code class="language-plaintext highlighter-rouge">hit</code>: a boolean representing if there is a hit or not</li> <li><code class="language-plaintext highlighter-rouge">time</code>: the ray’s <em>t</em>-value of the hit point</li> <li><code class="language-plaintext highlighter-rouge">position</code>: the exact position of the hit point. This can be easily computed by the <code class="language-plaintext highlighter-rouge">time</code> above as with the ray’s <code class="language-plaintext highlighter-rouge">point</code> and <code class="language-plaintext highlighter-rouge">dir</code>.</li> <li><code class="language-plaintext highlighter-rouge">normal</code>: the normal of the surface at the hit point. This normal should be the interpolated normal (obtained via interpolation of the per-vertex normals according to the barycentric coordinates of the hit point)</li> </ul> </li> </ul> <!-- * When intersection occurs with the back-face of a triangle (the side of the triangle opposite the direction of the normal) you should flip the returned normal to point in that direction. That is, always return a normal pointing in the direction the ray came from! --> <p>Once you’ve successfully implemented triangle intersection, you will be able to render many of the scenes in the media directory. However, your ray tracer will be very slow!</p> <p>While you are working with <code class="language-plaintext highlighter-rouge">student/tri_mesh.cpp</code>, you should implement <code class="language-plaintext highlighter-rouge">Triangle::bbox</code> as well, which are important for task 3.</p> <h3 id="step-2-intersecting-spheres"> <a href="#step-2-intersecting-spheres" class="anchor-heading" aria-labelledby="step-2-intersecting-spheres"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> <strong>Step 2: Intersecting Spheres</strong> </h3> <p>You also need to implement the <code class="language-plaintext highlighter-rouge">hit</code> routines for the <code class="language-plaintext highlighter-rouge">Sphere</code> class in <code class="language-plaintext highlighter-rouge">student/sphapes.cpp</code>. Remember that your intersection tests should respect the ray’s <code class="language-plaintext highlighter-rouge">time_bound</code>. Because spheres always represent closed surfaces, you should not flip back-facing normals you did with triangles.</p> <p>Note: take care <strong>not</strong> to use the <code class="language-plaintext highlighter-rouge">Vec3::normalize()</code> method when computing your normal vector. You should instead use <code class="language-plaintext highlighter-rouge">Vec3::unit()</code>, since <code class="language-plaintext highlighter-rouge">Vec3::normalize()</code> will actually change the <code class="language-plaintext highlighter-rouge">Vec3</code> object passed in rather than returning a normalized version.</p><hr /> <p><a href="visualization_of_normals.md">Visualization of normals</a> might be very helpful with debugging.</p> </div> </div> <div class="search-overlay"></div> </div> </body> </html>
<!DOCTYPE html> <html lang="en-US"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=Edge"> <title>(Task 6) Materials - </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 6) Materials</title> <meta name="generator" content="Jekyll v4.2.0" /> <meta property="og:title" content="(Task 6) Materials" /> <meta property="og:locale" content="en_US" /> <meta name="twitter:card" content="summary" /> <meta property="twitter:title" content="(Task 6) Materials" /> <script type="application/ld+json"> {"headline":"(Task 6) Materials","@type":"WebPage","url":"/pathtracer/materials","@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 "><a href="/pathtracer/bounding_volume_hierarchy" class="nav-list-link">(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 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/materials" class="nav-list-link active">(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 6) Materials</span></li> </ol> </nav> <div id="main-content" class="main-content" role="main"> <h1 id="task-6-materials"> <a href="#task-6-materials" class="anchor-heading" aria-labelledby="task-6-materials"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> (Task 6) Materials </h1> <center><img src="bsdf_diagrams.png" style="height:200px" /></center> <p>Now that you have implemented the ability to sample more complex light paths, it’s finally time to add support for more types of materials (other than the fully Lambertian material that you have implemented in Task 5). In this task you will add support for two types of materials: a perfect mirror and glass (a material featuring both specular reflection and transmittance) in <code class="language-plaintext highlighter-rouge">student/bsdf.cpp</code>.</p> <p>To get started take a look at the BSDF interface in <code class="language-plaintext highlighter-rouge">rays/bsdf.h</code>. There are a number of key methods you should understand in <code class="language-plaintext highlighter-rouge">BSDF class</code>:</p> <ul> <li><code class="language-plaintext highlighter-rouge">Spectrum evaluate(Vec3 out_dir, Vec3 in_dir)</code>: evaluates the distribution function for a given pair of directions.</li> <li><code class="language-plaintext highlighter-rouge">BSDF_Sample sample(Vec3 out_dir)</code>: given the <code class="language-plaintext highlighter-rouge">out_dir</code>, generates a random sample of the in-direction (which may be a reflection direction or a refracted transmitted light direction). It returns a <code class="language-plaintext highlighter-rouge">BSDF_Sample</code>, which contains the in-direction(<code class="language-plaintext highlighter-rouge">direction</code>), its probability (<code class="language-plaintext highlighter-rouge">pdf</code>), as well as the <code class="language-plaintext highlighter-rouge">attenuation</code> for this pair of directions. (You do not need to worry about the <code class="language-plaintext highlighter-rouge">emissive</code> for the materials that we are asking you to implement, since those materials do not emit light.)</li> </ul> <p>There are also two helper functions in the BSDF class in <code class="language-plaintext highlighter-rouge">student/bsdf.cpp</code> that you will need to implement:</p> <ul> <li> <p><code class="language-plaintext highlighter-rouge">Vec3 reflect(Vec3 dir)</code> returns a direction that is the <strong>perfect specular reflection</strong> direction corresponding to <code class="language-plaintext highlighter-rouge">dir</code> (reflection of <code class="language-plaintext highlighter-rouge">dir</code> about the normal, which in the surface coordinate space is [0,1,0]). More detail about specular reflection is <a href="http://15462.courses.cs.cmu.edu/fall2015/lecture/reflection/slide_028">here</a>.</p> </li> <li> <p><code class="language-plaintext highlighter-rouge">Vec3 refract(Vec3 out_dir, float index_of_refraction, bool&amp; was_internal)</code> returns the ray that results from refracting the ray in <code class="language-plaintext highlighter-rouge">out_dir</code> about the surface according to <a href="http://15462.courses.cs.cmu.edu/fall2015/lecture/reflection/slide_032">Snell’s Law</a>. The surface’s index of refraction is given by the argument <code class="language-plaintext highlighter-rouge">index_of_refraction</code>. Your implementation should assume that if the ray in <code class="language-plaintext highlighter-rouge">out_dir</code> <strong>is entering the surface</strong> (that is, if <code class="language-plaintext highlighter-rouge">cos(out_dir, N=[0,1,0]) &gt; 0</code>) then the ray is currently in vacuum (index of refraction = 1.0). If <code class="language-plaintext highlighter-rouge">cos(out_dir, N=[0,1,0]) &lt; 0</code> then your code should assume the ray is leaving the surface and entering vacuum. <strong>In the case of total internal reflection, you should set <code class="language-plaintext highlighter-rouge">*was_internal</code> to <code class="language-plaintext highlighter-rouge">true</code>.</strong></p> </li> <li> <p>Note that in <code class="language-plaintext highlighter-rouge">reflect</code> and <code class="language-plaintext highlighter-rouge">refract</code>, both the <code class="language-plaintext highlighter-rouge">out_dir</code> and the returned in-direction are pointing away from the intersection point of the ray and the surface, as illustrated in this picture below.</p> </li> </ul> <center><img src="rays_dir.png" style="height:420px" /></center> <h2 id="step-1"> <a href="#step-1" class="anchor-heading" aria-labelledby="step-1"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Step 1 </h2> <p>Implement the class <code class="language-plaintext highlighter-rouge">BSDF_Mirror</code> which represents a material with perfect specular reflection (a perfect mirror). You should Implement <code class="language-plaintext highlighter-rouge">BSDF_Mirror::sample</code>, <code class="language-plaintext highlighter-rouge">BSDF_Mirror::evaluate</code>, and <code class="language-plaintext highlighter-rouge">reflect</code>. <strong>(Hint: what should the pdf sampled by <code class="language-plaintext highlighter-rouge">BSDF_Mirror::sample</code> be? What should the reflectance function <code class="language-plaintext highlighter-rouge">BSDF_Mirror::evalute</code> be?)</strong></p> <h2 id="step-2"> <a href="#step-2" class="anchor-heading" aria-labelledby="step-2"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Step 2 </h2> <p>Implement the class <code class="language-plaintext highlighter-rouge">BSDF_Glass</code> which is a glass-like material that both reflects light and transmit light. As discussed in class the fraction of light that is reflected and transmitted through glass is given by the dielectric Fresnel equations.</p> <p>Specifically your implementation should:</p> <ul> <li>Implement <code class="language-plaintext highlighter-rouge">refract</code> to add support for refracted ray paths.</li> <li>Implement <code class="language-plaintext highlighter-rouge">BSDF_refract::sample</code> as well as <code class="language-plaintext highlighter-rouge">BSDF_Glass::sample</code>. Your implementation should use the Fresnel equations to compute the fraction of reflected light and the fraction of transmitted light. The returned ray sample should be either a reflection ray or a refracted ray, with the probability of which type of ray to use for the current path proportional to the Fresnel reflectance. (e.g., If the Fresnel reflectance is 0.9, then you should generate a reflection ray 90% of the time. What should the pdf be in this case?) Note that you can also use <a href="https://en.wikipedia.org/wiki/Schlick's_approximation">Schlick’s approximation</a> instead.</li> <li>You should read the notes below on the Fresnel equations as well as on how to compute a transmittance BSDF.</li> </ul> <h3 id="dielectrics-and-transmission"> <a href="#dielectrics-and-transmission" class="anchor-heading" aria-labelledby="dielectrics-and-transmission"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Dielectrics and Transmission </h3> <h3 id="fresnel-equations-for-dielectric"> <a href="#fresnel-equations-for-dielectric" class="anchor-heading" aria-labelledby="fresnel-equations-for-dielectric"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Fresnel Equations for Dielectric </h3> <p>The <a href="https://en.wikipedia.org/wiki/Fresnel_equations">Fresnel Equations</a> (another <a href="http://hyperphysics.phy-astr.gsu.edu/hbase/phyopt/freseq.html">link</a> here) describe the amount of reflection from a surface. The description below is an approximation for dielectric materials (materials that don’t conduct electricity). In this assignment you’re asked to implement a glass material, which is a dielectric.</p> <p>In the description below, <img src="dielectric_eq1.png" width="18" /> and <img src="dielectric_eq2.png" width="15" /> refer to the index of refraction of the medium containing an incoming ray, and the zenith angle of the ray to the surface of a new medium. <img src="dielectric_eq3.png" width="18" /> and <img src="dielectric_eq4.png" width="15" /> refer to the index of refraction of the new medium and the angle to the surface normal of a transmitted ray.</p> <p>The Fresnel equations state that reflection from a surface is a function of the surface’s index of refraction, as well as the polarity of the incoming light. Since our renderer doesn’t account for polarity, we’ll apply a common approximation of averaging the reflectance of polarizes light in perpendicular and parallel polarized light:</p> <p><img src="dielectric_eq5.png" width="200" /></p> <p>The parallel and perpendicular terms are given by:</p> <p><img src="dielectric_eq6.png" width="200" /></p> <p><img src="dielectric_eq7.png" width="200" /></p> <p>Therefore, for a dielectric material, the fraction of reflected light will be given by <img src="dielectric_eq8.png" width="18" />, and the amount of transmitted light will be given by <img src="dielectric_eq9.png" width="50" />.</p> <p>Alternatively, you may compute <img src="dielectric_eq8.png" width="18" /> using <a href="https://en.wikipedia.org/wiki/Schlick%27s_approximation">Schlick’s approximation</a>.</p> <h3 id="distribution-function-for-transmitted-light"> <a href="#distribution-function-for-transmitted-light" class="anchor-heading" aria-labelledby="distribution-function-for-transmitted-light"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Distribution Function for Transmitted Light </h3> <p>We described the BRDF for perfect specular reflection in class, however we did not discuss the distribution function for transmitted light. Since refraction “spreads” or “condenses” a beam, unlike perfect reflection, the radiance along the ray changes due to a refraction event. In your assignment you should use Snell’s Law to compute the direction of refraction rays, and use the following distribution function to compute the radiance of transmitted rays. We refer you guys to Pharr, Jakob, and and Humphries’s book <a href="http://www.pbr-book.org/">Physically Based Rendering</a> for a derivation based on Snell’s Law and the relation <img src="dielectric_eq10.png" width="150" />. (But you are more than welcome to attempt a derivation on your own!)</p> <p>When you are done, you will be able to render images like these:</p> <center><img src="new_results/32k_large.png" /></center> </div> </div> <div class="search-overlay"></div> </div> </body> </html>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment