Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Unity 2023 Command Buffer: Render Texture too bright in CameraEvent.AfterEverything

Discussion in 'General Graphics' started by _geo__, Jul 24, 2023.

  1. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,111
    I am using a command buffer with the "AfterEverything" event in Unity 2023.1.5 (Built-In) to render into a render texture. I then use that texture in a UI (UGUI) image. Sadly the RT is always too bright.

    If I use an event that catches the color buffer earlier (like BeforeImageEffets for example) then the output is okay. So my guess is there is something in the post pro step that causes this.

    It works just fine in Unity 2021 and 2022 (Built-In).

    upload_2023-7-24_9-53-25.png

    The RT is created like this:
    Code (CSharp):
    1. RenderTexture createRenderTexture()
    2. {
    3.     var texture = new RenderTexture(Resolution.x, Resolution.y, 16);
    4.     texture.filterMode = FilterMode.Bilinear;
    5.     texture.wrapMode = TextureWrapMode.Clamp;
    6.  
    7.     return texture;
    8. }
    What I have tried:
    * Changing the color space (sRGB vs linear), various RT formats -> FAIL
    * Adding an removing a post-pro layer (does not change the result)
    * Changing the event to something earlier -> success (yet I need "AfterEverything").

    Has anyone seen this behaviour before?
     
  2. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,111
    TLDR: In 2023 the default rendering mode seem to be "linear" and not "gamma". Once I had compensated for that it all worked flawlessly.

    Update: Seems like I had made an error and I did not use sRGB in all instances. Now with force sRGB it works for both "Linear" and "Gamma" render modes (for Gamma it should not be necessary anyways according to the docs).

    Code (CSharp):
    1. CommandBuffer buf = new CommandBuffer();
    2. buf.name = name;
    3.  
    4. // copy screen into temporary RT
    5. int screenCopyID = Shader.PropertyToID("_ScreenCopyTexture");
    6. var desc = new RenderTextureDescriptor(-1, -1);
    7. desc.depthBufferBits = 0;
    8. desc.useMipMap = false;
    9. desc.autoGenerateMips = false;
    10. desc.colorFormat = RenderTextureFormat.Default;
    11. if (QualitySettings.activeColorSpace == ColorSpace.Linear)
    12. {
    13.     // Makes sure to properly support linear color space.
    14.     desc.sRGB = true;
    15. }
    16. buf.GetTemporaryRT(screenCopyID, desc, FilterMode.Bilinear);
    17. buf.Blit(BuiltinRenderTextureType.CurrentActive, screenCopyID);
     
    Last edited: Jul 24, 2023