OpenGL Shading Language and flatshading



Is it possible to have a varying variable whose value is interpolated according to the shading model, as are the vertex colors?

I have a cube made of one triangle strip of 14 vertices and 12 normals. The normals are specified for flatshading. I would like to compute the lighting in the fragment shader (to have per-fragment specular and to bypass color clamping). With glShadeModel set to GL_FLAT, if I pass the normal as a varying variable to the fragment shader, it is interpolated linearly from one vertex to the other, resulting in incorrect per-fragment normals.

One way I found to prevent this is to range-compress the normal (like in a normal map) and assign the value to gl_FrontColor or gl_FrontSecondaryColor. This works fine, but results in banding artifacts due to the limited precision of the fixed-point color components.

Is there a way to “flatshade” a varying variable?



Hugues De Keyzer

No. This kind of effect could be done with a primitive assembly program.
For now, break up the faces of the cube.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.