'Why does this shader crash on Android?
This is a basic gaussian blur shader found on shadertoy, tweaked slightly.
I want it to look better, so by increasing mSize more samples are taken and the blur looks better. This works great when testing on desktop.
Once deployed to a device, even high-end, it seems changing mSize to anything beyond 15 or so results in a crash, no error message or anything.
Why is this, and is there any remedy or is it simply too much processing?
Also, seems to be only with larger textures, over 1280x720, give or take. There's obviously some computing bottleneck occurring but unsure if it's fixable or just the limit of the devices
#define LOWP lowp
precision mediump float;
#else
#define LOWP
#endif
uniform sampler2D u_texture;
uniform vec2 u_fboSize;
varying vec2 v_texCoord;
varying LOWP vec4 v_color;
float normpdf(in float x, in float sigma) {
return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;
}
void main() {
vec4 c = texture2D(u_texture, v_texCoord);
//declare stuff
const int mSize = 7; // <---------- changing this to anything above 15 or so results in crashing
const int kSize = (mSize-1)/2;
float kernel[mSize];
vec4 final_colour = vec4(0.0);
//create the 1-D kernel
float sigma = 7.0;
float Z = 0.0;
for (int j = 0; j <= kSize; ++j)
{
kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j), sigma);
}
//get the normalization factor (as the gaussian has been clamped)
for (int j = 0; j < mSize; ++j)
{
Z += kernel[j];
}
//read out the texels
for (int i=-kSize; i <= kSize; ++i)
{
for (int j=-kSize; j <= kSize; ++j)
{
vec4 tex_sample = texture2D(u_texture, ((v_texCoord.xy * u_fboSize.xy)+vec2(float(i),float(j))) / u_fboSize.xy);
final_colour += kernel[kSize+j]*kernel[kSize+i]*tex_sample;
}
}
final_colour = final_colour/(Z*Z);
gl_FragColor = final_colour;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
