Search Unity

Question Vertex displacement with shader graph causing seams to appear

Discussion in 'Shaders' started by b4gn0, Dec 22, 2020.

  1. b4gn0

    b4gn0

    Joined:
    Jul 26, 2019
    Posts:
    119
    Hi,

    We have a shader done with shader graph that displaces the vertex position by a very tiny amount to avoid z-fighting.

    However, this causes this to appear on certain meshes (this in particular is a very low-poly terrain mesh):


    Is it possible to somehow displace the vertex horizontally too in order to avoid the seams?

    The displacement is based on camera position like this (inspired from @bgolus in another thread):
    upload_2020-12-22_19-28-48.png

    I tried adding the x,z values of the normal vector in the opposite direction but it feels like it should be some kind of crossproduct with the camera? Here is the attempt (doesn't change much from the above result):
    upload_2020-12-22_19-29-57.png

    Thank you!
     
  2. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    Make sure the normals have been smoothed on your mesh before importing it. If you have hard-edges on your model in your modeling program, every hard edge is split for rendering hard on the GPU, resulting it unique verts for each triangle, allowing the triangles to separate if not moved together in a uniform direction.
     
  3. b4gn0

    b4gn0

    Joined:
    Jul 26, 2019
    Posts:
    119
    Will this impact the look of the model?
    We would like to maintain the "low-poly" feel. Is there a specific command in e.g. blender to use?

    Thank you!
     
  4. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    Mesh>Faces>Smooth.
    But yes you will lose the low-poly triangle shading look then.
    You could instead compute flat shading in the shader though by using screen-space derivatives, bgolus has posted examples of such a thing as well :p
    Or if you are not utilizing the vertex colors of your mesh, then you could store the smooth-shading normals in your vertex colors: https://philippseifried.com/blog/2020/03/blender-addon-normals-to-vertex-colors/

    And then in your shader graph, instead of using the "Normal Vector" node, you would use "Vertex Color" node.
     
  5. AlexTorbin

    AlexTorbin

    Joined:
    Dec 12, 2019
    Posts:
    48
    Probably instead of baking normals, a more simple way is to displace all vertices in the same direction. If it's always on the floor then just displace in world's up (0,1,0). For universal use displace towards the camera (-view direction). I believe you can get it from the view matrix in HLSL, I don't know where it is in shader graph.