Facepunch / sbox-issues

175 stars 12 forks source link

Tone mapping is always applied? #6111

Open chanoc1 opened 3 months ago

chanoc1 commented 3 months ago

Describe the bug

It seems like tone mapping is always applied, even if it's commented out in ColorGrading.shader -- and the debug views also seem to receive tone mapping.

To Reproduce

  1. Add a Camera and PostProcess component to a GameObject.
  2. Make sure the PostProcess's mode is set to anything but "Legacy."
  3. Make a copy of s&box's shader, ColorGrading.shader, and place it in the project's shaders directory.
  4. In ColorGrading.shader, comment out lines 452-456, to skip the tonemapping part of the shader entirely.
    //        #if ( D_TONEMAPPING != TONEMAPPING_NONE )
    //        {
    //            ApplyTonemapping( color );
    //        }
    //        #endif
  5. Observe that an unlit (using generic shader, with "Unlit" box checked) material's colors aren't 1:1 with it's texture.
  6. Observe that the background's color also does not match the Camera's "Background Color" set in the inspector.

Expected behavior

With no tone mapping or post-processing, I expect an unlit material's colors to be the same as it's texture, and for the background color to match the value displayed in the inspector.

Media/Files

Model with an unlit material (using generic shader, with "Unlit" box checked) and a flat color background for testing.

Albedo view mode with tone mapping disabled as per step 4. Everything looks good, colors are fine. image

Lit view mode, with tone mapping still disabled as per step 4. Note how colors on the unlit material and the background have been affected. image

Albedo view mode with no shader edit. Note how colors in this mode are affected by tonemapping. image

Additional context

I might be reporting two issues in one. It seems like there's always some tone mapping happening regardless of the Tone Map component and ColorGrading shader -- and in addition, tone mapping is being applied to the debug views, misrepresenting materials' albedos.

For context: I want my colors as close as they can be to the source art, so I'm trying to disable tone mapping (or just use a simple tone mapper that simply clamps values). I don't want the "filmic" or "photographic" look of the available tone mappers since I think they look bad with non photorealistic rendering.

rzkid commented 2 months ago

I have found more evidence towards this.

I had a more complicated setup to test this, but I found a way simpler one: override ColorGrading shader entirely to return float4(1.0, 0, 0, 1.0);, which should yield full unmodified red (when not set to "Legacy" enum). However that is not the case, as the red you get instead is 204 0 0 image

But just like chanoc noticed, if you toggle mat_fullbright 1 on, suddenly, the red is 255 0 0, just like how it's supposed to be. image

There couldn't be a clearer evidence that something is wrong (instead of just potential shading interference where it shouldn't), this means that all tonemapping that isn't Legacy, is applied WITH legacy hable, or some sort of additional tonemapping, EVEN the facepunch's own custom tonemapping algorithms. And when working with LUTs, color grading, or just with tonemapping, this shit is not ideal. please fix