weird shadows in the procedurally created mesh

after I procedurally generate mesh it gets weird shadows on edges in the middle of a face, or in some other seemingly random places. I assume I'm missing something - how to make the "shadows" regulary distributed on faces like on primitives available in unity - in this example: alt text on a cube. or on any imported meshes? alt text


function creatingMesh(newVertices, newTriangles){
    var newGameObject:GameObject = new GameObject("newCut");
    var newMesh:Mesh = new Mesh();

    newMesh.vertices = newVertices.ToArray();

    var uvs = new Vector2[newMesh.vertices.length];
    for (i= 0; i<uvs.length; i++){
        uvs <em>= Vector2(newMesh.vertices_.x, newMesh.vertices*.z);*_</em>
 <em>_*newMesh.uv = uvs;*_</em>
 <em>_*newMesh.triangles = newTriangles.ToArray();*_</em>
 <em>_*newGameObject.GetComponent(MeshFilter).mesh = newMesh;*_</em>
 <em>_*if(newObjectMaterial) newGameObject.renderer.material = newObjectMaterial;*_</em>
 <em>_*newGameObject.collider.convex = true;*_</em>

You need to split vertices so that hard edges have more than one vertex, since normals are per-vertex. You're getting the same result that you would if you imported something like a cube, and turned on Generate Normals and gave it a smoothing angle of 180. If you made a cube from 8 vertices, then you can only have smooth lighting since all vertices share the same normals. But that naturally looks totally wrong for a cube, so you'd need to make it from 24 vertices (4 per side). This way each vertex can have proper normals.