glMultiDraw函数和gl_InstanceID [英] glMultiDraw functions and gl_InstanceID

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

问题描述

当我查看 glMultiDrawElementsIndirect (或在 Wiki 中)表示对glMultiDrawElementsIndirect等同于重复调用glDrawElementsIndirect(只是使用不同的参数).

When I look at the documentation of glMultiDrawElementsIndirect (or in the Wiki) it says that a single call to glMultiDrawElementsIndirect is equivalent to repeatedly calling glDrawElementsIndirect (just with different parameters).

这是否意味着gl_InstanceID将为每个内部"调用重置?如果是这样,我怎么能在顶点着色器中区分所有这些调用?

Does that mean that gl_InstanceID will reset for each of these "internal" calls? And if so, how am I able to tell all these calls apart in my vertex shader?

背景:我正在尝试一次绘制所有不同的网格.但是我需要某种方式来知道我在顶点着色器中处理的顶点属于哪个网格.

Background: I'm trying to draw all my different meshes all at once. But I need some way to know to which mesh the vertex, I'm processing in my vertex shader, belongs.

推荐答案

文档说类似于". 等效"不是一回事.它还指向glDrawElementsInstancedBaseVertexBaseInstance,而不是glDrawElementsInstanced.

The documentation says "similarly to". "Equivalent" isn't the same thing. It also points to glDrawElementsInstancedBaseVertexBaseInstance, not glDrawElementsInstanced.

但是,是的,无论您提供什么基本实例,任何绘制的gl_InstanceId都将从零开始.不幸的是,这就是 gl_InstanceId的工作方式.

But yes, gl_InstanceId for any draw will start at zero, no matter what base instance you provide. That's how gl_InstanceId works, unfortunately.

此外,这不是您要回答的问题.您无需询问要渲染的实例,因为多绘制中的每个绘制都可以渲染多个实例.您要问的是您在多张图纸中的哪张.实例ID不能提供帮助.

Besides, that's not the question you want answered. You're not looking to ask which instance you're rendering, since each draw in the multi-draw can be rendering multiple instances. You're asking which draw in the multi-draw you are in. An instance ID isn't going to help.

如果是的话,如何在我的顶点着色器中区分所有这些调用?

And if so, how am I able to tell all these calls apart in my vertex shader?

除非具有OpenGL 4.6或ARB_shader_draw_parameters,否则不能.好吧,不是直接.

Unless you have OpenGL 4.6 or ARB_shader_draw_parameters, you can't. Well, not directly.

也就是说,基于从当前缓冲区对象的不同部分进行渲染,而不是基于着色器中的计算,预期多绘制操作会产生不同的结果.您正在使用不同的基础顶点进行渲染,该基础顶点会从数组中选择不同的顶点,或者您使用的索引范围也不相同.

That is, multidraw operations are expected to produce different results based on rendering from different parts of the current buffer objects, not based on computations in the shader. You're rendering with a different base vertex that selects different vertices from the arrays, or you're using different ranges of indices or whatever.

典型的pre-shader_draw_parameters解决方案是在每个单独的绘制上使用唯一的基本实例.当然,由于gl_InstanceId不会跟踪基本实例(如前所述),因此您需要使用

The typical pre-shader_draw_parameters solution would have been to use a unique base instance on each of the individual draws. Of course, since gl_InstanceId doesn't track the base instance (as previously stated), you would need to employ instanced arrays instead. So you'd get the mesh index from that.

当然,4.6/shader_draw_parameters为您提供gl_DrawId,它仅告诉您multidraw命令中的索引是什么.它也是动态统一的,因此您可以使用它来访问着色器中的不透明类型的数组.

Of course, 4.6/shader_draw_parameters gives you gl_DrawId, which just tells you what the index is within the multidraw command. It's also dynamically uniform, so you can use it to access arrays of opaque types in shaders.

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

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