//
// Basic HDR functions
// RvG, 11-3-09
//

float4 ToneMapHDR(float4 color,float exposure)
// Exponential (more contrast than L=L/(L+1)
{
  //return color;
  return 1.0-exp(-exposure*color);
}
float4 ToneMapHDR0(float4 color,float exposure)
// Easy trick
{
  return color/(color+1.0);
}

float4 ToneMapHDR1(float4 color,float exposure)
{
  // Currently unchanged (LDR)
  // Future: map HDR color to LDR color
  return color;
}

float4 ToneMapHDR2(float4 color,float exposure)
// Simple mapping from 0..inf -> 0..1
// Darkens image but bright colors remain visible
{
  float4 c;
  
  c.r=color.r/(color.r+1.0);
  c.g=color.g/(color.g+1.0);
  c.b=color.b/(color.b+1.0);
  c.a=color.a;
  return c;
}

float4 ToneMapHDR3(float4 color,float exposure)
// Simple mapping from 0..inf -> 0..1
// Darkens image but bright colors remain visible
{
  float4 c;

  c=color*0.5;
  c.a=1;
  return c;
}

float4 ToneMapHDR4(float4 color,float exposure)
// Exponential diminish
{
  return 1.0-exp(-exposure*color);
}

float4 ToneMapHDR5(float4 color,float exposure)
// From HDRRenderingInOpenGL.pdf
{
  float Y = dot(vec4(0.30, 0.59, 0.11, 0.0), color);
  float YD = exposure * (exposure/brightMax + 1.0) / (exposure + 1.0);
  color *= YD;
  return color;
}
