# Pixelated Normal Generation

I am generating normals for each vertex in a standard 512*512 quad. Yet when I do using the following code:

public Vector3f[] normals(Vector3f[] surface){
Vector3f[] normals = new Vector3f[surface.length];
for(int i = 0; i<normals.length; i+=4){

Vector3f n1 = surface[i];
Vector3f n2 = surface[i+1];
Vector3f n3 = surface[i+2];
Vector3f n4 = surface[i+3];

Vector3f p1 = n1.subtract(n2);
Vector3f p2 = n3.subtract(n2);
Vector3f p3 = n3.subtract(n4);
Vector3f p4 = n1.subtract(n4);

Vector3f norm1 = (p2.cross(p1)).normalize();
Vector3f norm2 = (p4.cross(p3)).normalize();
normals[i+1] = norm1;
normals[i+3] = norm2;

}
return normals;
}


I get the following from this:

Any ideas what is causing this? Thanks in advance.

• Is there any rounding going on anywhere? It's hard to tell from your code. – ashes999 Feb 23 '13 at 3:40
• normals[i+2] = (norm1.add(norm2)).divide(2) maybe this operation cause integer division try 2f. – user1075940 Feb 23 '13 at 10:29