2014-10-29 39 views
0

我用GL20.GL_POINTS阴影图片。其中一点是可变的('vKind'代码)。当属性发生变化时,我应该同时更改纹理。以下是我的方法。但我得到了一个低fps。我该怎么办?任何帮助谢谢!片段着色器中的多纹理。我得到了一个低fps

 final String fragmentShader = "precision highp float;\n" 
      + "uniform sampler2D u_texture0;\n" // diffuse texture for 
      + "uniform sampler2D u_texture1;\n" // diffuse texture for 
      + "uniform sampler2D u_texture2;\n" // diffuse texture for 
      + "uniform sampler2D u_texture3;\n" // diffuse texture for 
      + "uniform sampler2D u_texture4;\n" // diffuse texture for 
      + "uniform sampler2D u_texture5;\n" // diffuse texture for 
      + "uniform sampler2D u_texture6;\n" // diffuse texture for 
      + "uniform sampler2D u_texture7;\n" // diffuse texture for 
      + "varying float vRotation;\n" 
      + "varying float vKind;\n" 
      + "varying vec4 vColor;\n" // input color from vertex shader 
      + "void main() {\n" 
      + "highp vec2 center = vec2(0.5, 0.5);\n" 
      // Translate the center of the point the origin. 
      + "highp vec2 centeredPoint = gl_PointCoord - center;\n" 
      // Create a rotation matrix using the provided angle 
      + "highp mat2 rotation = mat2(cos(vRotation), sin(vRotation),\n" 
      + "-sin(vRotation), cos(vRotation)); \n" 
      // Perform the rotation. 
      + "centeredPoint = centeredPoint*rotation ;\n" 
      // Translate the point back to its original position and use 
      // that point 
      // to get your texture color. 
      + "if(vKind==0.0)\n" 
      + "gl_FragColor = texture2D(u_texture0, centeredPoint + center);\n" 
      + "else if(vKind==1.0)\n" 
      + "gl_FragColor = texture2D(u_texture1, centeredPoint + center);\n" 
      + "else if(vKind==2.0)\n" 
      + "gl_FragColor = texture2D(u_texture2, centeredPoint + center);\n" 
      + "else if(vKind==3.0)\n" 
      + "gl_FragColor = texture2D(u_texture3, centeredPoint + center);\n" 
      + "else if(vKind==4.0)\n" 
      + "gl_FragColor = texture2D(u_texture4, centeredPoint + center);\n" 
      + "else if(vKind==5.0)\n" 
      + "gl_FragColor = texture2D(u_texture5, centeredPoint + center);\n" 
      + "else if(vKind==6.0)\n" 
      + "gl_FragColor = texture2D(u_texture6, centeredPoint + center);\n" 
      + "else\n" 
      + "gl_FragColor = texture2D(u_texture7, centeredPoint + center);\n" 
      + "gl_FragColor *= vColor;\n" 

      // + 
      // " gl_FragColor.a = (gl_FragColor.b >= 0.5) ? gl_FragColor.a : 0.0;\n" 
      + "}\n"; 
+0

如果您依次使用每个纹理对所有点进行分组并绘制所有点,则会更加缓存/发散。 – jozxyqk 2014-11-04 11:01:15

回答

1

首先,尝试,如果纹理确实是什么使人下来的情况来分析:注释掉所有,但1纹理上,并且所有的if语句调用相同的纹理。然后,在确认后,考虑两件事情:

  • 既然你是画点你真的需要一个vKindvarying是一个uniform。您可以使用8个绘制调用,将您的点分成CPU上的8个阵列,具体取决于它们应使用的纹理,然后在片段着色器中仅使用1个纹理,并在8个绘制调用的每一个之前绑定正确的纹理。

  • 如果您真的需要所有这些纹理数据,请尝试查看如何使用atlas(将多个纹理合并为一个)并尝试尽可能减少纹理计数。

+0

感谢您的建议。我有一个尝试。 – 2014-10-30 12:02:27

相关问题