<p>After some testing and some research I have found that both the $\sin(\theta)$ and the $\cos(\theta)$ should be removed from the denominator.</p>

<p>the reasoning is that, since we want a probability function of steradians instead of angles, the $\sin(\theta)$ factor (which is essentially used to convert from steradians on a unit sphere to radians on the two polar axis) should be dropped.</p>

<p>Also, $\cos(\theta)$ (as Nathan Reed explains in <a href="http://reedbeta.com/blog/hows-the-ndf-really-defined/" rel="nofollow noreferrer">this</a> blog post) is there to convert from microfacet area to macrosurface area. Since we are generating microsurface samples, this should be removed.</p>

<p>After these corrections we get the formula</p>

<p>$$L_o(p,\omega_o)\approx\frac{1}{N}\sum_{i=1}^{N}\frac{L_i(p,\omega_i)FG}{4(n\cdot\omega_o)}$$</p>

<p>which is free of the artifacts of the formula on the question.</p>

CC BY-SA 3.0
2018-02-15T04:44:21.353Z
2018-02-15T04:44:21.353Z
Sebastián Mestre
<p>I am having my first encounter with the rendering of indirect reflections in the form of screen space reflections in a game engine, but i am struggling to get correct looking results.</p>

<p><a href="https://i.sstatic.net/E9xzy.png" rel="noreferrer"><img src="https://i.sstatic.net/E9xzy.png" alt="taken at low resolution and ray count"></a></p>

<p>(patterns arise from a bad way of generating noise for montecarlo integration)</p>

<p>(image taken at low ray count. otherwise the color values end up going to NaN)</p>

<p>From what i've gathered, a common formulation of the rendering equation is as follows:</p>

<p>$$L_o(p,\omega_o)=L_e(p,\omega_o)+\int_{\Omega}L_i(p,\omega_i)fr(\omega_i,\omega_o)(n\cdot\omega_i)d\omega_i$$</p>

<p>which, dropping the $L_e(p,\omega_o)$ term, can be approximated using the following monte carlo estimator:</p>

<p>$$L_o(p,\omega_o)\approx\frac{1}{N}\sum_{i=1}^{N}\frac{L_i(p,\omega_i)fr(\omega_i,\omega_o)(n\cdot\omega_i)}{p(\omega_i)}$$</p>

<p>where $n$ is a unit vector perpendicular to the surface.</p>

<p>for actual computation of values, all of these terms must be specified.</p>

<p>$L_i(p,\omega_i)$ is found through raymarching in screen space</p>

<p>$fr(\omega_i,\omega_o)$ is the Cook-Torrance BRDF:$\frac{FGD}{4(n\cdot\omega_i)(n\cdot\omega_o)}$</p>

<p>if we name the angle between $n$ and $m$ $\theta$, we get that the GGX NDF is:$D=\frac{\alpha^2}{\pi(\cos^2(\theta)(\alpha^2-1)+1)^2}$</p>

<p>where $m$ is the microfacet normal $m=\frac{\omega_i+\omega_o}{|\omega_i+\omega_o|}$</p>

<p>$p(\omega_i)$ Is the PDF that can be derived from the GGX NDF $\frac{\alpha^2\cos(\theta)\sin(\theta)}{\pi(\cos^2(\theta)(\alpha^2-1)+1)^2}$</p>

<p>When put all together we get:</p>

<p>$$L_o(p,\omega_o)\approx\frac{1}{N}\sum_{i=1}^{N} \frac{L_i(p,\omega_i)\frac{FG}{4(n\cdot\omega_i)(n\cdot\omega_o)}\frac{\alpha^2}{\pi(\cos^2(\theta)(\alpha^2-1)+1)^2}(n\cdot\omega_i)}{\frac{\alpha^2\cos(\theta)\sin(\theta)}{\pi(\cos^2(\theta)(\alpha^2-1)+1)^2}}$$</p>

<p>After simplifying, we get:</p>

<p>$$L_o(p,\omega_o)\approx\frac{1}{N}\sum_{i=1}^{N} \frac{L_i(p,\omega_i)FG}{4(n\cdot\omega_o)\cos(\theta)\sin(\theta)}$$</p>

<p>This procedure seems correct to me but the images produced by my implementation have over exposed reflections at sharp incidence angles or at low roughness values. However, when i remove the $\sin(\theta)$ factor from the denominator it looks plausible (not sure about correctness though).</p>

<p><a href="https://i.sstatic.net/eZnaa.png" rel="noreferrer"><img src="https://i.sstatic.net/eZnaa.png" alt="taken at low resolution with no denoise solution"></a></p>

<p>Thanks in advance.</p>

<rendering><brdf><real-time><reflection>
fix over exposure in importance sampling in screen space reflections
Sebastián Mestre
# fix over exposure in importance sampling in screen space reflections

(Asked by: username_0 on 2017-11-30)

I am having my first encounter with the rendering of indirect reflections in the form of screen space reflections in a game engine, but i am struggling to get correct looking results.

[![taken at low resolution and ray count](https://i.sstatic.net/E9xzy.png)](https://i.sstatic.net/E9xzy.png)

(patterns arise from a bad way of generating noise for montecarlo integration)

(image taken at low ray count. otherwise the color values end up going to NaN)

From what i've gathered, a common formulation of the rendering equation is as follows:

$$L\_o(p,\omega\_o)=L\_e(p,\omega\_o)+\int\_{\Omega}L\_i(p,\omega\_i)fr(\omega\_i,\omega\_o)(n\cdot\omega\_i)d\omega\_i$$

which, dropping the $L\_e(p,\omega\_o)$ term, can be approximated using the following monte carlo estimator:

$$L\_o(p,\omega\_o)\approx\frac{1}{N}\sum\_{i=1}^{N}\frac{L\_i(p,\omega\_i)fr(\omega\_i,\omega\_o)(n\cdot\omega\_i)}{p(\omega\_i)}$$

where $n$ is a unit vector perpendicular to the surface.

for actual computation of values, all of these terms must be specified.

$L\_i(p,\omega\_i)$ is found through raymarching in screen space

$fr(\omega\_i,\omega\_o)$ is the Cook-Torrance BRDF:$\frac{FGD}{4(n\cdot\omega\_i)(n\cdot\omega\_o)}$

if we name the angle between $n$ and $m$ $\theta$, we get that the GGX NDF is:$D=\frac{\alpha^2}{\pi(\cos^2(\theta)(\alpha^2-1)+1)^2}$

where $m$ is the microfacet normal $m=\frac{\omega\_i+\omega\_o}{|\omega\_i+\omega\_o|}$

$p(\omega\_i)$ Is the PDF that can be derived from the GGX NDF $\frac{\alpha^2\cos(\theta)\sin(\theta)}{\pi(\cos^2(\theta)(\alpha^2-1)+1)^2}$

When put all together we get:

$$L\_o(p,\omega\_o)\approx\frac{1}{N}\sum\_{i=1}^{N} \frac{L\_i(p,\omega\_i)\frac{FG}{4(n\cdot\omega\_i)(n\cdot\omega\_o)}\frac{\alpha^2}{\pi(\cos^2(\theta)(\alpha^2-1)+1)^2}(n\cdot\omega\_i)}{\frac{\alpha^2\cos(\theta)\sin(\theta)}{\pi(\cos^2(\theta)(\alpha^2-1)+1)^2}}$$

After simplifying, we get:

$$L\_o(p,\omega\_o)\approx\frac{1}{N}\sum\_{i=1}^{N} \frac{L\_i(p,\omega\_i)FG}{4(n\cdot\omega\_o)\cos(\theta)\sin(\theta)}$$

This procedure seems correct to me but the images produced by my implementation have over exposed reflections at sharp incidence angles or at low roughness values. However, when i remove the $\sin(\theta)$ factor from the denominator it looks plausible (not sure about correctness though).

[![taken at low resolution with no denoise solution](https://i.sstatic.net/eZnaa.png)](https://i.sstatic.net/eZnaa.png)

Thanks in advance.

**Tags:** rendering, brdf, real-time, reflection


---

## 1 answers

### Answer by username_0 on 2018-02-15. Score: 1 | Accepted answer

After some testing and some research I have found that both the $\sin(\theta)$ and the $\cos(\theta)$ should be removed from the denominator.

the reasoning is that, since we want a probability function of steradians instead of angles, the $\sin(\theta)$ factor (which is essentially used to convert from steradians on a unit sphere to radians on the two polar axis) should be dropped.

Also, $\cos(\theta)$ (as Nathan Reed explains in [this](http://reedbeta.com/blog/hows-the-ndf-really-defined/) blog post) is there to convert from microfacet area to macrosurface area. Since we are generating microsurface samples, this should be removed.

After these corrections we get the formula

$$L\_o(p,\omega\_o)\approx\frac{1}{N}\sum\_{i=1}^{N}\frac{L\_i(p,\omega\_i)FG}{4(n\cdot\omega\_o)}$$

which is free of the artifacts of the formula on the question.


---

