| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]--><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="Asciidoctor 1.5.4"><title>Physically Based Rendering – Part Two</title><link rel="stylesheet" href="./asciidoctor.css">
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
- <link rel="stylesheet" href="./coderay-asciidoctor.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css"><link rel="stylesheet" href="/home/travis/build/jMonkeyEngine/wiki/build/asciidoc/html5/jme3/advanced/twemoji-awesome.css"></head><body class="article toc2 toc-left"><div id="header"><div id="toolbar"><a href="https://github.com/jMonkeyEngine/wiki/edit/master/src/docs/asciidoc/jme3/advanced/pbr_part2.adoc"><i class="fa fa-pencil-square" aria-hidden="true"></i></a><a href="https://github.com/jMonkeyEngine/wiki/new/master/src/docs/asciidoc/jme3/advanced/"><i class="fa fa-plus-square" aria-hidden="true"></i></a><input dir="auto" style="position: relative; vertical-align: top;" spellcheck="false" autocomplete="off" class="searchbox__input aa-input" id="doc-search" name="search" placeholder="Search in the doc" required="required" type="search"></div><h1>Physically Based Rendering – Part Two</h1><div class="details"><span class="author" id="author"></span><br><span id="revnumber">version ,</span> <span id="revdate">2018/01/15 23:16</span></div><div id="toc" class="toc2"><div id="toctitle">Table of Contents</div><ul class="sectlevel1"><li><a href="#lighting-in-pbr">Lighting in PBR</a><ul class="sectlevel2"><li><a href="#direct-light-source">Direct light source</a></li><li><a href="#indirect-light-source">Indirect light source</a></li></ul></li><li><a href="#choosing-your-brdfs">Choosing your BRDFs</a><ul class="sectlevel2"><li><a href="#diffuse-brdf-lambert">Diffuse BRDF : Lambert</a></li><li><a href="#specular-brdf-cook-torrance">Specular BRDF : Cook-Torrance</a></li></ul></li><li><a href="#lexical">Lexical :</a></li></ul></div></div><div id="content"><div id="preamble"><div class="sectionbody"><div class="paragraph"><p><a href="../../jme3\advanced\pbr_part1.html">In Part one</a>, I explained what you had to know about Physically Based Rendering if you were an artist. If you’re a developer, and reading this article, you may have tried, or are planning to implement your own PBR system. If you started to read some of the available literature, you’ve probably been struck by the math complexity of it, and by the lack of explanation of the big picture. You usually see articles that focus on specifics parts of the process, and don’t talk much about other parts as they are assumed easier. At some point you have to assemble all these parts, and I had a hard time figuring out how to do it in my readings. I guess it’s considered basic stuff for other authors, but I think it deserves its proper explanation.</p></div>
- <div class="paragraph"><p>I don’t pretend these articles will enlighten you to the point you are ready to implement your own system, but I hope they will give you solid basis and understanding to start reading the literature without saying “WTF?? on every line as I did.</p></div>
- <div class="paragraph"><p>You can find a lexical, at the end, with all the strange words you’ll come across and their explanations.</p></div>
- <div class="paragraph"><p>So here is what I figured out about using PBR and lighting in general in a 3D rendering pipeline.</p></div>
- <div class="paragraph"><p><strong>Ligthing</strong></p></div>
- <div class="paragraph"><p>So first, lets talk about lighting in games. It all boils down to 2 things :</p></div>
- <div class="ulist"><ul><li><p>Computing <strong>Diffuse</strong> reflection: This represent the light that reflects off a surface in all directions</p></li><li><p>Computing <strong>Specular</strong> reflection : This represent the light that reflects off a surface directly to your eye.</p></li></ul></div>
- <div class="paragraph"><p>This image from wikipedia is the most simple and yet the most helpful to understand this</p></div>
- <div style="text-align: center;" class="imageblock"><div class="content"><img src="../../jme3/advanced/Lambert2.png" alt="Lambert2" width="320" height="250"></div></div>
- <div class="paragraph"><p>By GianniG46 (Own work) [CC-BY-SA-3.0 (<a class="bare" href="http://creativecommons.org/licenses/by-sa/3.0">http://creativecommons.org/licenses/by-sa/3.0</a>) or GFDL (<a class="bare" href="http://www.gnu.org/copyleft/fdl.html">http://www.gnu.org/copyleft/fdl.html</a>)], via Wikimedia Commons</p></div>
- <div class="paragraph"><p>To compute each of these factors, we’re going to use a function. This function answers to the delicate name of <strong>Bidirectional Reflectance Distribution Function or BRDF</strong>.</p></div>
- <div class="paragraph"><p>Don’t be scared by this, it’s a big name for just a function really. Usually, it will be a shader function.</p></div>
- <div class="paragraph"><p>Of course there are different BRDFs depending on what you want to compute, and on the lighting model you use. The BRDFs are usually called by the name of the guys that discovered/elaborated them.</p></div>
- <div class="paragraph"><p>Also, most of the time, in implementations for real time rendering, those BRDFs are approximated for the sake of performance. And incidentally, those approximations also have names, that can be people names or technique names…</p></div></div></div>
- <div class="sect2"><h3 id="lighting-in-pbr">Lighting in PBR</h3><div class="paragraph"><p>Computing lighting for PBR is exactly the same as with the current rendering ( the system we use today with ambient, diffuse, specular, sometimes called ad-hoc system in the literature) :</p></div>
- <div class="paragraph"><p>For each light source, compute the diffuse factor and the specular factor. The main difference is that the BRDFs used are different, more physically accurate, and works predictably under different light sources with few parameter entries.</p></div>
- <div class="paragraph"><p>So what is a light source?</p></div>
- <div class="sect2"><h3 id="direct-light-source">Direct light source</h3><div class="paragraph"><p>Something that emits light. In games the most common light sources are Directional lights (think of the sun), Spot lights (think of a torch light), Point lights (think of a light bulb).</p></div>
- <div class="paragraph"><p>That’s what is commonly used in the ad-hoc system, and PBR also handle those types of lights.</p></div></div>
- <div class="sect2"><h3 id="indirect-light-source">Indirect light source</h3><div class="paragraph"><p>Something that reflects light and indirectly lights its surroundings. Think for example of a red wall next to a car at daytime, the sunlight hits the wall and the wall reflects red light that, in turn, lights up the car.</p></div>
- <div class="paragraph"><p>This is not handled by the ad-hoc system, or very poorly faked with ambient lighting.</p></div>
- <div class="paragraph"><p>This part is optional for PBR, but that’s actually the part you really want. because that’s what make things pretty!</p></div>
- <div class="paragraph"><p>In games, indirect lighting is done by using an environment map as a light source. This technique is called <strong>Image Based Lighting (IBL)</strong>.</p></div>
- <div class="paragraph"><p>So let’s say we’re looking for the full package. we need to compute diffuse and specular contribution for each light source be it direct or indirect.</p></div>
- <div class="paragraph"><p>To do so we need a BRDF for diffuse and a BRDF for specular, and stick to them for each light source for consistency. Also those BRDF should accept as entry the parameters we want to expose for the artists (base color, metalness, roughness), or derived parameters with minimal transformation.</p></div>
- <div class="paragraph"><p>So the pseudo code for a complete lighting is this :</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code>//direct lighting
- for each directLightSource {
- directDiffuseFactor = DiffuseBRDF(directlightSource)
- directSpecularFactor = SpecularBRDF(directLightSource)
- directLighting += Albedo * directDiffuseFactor + SpecColor * directSpecularFactor
- }
- //Indirect Lighting, done through Image Based Rendering with an environment map
- indirectDiffuseFactor = DiffuseBRDF(EnvMap)
- indirectSpecularFactor = SpecularBRDF(EnvMap)
- indirectLighting = Albedo * indirectDiffuseFactor + SpecColor * indirectSpecularFactor
- Lighting = directLighting + indirectLighting</code></pre></div></div>
- <div class="paragraph"><p>I’ll go into more details, in the posts serie, on how to compute each factors, but that’s pretty much it.</p></div></div></div>
- <div class="sect2"><h3 id="choosing-your-brdfs">Choosing your BRDFs</h3><div class="paragraph"><p>There is a vast choice of BRDF, and I’m not going to talk about all of them but focus on the ones that I use in my implementation. I’ll just guide you to alternatives and provide links to relevant articles for more details.</p></div>
- <div class="paragraph"><p>I chose to use the same BRDF as the ones used in Unreal Engine 4 from <a href="http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf">this article</a> by Brian Karis, as I completely trust his judgement. The provided code helped a great deal, but it was far from straight forward to integrate. In the end I had to fully research, and understand all the whereabouts of BRDFs.</p></div>
- <div class="sect2"><h3 id="diffuse-brdf-lambert">Diffuse BRDF : Lambert</h3><div class="paragraph"><p>The most used diffuse BRDF in games. It’s very popular because it’s very cheap to compute and gives good results. This is the most simple way of computing diffuse. <a href="https://en.wikipedia.org/wiki/Lambertian_reflectance">here are the details</a></p></div>
- <div style="text-align: center;" class="imageblock"><div class="content"><img src="../../jme3/advanced/DiffuseLambert.jpg" alt="DiffuseLambert" width="320" height="250"></div></div>
- <div class="paragraph"><p>Diffuse Lambert factor for a direct light source (directional light) with a yellow surface color.</p></div>
- <div class="paragraph"><p>Some Alternatives :</p></div>
- <div class="paragraph"><p><strong>Oren-Nayar</strong> : Gives better visual results than classic Lambert, and has the advantage of using an entry parameter called roughness…rings a bell? Unfortunately, the additional computation cost is not really worth it,IMO. <a href="https://en.wikipedia.org/wiki/Oren%E2%80%93Nayar_reflectance_model">Details here</a></p></div>
- <div class="paragraph"><p><strong>Harahan-Krueger</strong> : Takes into consideration sub-surface scattering for diffuse lighting (every material surface has layers and light scatters into those different layers before going out of the material in a random direction). A lot of computations compared to Lambert, but may be important if you want to have a good sub surface scattering look for skin for example. <a href="http://cseweb.ucsd.edu/~ravir/6998/papers/p165-hanrahan.pdf">more details in this paper</a></p></div></div>
- <div class="sect2"><h3 id="specular-brdf-cook-torrance">Specular BRDF : Cook-Torrance</h3><div class="paragraph"><p>This is a bit more complicated for specular. We need a physically plausible BRDF. We use what is called a <strong>Microfacet BRDF</strong>. So what is it?</p></div>
- <div class="paragraph"><p>It states that at a micro level a surface is not plane, but formed of a multitude of little randomly aligned surfaces, the microfacets. Those surfaces acts as small mirrors that reflects incoming light. The idea behind this BRDF is that only some of those facets may be oriented so that the incoming light reflects to your eye. The smoother the surface, the more all facets are aligned, and the most neat is the light reflection. In the contrary, if a surface is rough, the facets are more randomly oriented so the light reflection is scattered on the surface, and the reflection looks more blurry.</p></div>
- <div style="text-align: center;" class="imageblock"><div class="content"><img src="../../jme3/advanced/DiffuseLambert.jpg" alt="Specular" width="320" height="250"></div></div>
- <div class="paragraph"><p>Microfacet specular factor for a direct light source. On the left a smooth surface, on the right a rough one. Note how the reflection is scattered on the surface when it’s rough.</p></div>
- <div class="paragraph"><p>The microfacet BRDF we use is called Cook-Torrance. From my readings, I couldn’t find any implementation that use another specular BRDF. It seems like this is the global form of any microfacet BRDF.</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code>f = D * F * G / (4 * (N.L) * (N.V));</code></pre></div></div>
- <div class="paragraph"><p><strong>N.L</strong> is the dot product between the normal of the shaded surface and the light direction.</p></div>
- <div class="paragraph"><p><strong>N.V</strong> is the dot product between the normal of the shaded surface and the view direction.</p></div>
- <div class="paragraph"><p>The other terms are :</p></div>
- <div class="ulist"><ul><li><p><strong>Normal Distribution Function called D</strong> (for distribution). You may also find some references to it as NDF. It computes the distribution of the microfacets for the shaded surface</p></li><li><p><strong>Fresnel factor called F</strong>. Discovered by Augustin Fresnel (frenchies are sooo clever), it describes how light reflects and refracts at the intersection of two different media (most often in computer graphics : Air and the shaded surface)</p></li><li><p><strong>Geometry shadowing term G</strong>. Defines the shadowing from the microfacets</p></li></ul></div>
- <div class="paragraph"><p>That’s where it gets complicated. For each of these terms, there are several models or approximations to computed them.</p></div>
- <div class="paragraph"><p>I’ve settled to use those models and approximations :</p></div>
- <div class="ulist"><ul><li><p><strong>D : Trowbridge-Reitz/GGX</strong> normal Distribution function.</p></li><li><p><strong>F : Fresnel term Schlick</strong>’s <a href="http://www.cs.virginia.edu/~jdl/bib/appearance/analytic%20models/schlick94b.pdf">approximation</a></p></li><li><p><strong>G : Schlick-GGX</strong> approximation</p></li></ul></div>
- <div class="paragraph"><p>I won’t go into the details of all the alternatives I just want to expose an overview of the whole process first. But I’ll dive into more technical details on the terms I use, in following posts. To have a neat overview of all alternatives you can see this <a href="http://graphicrants.blogspot.fr/2013/08/specular-brdf-reference.html">post</a> on Brian Karis’s blog.</p></div>
- <div class="paragraph"><p>That sums up the whole process, but there is still much to explain. In next post I’ll make a focus on indirect lighting, as it’s the part that gave me the hardest time to wrap my head around. I’ll explain the Image Based Lighting technique used, and how you can compute diffuse and specular from an Environment Map.</p></div></div></div>
- <div class="sect1"><h2 id="lexical">Lexical :</h2><div class="sectionbody"><div class="paragraph"><p><strong>Diffuse reflection :</strong> light that reflects from a surface in every direction.</p></div>
- <div class="paragraph"><p><strong>Specular reflection :</strong> light that reflects from a surface toward the viewer.</p></div>
- <div class="paragraph"><p><strong>Bidirectional Reflectance Distribution Function or BRDF :</strong> a function to compute Diffuse or Specular reflection.</p></div>
- <div class="paragraph"><p><strong>Image Based Rendering or IBL :</strong> a technique that uses an image as a light source</p></div>
- <div class="paragraph"><p><strong>Microfacet Specular BRDF :</strong> A specular BRDF that assumes a surface is made of a multitude of very small randomly aligned surfaces: the microfacets. it depends on 3 factors called D, F and G.</p></div>
- <div class="paragraph"><p><strong>Normal Distribution Function called D</strong> (for distribution). You may also find some references to it as NDF. It computes the distribution of the microfacets for the shaded surface</p></div>
- <div class="paragraph"><p><strong>Fresnel factor called F</strong>. Discovered by Augustin Fresnel (frenchies are sooo clever), it describes how light reflects and refracts at the intersection of two different media (most often in computer graphics : Air and the shaded surface)</p></div>
- <div class="paragraph"><p><strong>Geometry shadowing term G</strong>. Defines the shadowing from the micro facets</p></div>
- <hr>
- <div class="ulist"><ul><li><p><a href="../../jme3\advanced\pbr_part1.html">Physically Based Rendering – Part one</a></p></li><li><p><a href="../../jme3\advanced\pbr_part3.html">Physically Based Rendering – Part Three</a></p></li></ul></div></div></div></div><div id="footer"><div id="footer-text">Version <br>Last updated 2019-12-20 23:30:51 +00:00</div></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script><script>docsearch({
- apiKey: 'a736b6d93de805e26ec2f49b55013fbd',
- indexName: 'jmonkeyengine',
- inputSelector: '#doc-search',
- debug: false // Set debug to true if you want to inspect the dropdown
- });</script></body></html>
|