Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualChris_F

Posted 24 February 2013 - 04:22 AM

If you want to compare fresnel approximations you can use this:

 

 

analytic

::begin parameters
color Specular 1 1 1
float SpecularScale 0 0.999 .028
bool Schlick 0
::end parameters

::begin shader

vec3 Fresnel(float CosTheta, vec3 Ks)
{
    vec3 n2 = (1.0 + sqrt(Ks)) / (1.0 - sqrt(Ks));
    vec3 SinTheta = sqrt(1 - CosTheta * CosTheta);

    vec3 SinThetaT = SinTheta / n2;
    vec3 CosThetaT = sqrt(1 - SinThetaT * SinThetaT);

    vec3 n2CosThetaT = n2 * CosThetaT;
    vec3 n2CosTheta = n2 * CosTheta;

    vec3 RsSqrt = (CosTheta - n2CosThetaT) / (CosTheta + n2CosThetaT);
    vec3 Rs = RsSqrt * RsSqrt;

    vec3 RpSqrt = (n2CosTheta - CosThetaT) / (n2CosTheta + CosThetaT);
    vec3 Rp = RpSqrt * RpSqrt;

    return (Rs + Rp) / 2;
}

vec3 BRDF( vec3 L, vec3 V, vec3 N, vec3 X, vec3 Y )
{
    vec3 Ks = Specular * SpecularScale;

    float NdotV = dot(N, V);

    vec3 Full = Fresnel(NdotV, Ks);

    vec3 Fs;

    if(Schlick)
        Fs = Ks + (1 - Ks) * pow(1.0 - NdotV, 5);
    else
        Fs = Ks + (1 - Ks) * exp(-6 * NdotV);

    return abs(Full - Fs);
}

::end shader

#2Chris_F

Posted 24 February 2013 - 04:21 AM

If you want to compare fresnel approximations you can use this:

 

 

analytic

::begin parameters
color Specular 1 1 1
float SpecularScale 0 0.999 .028
bool Schlick 0
::end parameters

::begin shader

vec3 Fresnel(float CosTheta, vec3 Ks)
{
    vec3 n2 = (1.0 + sqrt(Ks)) / (1.0 - sqrt(Ks));
    vec3 SinTheta = sqrt(1 - CosTheta * CosTheta);

    vec3 SinThetaT = SinTheta / n2;
    vec3 CosThetaT = sqrt(1 - SinThetaT * SinThetaT);


    vec3 n2CosThetaT = n2 * CosThetaT;
    vec3 n2CosTheta = n2 * CosTheta;

    vec3 RsSqrt = (CosTheta - n2CosThetaT) / (CosTheta + n2CosThetaT);
    vec3 Rs = RsSqrt * RsSqrt;

    vec3 RpSqrt = (n2CosTheta - CosThetaT) / (n2CosTheta + CosThetaT);
    vec3 Rp = RpSqrt * RpSqrt;

    return (Rs + Rp) / 2;
}

vec3 BRDF( vec3 L, vec3 V, vec3 N, vec3 X, vec3 Y )
{
    vec3 Ks = Specular * SpecularScale;

    float NdotV = dot(N, V);

    vec3 Full = Fresnel(NdotV, Ks);

    vec3 Fs;

    if(Schlick)
        Fs = Ks + (1 - Ks) * pow(1.0 - NdotV, 5);
    else
        Fs = Ks + (1 - Ks) * exp(-6 * NdotV);

    return abs(Full - Fs);
}

::end shader

#1Chris_F

Posted 24 February 2013 - 04:20 AM

If you want to compare fresnel approximations you can use this:

 

analytic

::begin parameters
color Specular 1 1 1
float SpecularScale 0 0.999 .028
bool Schlicks 0
::end parameters

::begin shader

vec3 Fresnel(float CosTheta, vec3 Ks)
{
    vec3 n2 = (1.0 + sqrt(Ks)) / (1.0 - sqrt(Ks));
    vec3 SinTheta = sqrt(1 - CosTheta * CosTheta);

    vec3 SinThetaT = SinTheta / n2;
    vec3 CosThetaT = sqrt(1 - SinThetaT * SinThetaT);


    vec3 n2CosThetaT = n2 * CosThetaT;
    vec3 n2CosTheta = n2 * CosTheta;

    vec3 RsSqrt = (CosTheta - n2CosThetaT) / (CosTheta + n2CosThetaT);
    vec3 Rs = RsSqrt * RsSqrt;

    vec3 RpSqrt = (n2CosTheta - CosThetaT) / (n2CosTheta + CosThetaT);
    vec3 Rp = RpSqrt * RpSqrt;

    return (Rs + Rp) / 2;
}

vec3 BRDF( vec3 L, vec3 V, vec3 N, vec3 X, vec3 Y )
{
    vec3 Ks = Specular * SpecularScale;

    float NdotV = dot(N, V);

    vec3 Full = Fresnel(NdotV, Ks);

    vec3 Fs;

    if(Schlicks)
        Fs = Ks + (1 - Ks) * pow(1.0 - NdotV, 5);
    else
        Fs = Ks + (1 - Ks) * exp(-6 * NdotV);

    return abs(Full - Fs);
}

::end shader

PARTNERS