Back to shaders
Shader test bench
Diagonal Blur.fs
runnable fragment
Complete GLSL fragment shader. Stronghold runs it directly when the browser can compile it.
Code
uniform sampler2D inputImage;
uniform float width;
uniform float angle;
uniform int quality;
precision mediump float;
/*{
"CREDIT": "by VIDVOX",
"ISFVSN": "2",
"CATEGORIES": [
"Blur"
],
"INPUTS": [
{
"NAME": "inputImage",
"TYPE": "image"
},
{
"NAME": "width",
"LABEL": "Width",
"TYPE": "float",
"MIN": 0.0,
"MAX": 1.0,
"DEFAULT": 0.0
},
{
"NAME": "angle",
"LABEL": "Angle",
"TYPE": "float",
"MIN": -1.0,
"MAX": 1.0,
"DEFAULT": 0.125
},
{
"NAME": "quality",
"LABEL": "Quality",
"VALUES": [
12,
8,
4,
2
],
"LABELS": [
"Low",
"Mid",
"High",
"Best"
],
"DEFAULT": 4,
"TYPE": "long"
}
]
}*/
const float pi = 3.14159265359;
void main() {
vec2 loc = (gl_FragCoord.xy / u_resolution.xy) * u_resolution;
vec2 p1 = vec2(0.0);
vec2 p2 = vec2(1.0);
vec2 vector = vec2(cos(pi * angle),sin(pi * angle));
vec4 returnMe;
if (width > 0.0) {
p1 = loc - width * u_resolution * vector;
p2 = loc + width * u_resolution * vector;
// now we have the two points to smear between,
//float i;
float count = clamp(width * max(u_resolution.x,u_resolution.y) / float(quality), 5.0, 125.0);
//float count = 10.0;
vec2 diff = p2 - p1;
for (float i = 0.0; i < 125.0; ++i) {
if (i > float(count))
break;
float tmp = (i / (count - 1.0));
returnMe = returnMe + texture2D(inputImage, (p1 + diff * tmp) / u_resolution.xy) / count;
}
}
else {
returnMe = IMG_THIS_PIXEL(inputImage);
}
gl_FragColor = returnMe;
}