繁体   English   中英

在GLSL ES 2.0中如何有效地在许多颜色属性之间进行插值

[英]How effectively interpolate between many color attributes in GLSL ES 2.0

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

有没有更好,更有效的方法来计算最终颜色插值? 或者至少是选择插值颜色的更好方法?

您在此处使用的索引是统一的。 这意味着每个渲染命令中的每个顶点都使用相同的索引。 如果是这样的话...为什么您根本不愿意在VS中获取这些东西?

您应该只有2个颜色输入值。 然后,您可以使用glVertexAttribPointer选择将在其间进行插值的两个数组。

您的“显着性能下降”可能与获取此类值的方式无关,而与发送大量从未使用过的每个顶点数据有关。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM