Emulating glShadeModel( GL_FLAT )?

How would a shader program emulate glShadeModel( GL_FLAT )? I’m not using vertices with varying colors, so it’s a question of how to make the lighting constant across a triangle.

How would a shader program emulate glShadeModel( GL_FLAT )?

See the “flat” input/output qualifier section in the GLSL specification.

Ah. Looks like I’m out of luck, because I’m on the Mac, and so far Apple only supports GLSL 1.20. The “flat” qualifier came in with GLSL 1.30. Thanks anyway.

“flat” is also part of EXT_gpu_shader4, which has been shipping on the Mac since 10.4.8.

Interesting. I assume you mean it’s been shipping on the Mac for some video cards, as I see it on one of my Macs and not the other (both running Snow Leopard).

EXT_gpu_shader4 requires SM4.0 hardware, which translates into Nvidia 8000-series and Ati 2000-series or newer. Older hardware cannot support this extension.

I don’t know whether anything equivalent exists for GLSL 1.2.

You an use the dfdx/dfdy functions as shown in the post below:

http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=244511#Post244511

To get face normals and do something like flat shading, you won’t need to specify face normals as a vertex attribute.

Cool, the derivative trick works, so now I can get flat shading on any machine that supports GLSL at all. Thanks!