开发者

Why same fragment shader gives different results on different android phones?

开发者 https://www.devze.com 2023-04-04 15:22 出处:网络
I am trying to implement a blur filter with OpenGL ES 2.0 on Android. Here is the code i am using: varying highp vec2 fragTexCoord;

I am trying to implement a blur filter with OpenGL ES 2.0 on Android. Here is the code i am using:

varying highp vec2 fragTexCoord;
highp vec2 u_Scale;
uniform sampler2D s_texture;
highp vec2 gaussFilter[7];
uniform highp float radius;
highp vec4 boxVerBlur(){
    gaussFilter[0] = vec2( -3.0,0.015625);
    gaussFilter[1] = vec2(-2.0, 0.09375);
    gaussFilter[2] = vec2(-1.0, 0.234375);
    gaussFilter[3] = vec2(0.0,  0.3125);
    gaussFilter[4] = vec2(1.0,  0.234375);
    gaussFilter[5] = vec2(2.0,  0.09375);
    gaussFilter[6] = vec2(3.0,  0.015625);  
    highp vec4 color = vec4(0,0,0,1);
    u_Scale = vec2( 1.0/radius, 0 );
    for( int i = 0; i < 7; i++ )
    {
        color += texture2D( s_texture, vec2( 
                 fragTexCoord.x + gaussFilter[i].x*u_Scale.x, 
                 fragTexCoord.y + gaussFilter[i].x*u_Scale.y )) * gaussFilter[i].y;
    }
    return color;
}
void main(void)
{
    gl开发者_运维技巧_FragColor = boxVerBlur();
}

On "Samsung Galaxy S" it works as expected. However when i run same app on "Samsung Galaxy Ace," it results a brighter texture without blur effect.

Result from Galaxy S:

Why same fragment shader gives different results on different android phones?

Result from Galaxy ACE:

Why same fragment shader gives different results on different android phones?


I'll assume that by gaussFilter1 and gaussFilter2 you meant gaussFilter[1] and gaussFilter[2].

The only problem with your code I noticed is that you are adding the alpha, try adding only the rgb:

    color.rgb += texture2D( s_texture, vec2( 
             fragTexCoord.x + gaussFilter[i].x*u_Scale.x, 
             fragTexCoord.y + gaussFilter[i].x*u_Scale.y )).rgb * gaussFilter[i].y;

It shouldn't cause your problem, but imho it worth a try, and even if it don't solve the problem, you will be saving an unnecessary sum for each texture access.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号