gpt4 book ai didi

opengl-es - 为 OpenGL ES 2.0 中的数组索引提供一个整数?

转载 作者:行者123 更新时间:2023-12-04 15:46:44 24 4
gpt4 key购买 nike

我正在为 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;
}

这引发了一个错误:

int can't be an in in the vertex shader



我做了一些研究。 iPhone 最晚支持 OpenGL ES 2.0,这意味着它最晚支持 GLSL 1.2,显然整数只在 GLSL 1.3 及更高版本中支持。我尝试将 a_colorIndex 更改为浮点数。我没想到它会起作用,它没有。

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

最佳答案

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

关于opengl-es - 为 OpenGL ES 2.0 中的数组索引提供一个整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11379936/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com