I wrote a script that Creates a mesh procedurally
mr = gameObject.AddComponent<MeshRenderer>();
mf = gameObject.AddComponent<MeshFilter>();
//
mf.mesh = new Mesh
{
vertices = GetVertices(),
triangles = GetTriangles()
uvs = UpdateUVMap();
};
//assign material + shader.
mr.sharedMaterial = new Material( Shader.Find("Shader Graphs/surface") );
(the mesh is a sphere for this example)
I created my Shader in shader-graph (any shader seems to have the same result)
When played, all seems good except that the object is black. What's happening?
//basic uv map example from docs
public Vector2[] UpdateUVMap()
{
Vector2[] uv = new Vector2[this.vertices.Count];
for (int i = 0; i < uv.Length; i++)
{
uv[i] = new Vector2(vertices[i].x, vertices[i].z);
}
return uvs.ToArray();
//uvs.Clear();
//uvs.AddRange(uv);
}