OpenGL退化GL_TRIANGLES共享相同的顶点 [英] OpenGL degenerate GL_TRIANGLES sharing same vertices

查看:389
本文介绍了OpenGL退化GL_TRIANGLES共享相同的顶点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 glDrawElements()向GPU发送了 GL_TRIANGLES 的VertexBuffer + IndexBuffer。

I send a VertexBuffer+IndexBuffer of GL_TRIANGLES via glDrawElements() to the GPU.

在顶点着色器中,我想将一些顶点捕获到相同的坐标,以简化大型网格的动态。
作为结果,我预见了一个主要的性能提升,因为很多三角形崩溃到同一点,将退化。
但是我没有得到任何fps增益。

In the vertex shader I wanted snap some vertices to the same coordinates to simplify a large mesh on-the-fly. As result I expeceted a major performance boost because a lot of triangle are collapsing to the same point and would be degenerated. But I don't get any fps gain.

测试我的顶点着色器设置为 gl_Position(vec4(0))退化所有三角形,仍然没有区别...

Due testing I set my vertex shader just to gl_Position(vec4(0)) to degenerate ALL triangles, but still no difference...

有没有任何标志来激活退化或我失踪了什么?

Is there any flag to "activate" the degeneration or what am I'm missing?

glQuery GL_PRIMITIVES_GENERATED 也总是打印所有网格面的数量。

glQuery of GL_PRIMITIVES_GENERATED also prints always the number of all mesh faces.

推荐答案

您缺少的是您尝试使用的优化实际上是如何工作的。

What you're missing is how the optimization you're trying to use actually works.

您正在谈论的特定优化是 T& L的缓存。也就是说,如果相同的顶点要被处理两次,你只需处理一次,并使用结果两次。

The particular optimization you're talking about is post-caching of T&L. That is, if the same vertex is going to get processed twice, you only process it once and use the results twice.

你不明白是怎么相同顶点。它不是由任何你的顶点着色器可以计算。为什么?嗯,整个缓存点是避免运行顶点着色器。如果顶点着色器用于确定值是否已经缓存...您没有保存任何内容,因为您必须重新计算它以确定。

What you don't understand is how "the same vertex" is actually determined. It isn't determined by anything your vertex shader could compute. Why? Well, the whole point of caching is to avoid running the vertex shader. If the vertex shader was used to determine if the value was already cached... you've saved nothing since you had to recompute it to determine that.

相同的顶点实际上通过匹配顶点索引和顶点实例来确定。顶点数组中的每个顶点都有一个与之相关的唯一索引。如果您使用相同的索引两次(只能通过索引渲染),那么顶点着色器将接收相同的输入数据。因此,它将产生相同的输出数据。因此,您可以使用缓存的输出数据。

"The same vertex" is actually determined by matching the vertex index and vertex instance. Each vertex in the vertex array has a unique index associated with it. If you use the same index twice (only possible with indexed rendering of course), then the vertex shader would receive the same input data. And therefore, it would produce the same output data. So you can use the cached output data.

实例ID也适用于此,因为在执行实例化渲染,相同的顶点索引不一定意味着到VS的相同输入。但即使如此,如果你得到相同的顶点索引相同的实例id,那么你将获得相同的VS输入,因此获得相同的VS输出。因此在一个实例中,相同的顶点索引表示相同的值。

Instance ids also play into this, since when doing instanced rendering, the same vertex index does not necessarily mean the same inputs to the VS. But even then, if you get the same vertex index and the same instance id, then you would get the same VS inputs, and therefore the same VS outputs. So within an instance, the same vertex index represents the same value.

实例计数和顶点索引都是渲染过程的一部分。它们不是来自顶点着色器可以计算的任何东西。顶点着色器可以生成相同的位置,法线或其他任何东西,但实际的后转换缓存基于顶点索引和实例。

Both the instance count and the vertex indices are part of the rendering process. They don't come from anything the vertex shader can compute. The vertex shader could generate the same positions, normals, or anything else, but the actual post-transform cache is based on the vertex index and instance.

所以如果你想以将一些顶点捕获到相同的坐标以简化大网格,您必须在之前的渲染命令。如果您想在着色器中即时执行此操作,则需要某种类型的计算着色器几何着色器 / transform feedback 过程将计算新的网格。然后你需要渲染这个新的网格。

So if you want to "snap some vertices to the same coordinates to simplify a large mesh", you have to do that before your rendering command. If you want to do it "on the fly" in a shader, then you're going to need some kind of compute shader or geometry shader/transform feedback process that will compute the new mesh. Then you need to render this new mesh.

你可以丢弃几何着色器中的基元。但你还是要做T& L。另外,使用GS会使事情变慢,所以我很怀疑你会通过这样做获得更多的性能。

You can discard a primitive in a geometry shader. But you still had to do T&L on it. Plus, using a GS at all slows things down, so I highly doubt you'll gain much performance by doing this.

这篇关于OpenGL退化GL_TRIANGLES共享相同的顶点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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