GL_SMOOTH - Not so smooth ?

Started by
10 comments, last by RobTheBloke 14 years, 7 months ago
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]); }
--------------------------------------------------------------------------------Aurora Studio - PureLight - Animation & rendering software and API.http://www.polarlights.net
Advertisement
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 ?
--------------------------------------------------------------------------------Aurora Studio - PureLight - Animation & rendering software and API.http://www.polarlights.net
Sorry, didn't notice that.

Well is rather seems that you are assigning normals to incorrect vertices so normals are smooth but broken.
Vertex normals are averaged, not just summed.

No, I am not a professional programmer. I'm just a hobbyist having fun...

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.

No, I am not a professional programmer. I'm just a hobbyist having fun...

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
--------------------------------------------------------------------------------Aurora Studio - PureLight - Animation & rendering software and API.http://www.polarlights.net
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.
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!
--------------------------------------------------------------------------------Aurora Studio - PureLight - Animation & rendering software and API.http://www.polarlights.net

This topic is closed to new replies.

Advertisement