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 Edge problems when using scene depth in shader graph

Discussion in 'General Graphics' started by Uwi2k3, Apr 16, 2023.

  1. Uwi2k3

    Uwi2k3

    Joined:
    Mar 7, 2023
    Posts:
    5
    Hello there,

    i have created a water shader that is making use of the SCENE DEPTH to create a foam at the shore of the water. See A in my first image.


    This is working fine now. The problem is that there are areas in the image were this leeds to problem. See B in my second image.



    How can i get rid of this areas i marked in yellow?

    thanks a lot!!
    kai
     
  2. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,141
    This is unfortunately unavoidable when using MSAA. Because MSAA only applies to the screen color, not the underlying depth texture (which your water relies on). You can see how the depth values (right) are still aliased here, compared to the color (left):


    So the only (easy/viable) way around this is to use the Anti-Aliasing options on the camera, instead of MSAA.
     
  3. Rukhanka

    Rukhanka

    Joined:
    Dec 14, 2022
    Posts:
    177
    This is not true. When MSAA is used all target render buffers are muli-sampled (including depth buffer). If problem is really with MSAA, then correct depth buffer MSAA resolve step is required. This can be done in separate pass, or directly in shader where depth samples are used. To do so depth texture should be declared as Texture2DMS instead of ordinary Texture2D. For depth texture UNITY_DECLARE_DEPTH_TEXTURE_MS macro can be used. Than read all samples from pixel and decide how to handle edge cases properly (pick most distant one?).
     
  4. Uwi2k3

    Uwi2k3

    Joined:
    Mar 7, 2023
    Posts:
    5
    Hello there,

    thnak you both for the explanaition and the hint!
    Anti aliasing did the trick for me!

    thnaks
    kai
     
  5. JSmithIR

    JSmithIR

    Joined:
    Apr 13, 2023
    Posts:
    92
    Thanks, I think this is something I have been looking for. Do you have any examples of this being used in shader? I need subsample depth and normal values in order to implement this anti-aliasing method: https://history.siggraph.org/wp-con..._-Manifold-Garden-rendering-retrospective.pdf