glDrawElements and flat shading

后端 未结 2 1218
庸人自扰
庸人自扰 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)

提交回复
热议问题