I'm trying to draw a smooth cloth surface and I have a per-pixel shader. I expect to have a smooth surface but it's not the case. I think the problem comes from my normals.
The image show the surface drawn with multiple triangles. The surface is lit; the white zone are specular reflection.
Here is the way I calculate normals
ofVec3f v0(ps[i].pos.x, ps[i].pos.y, ps[i].pos.z);
ofVec3f v3(ps[i+cols+1].pos.x, ps[i+cols+1].pos.y, ps[i+cols+1].pos.z);
ofVec3f v1(ps[i+1].pos.x, ps[i+1].pos.y, ps[i+1].pos.z);
ofVec3f v2(ps[i+cols].pos.x, ps[i+cols].pos.y, ps[i+cols].pos.z);
ofVec3f n0 = (v1-v0).cross(v3-v0);
n0.normalize();
ofVec3f n2 = (v0-v2).cross(v3-v2);
n2.normalize();
ofVec3f n3 = (v0-v3).cross(v1-v3);
n3.normalize();
ofVec3f n1 = -(v0-v1).cross(v3-v1);
n1.normalize();
Here is the code to draw my surface. It's a 64x64 array of double triangles
glBegin(GL_TRIANGLES);
for (int i=0; i<ps.size()-(cols+1); i++) {
// v0 - v1
// | \ |
// v2 - v3
// v0
glNormal3f(n0.x, n0.y, n0.z);
glVertex3f(ps[i].pos.x, ps[i].pos.y, ps[i].pos.z);
//v3
glNormal3f(n3.x, n3.y, n3.z);
glVertex3f(ps[i+cols+1].pos.x, ps[i+cols+1].pos.y, ps[i+cols+1].pos.z);
//v1
glNormal3f(n1.x, n1.y, n1.z);
glVertex3f(ps[i+1].pos.x, ps[i+1].pos.y, ps[i+1].pos.z);
//v0
glNormal3f(n0.x, n0.y, n0.z);
glVertex3f(ps[i].pos.x, ps[i].pos.y, ps[i].pos.z);
//v2
glNormal3f(n2.x, n2.y, n2.z);
glVertex3f(ps[i+cols].pos.x, ps[i+cols].pos.y, ps[i+cols].pos.z);
//v3
glNormal3f(n3.x, n3.y, n3.z);
glVertex3f(ps[i+cols+1].pos.x, ps[i+cols+1].pos.y, ps[i+cols+1].pos.z);
I don't know how many normals I need and where to put them: at each vertex, one by face ? four by vertex ? I still have a flat triangulated surface although I have a per pixel glsl shader
Thanks for help.