我正在使用GL20.GL_POINTS拍照。点的归属之一是变量(代码中的'vKind')。当属性改变时,我应该同时改变纹理。以下是我的方法。但我得到了低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 :(得分:1)
首先尝试分析情况,如果纹理确实让你失望:注释除1纹理之外的所有纹理并使所有if语句调用相同的纹理。然后在确认后考虑两件事:
由于您正在绘制积分,您真的需要varying
vKind
或uniform
。您可以使用8个绘制调用,将您的点分成CPU上的8个数组,具体取决于它们应使用的纹理,然后在片段着色器中仅使用1个纹理,并在8个绘制调用中的每一个之前绑定正确的纹理。
如果您确实需要所有这些纹理数据,请尝试查看如何使用图集(将多个纹理合并为一个)并尝试尽可能减少纹理数量。