Summary: I get FPS slowdown as soon as I try to tint the sprites (i.e: multiply texture with color in the fragment shader)
Details:
Hardware: iPod touch 4
I am drawing 700 sprites on the screen using glDrawArrays. And yes I am batching all of these in a single draw call. Following shows Vertex data structure:
struct Vertex {
float Position[2];
float Color[4];
float Texture[2];
};
Yes I am sending colour with each vertex because I selectively need to tint some sprites but not others. Following is the fragment shader I am using:
varying lowp vec2 TexCoord;
uniform sampler2D TextureSampler;
void main(void)
{
gl_FragColor = texture2D( TextureSampler, TexCoord );
}
Till now it is working GREAT, giving me full 60 FPS !!!
BUT
As soon as I change the fragment shader to the following (to allowing tinting):
varying lowp vec4 DestinationColor;
varying lowp vec2 TexCoord;
uniform sampler2D TextureSampler;
void main(void)
{
gl_FragColor = texture2D( TextureSampler, TexCoord ) * DestinationColor;
}
Using following 64x64 png texture containing alpha channel, rendering with glEnable(GL_BLEND):
The performance drops to 47 FPS only due to this single change {just by multiplication with ONE vector} (FPS measured using xcode instruments and OpenGL detective). Any ideas what is going on ?
Thanks.
Edit:
I've also tried stripping off per vertex color attribute:
struct Vertex {
float Position[2];
float Texture[2];
};
And modifying the fragment shader as follows:
precision lowp float;
varying lowp vec2 TexCoord;
uniform sampler2D TextureSampler;
void main(void)
{
gl_FragColor = texture2D( TextureSampler, TexCoord ) * vec4(1.0,0.0,0.0,1.0);
}
It is running at 52 FPS for 700 sprites (a gain of only 5 FPS). So this is not interpolation, seems like the multiplication is extremely expensive. Just this ONE multiplication?