如果统一块太大,则会发现OpenGL统一nof [英] OpenGL uniform nof found if uniform block gets too big

查看:104
本文介绍了如果统一块太大,则会发现OpenGL统一nof的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现统一块.

I´m trying to implement a Uniform Block.

这是我的片段着色器中的块的样子:

This is how the block looks like in my fragment shader:

struct Light {
    uint LightType;
    vec3 Direction;
    float SpotBlur;
    vec3 AmbientColor;
    float LinearAttenuation;
    vec3 DiffuseColor;
    float QuadraticAttenuation;
    vec3 SpecularColor;
    float CubicAttenuation;
    vec3 Position;
    float SpotCutoff;
};

layout(std140) uniform LightBlock
{
    Light values;
} lights[32];

如您所见,我定义了固定大小为32的Light结构的数组.我可以上传数据而没有任何问题,但是现在我不了解了. 如果灯光"阵列的尺寸相对较小(大约为6),则将找到我所有的着色器制服.但是当增加灯"的尺寸时,它开始有点覆盖我的制服.例如,它不再能够从顶点着色器中找到我的"modelViewProjection"矩阵(返回-1作为统一位置).

As you can see, I defined an array of the Light struct with a fixed size of 32. I can upload the data without any problems but now comes what I dont understand. If the "lights" array has a relatively small size (something around 6) all of my shader uniforms are found. but when increasing the "lights" size then it begins to kinda override my uniforms. For example it could not find my "modelViewProjection" matrix from the vertex shader anymore (returned -1 as the uniform location).

推荐答案

问题

OpenGL通过MAX_VERTEX_UNIFORM_COMPONENTS_ARB限制统一数组的大小. 从我所见,通常将其设置为2048或4096,因此分别限制为512或1024字节. (这取决于图形硬件)
一个Light对象当前使用84字节的数据.
问题是当您创建由32个这些对象组成的数组时,这些数组将占用2688字节的数据.
之所以选择大小为6的原因是因为84 * 6为504,即< 512.

The Problem

OpenGL limits the size of uniform arrays by MAX_VERTEX_UNIFORM_COMPONENTS_ARB. From what I have seen, this is usually set to 2048 or 4096, thus a 512 or 1024 byte limit respectively. (It is dependent up on the graphics hardware)
One Light object currently uses 84 Bytes of data.
The issue is when you create an array of 32 of these objects that uses up 2688 Bytes of data.
The reason a size of 6 works is because 84*6 is 504 which is < 512.

不幸的是,根据我的研究,看来此限制是由硬件施加的,除非您切换到具有不同限制的图形卡(或者可能通过创建自定义图形来更改OpenGL实现),否则无法更改此限制.司机).解决问题的最简单方法是 减小灯光阵列的大小或减小灯光对象(或两者的组合)的大小.

Unfortunately, from my research, it appears that this limit is imposed by hardware and there is no way to change it unless you switch to a graphics card that has a different limit (or possibly change the OpenGL implementation by creating a custom graphics driver). The simplest way to fix your issue is to decrease the size of your lights array or decrease the size of your light object (or a combination of both).

谢谢BDL对于使用UBO或SSBO的出色建议.他是正确的,这些将使您能够通过更大的制服.我还编辑了答案,以反映MAX_VERTEX_UNIFORM_COMPONENTS的真实定义.

Thank you BDL For the excellent suggestion of using UBOs or SSBOs. He is correct that these will allow you to pass larger uniforms. I have also edited my answer to reflect the true definition of MAX_VERTEX_UNIFORM_COMPONENTS.

@bitQUAKE提出了一种使用不同大小限制的解决方法:
在下面的评论中查看他的解决方案. 此处是与该主题相关的讨论.

@bitQUAKE came up with a workaround that uses a different size limit:
Check in the comments below for his solution. Here is a relevant discussion on the topic.

这篇关于如果统一块太大,则会发现OpenGL统一nof的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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