Various online sources talk in sufficient detail about gamma correction. By following them, I achieved a rendering pipeline that looks somewhat like this:

// Both are set to 2.2
uniform float gammaIn;
uniform float gammaOut;

void main()
    vec3 color = pow(texture(material.albedo, texCoord).rgb, vec3(gammaIn));
    // Do lighting and then HDR tone mapping here.
    //   color = ...
    FragColor = pow(color, vec3(1.0 / gammaOut));

That is the easy part.

Now, many games implement the gamma correction adjustment slider that is meant to accommodate for display differences in various monitors that players may have. This presents some questions that I couldn't find any definitive answer to:

  1. Which value should the adjustment slider affect? I reckon it will be gammaOut because gammaIn deals with decoding of the sRGB picture and assuming that all textures are sRGB, this should always be the const 2.2. With this approach a lower gammaOut means darker picture.

  2. What's the reasonable value range for the slider? Should it start at 1.0 or somewhere higher? Where should it end?

  3. If I were to display the "barely visible / invisible" comparison combo picture to help the user with doing the adjustment correctly, what should be the color values for the "should be barely visible" dark picture and its background and ditto for the "should be invisible" bright picture and its background?

  • 1
    \$\begingroup\$ You probably don't want to apply your basic sRGB gamma in your shader as shown here. Use the hardware instead. You can configure your sampler state to read an sRGB texture and return the value to your shader in linear RGB, and similarly configure your writing state to take a linear RGB output from your shader and convert it to sRGB to write into the buffer. This ensures you get the correct sRGB adjustment (including the linear segment for very low values) and may be optimized in hardware vs. an arbitrary power function. \$\endgroup\$
    – DMGregory
    Feb 20 '20 at 21:29
  • \$\begingroup\$ @DMGregory yes I know that, I use the current solution as "good enough" for the time being and try to solve the difficult problems first. This also wouldn't bring me closer to the slider solution. I believe it would actually put me farther away, because I would no longer have any control over the final calculation. \$\endgroup\$
    – ZalewaPL
    Feb 20 '20 at 21:52

Your Answer

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

Browse other questions tagged or ask your own question.