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

Question Rendering issue after changing vertex positions and fragment color of plane.

Discussion in 'Shaders' started by Sprawl, Feb 21, 2022.

  1. Sprawl

    Sprawl

    Joined:
    Jan 19, 2014
    Posts:
    42
    Hello, I've been toying with a shader to create some sort of fog by deforming the vertex of a plane using shadergraph. However, when I apply color changes based on height and distance in the fragment, it seems that some of the triangles of my planes that are behind render in front. See Picture :
    upload_2022-2-21_12-34-23.png

    This issue only happen when I change the color based on the vertex positions (based on height or by applying the fog to the plane). I'm assuming it is because I change the the vertex position, but not their normals ?

    If so, could someone point me in the right direction for how I should also change the normals in the vertex step?


    If I'm not in the right direction, please let me know :)



    What I send to the Vertex position :
    upload_2022-2-21_12-38-9.png

    How I apply the fog to the final fragment color :
    upload_2022-2-21_12-38-28.png
     
  2. Sprawl

    Sprawl

    Joined:
    Jan 19, 2014
    Posts:
    42
    Bump
     
  3. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,495
    This is a common issue with transparent object rendering. The shader is not going to be able to render all the triangles in perfect z-order, merely the order the triangles are laid out in the mesh structure.
    For something like this, simply enabling ZWrite and ZTest on the Graph Settings should fix it, ensuring only the foremost pixels of the plane render instead of overlapping with ones behind.
    Though I'm not 100% sure on your desired result, so this may also have issues for you needs.