LYGIA Shader Library

fresnel (lygia/lighting/fresnel)

Resolve fresnel coeficient

Dependencies:

Use:

<float|vec3> fresnel(const <float|vec3> f0, <float> NoV)
<float|vec3> fresnel(const <float|vec3> f0, <float> NoV, float roughness)

Check it on Github




#ifndef FNC_FRESNEL
#define FNC_FRESNEL

vec3 fresnel(const in vec3 f0, vec3 normal, vec3 view) {
   return schlick(f0, 1.0, dot(view, normal));
}

vec3 fresnel(const in vec3 f0, const in float NoV) {
#if defined(TARGET_MOBILE) || defined(PLATFORM_RPI)
    return schlick(f0, 1.0, NoV);
#else
    float f90 = saturate(dot(f0, vec3(50.0 * 0.33)));
    return schlick(f0, f90, NoV);
#endif
}

float fresnel(const in float f0, const in float NoV) {
    return schlick(f0, 1.0, NoV);
}

// Roughness-adjusted fresnel function to attenuate high speculars at glancing angles
// Very useful when used with filtered environment maps
// See https://seblagarde.wordpress.com/2011/08/17/hello-world/
vec3 fresnel(vec3 f0, float NoV, float roughness) {
    return f0 + (max(vec3(1.0 - roughness), f0) - f0) * pow5(1.0 - NoV);
}

#endif

Dependencies:

Use:

<float3> fresnel(const <float3> f0, <float> NoV)
<float3> fresnel(const <float3> f0, <float> NoV, float roughness)

Check it on Github



#ifndef FNC_FRESNEL
#define FNC_FRESNEL

float3 fresnel(const in float3 f0, float3 normal, float3 view)
{
    return schlick(f0, 1.0, dot(view, normal));
}

float3 fresnel(const float3 f0, float NoV)
{
#if defined(TARGET_MOBILE) || defined(PLATFORM_RPI)
    return schlick(f0, 1.0, NoV);
#else
    float f90 = saturate(dot(f0, float3(50.0, 50.0, 50.0) * 0.33));
    return schlick(f0, f90, NoV);
#endif
}

float fresnel(const in float f0, const in float NoV)
{
    return schlick(f0, 1.0, NoV);
}

// Roughness-adjusted fresnel function to attenuate high speculars at glancing angles
// Very useful when used with filtered environment maps
// See https://seblagarde.wordpress.com/2011/08/17/hello-world/
float3 fresnel(float3 f0, float NoV, float roughness)
{
    return f0 + (max(1.0 - roughness, f0) - f0) * pow5(1.0-NoV);
}

#endif

Dependencies:

Check it on Github



fn fresnel(f0: f32, NoV: f32) -> f32 {
    return schlick(f0, 1.0, NoV);
}

Licenses

LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.

Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).

It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.

Get the latest news and releases

Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository