# OpenGL GL_SMOOTH - Not so smooth ?

This topic is 3373 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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]); }

##### Share on other sites
In order to have smooth faces, you need to specify per-vertex normal (as opposed to per-face normal you have now).

##### Share on other sites
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 ?

##### Share on other sites
Sorry, didn't notice that.

Well is rather seems that you are assigning normals to incorrect vertices so normals are smooth but broken.

##### Share on other sites
Vertex normals are averaged, not just summed.

##### Share on other sites
Quote:
 Original post by maspeirVertex 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.

##### Share on other sites
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.

##### Share on other sites

Can you tell me where I'm assigning normals to incorrect vertices ?

I don't understand where I have do an error !

Thanks

##### Share on other sites
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.

##### Share on other sites
Thanks,

It is an idea, in fact I read a 3DS file... so I have supposed they are correctly organized !

But maybe you're right !
I have :
- 32168 vertices !
- 21440 triangle (with 3 indices for each)

So, how can I reorganize my vertices... it sounds a complex task to keep good performance!

1. 1
2. 2
3. 3
Rutin
20
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633655
• Total Posts
3013175
×