<p>Just so we're on the same page, you should have stated the method you're talking about—something like (rewritten from link) (disclaimer: none of the code in this answer has been tested):</p>
<pre><code>vec3 diff_dir = normalize( normal + rand_unit_vec() );

vec3 mirr_dir = reflect( ray_in, normal );
vec3 spec_dir = normalize(mix( mirr_dir,diff_dir, roughness ));

vec3 ray_out = mix( diff_dir,spec_dir, specular_enabled );
</code></pre>
<p><strong>Fundamentally, your question is how you can cheaply remove directional &quot;bias&quot; from this.</strong></p>
<hr />
<p>The reason there's bias here should be apparent from what the code is doing—it's blending the specular reflection with the diffuse reflection—the diffuse reflection being random and in the upper hemisphere, and the specular reflection being the mirror direction.</p>
<p>The effect is that the specular gets blurred, but the diffuse being in only the upper hemisphere also pulls the result upward.  They probably did it this way because it prevents having to check that the specular direction is above the plane.</p>
<p><strong>A simple way to change that would be to do something else</strong>.  E.g. maybe instead calculate <code>spec_dir</code> as:</p>
<pre><code>vec3 mirr_dir=reflect( ray_in, normal ), spec_dir;
do {
    spec_dir = normalize( mirr_dir + roughness*rand_unit_vec() );
} while ( dot(spec_dir,normal) &lt; 0.0 );
</code></pre>
<p>That'll do a &quot;fuzzy&quot; specular reflection that's centered around the reflection direction and clipped (with rejection sampling) against the plane.</p>
<hr />
<p><strong>However, I <em>do not</em> recommend you do this</strong>.</p>
<p>First, a good specular BRDF <em>should</em> have this sort of biased-upward behavior, so this is a feature, not a bug.  A more familiar but still basic example will be the Phong BRDF (which is centered around the reflection direction) and the Blinn–Phong BRDF (which has more upward bias).  Although both BRDFs are obsolete for production purposes, the Blinn–Phong BRDF is widely considered to be superior for this biasing behavior—it leads to important perceptual effects like smearing out highlights lengthwise at glancing angles (see e.g. &quot;<a href="https://renderwonk.com/publications/s2010-shading-course/hoffman/s2010_physically_based_shading_hoffman_b.pdf" rel="nofollow noreferrer">Crafting Physically Motivated Shading Models for Game Development</a>&quot; for discussion and examples).</p>
<p>Second and more fundamentally, this is this is not a proper BRDF anyway and messing with its shape is not productive.  It was broken before you started.  Sampling the diffuse ray like this will not give you (e.g.) Lambertian, and this specular distribution is a poorly concealed blurred mirror.  You would be much better with a microfacet model like you were thinking of doing—and it's not even that much more difficult to implement!  Please just do that instead.</p>

CC BY-SA 4.0
2023-11-18T19:46:30.457Z
2023-11-18T19:46:30.457Z
geometrian
<p>Im currently making some modifications for a <a href="https://github.com/chunky-dev/chunky" rel="nofollow noreferrer">path tracer for Minecraft</a>, specifically adding glossy refractions. The program currently uses for specular reflections <a href="https://blog.demofox.org/2020/06/06/casual-shadertoy-path-tracing-2-image-improvement-and-glossy-reflections/" rel="nofollow noreferrer">this method</a>, linear interpolation between the diffuse lobe and the perfect specular refection depending on the roughness parameter. However this introduces a direction bias that is quite noticeable in renders.
Here I have reproduced in in python, the red line is the mean vector while the green line is the specular refection for roughness values of 1, 0.7, 0.5, 0.3, 0.1 and 0.
<a href="https://i.sstatic.net/ELDeI.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ELDeI.png" alt="enter image description here" /></a></p>
<p>What would be the best way to correct for this bias without introducing substantial computation overhead.
I do plan evenly to include more sophisticated BSDF like Cook-Tolerance in the renderer but wanted to have simpler model as an option.</p>

<pathtracing><brdf>
Fixing bias in Specular lobe
Consuelo Ugarte
# Fixing bias in Specular lobe

(Asked by: username_0 on 2023-11-06)

Im currently making some modifications for a [path tracer for Minecraft](https://github.com/chunky-dev/chunky), specifically adding glossy refractions. The program currently uses for specular reflections [this method](https://blog.demofox.org/2020/06/06/casual-shadertoy-path-tracing-2-image-improvement-and-glossy-reflections/), linear interpolation between the diffuse lobe and the perfect specular refection depending on the roughness parameter. However this introduces a direction bias that is quite noticeable in renders.
Here I have reproduced in in python, the red line is the mean vector while the green line is the specular refection for roughness values of 1, 0.7, 0.5, 0.3, 0.1 and 0.
[![enter image description here](https://i.sstatic.net/ELDeI.png)](https://i.sstatic.net/ELDeI.png)

What would be the best way to correct for this bias without introducing substantial computation overhead.
I do plan evenly to include more sophisticated BSDF like Cook-Tolerance in the renderer but wanted to have simpler model as an option.

**Tags:** pathtracing, brdf


---

## 1 answers

### Answer by username_1 on 2023-11-18. Score: 0

Just so we're on the same page, you should have stated the method you're talking about—something like (rewritten from link) (disclaimer: none of the code in this answer has been tested):

```
vec3 diff_dir = normalize( normal + rand_unit_vec() );

vec3 mirr_dir = reflect( ray_in, normal );
vec3 spec_dir = normalize(mix( mirr_dir,diff_dir, roughness ));

vec3 ray_out = mix( diff_dir,spec_dir, specular_enabled );

```

**Fundamentally, your question is how you can cheaply remove directional "bias" from this.**

---

The reason there's bias here should be apparent from what the code is doing—it's blending the specular reflection with the diffuse reflection—the diffuse reflection being random and in the upper hemisphere, and the specular reflection being the mirror direction.

The effect is that the specular gets blurred, but the diffuse being in only the upper hemisphere also pulls the result upward. They probably did it this way because it prevents having to check that the specular direction is above the plane.

**A simple way to change that would be to do something else**. E.g. maybe instead calculate `spec_dir` as:

```
vec3 mirr_dir=reflect( ray_in, normal ), spec_dir;
do {
    spec_dir = normalize( mirr_dir + roughness*rand_unit_vec() );
} while ( dot(spec_dir,normal) < 0.0 );

```

That'll do a "fuzzy" specular reflection that's centered around the reflection direction and clipped (with rejection sampling) against the plane.

---

**However, I *do not* recommend you do this**.

First, a good specular BRDF *should* have this sort of biased-upward behavior, so this is a feature, not a bug. A more familiar but still basic example will be the Phong BRDF (which is centered around the reflection direction) and the Blinn–Phong BRDF (which has more upward bias). Although both BRDFs are obsolete for production purposes, the Blinn–Phong BRDF is widely considered to be superior for this biasing behavior—it leads to important perceptual effects like smearing out highlights lengthwise at glancing angles (see e.g. "[Crafting Physically Motivated Shading Models for Game Development](https://renderwonk.com/publications/s2010-shading-course/hoffman/s2010_physically_based_shading_hoffman_b.pdf)" for discussion and examples).

Second and more fundamentally, this is this is not a proper BRDF anyway and messing with its shape is not productive. It was broken before you started. Sampling the diffuse ray like this will not give you (e.g.) Lambertian, and this specular distribution is a poorly concealed blurred mirror. You would be much better with a microfacet model like you were thinking of doing—and it's not even that much more difficult to implement! Please just do that instead.


---

