0 true #version 150 //OVE shader_name: gaussian blur //OVE shader_description: ported from Olive 0.1 filters //OVE main_input_name: Input uniform sampler2D tex_in; //OVE name: sigma //OVE type: FLOAT //OVE flag: NOT_CONNECTABLE //OVE min: 0.0 //OVE default: 5.5 //OVE description: uniform float sigma; //OVE name: horizontal //OVE type: BOOLEAN //OVE flag: NOT_CONNECTABLE //OVE default: true //OVE description: uniform bool horiz_blur; //OVE name: vertical //OVE type: BOOLEAN //OVE flag: NOT_CONNECTABLE //OVE default: true //OVE description: uniform bool vert_blur; //OVE end uniform vec2 resolution_in; #define M_PI 3.1415926535897932384626433832795 // pixel coordinates in range [0..1]x[0..1] in vec2 ove_texcoord; // output color out vec4 frag_color; float gaussian(float x, float sigma) { return (1.0/(sigma*sqrt(2.0*M_PI)))*exp(-0.5*pow(x/sigma, 2.0)); } float gaussian2(float x, float y, float sigma) { return (1.0/(pow(sigma, 2.0)*2.0*M_PI))*exp(-0.5*((pow(x, 2.0) + pow(y, 2.0))/pow(sigma, 2.0))); } void main(void) { float rad = ceil(3.0 * sigma); float sum = 0.0; vec4 color = vec4(0.0); bool radius_is_zero = (rad == 0.0 || sigma == 0.0); int pass = 0; if (!radius_is_zero) { for (float x=-rad+0.5;x<=rad;x+=2.0) { sum += gaussian2(x, 0.0, sigma); } } if ((!horiz_blur && !vert_blur) || (radius_is_zero)) { color = texture(tex_in, ove_texcoord); } if (horiz_blur && !radius_is_zero) { pass++; for (float x=-rad+0.5;x<=rad;x+=2.0) { float weight = (gaussian2(x, 0.0, sigma)/sum); color += texture(tex_in, (vec2(ove_texcoord.x + x/resolution_in.x, ove_texcoord.y)))*(weight); } } if (vert_blur && !radius_is_zero) { pass++; for (float y=-rad+0.5;y<=rad;y+=2.0) { float weight = (gaussian2(0.0, y, sigma)/sum); color += texture(tex_in, (vec2(ove_texcoord.x, ove_texcoord.y+y/resolution_in.y)))*(weight); } } if (pass == 2) { // color has twice the brightness it should have color /= 2.; } frag_color = color; } None 0 10 0 true 0 false 1898346680928 -1 -1 -1 -1 {114bacfc-96b2-4738-8074-4390bbdc9b71} {9b0707c3-5c71-4cab-aa76-ee5e663a000f} 0 -1.77976 0.0350877