在OpenGL ES 2.0中为数组索引提供整数?

Ell*_*ott 6 opengl-es glsl

我正在为iPhone开发一个OpenGL应用程序.在我的顶点着色器中,我需要一种方法来同时更改大量(但不是全部)顶点的颜色,因此我选择了颜色索引.这将允许我保持VBO静态,并修改单个统一变量,而不是循环遍历每个顶点并修改每个帧之间的颜色信息.

我的计划是使用颜色数组创建一个制服,在属性中添加一个包含索引的整数.这是我的顶点着色器:

uniform mat4 u_mvp_matrix;
uniform vec4 u_color_array[];

attribute vec4 a_position;
attribute int a_colorIndex;

varying lowp vec4 v_color;

void main()
{
    v_color = u_color_array[a_colorIndex];

    gl_Position = u_mvp_matrix * a_position;
}
Run Code Online (Sandbox Code Playgroud)

这引发了一个错误:

int不能是顶点着色器中的in

我做了一些研究.iPhone最迟支持OpenGL ES 2.0,这意味着它最迟支持GLSL 1.2,显然只有GLSL 1.3及更高版本才支持整数.我尝试将a_colorIndex更改为float.我没想到它会起作用,但事实并非如此.

如何为每个顶点指定颜色索引?

Nic*_*las 4

将属性指定为浮点数。您可以使用浮点数作为数组的索引。