glDrawElements和平面底纹 [英] glDrawElements and flat shading

查看:105
本文介绍了glDrawElements和平面底纹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用glDrawElements绘制对象时,是否可以在OpenGL中实现平面着色?理想的方法是,如果可能的话,对每个三角形仅计算一次法线.

该解决方案只能使用可编程管道(核心配置文件).

解决方案

确实存在解决此问题的方法,而不必复制顶点,但每个顶点都有一些限制(至少我在有限的OpenGL经验中可以想到这些限制).

我可以看到两个解决方案,它们可以为您在每个三角形上的法线提供恒定的值:

  • 在着色器中将输入声明为flat,并通过 glProvokingVertex来选择哪个顶点为其提供值;快速,但您会得到一个顶点的法线像整个三角形的法线一样,这看起来可能不正确
  • 使用几何着色器获取三角形并输出三角形,以计算每个面的单个法线.这是最灵活的方法,允许您控制所产生的效果,但是它可能很慢(显然是必需的具有几何着色器的硬件)

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

解决方案

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)

这篇关于glDrawElements和平面底纹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