<p>I am implementing fresnel reflections for materials in my renderer.<br />
According to this <a href="https://learnopengl.com/PBR/Theory" rel="nofollow noreferrer">source</a>, here the look I should obtain when rendering a sphere over a grey background:</p>
<p><a href="https://i.sstatic.net/kzYVo.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/kzYVo.jpg" alt="enter image description here" /></a></p>
<p><strong>I have two implementations</strong>. One of them is based on Cook Torrance model.<br />
The implementations use theses helper functions:</p>
<pre><code>float ComputeFresnel0(float ior)
{
    // @See: https://graphicscompendium.com/raytracing/11-fresnel-beer
    return std::powf((ior - 1.0f ) / (ior + 1.0f), 2.0f);
}

float ComputeFresnel(float F0, float NoV)
{
    // @See: https://graphicscompendium.com/raytracing/11-fresnel-beer
    return F0 + (1.0f - F0) * pow(1.0f - NoV, 5.0f);
}

float BlinnPhong(const SampleInput&amp; input, float shininess)
{
    //@See: https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_reflection_model
    return std::pow(input.HoN, shininess);
}
</code></pre>
<p>In term of output, here what i obtain:</p>
<p><strong>NO COOK-TORRANCE, I get this</strong>:<br />
<em>IOR = 1</em><br />
<a href="https://i.sstatic.net/9jEMm.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/9jEMm.jpg" alt="enter image description here" /></a></p>
<p><em>IOR = 4</em><br />
<a href="https://i.sstatic.net/97F1n.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/97F1n.jpg" alt="enter image description here" /></a></p>
<p>Source code:</p>
<pre><code>RGBFColor Evaluate_Brdf(const DistributionFunction::SampleInput&amp; distSampleInput, float ior)
{
    // No diffuse. We are only interested in specular.
    RGBFColor diffuse = RGBFColor(0.0f);

    // Specular.
    RGBFColor specular = RGBFColor(1.0f);
    {
        const float F0 = ComputeFresnel0(ior);
        const float F = ComputeFresnel(F0, distSampleInput.NoV);

        static const float shininesss = 256.0f;
        const float specularFactor = F * BlinnPhong(distSampleInput, shininesss);

        specular *= specularFactor;
    }

    return (diffuse + specular) * distSampleInput.NoL; //  Multiply by NoL here for purpose;
}
</code></pre>
<p><strong>WITH COOK-TORRANCE, I get this</strong>:</p>
<p><em>IOR = 1</em><br />
<a href="https://i.sstatic.net/elXfs.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/elXfs.jpg" alt="enter image description here" /></a></p>
<p><em>IOR = 4</em><br />
<a href="https://i.sstatic.net/xH29d.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/xH29d.jpg" alt="enter image description here" /></a></p>
<p><em>IOR =4 but no Fresnel</em><br />
<a href="https://i.sstatic.net/qxjbx.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/qxjbx.jpg" alt="enter image description here" /></a></p>
<p>Source code:</p>
<pre><code>RGBFColor Evaluate_Brdf(const DistributionFunction::SampleInput&amp; distSampleInput, float ior)
{
    // No diffuse. We are only interested in specular.
    RGBFColor diffuse = RGBFColor(0.0f);

    // Specular.
    RGBFColor specular = RGBFColor(1.0f);
    {
        const float F0 = ComputeFresnel0(ior);
        const float F = ComputeFresnel(F0, distSampleInput.NoV);

        static const float shininesss = 256.0f;
        float specularFactor = F * BlinnPhong(distSampleInput, shininesss);

        // Cook Torrance.
        specularFactor /= (4.0f * distSampleInput.HoV * distSampleInput.NoL);

        specular *= specularFactor;
    }

    return (diffuse + specular) * distSampleInput.NoL; //  Multiply by NoL here for purpose;
}
</code></pre>
<p><strong>As you can see the version with the Cook-Torrance division has the fresnel effect, even without the fresnel term. What I am doing wrong? I outputted the following values to debug:</strong></p>
<p><a href="https://i.sstatic.net/125ac.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/125ac.jpg" alt="enter image description here" /></a></p>
<p>Thanks for helping!</p>

