我正优化一个双向的游戏, iPhone 和 Android。 我用4个阴影来绘制场景, 我注意到如果我把其中一个变换成另一个, 纤维灯泡会从32个增加到42个, 即使只有1个符号是用这个阴影画的, 而这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
默认 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
Again,
If I modify 默认 2d- tex. shader and remove the product "* ucolor", the fps goes from 32 to 42, and I m using it for just one sprite in the scene!
这正常吗?为什么这个遮光剂这么慢,我怎么才能改进它呢?
<强度 > EDIT: 强度 >
我看到iPod和Android的性能减慢,比例相等。两者均为PowerVr SGX GPUs(iPod 3 gen和三星银河SL-PowerVR SGX 530-),iOS版本为4.1,Android版本为2.3.3。
绘图图I m 缩放以填充屏幕( 缩放为 4x), 我绘制每框架一次 。 它取自质地图, 因此纹理实际上更大( 1024x1024), 但所拍摄的部分为 80x120 。 启用了 Alpha 混合 。
<强 > EDIT 2 强 >
I made a mistake. The sprite is scaled 11x: its 32x48. If I don t draw that sprite at all, fps goes to 45. I m drawing a lot of sprites in the scene, why is that one taking so much time? Could it be because it s scaled so much?