Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

MSAA + normal manipulation in surface shader = bright flickering on edges, how to fix?

Discussion in 'General Graphics' started by Radiangames2, Nov 21, 2021.

  1. Radiangames2

    Radiangames2

    Joined:
    Aug 22, 2012
    Posts:
    45
    I'm modifying the normals of a mesh in a surface shader (SRP). The normals could be arbitrary, for instance, though in this case they are not. If I do this while MSAA is on, there are bright flickers at the edges of the meshes. See this image:



    In case that doesn't work: https://radiangames.com/images/msaa_flicker.gif

    * I've tried modifying the surface lighting function, but that makes zero difference, so I know it's not that (I output a solid color from the lighting function and the flicker still happens).
    * If I don't change the normals, but modify the mesh, the flicker doesn't happen.
    * If I turn off MSAA, the flicker doesn't happen.
    * If I just output a constant normal (0,1,0 for instance), there's less flickering, but still a slight bit at certain angles.

    How can I ensure that the normals in my surface shader comply to the correct values so that MSAA won't freak out with modified normals?

    Any assistance or hints would be greatly appreciated.

    Thanks,
    Luke
     
  2. Radiangames2

    Radiangames2

    Joined:
    Aug 22, 2012
    Posts:
    45
    Just wanted to follow-up with more details: It's not just normals that can cause the flicker. If I fix the normals, just having some tris changing color in the shader, the flicker happens with MSAA. I disabled post-processing and the flicker is still there, but less noticeable. So the question is happening with MSAA behind the scenes? Anything I can try to work around?
     
  3. Radiangames2

    Radiangames2

    Joined:
    Aug 22, 2012
    Posts:
    45
    And I figured out a work-around: Don't manipulate Glossiness or Metallic, and I can manipulate the colors and normals as much as I want. I can live with that, so that's what I'll do.

    When I avoided modifying normals/colors, the problem would also go away, but I prefer this workaround.