glDrawElements and flat shading

后端 未结 2 1191
庸人自扰
庸人自扰 2021-01-11 18:41

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 onl

相关标签:
2条回答
  • 2021-01-11 19:11

    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 :

    • declare the input as 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 right
    • use a geometry shader taking triangles and outputing triangles to calculate a single normal per face. This is the most flexible way, allowing you to control the resulting effect, but it might be slow (and required geometry shader capable hardware, obviously)
    0 讨论(0)
  • 2021-01-11 19:18

    Sadly, the only way to do that is to duplicate all your vertices, since attributes are per-vertex and not per-triangle

    When you think about it, this is what we did in immediate mode...

    0 讨论(0)
提交回复
热议问题