runtime LUT generation for Tonemapping

Hi

I want to generate, at the runtime, the 3D Texture for external tonemapping lut, but the result does not look right. after Appling the runtime lut, the intensity should be linear, but result in log curve shape.

The Doc for HDRP only explained how to use external software, like Photoshop to authoring the lut, but lack info for runtime lut. I noticed it says the lut should be a “log-encoded”, so I suspect that my runtime generated lut was linear without this log-encoding step, yet I don’t know what type of log-encoding HDRP needs. I tried sRGB encoding, but even worse.

Is anyone know about this issue, or other suggestions, It’ll be highly appreciated.

I tried an identity LUT in Tonemapping, it should have no effect, but to my suspicion that by using Tonemapping, the final framebuffer write somehow skipped sRGB encoding.

Here is the R,G,B measurement when Tonemapping turned off:

this is measured on an old CRT monitor by a spectroradiometer, becuase the framebuffer is written with sRGB encoding, so it counteracts with Gamma curve of the monitor, resulting a near linear response.

and here is the result after applying the identity LUT Tonemapping:

my idendity LUT is simply created in runtime by:

            var clut = new Texture3D(n, n, n, TextureFormat.RGB24, false);
            for (var r = 0; r < n; r++)
            {
                for (var g = 0; g < n; g++)
                {
                    for (var b = 0; b < n; b++)
                    {
                        clut.SetPixel(r, g, b, new Color(r/(n-1), g/(n-1), b/(n-1)));
                    }
                }
            }
            clut.Apply();
            return clut;

I should mention that the code works fine in the post-processing stack v2 for the build-in renderer before, as we used the flatten 256*16 runtime LDR lut in color grating.

7012996--829678--trinitron_raw1.png
7012996--829681--trinitron_raw1_corr1.png