// Copyright (C) 2014 NVIDIA Corporation.
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#ifndef DEFAULT_MATERIAL_FRESNEL_GLSLLIB
#define DEFAULT_MATERIAL_FRESNEL_GLSLLIB

float qt_dielectricSpecular(in float ior)
{
    return ((1.0-ior) * (1.0-ior)) / ((1.0+ior) * (1.0+ior));
}

vec3 qt_defaultMaterialSimpleFresnel(in vec3 baseColor, in float metalness, in vec3 N, in vec3 viewDir,
                                     in float ds, float fresnelPower)
{
    vec3 dielectricColor = vec3(ds);
    vec3 F = mix(dielectricColor, baseColor, metalness);
    float VdotN = max(dot(viewDir, N), 0.0);
    return F + (vec3(1.0) - F) * pow(1.0 - VdotN, fresnelPower);
}

vec3 qt_defaultMaterialSimpleFresnelNoMetalness(in vec3 N, in vec3 viewDir,
                                                in float ds, float fresnelPower)
{
    vec3 F = vec3(ds);
    float VdotN = max(dot(viewDir, N), 0.0);
    return F + (vec3(1.0) - F) * pow(1.0 - VdotN, fresnelPower);
}


#endif
