Wednesday, 4 September 2013

OpenGL ES2.0 FragmentShader with Color Matrix make my render unbelieve SLOW

OpenGL ES2.0 FragmentShader with Color Matrix make my render unbelieve SLOW

I'm trying to tuning my render system. It based on OpenGL ES2.0, and my
test device is an old IPAD1.(well or IPAD2, I'm not quite sure)
My pixel shader is like this:
uniform lowp mat4 ION_COLOR_MATRIX; //Color Matrix
uniform lowp sampler2D ION_SAMPLER; //Texture sampler
varying lowp vec4 _DestTexCoord; //Texture coordinates
void main(void)
{
lowp vec4 texColor= texture2D(ION_SAMPLER, _DestTexCoord.st);"
lowp vec4 colorAfterTransform= ION_COLOR_MATRIX * texColor;"
gl_FragColor.rgb = colorAfterTransform.rgb;"
gl_FragColor.a = texColor.a;"
}
The code is quite simple. It just trying to render a texture. Only
difference is that I have made a "ColorMatrix" with which I could easily
transform The final color drawn on each pixel.
I have tested this code on my device, It run good, but really slow, I have
got a FPS 12 which is totally unacceptable.
If I abandon my "ColorMatrix" idea, Then I get my FPS up to 47 with the
same sprites. The "47 FPS fragment" shader is like this:
uniform lowp mat4 ION_COLOR_MATRIX; //Color Matrix
uniform lowp sampler2D ION_SAMPLER; //Texture sampler
varying lowp vec4 _DestTexCoord; //Texture coordinates
void main(void)
{
gl_FragColor= texture2D(ION_SAMPLER, _DestTexCoord.st);"
}
As you can see, no color matrix thing. Thus it has a much better
performance, But I really need to keep Color Matrix feature.
Dose any one has any idea about how to keep my Color Matrix functionality
and not cause such a bad performance.
Any hint will be greatly appreciated.

No comments:

Post a Comment