GL_SMOOTH - Not so smooth ?
Hi,
I'm creating a small soft with OpenGL but when I load a 3DS model it looks like faceted ! There is no smoothing between the faces.
I use Gl.glShadeModel(Gl.GL_SMOOTH); but it change nothing !
Here is a picture :
http://picasaweb.google.com/viewon01/OpenGL#5380203925050881714
Here, you can download the Smurf model :
http://www.3dvalley.com/3d-models/characters
Do you have an idea ?
Here is the way I create the normals :
Vector3[] sum = new Vector3[Vertexes.Count];
for (int jj = 0; jj < TrianglesIndices.Count / 3; jj++)
{
int indice1 = TrianglesIndices[jj * 3];
int indice2 = TrianglesIndices[jj * 3 + 1];
int indice3 = TrianglesIndices[jj * 3 + 2];
Vector3 v1 = Vertexes[indice1];
Vector3 v2 = Vertexes[indice2];
Vector3 v3 = Vertexes[indice3];
// Calculate the surface normal
Vector3 e1 = Vertexes[indice1] - Vertexes[indice2];
Vector3 e2 = Vertexes[indice2] - Vertexes[indice3];
Vector3 surfaceNormal = e1.Cross(e2);
// Sum it at the vertex index
sum[indice1] += surfaceNormal;
sum[indice2] += surfaceNormal;
sum[indice3] += surfaceNormal;
}
for (int index = 0; index < Vertexes.Count; index++)
{
sum[index].Normalize();
Normals.Add(sum[index]);
}
In order to have smooth faces, you need to specify per-vertex normal (as opposed to per-face normal you have now).
Thanks,
I don't understand, I have a per-vertex normal.
I calculate the surface normal for each vertex, BUT I sum it...
at the end I normalize it, so every normal is different. Right ?
I don't understand, I have a per-vertex normal.
I calculate the surface normal for each vertex, BUT I sum it...
at the end I normalize it, so every normal is different. Right ?
Sorry, didn't notice that.
Well is rather seems that you are assigning normals to incorrect vertices so normals are smooth but broken.
Well is rather seems that you are assigning normals to incorrect vertices so normals are smooth but broken.
Quote:Original post by maspeir
Vertex normals are averaged, not just summed.
He normalizes them at the end, which ensures the normals are of unit length. It doesn't matter whether you sum them or average them, you must normalize them in the end. Averaging alone is not good enough, because it doesn't ensure the normals are of unit length.
I understand the need to normalize them after averaging. This is the first time I've heard that they can be summed with the same effect. I stand corrected.
Thanks for your answers,
Can you tell me where I'm assigning normals to incorrect vertices ?
I don't understand where I have do an error !
Thanks
Can you tell me where I'm assigning normals to incorrect vertices ?
I don't understand where I have do an error !
Thanks
One idea: your vertices aren't shared, I mean, all triangles have 3 vertices, which are not shared with the other, neighboring triangles, although they seem to be the same verices.
How many polygons/vertices you have?
If vertices=3*polygons, your vertices aren't shared, so you cannot calculate average that way.
I hope it made sense, or I didn't misunderstand something, or not giving dumb advice.
How many polygons/vertices you have?
If vertices=3*polygons, your vertices aren't shared, so you cannot calculate average that way.
I hope it made sense, or I didn't misunderstand something, or not giving dumb advice.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement