0
$\begingroup$

I am implementing fresnel reflections for materials in my renderer.
According to this source, here the look I should obtain when rendering a sphere over a grey background:

enter image description here

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

IOR = 4
enter image description here

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

IOR = 4
enter image description here

IOR =4 but no Fresnel
enter image description here

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

Thanks for helping!

$\endgroup$
6
  • $\begingroup$ 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. $\endgroup$ Commented Sep 27, 2023 at 13:43
  • $\begingroup$ My implementation is a simplified version of what is done here: 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. $\endgroup$ Commented Sep 27, 2023 at 17:19
  • $\begingroup$ 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);} $\endgroup$
    – Tare
    Commented Sep 28, 2023 at 7:03
  • $\begingroup$ Hello, here what i get.: imgur.com/a/BGpt6bn $\endgroup$ Commented Sep 30, 2023 at 2:27
  • 1
    $\begingroup$ 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. $\endgroup$
    – pmw1234
    Commented Oct 2, 2023 at 12:18

0

Browse other questions tagged or ask your own question.