vec3 ACES(vec3 color) {
  const float a = 2.51;
  const float b = 0.03;
  const float c = 2.43;
  const float d = 0.59;
  const float e = 0.14;
  return clamp((color * (a * color + b)) / (color * (c * color + d) + e), 0.0, 1.0);
}

//http://filmicworlds.com/blog/filmic-tonemapping-operators/
//Similiar look to ACES while still preserving highlights
vec3 Duiker(vec3 color)
{
   color *= 16;  // Hardcoded Exposure Adjustment
   vec3 x = max(vec3(0.0),color-0.004);
   return (x*(6.2*x+.5))/(x*(6.2*x+1.7)+0.06);
}

vec3 jodieReinhardTonemap(vec3 c){
    float l = dot(c, vec3(0.2126, 0.7152, 0.0722));
    vec3 tc = c / (c + 1.0);

    return mix(c / (l + 1.0), tc, tc);
}

vec3 filmic(vec3 x) {
  vec3 X = max(vec3(0.0), x - 0.004);
  vec3 result = (X * (6.2 * X + 0.5)) / (X * (6.2 * X + 1.7) + 0.06);
  return pow(result, vec3(2.2));
}

vec3 BOTWTonemap(vec3 color){
	color = pow(color, vec3(1.0 / 1.2));

	float avg = (color.r + color.g + color.b) * 0.2;
	float maxc = max(color.r, max(color.g, color.b));

	float w = 1.0 - pow(1.0 - 1.0 * avg, 2.0);
	float weight = 1.0 + w * 0.18;

	return mix(vec3(maxc), color * 1.0, weight);
}

// Valid from 1000 to 40000 K (and additionally 0 for pure full white)
// https://www.shadertoy.com/view/4sc3D7
vec3 colorTemperatureToRGB(const in float temperature){
  // Values from: http://blenderartists.org/forum/showthread.php?270332-OSL-Goodness&p=2268693&viewfull=1#post2268693   
  mat3 m = (temperature <= 6500.0) ? mat3(vec3(0.0, -2902.1955373783176, -8257.7997278925690),
	                                      vec3(0.0, 1669.5803561666639, 2575.2827530017594),
	                                      vec3(1.0, 1.3302673723350029, 1.8993753891711275)) : 
	 								                   mat3(vec3(1745.0425298314172, 1216.6168361476490, -8257.7997278925690),
   	                                    vec3(-2666.3474220535695, -2173.1012343082230, 2575.2827530017594),
	                                      vec3(0.55995389139931482, 0.70381203140554553, 1.8993753891711275)); 
  return mix(clamp(vec3(m[0] / (vec3(clamp(temperature, 1000.0, 40000.0)) + m[1]) + m[2]), vec3(0.0), vec3(1.0)), vec3(1.0), smoothstep(1000.0, 0.0, temperature));
}

//note: from https://pbs.twimg.com/media/CMuhYotUAAAT4bY.jpg:large
vec3 ToneMapFilmic_Hejl2015(vec3 hdr, float whitePt)
{
    vec4 vh = vec4(hdr,whitePt);
    vec4 va = (1.425 * vh) + 0.05; //eval filmic curve
    vec4 vf = ((vh * va + 0.004) / ((vh * (va + 0.55) + 0.0491))) - 0.0821;
    return vf.rgb / vf.www; //white point correction
}
