3
\$\begingroup\$

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 ?

\$\endgroup\$
3
\$\begingroup\$

Eye adaptation is a separate process from tone mapping. As shown in the code, exposure can be adjusted by scaling the HDR image value by some factor before applying the tone curve. The *= 16 and the exposure bias are doing this. You would replace these factors with your eye adaptation value.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ So I shouldn't change "w" parameter, right ? How can I use an average and max luminance to adjust the exposure ? \$\endgroup\$ – Irbis Sep 30 '13 at 22:31
  • \$\begingroup\$ @Irbis You have the average/max luminance thing working already, with Reinhard, right? You might have to tweak some parameters to get it looking good with the new tone curve, but it would work the same way. \$\endgroup\$ – Nathan Reed Sep 30 '13 at 23:04
  • \$\begingroup\$ Average luminance (in the simplest case) or average luminance and max luminance are part of reinhard tone mapping operator so we get an automatic eye adaptation. Uncharted tone mapping operator doesn't include such informations and I wonder how can I achieve an eye adaptation in that case. \$\endgroup\$ – Irbis Sep 30 '13 at 23:48
  • \$\begingroup\$ @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. \$\endgroup\$ – Nathan Reed Oct 1 '13 at 0:34
  • \$\begingroup\$ That's right, so L contains average luminance which is dynamically computed. I don't achieve eye adaptation using Uncharted 2 tone mapping without dynamically scaling exposure. Maybe something like this would be fine: texColor *= averageLum. After that I can use a tone mapping operator. \$\endgroup\$ – Irbis Oct 1 '13 at 23:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.