Search Unity

Disabling Camera MSAA has no effect if a later Camera has MSAA enabled

Discussion in 'Image Effects' started by NotSuspiciousLLC, Apr 16, 2021.

  1. NotSuspiciousLLC

    NotSuspiciousLLC

    Joined:
    Nov 26, 2019
    Posts:
    3
    Hi, I believe I've found some undocumented behavior regarding Camera MSAA settings in the built-in rendering pipeline, and I can't figure out a workaround. For context, my project has 2 cameras:

    1. The Background camera (Depth 0), which draws screen-space outlines using the DepthNormals texture.
    2. The Foreground camera (Depth 1), which has no post-processing, but needs MSAA because it includes animated meshes.

    As is visible in this image, the Background is rendering with MSAA despite the camera settings, causing some pixels from meshes to extend beyond the edges determined by the DepthNormals texture:

    Capture.PNG

    Here, it is seen working correctly (by disabling MSAA on the Foreground camera):

    Capture2.PNG

    From the Frame Debugger's "Resolve AA" step it's clear that MSAA is causing the pixel bleed. Additionally, it should be noted that the Camera MSAA setting does work if the camera depths are switched (i.e. the camera with MSAA turned on is earlier in the render pipeline).

    Capture3.PNG

    Unfortunately, in order to render the foreground correctly I must draw it after the background (to preserve depth information), so I'm at a loss for workarounds. Any ideas? Is Unity working as intended here?

    Thanks,
    Guillaume
     
  2. NotSuspiciousLLC

    NotSuspiciousLLC

    Joined:
    Nov 26, 2019
    Posts:
    3
    After further investigation, it seems the reason this happens is that MSAA sample count is not a "per-camera" setting at all. Behind the scenes, it is a render target setting. As a result, the workaround is to directly manipulate the render target for each camera using Camera.targetTexture, and to interpret the results of each camera render manually (using Graphics.Blit instead of the Camera Depth system) on a placeholder camera with Culling Mask = None.