[英]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.