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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question ScriptableRenderer.cameraColorTargetHandle renders black when MSAA is disabled

Discussion in 'Universal Render Pipeline' started by AdamLacko, May 25, 2022.

  1. AdamLacko

    AdamLacko

    Joined:
    Oct 10, 2017
    Posts:
    41
    I'm trying to create a simple grayscale fullscreen effect which used stencil buffer to exclude certain objects from the effect. I got it working with a simple grayscale shader and custom blit-like function (as all Blit functions ignore stencil for me) in a custom render pass. However, the effect only works with MSAA enabled, which, due to optimization reasons, I'd like to have disabled.

    I bind ScriptableRenderer.cameraColorTargetHandle (using URP 14.0) to a grayscale shader and then simply draw a fullscreen mesh with that shader (as any standard Blit function would).

    When MSAA is enabled, everything works fine - every pixel except those excluded by the stencil turns into grayscale, which is a desired result.
    However, when I disable MSAA, every pixel (except those excluded by the stencil - so stencil is still respected) turns solid black.

    I narrrowed down the problem to ScriptableRenderer.cameraColorTargetHandle. When MSAA is disabled, the texture this RTHandle points to is simply black (it's not null though, it's an existinig _CameraColorAttachmentA_xyz....).

    Is this a desired behaviour?
     
  2. FurretTurret

    FurretTurret

    Joined:
    Mar 12, 2014
    Posts:
    2
    +1 to this. I'm creating a custom render pass to do outlines, and when I try to retrieve the color buffer for the current camera via cameraColorTargetHandle, same thing; I get a black texture back unless MSAA is enabled.
     
  3. Gisle

    Gisle

    Joined:
    Mar 25, 2014
    Posts:
    26
    Im having this exact problem as well. It doesnt even work with unitys own CoreBlit shader. This a huge issue for us due to optimization requirements for other platforms.
     
  4. StenCG

    StenCG

    Joined:
    Mar 26, 2015
    Posts:
    63
    I solved this using it
    _BlitTexture

    like here