<p>So I found out where was a problem.</p>

<p>This whole equation is for specular BRDF which is only one part of light interaction. When you hit the surface you have to generate new microfacet normal from distribution D. Then use it to calculate Fresnel. it gives you value from 0 to 1. That is now much light is directly reflected from the surface, but there is another part I forgot about, the diffuse component also contributes to the equation with (1 - Fresnel value).</p>

<p>So the only problem was using just one component.</p>

<p>And I also introduced the importance of sampling, which negates the D resulting in:</p>

<p>Integral over omega = incoming light from wi *  (F * G * dot(wo, H(new microfacet normal))) / (dot(N, wo) * dot(N, H))</p>

<p>There is also one check. New direction wi cannot point towards the surface, because it would go through. </p>

<p>if (dot(wi, N) &lt; 0) ray.mask = (float3)(0.0, 0.0, 0.0);</p>

<p>This can darken an image quite a lot especially when you use it on the glass. But there is a solution in BSSRDF. This equation takes a multiple scattering of the light on surface into a count.</p>

<p>This is the specular part. For the diffuse, I used a basic cosine weighted distribution with (1 - Fresnel) multiplier.</p>

CC BY-SA 4.0
2020-04-24T13:13:52.277Z
2020-04-24T13:13:52.277Z
Vít Gardoň
<p>Some more clarity on the fresnel.</p>

<p>F tells you how much light is reflected, and (1 - F) therefore tells you how much light is transmitted through the layer/material/surface.</p>

<p>Generally we put fresnels into two types Dielectric(water/glass) and Conductor(metals).</p>

<p>The approximation you are using is for a dielectric fresnel, so what you are actually modelling is a thin layer over the top of your diffuse. In renderers this layer is normally called the coat or clearcoat. It can be used to emulate laminated materials or a coating of water/sweat.</p>

<p>If you want to render metals you would need to swap out the fresnel for a conductive one. There are better approximations, but an easy artistic approximation is to swap the F0 of your schlick approximation with the rgb of your material. You can layer a diffuse below this if you need to but you may find with conductive it's not nessisary.</p>

<p><a href="http://www.codinglabs.net/article_physically_based_rendering_cook_torrance.aspx" rel="nofollow noreferrer">http://www.codinglabs.net/article_physically_based_rendering_cook_torrance.aspx</a></p>

<p>This is a good article on the topic for further reading.</p>

CC BY-SA 4.0
2020-05-06T14:33:23.683Z
2020-05-06T14:33:23.683Z
Peter
<p>I am trying to implement BRDF microfacet path tracing and I think I need a little push.
I will explain what I understand so that you can correct my mistakes.</p>

<p>I start with simple rendering equation:
<a href="https://i.sstatic.net/nU5Ao.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/nU5Ao.png" alt="enter image description here"></a>
Le and Li are radiance we have no control of so I cannot change anything about them. The only thing I can change is function F which is called BRDF. Specifically, I am using this Cook-Torrance microfacet specular BRDF I found <a href="http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html" rel="nofollow noreferrer">here</a>. 
<a href="https://i.sstatic.net/hdv5m.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/hdv5m.png" alt="enter image description here"></a>
For functions F, G and D I choose these formulas.
<a href="https://i.sstatic.net/a4RIm.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/a4RIm.png" alt="enter image description here"></a></p>

<p>Let's start with the Fresnel function. Greater the angle between H and Wo (or Wi, it should be the same) the more light is reflected. When the angle between H and Wo will be 90° then the function will return 1. That means that all of the light is reflected. That is understandable, but when I will look directly down to normal the result will be 0.14163. is really so little light reflected back? I thought that Fresnel gives percentage between reflection and refraction on the water surface for example. Is this right?</p>

<p>Following with function G - Geometric shading. I want to use the Smith shadowing model because I want to improve it later for multiple scattering BSDF. The equation goes like this:
<a href="https://i.sstatic.net/cGRGi.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/cGRGi.png" alt="enter image description here"></a></p>

<p>As G1 can be used more types of functions, but I like GGX. D_GGX is evaluated for both incoming light and outgoing light. It describes how much light will <strong>NOT</strong> be blocked by surface imperfections.</p>

