-
Notifications
You must be signed in to change notification settings - Fork 0
/
gauss.glsl
31 lines (28 loc) · 947 Bytes
/
gauss.glsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// by Jan Eric Kyprianidis <www.kyprianidis.com>
#extension GL_EXT_gpu_shader4 : enable
uniform sampler2D src;
uniform float sigma;
varying out vec3 dst;
void main (void) {
vec2 src_size = vec2(textureSize2D(src, 0));
vec2 uv = gl_FragCoord.xy / src_size;
float twoSigma2 = 2.0 * sigma * sigma;
int halfWidth = int(ceil( 2.0 * sigma ));
vec3 sum = vec3(0.0);
float norm = 0.0;
if (halfWidth > 0) {
for ( int i = -halfWidth; i <= halfWidth; ++i ) {
for ( int j = -halfWidth; j <= halfWidth; ++j ) {
float d = length(vec2(i,j));
float kernel = exp( -d *d / twoSigma2 );
vec3 c = texture2D(src, uv + vec2(i,j) / src_size ).rgb;
sum += kernel * c;
norm += kernel;
}
}
} else {
sum = texture2D(src, uv).rgb;
norm = 1.0;
}
dst = sum / norm;
}