Problem with GL_FLAT shading

no, that is not incorrect. It is the answer to his question, which everyone else failed to give.

GL_FLAT_SHADING is not what he wants, though he though it was. He just wants to shade polygons using the surface normal of the polygon to determine the light color instead of using the 3 vertex normals.

The way to accomplish this in OpenGL is to use duplicate vertices and normals so that each polygon has its own set of normals, and then to make all 3 normals for the polygon equal to the surface normal of the polygon.

right. which is what i said about 9 posts ago, in reference to what someone else said a bunch of posts ago.

use the surface normal for all 3 vertices…what’s the problem here?

sigh

Because for certain lighting calculations the position of the “to be lit” vertex and its associated normal is important, especially for bigger polygons.

Spot direction, spot cut off and quadratic attenuation if any of that rings a bell.

If you follow cesarsalad post’s this is exactly what he is complaining about, assigning the surface normal to all verticies only works for simple directional lighting and hence is the given advice incorrect.

Besides, if you look at the code example he gave in his very first post, he already specifies the normal before the verticies, so that normal will be used for all the following verticies.

I am not sure what exactly he is doing but if he says he needs the lighting the way he descriped, I believe he has his reasons.

Cheers!

Originally posted by lgrosshennig:
Unless you subdivide your polygon into a triangle fan and make sure the "center point " is the "i + 2"th vertex in every triangle, I am afraid not.
I agree; this is the only way to get the result the OP wants.

Though for a mesh of any size I suspect that GL_TRIANGLES would be better than GL_TRIANGLE_FAN; you’d be sending more data to GL, but you’d have the same number of verts (assuming indexing), the pattern would be pretty vertex-cache-friendly and you’d get far more efficient batching.

Edit: plus GL_TRIANGLE_FAN couldn’t work, because the centre vertex is only issued once. I guess you were speaking loosely. Which makes this post somewhat redundant. Oh well.

Originally posted by MikeC:
I agree; this is the only way to get the result the OP wants.

Though for a mesh of any size I suspect that GL_TRIANGLES would be better than GL_TRIANGLE_FAN; you’d be sending more data to GL, but you’d have the same number of verts (assuming indexing), the pattern would be pretty vertex-cache-friendly and you’d get far more efficient batching.

Edit: plus GL_TRIANGLE_FAN couldn’t work, because the centre vertex is only issued once. I guess you were speaking loosely. Which makes this post somewhat redundant. Oh well.[/QB]
Agreed :slight_smile: . I was thinking of an triangle fan first because it was the first plausible thing that came to mind but you are right, you need independent triangles (which share verticies using indexing) and locate the “center point” at 3i.

It dosent change the idea behind it though, just the implementation.

Thanks for pointing it out.

Flat shading in OpenGL is not exclusively about normals it is also about the interpolation of per vertex values.

With flat shading the last color value or lighting result calculated before (or with) the last vertex is the color used across the whole triangle.

If you want a ‘faceted’ appearance with correct lighting per vertex then you should specify the same normal for each triangle vertex and keep smooth shading on. The only problem with this is you won’t be able to use meshed primitives for the facets, but GL_TRIANGLES would probably be the method of choice.

Originally posted by dorbie:
Flat shading in OpenGL is not exclusively about normals it is also about the interpolation of per vertex values.
Excuse me? In flat shading there is no color interpolation going on (unless you count an increment of ZERO for all color channels as an increment). Depending on the primitive, one of the specified verticies will be lit and colored and that color will be substituted for the entire polygon. This is not what the OP wants though, he wants the “center” of a polygon to be lit and colored.

Originally posted by dorbie:
With flat shading the last color value or lighting result calculated before (or with) the last vertex is the color used across the whole triangle.

Or the first one in case of an single polygon, if you check the piece of spec thats being posted.

Originally posted by dorbie:
If you want a ‘faceted’ appearance with correct lighting per vertex then you should specify the same normal for each triangle vertex and keep smooth shading on.

Ok, its obvious now that you havent even read the thread or know what the OP desires.

Originally posted by dorbie:
The only problem with this is you won’t be able to use meshed primitives for the facets, but GL_TRIANGLES would probably be the method of choice.
Congrats to come to the only logical conclusion left over.

Cheers!