以下は、パフォーマンスの低いフラグメント シェーダーです。条件分岐を削除してもパフォーマンスは向上しないようです。わずか 150 ポリゴンで、Kindle Fire で 10 fps、Galaxy S3 で 20 fps が得られます。これを最適化する最善の方法について何か考えはありますか? iPad 2 の同様のシェーダーは 30+fps で動作します。
以下のコードでは、texture1 ~ texture8 が 8 つのテクスチャにバインドされています。VertexTexturesOut1 と VertexTexturesOut2 は頂点シェーダーから渡され、ブレンドされるシェーディング量を示す 0.0 ~ 1.0 の値を持ちます。ランドスケープ テクスチャをブレンドして、草が土、岩、砂などに均等に溶け込むようにします。
uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;
uniform sampler2D texture4;
uniform sampler2D texture5;
uniform sampler2D texture6;
uniform sampler2D texture7;
uniform sampler2D texture8;
varying mediump vec2 TextureCoordOut;
varying lowp vec4 VertexTexturesOut1;
varying lowp vec4 VertexTexturesOut2;
...
lowp vec4 Color = vec4( 0.0, 0.0, 0.0, 0.0);
if (VertexTexturesOut1.x != 0.0) Color = Color + texture2D ( texture1, TextureCoordOut ) * VertexTexturesOut1.x;
if (VertexTexturesOut1.y != 0.0) Color = Color + texture2D ( texture2, TextureCoordOut ) * VertexTexturesOut1.y;
if (VertexTexturesOut1.z != 0.0) Color = Color + texture2D ( texture3, TextureCoordOut ) * VertexTexturesOut1.z;
if (VertexTexturesOut1.w != 0.0) Color = Color + texture2D ( texture4, TextureCoordOut ) * VertexTexturesOut1.w;
if (VertexTexturesOut2.x != 0.0) Color = Color + texture2D ( texture5, TextureCoordOut ) * VertexTexturesOut2.x;
if (VertexTexturesOut2.y != 0.0) Color = Color + texture2D ( texture6, TextureCoordOut ) * VertexTexturesOut2.y;
if (VertexTexturesOut2.z != 0.0) Color = Color + texture2D ( texture7, TextureCoordOut ) * VertexTexturesOut2.z;
if (VertexTexturesOut2.w != 0.0) Color = Color + texture2D ( texture8, TextureCoordOut ) * VertexTexturesOut2.w;
gl_FragColor = Color;