<!DOCTYPE html><htmllang="en-US"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=Edge"><title>(Task 6) Materials - </title><linkrel="shortcut icon"href="/favicon.ico"type="image/x-icon"><linkrel="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><metaname="viewport"content="width=device-width, initial-scale=1"><!-- Begin Jekyll SEO tag v2.7.1 --><title>(Task 6) Materials</title><metaname="generator"content="Jekyll v4.2.0"/><metaproperty="og:title"content="(Task 6) Materials"/><metaproperty="og:locale"content="en_US"/><metaname="twitter:card"content="summary"/><metaproperty="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><svgxmlns="http://www.w3.org/2000/svg"style="display: none;"><symbolid="svg-link"viewBox="0 0 24 24"><title>Link</title><svgxmlns="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"><pathd="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><pathd="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><symbolid="svg-search"viewBox="0 0 24 24"><title>Search</title><svgxmlns="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"><circlecx="11"cy="11"r="8"></circle><linex1="21"y1="21"x2="16.65"y2="16.65"></line></svg></symbol><symbolid="svg-menu"viewBox="0 0 24 24"><title>Menu</title><svgxmlns="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"><linex1="3"y1="12"x2="21"y2="12"></line><linex1="3"y1="6"x2="21"y2="6"></line><linex1="3"y1="18"x2="21"y2="18"></line></svg></symbol><symbolid="svg-arrow-right"viewBox="0 0 24 24"><title>Expand</title><svgxmlns="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"><polylinepoints="9 18 15 12 9 6"></polyline></svg></symbol><symbolid="svg-doc"viewBox="0 0 24 24"><title>Document</title><svgxmlns="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"><pathd="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"></path><polylinepoints="13 2 13 9 20 9"></polyline></svg></symbol></svg><divclass="side-bar"><divclass="site-header"><ahref="/"class="site-title lh-tight"></a><ahref="#"id="menu-button"class="site-button"><svgviewBox="0 0 24 24"class="icon"><usexlink:href="#svg-menu"></use></svg></a></div><navrole="navigation"aria-label="Main"id="site-nav"class="site-nav"><ulclass="nav-list"><liclass="nav-list-item"><ahref="/"class="nav-list-link">Home</a></li><liclass="nav-list-item"><ahref="/git/"class="nav-list-link">GitHub Setup</a></li><liclass="nav-list-item"><ahref="/build/"class="nav-list-link">Building Scotty3D</a></li><liclass="nav-list-item"><ahref="#"class="nav-list-expander"><svgviewBox="0 0 24 24"><usexlink:href="#svg-arrow-right"></use></svg></a><ahref="/guide/"class="nav-list-link">User Guide</a><ulclass="nav-list "><liclass="nav-list-item "><ahref="/guide/animate_mode/"class="nav-list-link">Animate</a></li><liclass="nav-list-item "><ahref="/guide/layout_mode/"class="nav-list-link">Layout</a></li><liclass="nav-list-item "><ahref="/guide/model_mode/"class="nav-list-link">Model</a></li><liclass="nav-list-item "><ahref="/guide/render_mode/"class="nav-list-link">Render</a></li><liclass="nav-list-item "><ahref="/guide/rigging_mode/"class="nav-list-link">Rig</a></li><liclass="nav-list-item "><ahref="/guide/simulate_mode/"class="nav-list-link">Simulate</a></li></ul></li><liclass="nav-list-item"><ahref="#"class="nav-list-expander"><svgviewBox="0 0 24 24"><usexlink:href="#svg-arrow-right"></use></svg></a><ahref="/meshedit/"class="nav-list-link">A2: MeshEdit</a><ulclass="nav-list "><liclass="nav-list-item "><ahref="/meshedit/halfedge"class="nav-list-link">Halfedge Mesh</a></li><liclass="nav-list-item "><ahref="#"class="nav-list-expander"><svgviewBox="0 0 24 24"><usexlink:href="#svg-arrow-right"></use></svg></a><ahref="/meshedit/local/"class="nav-list-link">Local Operations</a><ulclass="nav-list"><liclass="nav-list-item "><ahref="/meshedit/local/edge_flip"class="nav-list-link">Edge Flip Tutorial</a></li><liclass="nav-list-item "><ahref="/meshedit/local/bevel/"class="nav-list-link">Bevelling</a></li></ul></li><liclass="nav-list-item "><ahref="#"class="nav-list-expander"><svgviewBox="0 0 24 24"><usexlink:href="#svg-arrow-right"></use></svg></a><ahref="/meshedit/global/"class="nav-list-link">Global Operations</a><ulclass="nav-list"><liclass="nav-list-item "><ahref="/meshedit/global/catmull/"class="nav-list-link">Catmull-Clark Subdivision</a></li><liclass="nav-list-item "><ahref="/meshedit/global/remesh/"class="nav-list-link">Isotropic Remeshing</a></li><liclass="nav-list-item "><ahref="/meshedit/global/linear/"class="nav-list-link">Linear Subdivision</a></li><liclass="nav-list-item "><ahref="/meshedit/global/loop/"class="nav-list-link">Loop Subdivision</a></li><liclass="nav-list-item "><ahref="/meshedit/global/simplify/"class="nav-list-link">Simplification</a></li><liclass="nav-list-item "><ahref="/meshedit/global/triangulate/"class="nav-list-link">Triangulation</a></li></ul></li></ul></li><liclass="nav-list-item active"><ahref="#"class="nav-list-expander"><svgviewBox="0 0 24 24"><usexlink:href="#svg-arrow-right"></use></svg></a><ahref="/pathtracer/"class="nav-list-link">A3: Pathtracer</a><ulclass="nav-list "><liclass="nav-list-item "><ahref="/pathtracer/camera_rays"class="nav-list-link">(Task 1) Camera Rays</a></li><liclass="nav-list-item "><ahref="#"class="nav-list-expander"><svgviewBox="0 0 24 24"><usexlink:href="#svg-arrow-right"></use></svg></a><ahref="/pathtracer/intersecting_objects"class="nav-list-link">(Task 2) Intersections</a><ulclass="nav-list"><liclass="nav-list-item "><ahref="/pathtracer/ray_triangle_intersection"class="nav-list-link">Ray Triangle Intersection</a></li><liclass="nav-list-item "><ahref="/pathtracer/ray_sphere_intersection"class="nav-list-link">Ray Sphere Intersection</a></li></ul></li><liclass="nav-list-item "><ahref="/pathtracer/bounding_volume_hierarchy"class="nav-list-link">(Task 3) BVH</a></li><liclass="nav-list-item "><ahref="/pathtracer/shadow_rays"class="nav-list-link">(Task 4) Shadow Rays</a></li><liclass="nav-list-item "><ahref="/pathtracer/path_tracing"class="nav-list-link">(Task 5) Path Tracing</a></li><liclass="nav-list-item active"><ahref="#"class="nav-list-expander"><svgviewBox="0 0 24 24"><usexlink:href="#svg-arrow-right"></use></svg></a><ahref="/pathtracer/materials"class="nav-list-link active">(Task 6) Materials</a><ulclass="nav-list"><liclass="nav-list-item "><ahref="/pathtracer/dielectrics_and_transmission"class="nav-list-link">Dielectrics and Transmission</a></li></ul></li><liclass="nav-list-item "><ahref="#"class="nav-list-expander"><svgviewBox="0 0 24 24"><usexlink:href="#svg-arrow-right"></use></svg></a><ahref="/pathtracer/environment_lighting"class="nav-list-link">(Task 7) Environment Lighting</a><ulclass="nav-list"><liclass="nav-list-item "><ahref="/pathtracer/importance_sampling"class="nav-list-link">Environment Light Importance Sampling</a></li></ul></li><liclass="nav-list-item "><ahref="/pathtracer/visualization_of_normals"class="nav-list-link">Visualization of normals</a></li></ul></li><liclass="nav-list-item"><ahref="#"class="nav-list-expander"><svgviewBox="0 0 24 24"><usexlink:href="#svg-arrow-right"></use></svg></a><ahref="/animation/"class="nav-list-link">A4: Animation</a><ulclass="nav-list "><liclass="nav-list-item "><ahref="/animation/splines"class="nav-list-link">Splines</a></li><liclass="nav-list-item "><ahref="/animation/skeleton_kinematics"class="nav-list-link">Skeleton Kinematics</a></li><liclass="nav-list-item "><ahref="/animation/skinning"class="nav-list-link">Skinning</a></li><liclass="nav-list-item "><ahref="/animation/particles"class="nav-list-link">Particles</a></li></ul></li></ul></nav><footerclass="site-footer"> This site uses <ahref="https://github.com/pmarsceill/just-the-docs">Just the Docs</a>, a documentation theme for Jekyll. </footer></div><divclass="main"id="top"><divid="main-header"class="main-header"><divclass="search"><divclass="search-input-wrap"><inputtype="text"id="search-input"class="search-input"tabindex="0"placeholder="Search "aria-label="Search "autocomplete="off"><labelfor="search-input"class="search-label"><svgviewBox="0 0 24 24"class="search-icon"><usexlink:href="#svg-search"></use></svg></label></div><divid="search-results"class="search-results"></div></div></div><divid="main-content-wrap"class="main-content-wrap"><navaria-label="Breadcrumb"class="breadcrumb-nav"><olclass="breadcrumb-nav-list"><liclass="breadcrumb-nav-list-item"><ahref="/pathtracer/">A3: Pathtracer</a></li><liclass="breadcrumb-nav-list-item"><span>(Task 6) Materials</span></li></ol></nav><divid="main-content"class="main-content"role="main"><h1id="task-6-materials"><ahref="#task-6-materials"class="anchor-heading"aria-labelledby="task-6-materials"><svgviewBox="0 0 16 16"aria-hidden="true"><usexlink:href="#svg-link"></use></svg></a> (Task 6) Materials </h1><center><imgsrc="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 <codeclass="language-plaintext highlighter-rouge">student/bsdf.cpp</code>.</p><p>To get started take a look at the BSDF interface in <codeclass="language-plaintext highlighter-rouge">rays/bsdf.h</code>. There are a number of key methods you should understand in <codeclass="language-plaintext highlighter-rouge">BSDF class</code>:</p><ul><li><codeclass="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><codeclass="language-plaintext highlighter-rouge">BSDF_Sample sample(Vec3 out_dir)</code>: given the <codeclass="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 <codeclass="language-plaintext highlighter-rouge">BSDF_Sample</code>, which contains the in-direction(<codeclass="language-plaintext highlighter-rouge">direction</code>), its probability (<codeclass="language-plaintext highlighter-rouge">pdf</code>), as well as the <codeclass="language-plaintext highlighter-rouge">attenuation</code> for this pair of directions. (You do not need to worry about the <codeclass="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 <codeclass="language-plaintext highlighter-rouge">student/bsdf.cpp</code> that you will need to implement:</p><ul><li><p><codeclass="language-plaintext highlighter-rouge">Vec3 reflect(Vec3 dir)</code> returns a direction that is the <strong>perfect specular reflection</strong> direction corresponding to <codeclass="language-plaintext highlighter-rouge">dir</code> (reflection of <codeclass="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 <ahref="http://15462.courses.cs.cmu.edu/fall2015/lecture/reflection/slide_028">here</a>.</p></li><li><p><codeclass="language-plaintext highlighter-rouge">Vec3 refract(Vec3 out_dir, float index_of_refraction, bool& was_internal)</code> returns the ray that results from refracting the ray in <codeclass="language-plaintext highlighter-rouge">out_dir</code> about the surface according to <ahref="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 <codeclass="language-plaintext highlighter-rouge">index_of_refraction</code>. Your implementation should assume that if the ray in <codeclass="language-plaintext highlighter-rouge">out_dir</code><strong>is entering the surface</strong> (that is, if <codeclass="language-plaintext highlighter-rouge">cos(out_dir, N=[0,1,0]) > 0</code>) then the ray is currently in vacuum (index of refraction = 1.0). If <codeclass="language-plaintext highlighter-rouge">cos(out_dir, N=[0,1,0]) < 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 <codeclass="language-plaintext highlighter-rouge">*was_internal</code> to <codeclass="language-plaintext highlighter-rouge">true</code>.</strong></p></li><li><p>Note that in <codeclass="language-plaintext highlighter-rouge">reflect</code> and <codeclass="language-plaintext highlighter-rouge">refract</code>, both the <codeclass="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><imgsrc="rays_dir.png"style="height:420px"/></center><h2id="step-1"><ahref="#step-1"class="anchor-heading"aria-labelledby="step-1"><svgviewBox="0 0 16 16"aria-hidden="true"><usexlink:href="#svg-link"></use></svg></a> Step 1 </h2><p>Implement the class <codeclass="language-plaintext highlighter-rouge">BSDF_Mirror</code> which represents a material with perfect specular reflection (a perfect mirror). You should Implement <codeclass="language-plaintext highlighter-rouge">BSDF_Mirror::sample</code>, <codeclass="language-plaintext highlighter-rouge">BSDF_Mirror::evaluate</code>, and <codeclass="language-plaintext highlighter-rouge">reflect</code>. <strong>(Hint: what should the pdf sampled by <codeclass="language-plaintext highlighter-rouge">BSDF_Mirror::sample</code> be? What should the reflectance function <codeclass="language-plaintext highlighter-rouge">BSDF_Mirror::evalute</code> be?)</strong></p><h2id="step-2"><ahref="#step-2"class="anchor-heading"aria-labelledby="step-2"><svgviewBox="0 0 16 16"aria-hidden="true"><usexlink:href="#svg-link"></use></svg></a> Step 2 </h2><p>Implement the class <codeclass="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 <codeclass="language-plaintext highlighter-rouge">refract</code> to add support for refracted ray paths.</li><li>Implement <codeclass="language-plaintext highlighter-rouge">BSDF_refract::sample</code> as well as <codeclass="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 <ahref="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><h3id="dielectrics-and-transmission"><ahref="#dielectrics-and-transmission"class="anchor-heading"aria-labelledby="dielectrics-and-transmission"><svgviewBox="0 0 16 16"aria-hidden="true"><usexlink:href="#svg-link"></use></svg></a> Dielectrics and Transmission </h3><h3id="fresnel-equations-for-dielectric"><ahref="#fresnel-equations-for-dielectric"class="anchor-heading"aria-labelledby="fresnel-equations-for-dielectric"><svgviewBox="0 0 16 16"aria-hidden="true"><usexlink:href="#svg-link"></use></svg></a> Fresnel Equations for Dielectric </h3><p>The <ahref="https://en.wikipedia.org/wiki/Fresnel_equations">Fresnel Equations</a> (another <ahref="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, <imgsrc="dielectric_eq1.png"width="18"/> and <imgsrc="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. <imgsrc="dielectric_eq3.png"width="18"/> and <imgsrc="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><imgsrc="dielectric_eq5.png"width="200"/></p><p>The parallel and perpendicular terms are given by:</p><p><imgsrc="dielectric_eq6.png"width="200"/></p><p><imgsrc="dielectric_eq7.png"width="200"/></p><p>Therefore, for a dielectric material, the fraction of reflected light will be given by <imgsrc="dielectric_eq8.png"width="18"/>, and the amount of transmitted light will be given by <imgsrc="dielectric_eq9.png"width="50"/>.</p><p>Alternatively, you may compute <imgsrc="dielectric_eq8.png"width="18"/> using <ahref="https://en.wikipedia.org/wiki/Schlick%27s_approximation">Schlick’s approximation</a>.</p><h3id="distribution-function-for-transmitted-light"><ahref="#distribution-function-for-transmitted-light"class="anchor-heading"aria-labelledby="distribution-function-for-transmitted-light"><svgviewBox="0 0 16 16"aria-hidden="true"><usexlink: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 <ahref="http://www.pbr-book.org/">Physically Based Rendering</a> for a derivation based on Snell’s Law and the relation <imgsrc="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><imgsrc="new_results/32k_large.png"/></center></div></div><divclass="search-overlay"></div></div></body></html>