<p>I would like to intuitively understand the <a href="https://en.wikipedia.org/wiki/Path_tracing#Algorithm" rel="nofollow noreferrer">Path Tracing</a> equation/formula/pseudocode, but I'm not fully getting the last <code>return</code> statement.
As per Wikipedia page:</p>

<pre><code>// Probability of the newRay
const float p = 1/(2*M_PI);
// Compute the BRDF for this ray (assuming Lambertian reflection)
float cos_theta = DotProduct(newRay.direction, ray.normalWhereObjWasHit);
Color BRDF = material.reflectance / M_PI ;
...
// Apply the Rendering Equation here.
return emittance + (BRDF * incoming * cos_theta / p);
</code></pre>

<p>I would understand:</p>

<ul>
<li><em>p</em> is the probability of new ray (not quite sure what this means), though it's <code>1 / (2 * PI)</code></li>
<li><em>cos_theta</em> is the angle between the normal of a given surface and the <em>incoming</em> ray</li>
<li><em>BRDF</em> is the material colour divided by <code>PI</code></li>
<li>After computing the <em>incoming</em> colour, we add the <em>emittance</em> component with the <em>Lambertian</em></li>
</ul>

<p>I would interpret the second part of the return statement as:</p>

<ol>
<li>Reflect current colour based on how much is incoming <code>BRDF * incoming</code></li>
<li>"Weight" it by the angle (rays that are next to the <em>normal</em> would reflect more colour, energy) <code>* cos_theta</code></li>
<li>But then we <code>/ p</code>, which if we consider the <em>BRDF</em>, removed the PI component and leave a factor of <strong>2</strong> (<code>BRDF / p = material.reflectance / M_PI * (2 * M_PI) = material.reflectance * 2</code>)</li>
</ol>

<p>Why is there such factor of <strong>2</strong>?
What is the most logical explanation to this?</p>

CC BY-SA 4.0
2019-10-22T00:14:11.417Z
The division by $\pi$ in the brdf's constant is for energy preservation (then `material.reflectance` can be anything in `[0,1]`). This is unrelated to the division by $\frac{1}{2\pi}$ which is due to the pdf. The pdf is $\frac{1}{2\pi}$, since the probability of uniformly generating any point on the upper hemisphere is $\frac{\sin\theta}{2\pi}$. The $\sin\theta$ gets canceled with a term from the rendering equation, and $2\pi$ is the surface area of the unit hemisphere (the whole sphere has area $4\pi r^2$, and $r=1$ for the unit sphere).
lightxbulb
CC BY-SA 4.0
2019-10-22T06:07:52.277Z
Thanks for this, so it's a chance that 2 factor gets left there. Do you have a link to the full equation you mentioned there?
Emanuele
CC BY-SA 4.0
2019-10-22T09:44:38.277Z
The rendering equation? Search for rendering equation in google/wikipedia.
lightxbulb
<rendering><pathtracing><mathematics>
Why does the reflected component in Lambertian path tracing get multiplied by a factor of 2?
Emanuele
# Why does the reflected component in Lambertian path tracing get multiplied by a factor of 2?

(Asked by: username_0 on 2019-10-21)

I would like to intuitively understand the [Path Tracing](https://en.wikipedia.org/wiki/Path_tracing#Algorithm) equation/formula/pseudocode, but I'm not fully getting the last `return` statement.
As per Wikipedia page:

```
// Probability of the newRay
const float p = 1/(2*M_PI);
// Compute the BRDF for this ray (assuming Lambertian reflection)
float cos_theta = DotProduct(newRay.direction, ray.normalWhereObjWasHit);
Color BRDF = material.reflectance / M_PI ;
...
// Apply the Rendering Equation here.
return emittance + (BRDF * incoming * cos_theta / p);

```

I would understand:

* *p* is the probability of new ray (not quite sure what this means), though it's `1 / (2 * PI)`
* *cos\_theta* is the angle between the normal of a given surface and the *incoming* ray
* *BRDF* is the material colour divided by `PI`
* After computing the *incoming* colour, we add the *emittance* component with the *Lambertian*

I would interpret the second part of the return statement as:

1. Reflect current colour based on how much is incoming `BRDF * incoming`
2. "Weight" it by the angle (rays that are next to the *normal* would reflect more colour, energy) `* cos_theta`
3. But then we `/ p`, which if we consider the *BRDF*, removed the PI component and leave a factor of **2** (`BRDF / p = material.reflectance / M_PI * (2 * M_PI) = material.reflectance * 2`)

Why is there such factor of **2**?
What is the most logical explanation to this?

**Tags:** rendering, pathtracing, mathematics

> **Comments:**
> **username_1**: The division by $\pi$ in the brdf's constant is for energy preservation (then `material.reflectance` can be anything in `[0,1]`). This is unrelated to the division by $\frac{1}{2\pi}$ which is due to the pdf. The pdf is $\frac{1}{2\pi}$, since the probability of uniformly generating any point on the upper hemisphere is $\frac{\sin\theta}{2\pi}$. The $\sin\theta$ gets canceled with a term from the rendering equation, and $2\pi$ is the surface area of the unit hemisphere (the whole sphere has area $4\pi r^2$, and $r=1$ for the unit sphere).  
> **username_0**: Thanks for this, so it's a chance that 2 factor gets left there. Do you have a link to the full equation you mentioned there?  
> **username_1**: The rendering equation? Search for rendering equation in google/wikipedia.  

---

## 0 answers

