- Home /
Mesh breaks apart when using vertex displacement with shadergraph.
Hello, the problem I'm having is that the face's of my meshes are breaking apart when using my little shader. This doesn't seem happen to the sphere.
So... how can I create a mesh that behaves like the sphere and well... stays intact :).
So here is whats happening:
And thats the shader:
Answer by Bunny83 · Feb 01, 2020 at 06:36 PM
That's not possible unless you base your displacement only on the original vertex position. That's because different faces where you have a UV seem have seperate vertices at the same corner. So the faces are not "connected" in any way. Since you offset your vertices along the vertex normal you will offset the vertices which actually belong to the same position into different directions. So you're moving them apart.
When you have a shared mesh this is not that of an issue since there are (almost) no duplicate vertices. A Sphere doesn't have any issues at the UV seems since the vertices actually have the same normal at the same point. This is not true for most other (hard edge) shapes. Keep in mind that shaders always work on individual vertices (vertex shader) and on individual triangles which are rasterized independently from each other. So a shader can not take other neighboring faces into account. If you want to apply such an effect you either need to provide more information per vertex, or use a different approach. For example instead of using the vertex normal you might want to use the vector from the object origin (in other words the normalized local space coordinate of that vertex). Of course that would only work properly when the origin is somewhat in the center of your mesh.
I think I understand :) Now I just need to figure out how to do that with the object origin. Thank you alot, I feel like I became smarter.
I haven't really used Unity's shader graph yet. However ins$$anonymous$$d of your "normal" node you should be able to just use the vertex position and normalize it first. This gives you a direction vector from the object's origin to the vertex.
If you want / need to specify a different center position manually, you have to add a property which you can set from C# to specify the center of your object in local space and just subtract that vector from your vertex position before normalizing it .
Answer by FinXzuOP · Nov 29, 2021 at 07:07 AM
nicholascarrow is right. The problem lays in your normals. If your object/edges are shaded flat, the vertex at the edges do have splitted normals pointing in the direction of both faces they are connecting. If they are shaded smooth however there is only one normal pointing inbetween the two normals of the splitted normals.
Having only one normal istead of two means that your vertex only get displaced along one normal and there wont arise a gap inbetween your object do not have any faces for.,nicholascarrow is right. Just shade smooth your object. The problem is, that there are two normals for your vertex at the edges pointing 90 degree in the direction at the surface of your faces. If the edge is shaded smooth however you only have one normal instead of thwo, pointing at the degree midway inbetween your other two normals at the vertex. So your vertex only gets displaced along that one normal istead of two normals.
Answer by nicholascarrow · Mar 25, 2021 at 06:54 AM
you can also try to set your meshes to shade smooth in blender and to import them with a 180 degrees smoothing angle, that might fix it for you
Your answer
Follow this Question
Related Questions
Understanding verts and triangles in Unity 1 Answer
uv sub meshes in cube c# 0 Answers
Calculate UV coordinates of 3D point on plane of mesh's triangle 1 Answer
How to split UV in Mesh 1 Answer