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