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:
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.
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.
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