Description
- I using the OpenGL es 2.0 in the android with the glsl shader to do the gaussian blur effect.
- If without alpha channel, it works correct, but when i have alpha channel with png, the result will become too dark, it will be the same the link: http://www.jhlabs.com/ip/premultiplied_blur.jpg (the middle one effect with some dark).
- And all the article says using the premultiplied alpha, but i don't know how to using it, is same one can help me, thanks.
- I using the OpenGL es 2.0 in the android with the glsl shader to do the gaussian blur effect.
How i do the blur
- Load png texture
- Create FBO to render the horizontal blur
- Create FBO to render the vertical blur
- Render the result texture to the screen
My shader file
static const char* ULBlurShader_vertexShader =
"uniform mat4 fpsWorldViewProjectionMatrix;\n"
"attribute vec4 gInPosition;\n"
"attribute vec2 gInTex0;\n"
"varying vec2 varTex0;\n"
"void main() {\n"
" gl_Position = fpsWorldViewProjectionMatrix * gInPosition;\n"
" varTex0 = gInTex0.xy;\n"
"}\n";
static const char* ULBlurShaderHor_pixelShader =
"uniform sampler2D sampler0; \n"
"uniform vec4 fpsGaussBlur; \n"
"uniform vec4 fpsGaussWeights[65]; \n"
"varying vec2 varTex0;\n"
"vec4 gaussBlurHorizontal(const int anRadius,vec2 avBaseCoo, vec2 avSamplerRes)"
"{ \n"
" float fStartX = avBaseCoo.x - anRadius*avSamplerRes.x; \n"
" vec4 color = vec4(0, 0, 0, 0); \n"
" for (int x = 0; x < anRadius * 2; x++) \n"
" { \n"
" color += texture2D(sampler0, vec2(fStartX + x*avSamplerRes.x, avBaseCoo.y))*fpsGaussWeights[x / 4][x % 4]; \n"
" } \n"
" return color; \n"
"}\n"
"void main() {\n"
" gl_FragColor.rgba = gaussBlurHorizontal(int(fpsGaussBlur.y), varTex0, vec2(fpsGaussBlur.z, fpsGaussBlur.w)); \n"
"}\n";
static const char* ULBlurShaderVert_pixelShader =
"uniform sampler2D sampler0; \n"
"uniform vec4 fpsGaussBlur; \n"
"uniform vec4 fpsGaussWeights[65]; \n"
"varying vec2 varTex0;\n"
"vec4 gaussBlurVertical(const int anRadius,vec2 avBaseCoo, vec2 avSamplerRes)"
"{ \n"
" float fStartY = avBaseCoo.y - (anRadius*avSamplerRes.y); \n"
" vec4 color = vec4(0, 0, 0, 0); \n"
" for(int y=0; y<anRadius*2; y++) \n"
" { \n"
" color += texture2D(sampler0, vec2(avBaseCoo.x, fStartY+y*avSamplerRes.y))*fpsGaussWeights[y/4][y%4]; \n"
" } \n"
" return color; \n"
"}\n"
"void main() {\n"
" gl_FragColor.rgba = gaussBlurVertical(int(fpsGaussBlur.y), varTex0, vec2(fpsGaussBlur.z, fpsGaussBlur.w));\n"
"}\n";