Jump to content
  • Advertisement
Sign in to follow this  
polar01

OpenGL GL_SMOOTH - Not so smooth ?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
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 this post


Link to post
Share on other sites
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

Share this post


Link to post
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 this post


Link to post
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!