   Calculating normals for a modified sphere
  I have a procedurally-generated sphere on which I'm apply a heightmap. Before the heightmap, the normals were trivial to calculate given it was a sphere. However with the heightmap applied, this will no longer work.I'm storing the sphere in a 2d array [j] (with i being the stacks and j being the slices). I was thinking of firstly calculating all the vertexes, the looping through the entire structure and calculating the normal of each vertex one at a time. However, I'm a bit unsure of how to do this. I'm creating the sphere with quads - I know the normal of each vertex is the normalized cross-product of two edges (excuse any mistakes in terminology).I'm thinking this part would be relatively simple. The hard part (at least from my understanding) would be averaging shared vertexes. To take an example, you have for quads:--a--qA|qBb-x-cqC|qD--d--x is the vertex shared by the other quads. a, b, c and d are the vertexes that connect to x. Now, to my understanding, I have to get the normals of a, b c and d, and then average them to get the final normal for x. But assume that x is the first vertex in the 'averaging' step. a, b, c and d haven't been averaged yet, so would the normal for x be correct?I'm sorry if that doesn't make complete sense. I'm quite confused and am finding it hard to express the problems I'm having. If anyone can help by pointing me in the right direction?
  Iterate the quads, accumulating the quad normal into the vertex normal.Then iterate the vertices, normalising the accumulate normal.   ;  Iterate the quads, accumulating the quad normal into the vertex normal.Then iterate the vertices, normalising the accumulate normal.Could you elaborate on that a bit? I'm not sure exactly what you mean.What do you mean by accumulating the quad normal into the vertex normal? What exactly is the quad normal as opposed to the vertex normal in this case?   ;  One vector per vertex, initially all zero. The cross product of two edges gives you the normal for the quad. Do this for all quads, and add the result to the vector for each vertex that forms the quad. When you are done with all quads, each vertex has a vector that points in the right direction, but its size is all messed up: Iterate through the vertices and normalize the vectors.   ;  Thanks for the help! Much appreciated. I've got it almost working now. The lighting looks pretty good and all however there's one issue remaining. If you look at the image below, you'll see a large seam along the y-axis where x = 0. I'm thinking this is because I'm not looping around however I haven't been able to fix it.The way I'm doing the algorithm at the moment is as follows (using pseudo-code because this is for an assignment):for i in range 0:stacks-1  for j in range 0:slices-1  {    //Get the direction vector from v0 to v1, and from v0 to v2 and calculate the normal    // += to add all the vectors that make use of this vertex together and then normalize them in another loop    vertex[j].normal += calcCrossProduct(vertex[j], vertex[i+1][j], vertex[j+1]    vertex[i+1][j].normal += calcCrossProduct(vertex[i+1][j], vertex[j], vertex[i+1][j+1]    //Repeat for last two vertices in quad  }  //Attempt to calculate to address the seaming  //Probably logic error here although I can't see  vertex[slices-1].normal += calcCrossProduct(vertex[slices-1], vertex[0], vertex[i+1][slices-1]  vertex[0].normal += calcCrossProduct(vertex[0], vertex[slices-1], vertex[i+1][0]//Another loop to normalize vectorsAny ideas why this is occurring?   