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:
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
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:
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:
Thanks for helping!
RGBFColor Evaluate_Brdf(){const float F0 = ComputeFresnel0(ior); const float F = ComputeFresnel(F0, distSampleInput.NoV); return RGBFColor(F);}
$\endgroup$