Minimal AgX in GLSL, WITHOUT LUT.
Agx is a tone mapping transform that improves on Filmic, giving more photorealistic results. AgX offers 16.5 stops of dynamic range and unsaturates highly exposed colors to mimic film’s natural response to light[1].
Original AgX work with an 1D LUT which Length = 4096. It's too heavy for me. There are also some derived version use polynomial to fitting that LUT. However, it is evident that this will introduce errors. So I found the generation code for LUT and trying to understand the algorithm behind AgX. This process is not pleasant, because AgX use tunable sigmoid function and hundreds of lines of code to structure the tone mapping curve. But there are still traces to follow.
So, This is the analytical formula of AgX. This is not an approximate value, but an exact value. The complexity of expressions mainly comes from coefficients, and the computational cost in real-time rendering is actually acceptable (At least better than a lookup table). The coefficients have been calculated as machine precision floating-point numbers, some of them came from original AgX, some of them, some of them were calculated by me using Wolfram Mathematica. The significant digits of all coefficients exceed single precision floating-point numbers.
- About
agx_mat
. I re derived the AgX color space matrix and found there is a little difference between origin version and my version. I think (but not sure) that is because I use high-precision to compute this matrix. Anyway, this error is very small. - About sRGB. In practice, there is still debate and confusion around whether sRGB data should be displayed with pure 2.2 gamma as defined in the standard, or with the inverse of the OETF. So I provided both versions.
- LookTransform: "Golden", "Punchy"