(OpenGL 3.1-4.2)动态统一数组? [英] (OpenGL 3.1 - 4.2) Dynamic Uniform Arrays?

查看:90
本文介绍了(OpenGL 3.1-4.2)动态统一数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有2种物种,例如人类和小马.它们具有不同的骨骼系统,因此每个物种的统一骨排列必须不同.我是否必须实现两个单独的着色器程序以能够正确渲染每个骨骼阵列,还是有一种方法可以动态声明统一的数组并通过该动态数组进行迭代?

Lets say I have 2 species such as humans and ponies. They have different skeletal systems so the uniform bone array will have to be different for each species. Do I have to implement two separate shader programs able to render each bone array properly or is there a way to dynamically declare uniform arrays and iterate through that dynamic array instead?

请牢记性能(所有着色器都对决策分支无所适从).

Keeping in mind performance (There's all of the shaders suck at decision branching going around).

推荐答案

直到OpenGL 4.3,GLSL中的数组必须具有固定的编译时大小. 4.3允许使用着色器存储缓冲区对象,该对象允许其最终长度无界".基本上,您可以这样做:

Until OpenGL 4.3, arrays in GLSL had to be of a fixed, compile-time size. 4.3 allows the use of shader storage buffer objects, which allow for their ultimate length to be "unbounded". Basically, you can do this:

buffer BlockName
{
  mat4 manyManyMatrices[];
};

OpenGL将根据您使用 .因此,您仍然可以使用manyManyMatrices.length()来获取长度,但是它不是编译时常量.

OpenGL will figure out how many matrices are in this array at runtime based on how you use glBindBufferRange. So you can still use manyManyMatrices.length() to get the length, but it won't be a compile-time constant.

但是,此功能(在进行编辑时)是非常新的功能,仅在beta中实现.它还需要GL 4.x级硬件(也称为Direct3D 11级硬件).最后,由于它使用着色器存储块,因此访问数据的速度可能比人们希望的慢.

However, this feature is (at the time of this edit) very new and only implemented in beta. It also requires GL 4.x-class hardware (aka: Direct3D 11-class hardware). Lastly, since it uses shader storage blocks, accessing the data may be slower than one might hope for.

因此,我建议您仅使用要使用的矩阵数量最多的统一块.如果这成为内存问题(不太可能),那么您可以根据阵列大小拆分着色器,或者使用着色器存储块或其他任何方法.

As such, I would suggest that you just use a uniform block with the largest number of matrices that you would use. If that becomes a memory issue (unlikely), then you can split your shaders based on array size or use shader storage blocks or whatever.

这篇关于(OpenGL 3.1-4.2)动态统一数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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