made a REAL gaussian blur filter
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#version 110
|
||||
|
||||
uniform vec4 keyColor;
|
||||
uniform float threshold;
|
||||
uniform sampler2D myTexture;
|
||||
varying vec2 vTexCoord;
|
||||
|
||||
void main(void) {
|
||||
vec4 textureColor = texture2D(myTexture, vTexCoord);
|
||||
float diff = length(keyColor - textureColor);
|
||||
if (diff < threshold) {
|
||||
gl_FragColor = vec4(0, 0, 0, 0);
|
||||
} else {
|
||||
gl_FragColor = textureColor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#version 110
|
||||
|
||||
varying vec2 vTexCoord;
|
||||
|
||||
void main() {
|
||||
vTexCoord = gl_MultiTexCoord0.xy;
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
#version 110
|
||||
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
|
||||
uniform sampler2D image;
|
||||
|
||||
uniform float kernel_size;
|
||||
uniform float sigma;
|
||||
uniform vec2 resolution;
|
||||
uniform bool horiz_blur;
|
||||
uniform bool vert_blur;
|
||||
|
||||
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) {
|
||||
if (kernel_size == 0.0 || sigma == 0.0 || (!horiz_blur && !vert_blur)) {
|
||||
gl_FragColor = texture2D(image, gl_FragCoord.xy/resolution);
|
||||
} else {
|
||||
float half_kernel = floor(kernel_size*0.5);
|
||||
|
||||
float middleWeight = gaussian(0.0, sigma);
|
||||
float sum = middleWeight;
|
||||
|
||||
if (horiz_blur && vert_blur) {
|
||||
for (float x=0.0;x<half_kernel;x++) {
|
||||
for (float y=0.0;y<half_kernel;y++) {
|
||||
sum += (4.0*gaussian2(x, y, sigma));
|
||||
}
|
||||
}
|
||||
|
||||
gl_FragColor = texture2D(image, gl_FragCoord.xy/resolution)*(middleWeight/sum);
|
||||
|
||||
for (float x=0.0;x<half_kernel;x++) {
|
||||
for (float y=0.0;y<half_kernel;y++) {
|
||||
float weight = (gaussian2(x, y, sigma)/sum);
|
||||
gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x-x, gl_FragCoord.y-y))/resolution)*(weight);
|
||||
gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x+x, gl_FragCoord.y+y))/resolution)*(weight);
|
||||
gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x-x, gl_FragCoord.y+y))/resolution)*(weight);
|
||||
gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x+x, gl_FragCoord.y-y))/resolution)*(weight);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (float i=1.0;i<half_kernel;i++) {
|
||||
sum += (2.0*gaussian(i, sigma));
|
||||
}
|
||||
|
||||
gl_FragColor = texture2D(image, gl_FragCoord.xy/resolution)*(middleWeight/sum);
|
||||
|
||||
for (float i=0.0;i<half_kernel;i++) {
|
||||
float weight = gaussian(i, sigma)/sum;
|
||||
if (horiz_blur) {
|
||||
gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x-i, gl_FragCoord.y))/resolution)*(weight);
|
||||
gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x+i, gl_FragCoord.y))/resolution)*(weight);
|
||||
} else {
|
||||
gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x, gl_FragCoord.y-i))/resolution)*(weight);
|
||||
gl_FragColor += texture2D(image, (vec2(gl_FragCoord.x, gl_FragCoord.y+i))/resolution)*(weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#version 110
|
||||
|
||||
uniform mediump float amount_val;
|
||||
uniform sampler2D myTexture;
|
||||
varying vec2 vTexCoord;
|
||||
|
||||
void main(void) {
|
||||
vec4 textureColor = texture2D(myTexture, vTexCoord);
|
||||
gl_FragColor = vec4(
|
||||
textureColor.r+((1.0-textureColor.r-textureColor.r)*amount_val),
|
||||
textureColor.g+((1.0-textureColor.g-textureColor.g)*amount_val),
|
||||
textureColor.b+((1.0-textureColor.b-textureColor.b)*amount_val),
|
||||
textureColor.a
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<RCC>
|
||||
<qresource prefix="/shaders">
|
||||
<file>gaussianblureffect.frag</file>
|
||||
<file>common.vert</file>
|
||||
<file>inverteffect.frag</file>
|
||||
<file>chromakeyeffect.frag</file>
|
||||
<file>solideffect.frag</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
@@ -0,0 +1,16 @@
|
||||
#version 110
|
||||
|
||||
uniform vec4 solidColor;
|
||||
uniform float amount_val;
|
||||
uniform sampler2D myTexture;
|
||||
varying vec2 vTexCoord;
|
||||
|
||||
void main(void) {
|
||||
vec4 textureColor = texture2D(myTexture, vTexCoord);
|
||||
gl_FragColor = vec4(
|
||||
textureColor.r+((solidColor.r-textureColor.r)*amount_val),
|
||||
textureColor.g+((solidColor.g-textureColor.g)*amount_val),
|
||||
textureColor.b+((solidColor.b-textureColor.b)*amount_val),
|
||||
textureColor.a
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user