尝试在 for 循环中递增变量时出现 Glsl 错误

Glsl error when trying to increment a variable inside a for loop

上下文:我将一个统一的浮点数数组传递给我的片段着色器,然后用这个数组中的值初始化一个浮点数,最后尝试在 for 循环中增加这个浮点数,代码如下:

var regl = createREGL()

var drawTriangle = regl({
  vert: `
  precision mediump float;
  attribute vec2 position;

  void main () {
    gl_Position = vec4(position, 0, 1);
  }
  `,

  frag: `
  precision mediump float;
  uniform float refPoints[3];
  varying vec3 fcolor;

  void main () {
    float a_value = refPoints[1];
    for(int i=0;i<3;++i) {
      a_value += 1.; // <-- this line is causing the error
    }
    gl_FragColor = vec4(1, 1, 1, 1);
  }
  `,
  attributes: {
    position: [
      [1, 0],
      [0, 1],
      [-1, -1]
    ],
  },
  uniforms : {
    refPoints : [0., 1., 0., 2.]
  },
  count: 3
})

regl.frame(function () {
  regl.clear({
    color: [0, 0, 0, 1],
    depth: 1
  })
  drawTriangle()
})
<script src="https://npmcdn.com/regl/dist/regl.js"></script>

我遇到了一个奇怪的错误:

Error: (regl) bad data or missing for uniform "refPoints[0]".  invalid type, expected number in command unknown

我不明白为什么这个特定循环中的增量会造成这么多麻烦。你有什么想法吗?

AFAICT 这是 regl 中的错误?如果您使用

它会起作用
    uniforms: { 
      "refPoints[0]": 0.,
      "refPoints[1]": 1.,
      "refPoints[2]": 0.,
    }

var regl = createREGL()

var drawTriangle = regl({
  vert: `
  precision mediump float;
  attribute vec2 position;

  void main () {
    gl_Position = vec4(position, 0, 1);
  }
  `,

  frag: `
  precision mediump float;
  uniform float refPoints[3];
  varying vec3 fcolor;

  void main () {
    float a_value = refPoints[1];
    for(int i=0;i<3;++i) {
      a_value += 1.; // <-- this line is causing the error
    }
    gl_FragColor = vec4(1, 1, 1, 1);
  }
  `,
  attributes: {
    position: [
      [1, 0],
      [0, 1],
      [-1, -1]
    ],
  },
  uniforms : {
    "refPoints[0]" : 0.,
    "refPoints[1]" : 1.,
    "refPoints[2]" : 0.,
  },
  count: 3
})

regl.frame(function () {
  regl.clear({
    color: [0, 0, 0, 1],
    depth: 1
  })
  drawTriangle()
})
<script src="https://npmcdn.com/regl/dist/regl.js"></script>