summaryrefslogtreecommitdiffstats
path: root/res/effectlib/defaultMaterialFresnel.glsllib
blob: 0d474bc7950fea391b8894e8757e899367b0d6a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#ifndef DEFAULT_MATERIAL_FRESNEL_GLSLLIB
#define DEFAULT_MATERIAL_FRESNEL_GLSLLIB

float defaultMaterialSimpleFresnel( in vec3 N, in vec3 viewDir, in float ior, float fresnelPower )
{
    float F = ((1.0-ior) * (1.0-ior)) / ((1.0+ior) * (1.0+ior));
    float VdotN = dot(viewDir, N);
    float dvn = abs( dFdx(VdotN) * dFdy(VdotN) );
    VdotN = clamp( VdotN, 0.0, 1.0 );
    float ratio = F + (1.0 - F) * pow(1.0 - VdotN, fresnelPower);

    return clamp( ratio * pow( VdotN, dvn * fresnelPower ), 0.0, 1.0 );
}

#endif