//
// Standard with cubemap+bumpmap (3 textures); HDR
// 26-03-09, RvG
//

float Fresnel(float bias,float scale,float power,float3 I,float3 N)
{
  float fresnel;
  // Fresnel (func!)
  //const float fresnelBias=0.15; //0.2;
  //const float fresnelScale=0.85; //0.9
  //const float fresnelPower=2.0; //4.0;
  //float3 I=normalize(IN.I);
  float dotIN=dot(I,N);
  // Avoid sharp edges
  //dotIN=min(dotIN,0.9);
  //dotIN=max(dotIN,-0.9);
  fresnel=bias+scale*pow(1.0+dotIN,power);
  // Avoid overblows
  fresnel=min(fresnel,0.95);
  return fresnel;
}

float3 FresnelMix(float3 diffCol,float3 envCol,float Kr,float fresnel)
// Mixing of diffuse & environment color based on fresnel
{
  float3 c=diffCol.rgb+envCol.rgb*Kr*fresnel;
  //c=min(c,100);
  return c;
}