CC BY-SA 4.0
2023-09-27T13:43:28.337Z
Can you post the reference of your implementation? I was having a hard time figuring out what kind of BRDF model you are implementing, it looks like FresnelBlend but there are several terms missing, making the code looks not so physically based.
Enigmatisms
CC BY-SA 4.0
2023-09-27T17:19:39.347Z
My implementation is a simplified version of what is done here:  
https://learnopengl.com/PBR/Theory.

There are the following differences:  

1) I do not use the geometric term of the CookTorrance model(even when i use it it 
   doesnt change much).  

2) The NDF I use is Blinn-Phong.
TheChamp
CC BY-SA 4.0
2023-09-28T07:03:09.693Z
I assume the first image you (re)posted from LeanOpenGL is _only_ the reflection calculated through the Schlick approximation. Your images seem to include the shininess though. So for now, just render out the Fresnel term: `RGBFColor Evaluate_Brdf(){const float F0 = ComputeFresnel0(ior); const float F = ComputeFresnel(F0, distSampleInput.NoV); return RGBFColor(F);}`
Tare
CC BY-SA 4.0
2023-09-30T02:27:18.070Z
Hello, here what i get.:
https://imgur.com/a/BGpt6bn
TheChamp
CC BY-SA 4.0
2023-10-02T12:18:05.727Z
Is plain old Blinn-Phong specular shading working correctly in this render? Verifying 
 Blinn-Phong is an important step because it verifies that the normal and half way vector are correct and only takes a few minutes to setup and test.
