Passing large array into uniform in WebGL

后端 未结 1 1305
悲&欢浪女
悲&欢浪女 2021-01-13 07:48

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

// array here
uniform vec4[huge] mydynamicarray;

void main() {
  // iterat         


        
相关标签:
1条回答
  • 2021-01-13 08:24

    Most WebGL implementations have a limit of 1024 or less uniform vectors

    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.

    You can declare arrays

    uniform vec4 foo[3];
    

    And set their values with

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

    Textures are how you pass in large amounts of random access data into WebGL. This answer might be relevant.

    0 讨论(0)
提交回复
热议问题