Sign in to follow this  
dawberj3

Smoothing my cylinder

Recommended Posts

I have created a cylinder coloured red, each side of it is 36 degrees rotated and I have defined the normal for each side. But you can still see each polygon, Im trying to get the look of a pipe without having too many polygons. I have enabled glShadeModel(GL_SMOOTH); but this makes not difference. Am I missing something? Thx

Share this post


Link to post
Share on other sites
I'm guessing you need per-vertex normals. Calculate a normal for each vertex as the normalized average of the normals of all faces incident on that vertex, and then wrap the whole thing up in a vertex array. This will give you smooth rather than faceted shading. The tessellation will still be visible in silhouette, but that's a different problem.

That's rather cursory, so ask if you need further details.

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk
Calculate a normal for each vertex as the normalized average of the normals of all faces incident on that vertex, and then wrap the whole thing up in a vertex array.
For cylinders you can do it much more easily. All you have to do is to take the vertex position relative to the cylinder's center and normalize. (With a little bit of special case stuff if you want a sharp edge at the caps.)

Share this post


Link to post
Share on other sites
Im not fully understand this vertex position etc.

All I know is the 4 corners of the polygon and the center of the cylinder.

Would vertex arrays be faster than increasing the ammount of sides on the cylinder?

Share this post


Link to post
Share on other sites
Quote:
Original post by dawberj3
Would vertex arrays be faster than increasing the ammount of sides on the cylinder?

Vertex arrays are a special kind of supplying vertices to the gfx API. Their purpose is to speed up rendering. It has nothing to do with a higher resolution by itself. Only, if you supply more vertices to yield in a higher resolution, using a vertex array will lower the impact of the additional vertices w.r.t. the rendering speed.

Share this post


Link to post
Share on other sites
Quote:
Original post by Promit
For cylinders you can do it much more easily.
Oops, sorry, I was lazy and just gave a general solution. But as Promit suggests, for many simple shapes (cylinders, capsules, spheres, torii, etc.), the normals can be generated directly from the definition of the shape.

Anyway, how you construct the normals is a detail, more or less. The important part is that you have a correct normal for every vertex, and then render in such a way that colors are smoothly interpolated across the face boundaries.

Share this post


Link to post
Share on other sites
Assuming you're not going to use normals calculated from the actual mathematical cylinder, you should read this article: http://lighthouse3d.com/opengl/terrain/index.php3?normals

It's geared towards a terrain engine, but it's a very detailed method of calculating vertex normals taking the surrounding vertices into consideration, worth reading.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this