Problem with Gaussian Blur Shader on android

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Ghust1995
Prole
Posts: 3
Joined: Sat Apr 29, 2017 4:21 am

Problem with Gaussian Blur Shader on android

Post by Ghust1995 »

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;
}
moreginger
Prole
Posts: 2
Joined: Sun Oct 15, 2017 12:28 pm

Re: Problem with Gaussian Blur Shader on android

Post by moreginger »

Did you ever get good performance from a blur shader on Android?

I'm finding that `shine.gaussian` blur at least works, but the performance isn't good enough to use. At sigma 5, I drop from 60fps locked to ~5fps. `shine.boxblur` can manage 50fps with radius 2, which is still neither fast enough nor gives a particularly noticeable effect. At higher radius performance, obviously, decreases further.
moreginger
Prole
Posts: 2
Joined: Sun Oct 15, 2017 12:28 pm

Re: Problem with Gaussian Blur Shader on android

Post by moreginger »

Just submitted a patch for a slightly faster gaussian blur: https://github.com/vrld/shine/pull/27

It's about 1.5x-2x as fast (depending on number of taps) for basically identical output. You can also set a larger offset than 1 for low entropy images. For example I can do { taps = 11, offset = 2 } at almost 60fps. That gives you a blur over a 21 pixel window, roughly sigma 3 on the existing gaussian shader (actually 19 pixels in that case), with ~3x the speed and similar quality, in my use case at least.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 50 guests