vec3 TonemapReinhard(vec3 color)
{
    return color / (1.0 + color);
}

vec3 TonemapReinhardWhite(vec3 color, float whitePoint)
{
    return (color * (1.0 + color / (whitePoint * whitePoint))) /
           (1.0 + color);
}

vec3 TonemapACES(vec3 x)
{
    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((x*(a*x+b))/(x*(c*x+d)+e),0.0,1.0);
}


vec3 Tonemap(vec3 color)
{
#if TONEMAPPER == TONEMAP_REINHARD
    return TonemapReinhard(color);

#elif TONEMAPPER == TONEMAP_ACES
    return TonemapACES(color);


#elif TONEMAPPER == TONEMAP_WHITE
    return TonemapReinhardWhite(color,4.0);

#else
    return color;
#endif
}