Is it possible to achieve flat shading in OpenGL when using glDrawElements to draw objects, and if so how? The ideal way would be to calculate a normal for each triangle only once, if possible.
The solution must only use the programmable pipeline (core profile).
Flat shading is the simplest shading model which calculates the illumination at a single point for each polygon (or polygon vertices in OpenGL) which means that it yields the same value for all the pixels across the polygon. Advantages. Fast, a single computation per polygon (or one per polygon vertex in OpenGL)
The glShadeModel function selects flat or smooth shading.
There are indeed ways around this without duplicating vertices, with some limitations for each one (at least those I can think of with my limited OpenGL experience).
I can see two solutions that would give you a constant value for the normal over each triangle :
flat
in your shader and pick which vertex gives its value via glProvokingVertex; fast but you'll get the normal for one vertex as the normal for the whole triangle, which might not look rightIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With