【发布时间】:2024-01-01 07:47:01
【问题描述】:
我正在使用 OpenGL ES 2.0 进行项目。我的网格中的每个顶点都有固定数量的颜色属性(比如说 5 个)。最终的每个顶点颜色计算为两个选定颜色属性之间的插值。
在我的实现中,两种颜色的选择基于两个给定的索引。我知道if 语句可能会对性能造成很大影响,因此选择将所有属性放入一个数组并使用索引来检索想要的颜色。我仍然看到性能显着下降。
attribute vec4 a_position;
//The GLSL ES 2.0 specification states that attributes cannot be declared as arrays.
attribute vec4 a_color;
attribute vec4 a_color1;
attribute vec4 a_color2;
attribute vec4 a_color3;
attribute vec4 a_color4;
uniform mat4 u_projTrans;
uniform int u_index;
uniform int u_index1;
uniform float u_interp;
varying vec4 v_color;
void main()
{
vec4 colors[5];
colors[0] = a_color;
colors[1] = a_color1;
colors[2] = a_color2;
colors[3] = a_color3;
colors[4] = a_color4;
v_color = mix(colors[u_index], colors[u_index1], u_interp);
gl_Position = u_projTrans * a_position;
}
有没有更好更有效的方法来计算最终的颜色插值?或者至少是选择插值颜色的更好方法?
【问题讨论】: