我可以在OpenGL ES中指定每面法线并实现不平滑/平坦的阴影吗? [英] Can I specify per face normal in OpenGL ES and achieve non-smooth/flat shading?

查看:126
本文介绍了我可以在OpenGL ES中指定每面法线并实现不平滑/平坦的阴影吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在OpenGL ES 2.0中显示网格模型,在该模型中可以清楚地显示实际的网格,所以我不想在每个图元/三角形上都具有平滑的阴影.我唯一能想到的两个选择是

I want to display mesh models in OpenGL ES 2.0, where it clearly shows the actual mesh, so I don't want smooth shading across each primitive/triangle. The only two options I can think about are

  1. 每个三角形都有自己的一组法线,所有法线都垂直于三角形表面(但是我想我不能使用此选项在三角形之间共享顶点)
  2. 使用黑线指示三角形/原始边,并坚持使用共享顶点的法线和每个顶点一个法线

一定要这样吗?为什么我不能简单地读入基元并且不指定任何法线,而又以某种方式让OpenGL ES 2.0在每个面上制作平坦的阴影?

Does it have to be like this? Why can't I simply read in primitives and don't specify any normals and somehow let OpenGL ES 2.0 make a flat shade on each face?

类似的问题类似的Stackoverflow问题,但没有解决方案的建议

推荐答案

因为要在网格上(任何平滑或平坦的)阴影,您需要一个光照模型,而OpenGL ES无法猜测. GL ES 2中没有固定的管道,因此您不能使用任何可以为您完成工作的内置功能(使用内置照明模型).

Because in order to have shading on your mesh (any, smooth or flat), you need a lighting model, and OpenGL ES can't guess it. There is no fixed pipeline in GL ES 2 so you can't use any built-in function that will do the job for you (using a built-in lighting model).

在平面阴影中,整个三角形将使用相同的颜色绘制,该颜色是从其法线和光源之间的角度计算得出的(是的,您还需要一个光源,它可能只是透视图的原点) .这就是每个三角形至少需要一个法线的原因.

In flat shading, the whole triangle will be drawn with the same color, computed from the angle between its normal and the light source (Yes, you also need a light source, which could simply be the origin of the perspective view). This is why you need at least one normal per triangle.

然后,GPU以非常并行的方式工作,同时处理多个顶点(然后是片段).为了提高效率,它不能在顶点之间共享数据.这就是为什么您需要为每个顶点复制法线的原因.

Then, a GPU works in a very parallelized way, processing several vertices (and then fragments) at the same time. To be efficient, it can't share data among vertices. This is why you need to replicate normals for each vertex.

此外,您的网格不再能够像您所说的那样在三角形之间共享顶点,因为它们仅共享顶点位置,而不共享顶点法线.因此,您需要在缓冲区中放置3 * NbTriangles个顶点,每个顶点具有一个位置和一个法线.使用三角形条纹/扇形将不会带来任何好处,因为您的任何一个面都不会与另一个面具有相同的顶点(因为再次有不同的法线).

Also, your mesh can't share vertices among triangles anymore as you said, because they share only the vertex position, not the vertex normal. So you need to put 3 * NbTriangles vertices in you buffer, each one having one position and one normal. You can't either have the benefit of using triangle strips/fans, because none of your faces will have a common vertex with another one (because, again, different normals).

这篇关于我可以在OpenGL ES中指定每面法线并实现不平滑/平坦的阴影吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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