Skip to main content
GameDev.net gamedev.net
🔒 Locked

smooth shading problem

Started by concentrator Oct 24, 2005 at 5:04 AM 5 replies 950+ views
Original Post
concentrator
concentrator
I'm having a difficulty in smooth shading: I specfy the vertices and normals of an object one by one in between glBegin(gl.GL_QUADS) and glEnd() and flat shading is working properly. However when I switch to smooth shading, instead of shading the whole object, the program smooth shades each quad one by one, which is not what I'm trying to do. What's the correct way of doing that? Thank you for any help
Nickolay_Smirnov
Nickolay_Smirnov
As I understood, you want to draw a surface, right? Then, if you want to do it by hands, specifying normal to each quad, you'll have to create a LOT of those quads to approximate surface. In OpenGL there are evaluators for these things. If you still want to draw a surface without them, I advise you to refer to NeHe tutorials. There is an example of flag. It's just a simple sin surface, created in cycle.
Cogito ergo sum (Descartes)
deavik
deavik
Why don't you throw us a screen shot with the smooth shading?

Without a pic, the first question I thought I'd ask was: how are you calculating the vertex normals? I'd say its most likely that there is an error in there which is causing your object to look weird. It's actually really simple, you calculate the face normals with a cross product, and average the face normals of faces which share a vertex for each vertex in your mesh.

Just post back with an answer to the first question and we can step you through the whole process if you have any difficulty understanding.
concentrator
concentrator
Yes I want to draw a surface(toroid) and i'm calculating the vertex normals using the parametric superquadratic function. When I use glShadeModel(GL_SMOOTH), the shape looks like the one at right. It's shading each quad one by one however I want the whole object to be shaded but I'm missing something.

Here's the image
http://www.geocities.com/concentrator2/toroid.jpg
Mantear
Mantear
1 - Double check your normals. I find it helps to actually draw the normals (pretty simple to do) for easy sanity checks.
2 - Are the normals at the verticies the surface normal of the quad? It almost looks like you're just applying the surface normal of the quad at the verticies, instead of finding and using the vertex normal (which would be the average of all the surface normals of the quads the vertex is a part of).
vNistelrooy
vNistelrooy
Quote:
Original post by concentrator
Yes I want to draw a surface(toroid) and i'm calculating the vertex normals using the parametric superquadratic function. When I use glShadeModel(GL_SMOOTH), the shape looks like the one at right. It's shading each quad one by one however I want the whole object to be shaded but I'm missing something.

Here's the image
http://www.geocities.com/concentrator2/toroid.jpg


OpenGL can't magically smoothly shade all you model. The gouraud shading happens per triangle, however if you have one normal for every shared vertex the surface of your model will look smooth. So, the normal at the bottom left of quad A must equal to the normal at the bottom right of the quad left to quad A, and so on.
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
deavik
deavik
Concentrator, there is something fundamentally wrong here. In smooth shading, each vertex has one constant normal. Let me explain better what is wrong:

Say quadrilaterals 1, 2, 3 and 4 share vertex # 47. When you are drawing these quads, you are specifying a different normal for vertex # 47 each time. That doesn't give you smooth shading.

To be safe, you should make a vertex struct, and make it have 2 member vectors, one for the position coords of the vertex, another for the direction of the normal. But the problem at the moment is with your calculations. If it helps, what should look like a convex bulge for each quad is looking like a concave depression.

Personally, I think it would be easier to average the face normals and store it once and for all in your vertex struct.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.