UraniumSlug

05-21-2013, 10:41 AM

I've been attempting to code a normal Gaussian Blur shader which scales the image down to half the size in the vertex shader. The scaling works, but when I attempted to code the gaussian blur my results are coming out white and sadly I don't have enough knowledge to figure out why this is the case. Here is how I'm doing things at the moment:

float offset[5] = { 0.0, 1.0, 2.0, 3.0, 4.0 };

float weight[5] = { 0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162 };

anchors.fill: parent

vertexShader: "

uniform mat4 matrix;

uniform float scale;

attribute vec4 gl_Vertex;

attribute vec2 gl_MultiTexCoord0;

varying vec2 coord;

void main() {

coord = gl_MultiTexCoord0;

coord.x /= scale;

lowp vec4 vertex = gl_Vertex;

vertex.x *= scale;

gl_Position = matrix * vertex;

}"

fragmentShader: "

varying vec2 coord;

uniform sampler2D src;

uniform float qt_Opacity;

uniform float textureWidth;

uniform float offset[5];

uniform float weight[5];

void main() {

vec4 acc = texture2D(src, coord / textureWidth) * weight[0];

for (int i = 1; i < 5; i++)

{

acc += texture2D(src, coord + vec2(offset[i] / textureWidth, 0.0)) * weight[i];

acc += texture2D(src, coord - vec2(offset[i] / textureWidth, 0.0)) * weight[i];

}

gl_FragColor = acc;

}"

}

Any comments are tips would be much appreciated!

float offset[5] = { 0.0, 1.0, 2.0, 3.0, 4.0 };

float weight[5] = { 0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162 };

anchors.fill: parent

vertexShader: "

uniform mat4 matrix;

uniform float scale;

attribute vec4 gl_Vertex;

attribute vec2 gl_MultiTexCoord0;

varying vec2 coord;

void main() {

coord = gl_MultiTexCoord0;

coord.x /= scale;

lowp vec4 vertex = gl_Vertex;

vertex.x *= scale;

gl_Position = matrix * vertex;

}"

fragmentShader: "

varying vec2 coord;

uniform sampler2D src;

uniform float qt_Opacity;

uniform float textureWidth;

uniform float offset[5];

uniform float weight[5];

void main() {

vec4 acc = texture2D(src, coord / textureWidth) * weight[0];

for (int i = 1; i < 5; i++)

{

acc += texture2D(src, coord + vec2(offset[i] / textureWidth, 0.0)) * weight[i];

acc += texture2D(src, coord - vec2(offset[i] / textureWidth, 0.0)) * weight[i];

}

gl_FragColor = acc;

}"

}

Any comments are tips would be much appreciated!