0

I am making a app where i need to draw a lot of circles in the screen, so i had the idea of replacing the texture of the triangles i am using to draw the texture with a function to draw a circle. However after testing, it turned out to be slower than picking the values off a texture (although the quality is vastly superior). Is it a problem with the way i produce the circle, or reading from a texture is really a lot faster? (about twice as fast)

new code:

precision mediump float; 
uniform sampler2D u_Texture;
varying vec4 vColor; 
varying vec2 vTexCoordinate;
void main() {
  gl_FragColor = vec4(0, 0, 0, 0);
  mediump float thing = vTexCoordinate.x * vTexCoordinate.x + vTexCoordinate.y * vTexCoordinate.y;
  if(thing < 1.0 && thing > 0.9){
     gl_FragColor = vec4(0, 0, 0, 1);
  }
  if(thing < 0.9){
     gl_FragColor = vec4(1, 1, 1, 1) * vColor;
  }
};

old code:

gl_FragColor = texture2D(u_Texture, vTexCoordinate) * vColor;

obs: i didn't bother to rename vTexCoordinate, so it now have a value of [-1, 1] where it was [0, 1]

4

1 回答 1

0

条件分支在 GPU 上非常昂贵,因为没有分支预测,可能还有其他原因。此外,纹理查找延迟通常可以隐藏在着色器处理开销下,因此最终它实际上可能工作得更快。因此,如果可以的话,最好避免 GLSL 中的分支和循环。

于 2013-09-13T19:09:23.700 回答