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

Question UV Sphere's verts aren't merged, all moving to distinct positions

Discussion in 'Shader Graph' started by dgoyette, Jun 13, 2020.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    I'm not sure if this is a problem with the shader, or with the model. But to show an example, I have a very simple UV Sphere model created in blender. All the verts are merged by distance, so there's only one vert at the "pole":

    upload_2020-6-13_13-21-48.png

    However, if I move the verts around in SG using the Position node, suddenly all of those verts are no longer merged, and i get 36 different "poles":

    upload_2020-6-13_13-20-48.png

    Sorry if that's hard to see, but you can sort of tell how there are a bunch of pointy triangle strips not converging in the center. So the question is why these verts aren't "merged" anymore, and getting set to independent positions by the shader?

    On the model, I have the FBX set to Merge Vertices:

    upload_2020-6-13_13-24-6.png

    And the shader is just adding some noise to the vert position, just testing some stuff out:

    upload_2020-6-13_13-25-29.png

    Anyone have an idea why the verts aren't merging correctly in this model? Note that pretty much the same thing happens with a standard Unity sphere primitive, but I had hoped that my explicit merging of verts in blender would make the bespoke sphere behave better.
     
  2. TimmyTheTerrible

    TimmyTheTerrible

    Joined:
    Feb 18, 2017
    Posts:
    186
    Vertices are duplicated automatically when they require different sets of data. For faceted geometry every face vertex will be split in unity, as well as any vertices that have a UV seam.
     
  3. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    Okay. I guess I thought Weld Vertices somehow would prevent that. I see that the issue I'm having is the result of moving the different verts according to a UV-relative noise texture. The problem is that, UV-wise, all of those points have different UV coordinates:

    upload_2020-6-13_19-43-8.png

    I wonder if there's some way to unwrap an object such that coincident points are coincident on the UV map too. Otherwise, I don't see how I can perform vertex displacement without creating gaps.
     
  4. TimmyTheTerrible

    TimmyTheTerrible

    Joined:
    Feb 18, 2017
    Posts:
    186
    one way you may consider to hide these gaps is to plant weight painting into one of the channels of a texture. in this way, you could make the grayscale values affect how much weight an area of a model gets displaced, and just paint all UV seams for facets as black(zero weight) and multiply the weight by the desired displacement. It could also be stored as vertex paint.
     
  5. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    That's an interesting idea. Basically, provide a map that keeps certain verts from moving within the shader, with the hope that these verts at the poles can be more or loss locked, or perhaps forced to move in unison. Worth trying. Thanks.
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    The other trick that can be used is to not rely on the mesh UVs at all, and instead calculate them in the shader from the vertex positions. This avoids issues with UV seams as the calculated UV should match perfectly assuming the vertex positions are properly welded.

    This can either be done by reproducing the polar coordinate spherical UVs you probably generated in Blender, or more complex setups akin to triplanar or capped cylinder UVs and using cycled scaling rather than panning for the top & bottom.
     
    dgoyette likes this.
  7. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    I'll give that a try. Thanks.
     
  8. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    I just figured I'd mention that using spherical UVs worked well for this. I unwrapped uv0 normally, and uv1 using spherical projection:

    upload_2020-6-16_13-1-40.png

    If I sample the noise texture using uv1, the results are that I can apply noise without seams. Here's what I'm sending into the position:

    upload_2020-6-16_13-8-42.png

    The result is a spiky sphere that has no gaps/seams:

    upload_2020-6-16_13-9-26.png

    Using uv0 instead of uv1 definitely results in seams, so this really did come down to using the correct approach to uv unwrapping. Thanks for the advice.
     
    florianhanke likes this.
  9. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    You'll still technically have some separation at the poles, it just might be well hidden.
     
  10. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    You're right. I tried this with a UV sphere instead of an Ico sphere, and unwrapped it with the proper orientation, yielding this:

    upload_2020-6-16_15-39-45.png

    There seem to be no gaps now. And it seems like all the verts line up at the edges.