Texture Not Showing On Mesh
I have a problem in Unity where the mesh is appearing completely black. This is the C# code to set the texture:
public void GenerateMap()
{
float[,] noiseMap = GenerateMapData();
Texture2D colorMap = TextureGenerator.GenerateColorMap(noiseMap, mapWidth, mapHeight);
Mesh mesh = new Mesh();
mesh = MeshGenerator.GenerateMesh(noiseMap, mapHeight, mapWidth);
meshFilter.sharedMesh = mesh;
meshRenderer.sharedMaterial.mainTexture = colorMap;
meshRenderer.transform.localScale = new Vector3(colorMap.width, 1, colorMap.height);
}
Generating the mesh is fine, but the texture is not appearing. The material applied to the mesh is a standard material called 'Mesh' with smoothness set to zero. Overall project is a Perlin noise terrain generator. colorMap is correct as I can apply it to a plane with:
textureRender.sharedMaterial.mainTexture = colorMap;
textureRender.transform.localScale = new Vector3(colorMap.width, 1, colorMap.height);
Any help would be appreciated.
And no, I didn't forget the uvs:
uvs[currentVertex] = new Vector2(x / width, z / height);
Mesh mesh = new Mesh
{
vertices = vertices,
triangles = triangles,
uv = uvs
};
mesh.RecalculateNormals();
Your answer
Follow this Question
Related Questions
Texture does not scale correctly on a mesh 0 Answers
Having trouble with a texture not showing on a generated mesh. 1 Answer
How do you draw a sprite from an atlas on to a mesh? 1 Answer
importing log captured by renderdoc in unity3d and processing it 0 Answers
Blocky (pixelated) textures on build only (not in editor) 0 Answers