iPhone と Android の両方で動作するゲームを最適化しています。4 つのシェーダーを使用してシーンを描画していますが、そのうちの 1 つを別のシェーダーに変更すると、そのシェーダーで描画されるスプライトが 1 つしかないにもかかわらず、fps が 32 から 42 になることに気付きました。この 2 つのシェーダーの唯一の違いです。フラグメント シェーダーの単なる製品です。
これらはシェーダーです:
デフォルト-2d-tex.shader
#ifdef GL_ES
precision highp float;
precision lowp int;
#endif
#ifdef VERTEX
uniform mat4 umvp;
attribute vec4 avertex;
attribute vec2 auv;
varying vec2 vuv;
void main()
{
// Pass the texture coordinate attribute to a varying.
vuv = auv;
// Here we set the final position to this vertex.
gl_Position = umvp * avertex;
}
#endif
#ifdef FRAGMENT
uniform sampler2D map0;
uniform vec4 ucolor;
varying vec2 vuv;
void main()
{
gl_FragColor = texture2D(map0, vuv) * ucolor;
}
#endif
default-2d-tex-white.shader
#ifdef GL_ES
precision highp float;
precision lowp int;
#endif
#ifdef VERTEX
uniform mat4 umvp;
attribute vec4 avertex;
attribute vec2 auv;
varying vec2 vuv;
void main()
{
// Pass the texture coordinate attribute to a varying.
vuv = auv;
// Here we set the final position to this vertex.
gl_Position = umvp * avertex;
}
#endif
#ifdef FRAGMENT
uniform sampler2D map0;
varying vec2 vuv;
void main()
{
gl_FragColor = texture2D(map0, vuv);
}
#endif
繰り返しますが、
default-2d-tex.shader を変更して製品 "* ucolor" を削除すると、fps が 32 から 42 になり、シーン内の 1 つのスプライトだけに使用されます!
これは正常ですか?このシェーダが非常に遅いのはなぜですか?どうすれば改善できますか?
編集:
このパフォーマンスの低下は、iPod と Android の両方で同じ比率で見られます。どちらも PowerVr SGX GPU (iPod 第 3 世代および Samsung Galaxy SL -PowerVR SGX 530-) です。iOS のバージョンは 4.1、Android は 2.3.3 です。
私が描いているスプライトは、画面いっぱいに拡大され (4 倍に拡大)、フレームごとに 1 回描画しています。これはテクスチャ マップから取得されているため、テクスチャは実際には大きくなります (1024x1024) が、取得される部分は 80x120 です。アルファ ブレンディングが有効になっています。
編集2
私はミスを犯した。スプライトは 11 倍にスケーリングされます: 32x48 です。そのスプライトをまったく描画しないと、fps は 45 になります。シーン内に多数のスプライトを描画していますが、なぜ 1 つに時間がかかるのですか? スケールが大きいからだろうか。