materials.html 20.3 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 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>