pmw1234
CC BY-SA 4.0
2023-11-18T22:48:51.487Z
The first image from LearnOpenGL is indeed the Fresnel term alone. Your rendering of it (on Imgur) looks a little sketchy, but plausible. I think if there's a problem here, it might be with the rest of the BRDF, not the Fresnel, in which case this question needs a serious refactor. Incidentally, just use the real Fresnel term—Schlick's approximation is limiting, for not being much faster (especially if you're using actual `pow`).
geometrian
<brdf><pbr><specular><fresnel>
Unable to compute fresnel reflections properly
TheChamp
# Unable to compute fresnel reflections properly

(Asked by: username_0 on 2023-09-27)

I am implementing fresnel reflections for materials in my renderer.  
According to this [source](https://learnopengl.com/PBR/Theory), here the look I should obtain when rendering a sphere over a grey background:

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

**I have two implementations**. One of them is based on Cook Torrance model.  
The implementations use theses helper functions:

```
float ComputeFresnel0(float ior)
{
    // @See: https://graphicscompendium.com/raytracing/11-fresnel-beer
    return std::powf((ior - 1.0f ) / (ior + 1.0f), 2.0f);
}

float ComputeFresnel(float F0, float NoV)
{
    // @See: https://graphicscompendium.com/raytracing/11-fresnel-beer
    return F0 + (1.0f - F0) * pow(1.0f - NoV, 5.0f);
}

float BlinnPhong(const SampleInput& input, float shininess)
{
    //@See: https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_reflection_model
    return std::pow(input.HoN, shininess);
}

```

In term of output, here what i obtain:

**NO COOK-TORRANCE, I get this**:  
*IOR = 1*  
[![enter image description here](https://i.sstatic.net/9jEMm.jpg)](https://i.sstatic.net/9jEMm.jpg)

*IOR = 4*  
[![enter image description here](https://i.sstatic.net/97F1n.jpg)](https://i.sstatic.net/97F1n.jpg)

Source code:

```
RGBFColor Evaluate_Brdf(const DistributionFunction::SampleInput& distSampleInput, float ior)
{
    // No diffuse. We are only interested in specular.
    RGBFColor diffuse = RGBFColor(0.0f);

    // Specular.
    RGBFColor specular = RGBFColor(1.0f);
    {
        const float F0 = ComputeFresnel0(ior);
        const float F = ComputeFresnel(F0, distSampleInput.NoV);

        static const float shininesss = 256.0f;
        const float specularFactor = F * BlinnPhong(distSampleInput, shininesss);

        specular *= specularFactor;
    }

    return (diffuse + specular) * distSampleInput.NoL; //  Multiply by NoL here for purpose;
}

```

**WITH COOK-TORRANCE, I get this**:

*IOR = 1*  
[![enter image description here](https://i.sstatic.net/elXfs.jpg)](https://i.sstatic.net/elXfs.jpg)

*IOR = 4*  
[![enter image description here](https://i.sstatic.net/xH29d.jpg)](https://i.sstatic.net/xH29d.jpg)

*IOR =4 but no Fresnel*  
[![enter image description here](https://i.sstatic.net/qxjbx.jpg)](https://i.sstatic.net/qxjbx.jpg)

Source code:

```
RGBFColor Evaluate_Brdf(const DistributionFunction::SampleInput& distSampleInput, float ior)
{
    // No diffuse. We are only interested in specular.
    RGBFColor diffuse = RGBFColor(0.0f);

    // Specular.
    RGBFColor specular = RGBFColor(1.0f);
    {
        const float F0 = ComputeFresnel0(ior);
        const float F = ComputeFresnel(F0, distSampleInput.NoV);

        static const float shininesss = 256.0f;
        float specularFactor = F * BlinnPhong(distSampleInput, shininesss);

        // Cook Torrance.
        specularFactor /= (4.0f * distSampleInput.HoV * distSampleInput.NoL);

        specular *= specularFactor;
    }

    return (diffuse + specular) * distSampleInput.NoL; //  Multiply by NoL here for purpose;
}

```

**As you can see the version with the Cook-Torrance division has the fresnel effect, even without the fresnel term. What I am doing wrong? I outputted the following values to debug:**

[![enter image description here](https://i.sstatic.net/125ac.jpg)](https://i.sstatic.net/125ac.jpg)

Thanks for helping!

**Tags:** brdf, pbr, specular, fresnel

> **Comments:**
> **username_1**: Can you post the reference of your implementation? I was having a hard time figuring out what kind of BRDF model you are implementing, it looks like FresnelBlend but there are several terms missing, making the code looks not so physically based.  
> **username_0**: My implementation is a simplified version of what is done here:   https://learnopengl.com/PBR/Theory.  There are the following differences:    1) I do not use the geometric term of the CookTorrance model(even when i use it it     doesnt change much).    2) The NDF I use is Blinn-Phong.  
> **username_2**: I assume the first image you (re)posted from LeanOpenGL is _only_ the reflection calculated through the Schlick approximation. Your images seem to include the shininess though. So for now, just render out the Fresnel term: `RGBFColor Evaluate_Brdf(){const float F0 = ComputeFresnel0(ior); const float F = ComputeFresnel(F0, distSampleInput.NoV); return RGBFColor(F);}`  
> **username_0**: Hello, here what i get.: https://imgur.com/a/BGpt6bn  
> **username_3**: Is plain old Blinn-Phong specular shading working correctly in this render? Verifying   Blinn-Phong is an important step because it verifies that the normal and half way vector are correct and only takes a few minutes to setup and test.  
> **username_4**: The first image from LearnOpenGL is indeed the Fresnel term alone. Your rendering of it (on Imgur) looks a little sketchy, but plausible. I think if there's a problem here, it might be with the rest of the BRDF, not the Fresnel, in which case this question needs a serious refactor. Incidentally, just use the real Fresnel term—Schlick's approximation is limiting, for not being much faster (especially if you're using actual `pow`).  

---

## 0 answers

