glDrawElements and flat shading

拥有回忆 提交于 2019-12-01 03:36:20

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)

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...

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!