在WebGL中将大型数组传递给统一 [英] Passing large array into uniform in WebGL

查看:77
本文介绍了在WebGL中将大型数组传递给统一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想知道是否可以将大型数组传递到WebGL着色器中,例如:

Wondering if it's possible to pass a large array into a WebGL shader, like this:

// array here
uniform vec4[huge] mydynamicarray;

void main() {
  // iterate through the array here to perform processing on it,
  // then write value to gl_Position
  gl_Position = ...;
}

然后将其填充为这样:

gl.uniform4fv(myarrayloc, myarray)

我已经看到许多示例像这样的值,例如:

I have seen many examples of how to pass in values like this, such as:

gl.uniform4fv(offsetLoc, [1, 0, 0, 0])

但是我还没有看到是否可以传递一个很大的,动态大小的数组.

But I have not seen if it's possible to pass in a very large, dynamically sized array.

之所以这样做,是因为您可以处理2个数组:

The reason to do this would be you could process 2 arrays:

  1. 一个是在WebGL中并行运行的向量数组.
  2. 一个是您可以为每个向量迭代的统一数组.

推荐答案

大多数WebGL实现的限制为1024个或更少的均匀向量

换句话说, huge 不能大于1024 vec4s或特定GPU的限制.还要注意,基于规范中指定的统一打包规则,这也意味着最大的float统一数组也为1024或特定GPU的限制.

In other words huge can't be greater than 1024 vec4s or whatever the limit of your particular GPU is. Also note that based on uniform packing rules specified in the spec that also means the largest float uniform array is also 1024 or whatever the limit of your particular GPU is.

您可以声明数组

uniform vec4 foo[3];

并使用

gl.uniform4fv(fooLoc, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);

纹理是您将大量随机访问数据传递到WebGL中的方式.此答案可能很重要.

这篇关于在WebGL中将大型数组传递给统一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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