GLSL 动态索引数组

发布于 2024-10-06 14:33:25 字数 509 浏览 6 评论 0原文

我使用 DirectX(带有 XNA)已经有一段时间了,最​​近改用了 OpenGL。我真的很喜欢它,但有一件事让我很恼火。

我一直在尝试实现一些需要在顶点着色器中动态索引的东西,但我被告知这需要 SM 4.0 的等效项。但我知道即使使用 SM 2.0,甚至可能是 1.0,这也适用于 DX。 XNA 的实例化示例使用它在仅 SM2.0 的卡上进行实例化 http:// /create.msdn.com/en-US/education/catalog/sample/mesh_instancing

编译器不可能将其“展开”到一个巨大的 if 语句列表中,因为这肯定会超出 SM2 对 250 个实例的指令限制。

那么,DX 是否做了一些我用 OpenGL 无法做到的技巧,我可以操纵 OpenGL 来做同样的事情,还是 OpenGL 没有公开的硬件功能?

I've been using DirectX (with XNA) for a while now, and have recently switched to OpenGL. I'm really loving it, but one thing has got me annoyed.

I've been trying to implement something that requires dynamic indexing in the vertex shader, but I've been told that this requires the equivilant of SM 4.0. However I know that this works in DX even with SM 2.0, possibly even 1.0. XNA's instancing sample uses this to do instancing on SM2.0 only cards http://create.msdn.com/en-US/education/catalog/sample/mesh_instancing.

The compiler can't have been "unrolling" it into a giant list of if statements, since this would surely exceed the instruction limit on SM2 for our 250 instances.

So is DX doing some trickery that I can't do with OpenGL, can I manipulate OpenGL to do the same, or is it a hardware feature that OpenGL doesn't expose?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷弦 2024-10-13 14:33:25

您可以使用 glUniform3fv 之类的东西上传一个用于您的光线方向的数组,然后(假设我理解您想要正确执行的操作)您只需要顶点格式将索引包含到该数组中(因此这些数组会有很多重复)索引(如果索引每个网格仅更改一次或其他)。如果您还不知道,可以使用 glGetAttribLocation + glVertexAttribPointer 将任意顶点属性发送到着色器(而不是使用已弃用的内置属性,如 gl_Vertex、gl_Normal 等)。

You can upload an array for your light directions with something like glUniform3fv, then (assuming I understand what you're trying to do correctly) you just need your vertex format to include an index into this array (so there be lots of duplication of these indices if the index only changes once per mesh or something). If you don't already know, you can use glGetAttribLocation + glVertexAttribPointer to send arbitrary vertex attributes like this to the shader (as opposed to using the deprecated built-in attributes like gl_Vertex, gl_Normal, etc).

狼性发作 2024-10-13 14:33:25

从您的链接:

请注意,没有单一的完美
实例化技术。这必须是
以不同的方式实施
Windows 与 Xbox 360 的比较
Windows 理想的技术要求
着色器 3.0,但还有一个
后备方法将与
着色器 2.0。该示例实现了
几个不同的实例
技术,因此它可以同时工作
平台和着色器版本。


不是加粗的部分。因此,在此基础上,您应该能够在着色器模型 3 上执行类似的实例化。着色器模型 2 的实例化通常使用矩阵调色板执行。简而言之,您可以通过一次性上传大量变换矩阵来在一次调用中渲染多个网格。这减少了绘制调用并提高了速度。

不管怎样,对于 OpenGL 来说,完成这个扩展有很多麻烦,因此你需要着色器 4。但是,你仍然可以在 yoru 顶点结构中粘贴每个顶点矩阵调色板索引,并使用着色器进行矩阵调色板渲染...

From your link:

Note that there is no single perfect
instancing technique. This must be
implemented in a different way on
Windows compared to Xbox 360, and on
Windows the ideal technique requires
shader 3.0, but there is also a
fallback approach that will work with
shader 2.0
. This sample implements
several different instancing
techniques, so it can work on both
platforms and shader versions.

Not the emboldened part. So ont hat basis you should be able to do similar instancing on shader model 3. Shader model 2's instancing is usually performed using a matrix palette. It sumply means you can render multiple meshes in one call by uploading a load of transformation matrices in one go. This reduces draw calls and improves speed.

Anyway for OpenGL there was a lot of troubles finalising this extension and hence you need shader 4. You CAN, however, still stick a per vertex matrix palette index in yoru vertex structure and do matrix palette rendering using a shader...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文