question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"gamma correction" name as opposed to linear-to-sRGB

See original GitHub issue

The conversion from sRGB to linear is approximated here with:

// sRGB to linear approximation
// see http://chilliant.blogspot.com/2012/08/srgb-approximations-for-hlsl.html
vec4 SRGBtoLINEAR(vec4 srgbIn)
{
    return vec4(pow(srgbIn.xyz, vec3(u_Gamma)), srgbIn.w);
}

The normal approximation uses 2.2 as the gamma, but this viewer allows the user to change this value as u_Gamma, without making it clear that it’s meant to be a transfer function approximation value as opposed to artistic discretion.

Later, the color needs to be transformed back the other way, from linear back to sRGB. The function to do this is called gamma correction, with some comments reinforcing the idea that this is meant to be artistic discretion, when really it is being used as an approximation of a transfer function.

// Gamma Correction in Computer Graphics
// see https://www.teamten.com/lawrence/graphics/gamma/
vec3 gammaCorrection(vec3 color)
{
    return pow(color, vec3(1.0 / u_Gamma));
}

I propose that gammaCorrection should be renamed to LINEARtoSRGB or similar, with comments updated accordingly. Further I propose that the user should not have control over the existing u_Gamma value, at least in these transfer function approximations. (There could be a different debate over whether an artistic gamma correction is desired, separately from these transfer functions).

/cc KhronosGroup/glTF#1609

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
lexaknyazevcommented, May 10, 2019

Performing sRGB-to-linear conversion in a fragment shader is technically wrong because it would happen after filtering. The proper way is to use hardware conversion that is available with EXT_sRGB or WebGL 2.0. Also, it cannot be configurable (at least in this direction).

2reactions
bghgarycommented, May 10, 2019

Babylon.js has the same issue as @lexaknyazev pointed out here. I’m all for fixing it here and in Babylon.js, but it’s likely not going to make a big impact on the visuals.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding sRGB and gamma corrected values in the ...
I'm trying to get a firm understanding of working in linear color space - not just the theory and definitions, but the underlying...
Read more >
What every coder should know about gamma | John Novak
What is gamma and why do we need it? Light emission vs perceptual brightness; Physical vs perceptual linearity; Efficient image encoding; The ...
Read more >
Apply gamma correction to linear RGB values - MATLAB lin2rgb
This MATLAB function applies a gamma correction to the linear RGB values in image A so that B is in the sRGB color...
Read more >
What are the practical differences when working with colors in ...
Gamma correction means transforming the colors you start with (probably linear) and transforming them for the gamma of the user's CRT.
Read more >
Working with linear Textures - Unity - Manual
This prevents values from the sampled Texture having non-existent gamma correction removed before they are used in the Shader, with calculations made with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found