# Uncharted 2 tone mapping and an eye adaptation

I found an example of uncharted 2 tone mapping on this site. Here is the code:

float A = 0.15;
float B = 0.50;
float C = 0.10;
float D = 0.20;
float E = 0.02;
float F = 0.30;
float W = 11.2;

float3 Uncharted2Tonemap(float3 x)
{
return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;
}

float4 ps_main( float2 texCoord  : TEXCOORD0 ) : COLOR
{
float3 texColor = tex2D(Texture0, texCoord );
texColor *= 16;  // Hardcoded Exposure Adjustment
float ExposureBias = 2.0f;
float3 curr = Uncharted2Tonemap(ExposureBias*texColor);
float3 whiteScale = 1.0f/Uncharted2Tonemap(W);
float3 color = curr*whiteScale;
float3 retColor = pow(color,1/2.2);
return float4(retColor,1);
}


I use Reinhard tone mapping. I calculate an average luminance and max luminance in screen space. Based on those parameters I get an eye adaptation, for example when a camera is moved from a bright outdoor area to the dark room. How an eye adaptation process is achieved in Uncharted 2 tone mapping ? In my engine I render results of the shading to the floating point texture. I assume that I don’t need hardcoded exposure adjustment (texColor *= 16) and exposure bias = 2.0f. Or maybe I should interpret those parameters based on the average luminance ? What about “w” parameter ? Can I assign to “w” a maximum luminance from the screen space ?

• @Irbis The Reinhard tone mapping operator is just L / (1 + L) (equation 3 in the paper). That's the part you replace with the Uncharted tone mapping operator. The Reinhard paper also shows how to prescale the luminances based on an adaptation value (equation 2). That part you would leave alone. – Nathan Reed Oct 1 '13 at 0:34