Search Unity

Question Issue with vertex displacement causing puckered seams

Discussion in 'Shader Graph' started by chasethomas, Jan 17, 2021.

  1. chasethomas

    chasethomas

    Joined:
    Oct 16, 2015
    Posts:
    17
    I've created a pretty simple vertex displacement shader, using a map I created in photoshop. It's working well, but there are these puckered seams in every mesh I try to use it on.

    This example is 4 different spheres exported as .FBX from C4D (each with increasing #s of segments). You can see the seams at the top of each (more pronounced in the lower segments, but still there in the ones with more segments). Obviously this looks weird to have a bush or tree with a spiky seam.

    shaderSeams.png

    I tried on a built in unity mesh and had somewhat similar results. Is there anything obvious about my graph?

    shaderGraphSeams.png

    Thanks in advance!
     
  2. Oxeren

    Oxeren

    Joined:
    Aug 14, 2013
    Posts:
    121
    I'd guess that this issue is caused by the topology of a sphere with a pole on it's top and a lot of triangles connecting in a single vertex, and also with the way these pole triangles are UV mapped.
    Using a rounded cube instead should fix this issue.
    upload_2021-1-18_0-13-42.png

    Also the texture used for displacement have to tile seamlessly along all borders to prevent mesh tearing at UV seams.
     
  3. chasethomas

    chasethomas

    Joined:
    Oct 16, 2015
    Posts:
    17
    Ahh interesting- I suspect my texture isn't tiling seamlessly, though I did try it with Unity's built in gradient noise and still had some tearing.

    I will try the rounded cube... I've tried this with a cone with a rounded top separately and had the same issue. Is there a common trick to ensure your meshes won't tear at UV seams?
     
  4. Oxeren

    Oxeren

    Joined:
    Aug 14, 2013
    Posts:
    121
    I'd say that the easiest way is to use vertex positions instead of UVs, this way there 100% will be no tearing. But then the question is how to map 3d positions of the vertices onto the 2d displacement texture. Well... that's what UV coordinates are usually used to o_O.
    But there are other ways. The most accurate would be to use a 3d texture or a 3d procedural noise (like these ones) for displacement. Big 3d textures are very heavy, but it is often enough to use a small one. 3d procedural noises are rather computationally expensive, but if your meshes are not too high poly and there aren't too many of them in the frame than it should not be that big of a problem.
    You can also use something like triplanar mapping to seamlessly map the texture onto the mesh, but the issue is that you can't use Shader Graph's built-in Triplanar node for that because it does not work for vertex stage (I presume for the same reason that you have to use Sample Texture 2D LOD instead of a regular Sample Texture 2D in the vertex shader), so that would require making a custom implementation.
    By the way, if you don't need to change the displacement position (so it will be the same on all objects), you can just bake 3d noise into a texture (or even into vertex color), this way there will be no tearing and it also is super cheap.
     
  5. chasethomas

    chasethomas

    Joined:
    Oct 16, 2015
    Posts:
    17
    Thanks for the response- apologies for the delay on getting back to you.

    It sounds like baking 3d noise would be my best approach (esp given that this will need to be mobile friendly). I'm not familiar with the general concept, though I did some googling on it. It seems to be different from a normal displacement map. Curious how it actually slots into shader graph (compared to what I've done above).