Gouraud shading: http://en.wikipedia.org/wiki/Gouraud_shading
Video: http://www.youtube.com/watch?v=PMgjVJogIbc
I have a model, expressed here:
My engine uses a standard model class, which is setup like this:
private float[] vertX;
private float[] vertY;
private float[] vertZ;
private float[] norX;
private float[] norY;
private float[] norZ;
private float[] texX;
private float[] texY;
I only know the math behind flat shading, so this is what I came up with:
public void flatShade() {
for (int i = 0; i < amountVertices; i+=3) {
float[] norm = CollisionHelper.getTriangleNormal(vertX[i], vertY[i], vertZ[i], vertX[i + 1], vertY[i + 1], vertZ[i + 1], vertX[i + 2], vertY[i + 2], vertZ[i + 2]);
norX[i] = norm[0];
norX[i + 1] = norm[0];
norX[i + 2] = norm[0];
norY[i] = norm[1];
norY[i + 1] = norm[1];
norY[i + 2] = norm[1];
norZ[i] = norm[2];
norZ[i + 1] = norm[2];
norZ[i + 2] = norm[2];
}
}
And while this works for light calculations (as seen in the picture above), it looks odd, as the triangles which share vertices have normals facing different directions.
What should I do for proper gouraud shading?