elios264
elios264

Reputation: 395

open gles 2 shader performance

Im making a game in android but the colors are too shiny and i cant change the sprites so i decided to implement a shader:

const char* fETCShader = "\
uniform mediump sampler2D sTexture 
uniform mediump sampler2D sTexture_alpha 
\
varying mediump vec4 vColor 
varying mediump vec2 vTexCoord 
uniform lowp mat4 cCorrection 
\
void main()\
{\
    lowp vec4 color = vec4(texture2D(sTexture, vTexCoord).rgb, texture2D(sTexture_alpha, vTexCoord).r) * vColor 
    gl_FragColor = cCorrection * color 
}"

but the fps drops dramatically (like 20 )

does anyone know if exist a less expensive operation to do this.

Thanks.

Upvotes: 1

Views: 426

Answers (2)

Tommy
Tommy

Reputation: 100602

Could you not change the sprites exactly once, when they're first loaded, then use whatever mechanism you were using before? Failing that, at least combine the two textures into one.

Upvotes: 0

Robert Rouhani
Robert Rouhani

Reputation: 14668

Instead of using 2 textures with 3 and 1 channels respectively, just make a single 4 channel RGBA texture, so that you only have to do 1 texture fetch.

Fragment shaders on phones very quickly become a bottleneck. Always try to minimize the amount of work your frag shaders have to do.

Your shader will look something like this:

const char* fETCShader = "\
uniform mediump sampler2D sTexture 
uniform mediump sampler2D sTexture_alpha 
\
varying mediump vec4 vColor 
varying mediump vec2 vTexCoord 
uniform lowp mat4 cCorrection 
\
void main()\
{\
    gl_FragColor = cCorrection * texture2D(sTexture, vTexCoord) * vColor; 
}"

Upvotes: 1

Related Questions