[x3d-public] Gamma correction in X3D and glTF

Andreas Plesch andreasplesch at gmail.com
Mon Jan 20 12:55:17 PST 2020


Thanks for this nice summary.

Here is what the default shader for x3dom does:

First it decodes Gamma:

https://github.com/x3dom/x3dom/blob/810d5cd36f766bd9161f79881cab24dc6771aba5/src/shader/ShaderDynamic.js#L818

but only for textures, judging from the shader code. So this behaviour
seems to follow the glTF convention of treating textures differently
from straight color values.

Decoding means pow(color, 2,2):

https://github.com/x3dom/x3dom/blob/b27bda43ee1662bb7cf3488d16051477a99d7601/src/shader/ShaderParts.js#L183

Then it goes through lighting and at the very end it encodes again:

https://github.com/x3dom/x3dom/blob/810d5cd36f766bd9161f79881cab24dc6771aba5/src/shader/ShaderDynamic.js#L1270

encoding means pow(color, 1/2.2). This is applied regardless of the
origin of the color.

Tonemapping happens before encoding but applying fog happens after
encoding, as the very very last step. Tonemapping seems to be a way to
bring out colors in High Dynamic Range source images.

Monitor color calibration by colorimetry and OS level color
adjustments (color management) all also exist but have to be assumed
to be set up as truthful as possible.

I remember seeing long discussions about the linear workflow in the
glTF github issues section but I think they have settled down. I think
one aspect is that the PBR rendering equations assume that their input
is gamma corrected, "linear".

I am not sure if it was a good idea have 'linear' as the default gamma
correction in x3dom since most existing scenes were tuned, either
automatically or manually, to look correct already, without gamma
correction. Perhaps textures from linear workflows were already
decoded/altered to look better.

-Andreas


> Date: Sun, 19 Jan 2020 21:31:17 +0100
> From: Michalis Kamburelis <michalis.kambi at gmail.com>
> To: X3D Graphics public mailing list <x3d-public at web3d.org>
> Subject: [x3d-public] Gamma correction in X3D and glTF
> Message-ID:
>         <CAKzBGZPuG=-c1vN0zuifR68RccWmgY103mp-5ZBnd+XCzkYd3Q at mail.gmail.com>
> Content-Type: text/plain; charset="UTF-8"
>
> Hi,
>
> I was following information about gamma correction from the other
> thread, in particular information from Andreas Plesch about what X3DOM
> does (thank you -- your mention of X3DOM + gamma correction was
> incredibly important for me, it jump-started a small reading session
> after which I'm hopefully smarter :) )...
>
> I looked at glTF specification and sample implementation, in regards
> "what do they say about gamma-correction".
>
> I collected my conclusions on
> https://github.com/michaliskambi/x3d-tests/wiki/Gamma-correction-in-X3D-and-glTF
> . Comments are of course welcome.
>
> A summary, along with notes "what to do in X3D spec (4.0 or future
> spec version)" are at the bottom.
>
> Regards,
> Michalis

-- 
Andreas Plesch
Waltham, MA 02453



More information about the x3d-public mailing list