<p>And last function D - Normal distribution function. With this one, I have the biggest problems. It describes the probability that a new microfacet normal will be pointing to the given direction. This depends on roughness. So perfectly smooth surface will have every normal pointing upward, but as the surface gets rougher and rougher normals will start to point to different directions. With 100% rough material the chance of normal pointing a given direction should be uniform over the whole hemisphere. Because we are talking about probability the integral of probability over hemisphere should be 1. as this equation says, but I don't understand why there is a dot product of N and H.
<a href="https://i.sstatic.net/ujEqV.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ujEqV.png" alt="enter image description here"></a></p>

<p>Now I will explain how I am using these equations.</p>

<p>I start with generation microfacet normal H with distribution D_ggx. Spherical coordinates a generated like this: (epsilon is a random number from the interval (0;1>. I can't use 1 because we cannot divide by 0)
<a href="https://i.sstatic.net/T4MdA.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/T4MdA.png" alt="enter image description here"></a></p>

<p>With H defined I can reflect Wo and get Wi. H is now half vector between Wo and Wi. Now I calculate F and G. I am not using D anymore because I already used it for generating the microfacet normal H (that is against what I read in this <a href="https://computergraphics.stackexchange.com/questions/4394/path-tracing-the-cook-torrance-brdf">answer</a>).  I divide them by 4 * dot(H, Wi)<em>dot(n</em>Wo). This final number should be weight describing how much light [Li(Wi)] is reflected towards Wo. Together with a dot product of n and Wi from rendering equation. I think I have this part wrong.</p>

<p>I am not using any importance sampling for now because I think it is not necessary to work. Am I right? Of cause with importance sampling, the image would converge faster. This is my final equation.</p>

<p>Of cause, as you might guess when I implement this it returns almost totally black image. If you don't find any mistake in the math then the error has to be in code (but I will bet a 10$ it is a math problem)</p>

<p><a href="https://i.sstatic.net/H0H3s.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/H0H3s.png" alt="enter image description here"></a></p>

<p>If you need any specification of my decisions or goals I will happy to answer you.</p>

CC BY-SA 4.0
2020-05-04T04:29:24.280Z
The integral of the microfacets distribution is NOT over the hemisphere. It is over the area of the surface. The cosine term is related to the projected areas of the microfacets. and the integral basically says that the sum of projected areas of microfacets must equal the surface area.
ali
CC BY-SA 4.0
2020-05-04T04:29:41.423Z
Have a look at pbrt here somewhere in the middle of the page has the diagram:  http://www.pbr-book.org/3ed-2018/Reflection_Models/Microfacet_Models.html
ali
<raytracing><pathtracing><brdf>
Understanding of Microfacet monte-carlo path tracing
Vít Gardoň
# Understanding of Microfacet monte-carlo path tracing

(Asked by: username_0 on 2020-04-21)

I am trying to implement BRDF microfacet path tracing and I think I need a little push.
I will explain what I understand so that you can correct my mistakes.

I start with simple rendering equation:
[![enter image description here](https://i.sstatic.net/nU5Ao.png)](https://i.sstatic.net/nU5Ao.png)
Le and Li are radiance we have no control of so I cannot change anything about them. The only thing I can change is function F which is called BRDF. Specifically, I am using this Cook-Torrance microfacet specular BRDF I found [here](http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html).
[![enter image description here](https://i.sstatic.net/hdv5m.png)](https://i.sstatic.net/hdv5m.png)
For functions F, G and D I choose these formulas.
[![enter image description here](https://i.sstatic.net/a4RIm.png)](https://i.sstatic.net/a4RIm.png)

Let's start with the Fresnel function. Greater the angle between H and Wo (or Wi, it should be the same) the more light is reflected. When the angle between H and Wo will be 90° then the function will return 1. That means that all of the light is reflected. That is understandable, but when I will look directly down to normal the result will be 0.14163. is really so little light reflected back? I thought that Fresnel gives percentage between reflection and refraction on the water surface for example. Is this right?

Following with function G - Geometric shading. I want to use the Smith shadowing model because I want to improve it later for multiple scattering BSDF. The equation goes like this:
[![enter image description here](https://i.sstatic.net/cGRGi.png)](https://i.sstatic.net/cGRGi.png)

As G1 can be used more types of functions, but I like GGX. D\_GGX is evaluated for both incoming light and outgoing light. It describes how much light will **NOT** be blocked by surface imperfections.

And last function D - Normal distribution function. With this one, I have the biggest problems. It describes the probability that a new microfacet normal will be pointing to the given direction. This depends on roughness. So perfectly smooth surface will have every normal pointing upward, but as the surface gets rougher and rougher normals will start to point to different directions. With 100% rough material the chance of normal pointing a given direction should be uniform over the whole hemisphere. Because we are talking about probability the integral of probability over hemisphere should be 1. as this equation says, but I don't understand why there is a dot product of N and H.
[![enter image description here](https://i.sstatic.net/ujEqV.png)](https://i.sstatic.net/ujEqV.png)

Now I will explain how I am using these equations.

I start with generation microfacet normal H with distribution D\_ggx. Spherical coordinates a generated like this: (epsilon is a random number from the interval (0;1>. I can't use 1 because we cannot divide by 0)
[![enter image description here](https://i.sstatic.net/T4MdA.png)](https://i.sstatic.net/T4MdA.png)

With H defined I can reflect Wo and get Wi. H is now half vector between Wo and Wi. Now I calculate F and G. I am not using D anymore because I already used it for generating the microfacet normal H (that is against what I read in this [answer](https://computergraphics.stackexchange.com/questions/4394/path-tracing-the-cook-torrance-brdf)). I divide them by 4 \* dot(H, Wi)*dot(n*Wo). This final number should be weight describing how much light [Li(Wi)] is reflected towards Wo. Together with a dot product of n and Wi from rendering equation. I think I have this part wrong.

I am not using any importance sampling for now because I think it is not necessary to work. Am I right? Of cause with importance sampling, the image would converge faster. This is my final equation.

Of cause, as you might guess when I implement this it returns almost totally black image. If you don't find any mistake in the math then the error has to be in code (but I will bet a 10$ it is a math problem)

[![enter image description here](https://i.sstatic.net/H0H3s.png)](https://i.sstatic.net/H0H3s.png)

If you need any specification of my decisions or goals I will happy to answer you.

**Tags:** raytracing, pathtracing, brdf

> **Comments:**
> **username_1**: The integral of the microfacets distribution is NOT over the hemisphere. It is over the area of the surface. The cosine term is related to the projected areas of the microfacets. and the integral basically says that the sum of projected areas of microfacets must equal the surface area.  
> **username_1**: Have a look at pbrt here somewhere in the middle of the page has the diagram:  http://www.pbr-book.org/3ed-2018/Reflection_Models/Microfacet_Models.html  

---

## 2 answers

### Answer by username_0 on 2020-04-24. Score: 0 | Accepted answer

So I found out where was a problem.

This whole equation is for specular BRDF which is only one part of light interaction. When you hit the surface you have to generate new microfacet normal from distribution D. Then use it to calculate Fresnel. it gives you value from 0 to 1. That is now much light is directly reflected from the surface, but there is another part I forgot about, the diffuse component also contributes to the equation with (1 - Fresnel value).

So the only problem was using just one component.

And I also introduced the importance of sampling, which negates the D resulting in:

Integral over omega = incoming light from wi \* (F \* G \* dot(wo, H(new microfacet normal))) / (dot(N, wo) \* dot(N, H))

There is also one check. New direction wi cannot point towards the surface, because it would go through.

if (dot(wi, N) < 0) ray.mask = (float3)(0.0, 0.0, 0.0);

This can darken an image quite a lot especially when you use it on the glass. But there is a solution in BSSRDF. This equation takes a multiple scattering of the light on surface into a count.

This is the specular part. For the diffuse, I used a basic cosine weighted distribution with (1 - Fresnel) multiplier.


---

### Answer by username_2 on 2020-05-06. Score: 1

Some more clarity on the fresnel.

F tells you how much light is reflected, and (1 - F) therefore tells you how much light is transmitted through the layer/material/surface.

Generally we put fresnels into two types Dielectric(water/glass) and Conductor(metals).

The approximation you are using is for a dielectric fresnel, so what you are actually modelling is a thin layer over the top of your diffuse. In renderers this layer is normally called the coat or clearcoat. It can be used to emulate laminated materials or a coating of water/sweat.

If you want to render metals you would need to swap out the fresnel for a conductive one. There are better approximations, but an easy artistic approximation is to swap the F0 of your schlick approximation with the rgb of your material. You can layer a diffuse below this if you need to but you may find with conductive it's not nessisary.

<http://www.codinglabs.net/article_physically_based_rendering_cook_torrance.aspx>

This is a good article on the topic for further reading.


---

