Problem with Gaussian Blur Shader on android
Posted: Wed May 03, 2017 4:30 pm
I am trying to implement a gaussian blur filter no make a bloom effect for my game on android, however with the approach taken here https://github.com/vrld/shine/blob/mast ... anblur.lua , I am having some perf issues and the results are not looking very bloomy (only with higher sigmas, which increase perf issues even more).
To fix that problem I currently have 2 optimizations in mind, the first is to pass the coordinates through a vertex shader (which I believe would speed up the texture lookup), and the second would be to use linear sampling in the same vertex shader in order to decrease number of texture reads (http://rastergrid.com/blog/2010/09/effi ... -sampling/).
However I am currently having a problem in most android phones in which the screen renders all black when using the vertex shader solution (it works on my cellphone, and runs in my computer, but does not in most of my testers phones). Is there any common pitfall with vertex shaders on android phones?
Here is my generated shader code:
//Vertex Shader Generated:
#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
varying vec2 coordinate3b;
varying vec2 coordinate2b;
varying vec2 coordinate1b;
varying vec2 coordinate0f;
varying vec2 coordinate1f;
varying vec2 coordinate2f;
varying vec2 coordinate3f;
uniform vec2 offset_direction;
vec4 position(mat4 transform_projection, vec4 vertex_position)
{
coordinate3b = VertexTexCoord.xy + -3.000000 * offset_direction;
coordinate2b = VertexTexCoord.xy + -2.000000 * offset_direction;
coordinate1b = VertexTexCoord.xy + -1.000000 * offset_direction;
coordinate0f = VertexTexCoord.xy + 0.000000 * offset_direction;
coordinate1f = VertexTexCoord.xy + 1.000000 * offset_direction;
coordinate2f = VertexTexCoord.xy + 2.000000 * offset_direction;
coordinate3f = VertexTexCoord.xy + 3.000000 * offset_direction;
return transform_projection * vertex_position;
}
//Fragment Shader Generated:
#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
varying vec2 coordinate3b;
varying vec2 coordinate2b;
varying vec2 coordinate1b;
varying vec2 coordinate0f;
varying vec2 coordinate1f;
varying vec2 coordinate2f;
varying vec2 coordinate3f;
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords)
{
vec4 c = vec4(0.0);
c += vec4(11.108997) * Texel(texture, coordinate3b);
c += vec4(135.335283) * Texel(texture, coordinate2b);
c += vec4(606.530660) * Texel(texture, coordinate1b);
c += vec4(1000.000000) * Texel(texture, coordinate0f);
c += vec4(606.530660) * Texel(texture, coordinate1f);
c += vec4(135.335283) * Texel(texture, coordinate2f);
c += vec4(11.108997) * Texel(texture, coordinate3f);
return c * vec4(0.399050) * color / 1000.0;
}
To fix that problem I currently have 2 optimizations in mind, the first is to pass the coordinates through a vertex shader (which I believe would speed up the texture lookup), and the second would be to use linear sampling in the same vertex shader in order to decrease number of texture reads (http://rastergrid.com/blog/2010/09/effi ... -sampling/).
However I am currently having a problem in most android phones in which the screen renders all black when using the vertex shader solution (it works on my cellphone, and runs in my computer, but does not in most of my testers phones). Is there any common pitfall with vertex shaders on android phones?
Here is my generated shader code:
//Vertex Shader Generated:
#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
varying vec2 coordinate3b;
varying vec2 coordinate2b;
varying vec2 coordinate1b;
varying vec2 coordinate0f;
varying vec2 coordinate1f;
varying vec2 coordinate2f;
varying vec2 coordinate3f;
uniform vec2 offset_direction;
vec4 position(mat4 transform_projection, vec4 vertex_position)
{
coordinate3b = VertexTexCoord.xy + -3.000000 * offset_direction;
coordinate2b = VertexTexCoord.xy + -2.000000 * offset_direction;
coordinate1b = VertexTexCoord.xy + -1.000000 * offset_direction;
coordinate0f = VertexTexCoord.xy + 0.000000 * offset_direction;
coordinate1f = VertexTexCoord.xy + 1.000000 * offset_direction;
coordinate2f = VertexTexCoord.xy + 2.000000 * offset_direction;
coordinate3f = VertexTexCoord.xy + 3.000000 * offset_direction;
return transform_projection * vertex_position;
}
//Fragment Shader Generated:
#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
varying vec2 coordinate3b;
varying vec2 coordinate2b;
varying vec2 coordinate1b;
varying vec2 coordinate0f;
varying vec2 coordinate1f;
varying vec2 coordinate2f;
varying vec2 coordinate3f;
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords)
{
vec4 c = vec4(0.0);
c += vec4(11.108997) * Texel(texture, coordinate3b);
c += vec4(135.335283) * Texel(texture, coordinate2b);
c += vec4(606.530660) * Texel(texture, coordinate1b);
c += vec4(1000.000000) * Texel(texture, coordinate0f);
c += vec4(606.530660) * Texel(texture, coordinate1f);
c += vec4(135.335283) * Texel(texture, coordinate2f);
c += vec4(11.108997) * Texel(texture, coordinate3f);
return c * vec4(0.399050) * color / 1000.0;
}