I'm creating a procedurally generated planet object in Unity. I start with a cube which is created from 6 meshes (6 sides) and normalize the vertices to get a standard sphere. The problem is that there are visible seams between the meshes. I know if I set the vertex normals to the direction from the center of the sphere to the current vertex then seams will gone but my next step is to add noise to the meshes to generate terrain on the sphere.
What I already tried to remove the seams:
- Generating an extra strip around the mesh
- Generating an extra strip around the mesh which is located on the adjacent sides
The second solution is almost perfect but seams are still visible a little bit.
When I create the mesh object:
- call the built-in RecalculateNormals on the mesh (including the borders)
- remove the border vertices, indices and normals
- reassign the vertices, indices and normals to the mesh object (excluding the borders)
I use libnoisedotnet to create simplex Perlin noise on the surface:
private MeshData CalculateMeshData()
{
MeshData meshData = new MeshData();
meshData.ChunkSize = CHUNK_SIZE;
meshData.BorderSize = BORDER_SIZE;
int borderedResolution = meshData.BorderedResolution;
int vertexIndex = -1;
float faceWidth = _radius * 2 / CHUNK_SIZE;
float currentYPosition = -_radius - faceWidth * BORDER_SIZE;
for (int y = 0; y < borderedResolution; y++)
{
float currentXPosition = -_radius - faceWidth * BORDER_SIZE;
for (int x = 0; x < borderedResolution; x++)
{
bool isMeshVertex = !IsBorderVertex(x, y, borderedResolution);
Vector3 axisAOffset = _axisA * currentXPosition;
Vector3 axisbOffset = _axisB * currentYPosition;
Vector3 pointOnUnitCube = _center + axisAOffset + axisbOffset;
Vector3 vertex = pointOnUnitCube.normalized;
vertex = vertex * GetElevation(vertex);
vertexIndex++;
meshData.AddVertex(vertex, isMeshVertex);
// Prevents to create more two triangles next to the edge of the mesh.
if (x != borderedResolution - 1 && y != borderedResolution - 1)
{
bool isMeshTriangle = IsMeshTriangle(x, y, borderedResolution);
meshData.AddTriangle(vertexIndex,
vertexIndex + borderedResolution + 1,
vertexIndex + borderedResolution,
isMeshTriangle);
meshData.AddTriangle(vertexIndex,
vertexIndex + 1,
vertexIndex + borderedResolution + 1,
isMeshTriangle);
}
currentXPosition += faceWidth;
}
currentYPosition += faceWidth;
}
return meshData;
}
private float GetElevation(Vector3 position)
{
return 1 + _noise.Evaluate(position) / 10f;
}
Here is the noise library what I tried to use: https://github.com/SebLague/Procedural-Planets/blob/master/Procedural%20Planet%20E03/Assets/Noise.cs
Is it possible to remove the seams fully?