const float MIDDLE_GREY = 0.52;
const float FUDGE = 0.001;
const float L_WHITE = 1.4;
const float MAX_LUM = 0.4;
const float MIN_LUM = 0.2;

/** Tone mapping function 
@note Only affects rgb, not a
@param inColour The HDR colour
@param lum The scene lumninence 
@returns Tone mapped colour
*/
vec4 toneMap(in vec4 inColour, in float lum)
{
	if (lum > MAX_LUM) {
		lum = MAX_LUM;
	}
	if (lum < MIN_LUM) {
		lum = MIN_LUM;
	}
	// From Reinhard et al
	// "Photographic Tone Reproduction for Digital Images"
	// Initial luminence scaling (equation 2)
    inColour.rgb *= MIDDLE_GREY / (FUDGE + lum);
	vec4 orgColour = inColour;
	// Control white out (equation 4 nom)
    inColour.rgb *= (1.0 + inColour.rgb / L_WHITE);
	

	// Final mapping (equation 4 denom)
	inColour.rgb /= (1.0 + orgColour.rgb);
	
	return inColour;

}


