-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfb_fshader.glsl
58 lines (52 loc) · 1.77 KB
/
fb_fshader.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
R"(
#version 330 core
uniform sampler2D tex;
uniform float tex_width;
uniform float tex_height;
in vec2 uv;
out vec3 color;
//#define GAUSSIAN
//#define SOBEL
#define NORMAL
#ifdef SOBEL
float rgb_2_luma(vec3 c){ return .3*c[0] + .59*c[1] + .11*c[2]; }
#endif
void main() {
#ifdef GAUSSIAN
///--- Gaussian convolution
float std = 2; ///< standard deviation (<.3 disable)
// float std = .1; ///< standard deviation (<.3 disable)
vec3 color_tot = vec3(0,0,0);
float weight_tot = 0;
int SIZE = 1 + 2 * 3 * int( ceil(std) );
for(int i=-SIZE; i<=SIZE; i++){
for(int j=-SIZE; j<=SIZE; j++){
float w = exp(-(i*i+j*j)/(2.0*std*std*std*std));
vec3 neigh_color = texture(tex, uv+vec2(i/tex_width,j/tex_height)).rgb;
color_tot += w * neigh_color;
weight_tot += w;
}
}
color = color_tot / weight_tot; ///< ensure \int w = 1
#endif
#ifdef SOBEL
float t_00 = rgb_2_luma( textureOffset(tex, uv, ivec2(-1, -1)).rgb );
float t_01 = rgb_2_luma( textureOffset(tex, uv, ivec2(-1, 0)).rgb );
float t_02 = rgb_2_luma( textureOffset(tex, uv, ivec2(-1, +1)).rgb );
///--- x=0
float t_10 = rgb_2_luma( textureOffset(tex, uv, ivec2( 0, -1)).rgb );
float t_12 = rgb_2_luma( textureOffset(tex, uv, ivec2( 0, +1)).rgb );
///--- x=+1
float t_20 = rgb_2_luma( textureOffset(tex, uv, ivec2(+1, -1)).rgb );
float t_21 = rgb_2_luma( textureOffset(tex, uv, ivec2(+1, 0)).rgb );
float t_22 = rgb_2_luma( textureOffset(tex, uv, ivec2(+1, +1)).rgb );
float Gx = t_20 + t_21*2 + t_22 - t_00 - t_01*2 - t_02;
float Gy = t_02 + t_12 * 2 + t_22 - t_00 - t_10*2 - t_20;
float G = sqrt(Gx * Gx + Gy * Gy);
color = vec3(G, G, G);
#endif
#ifdef NORMAL
color = texture(tex,uv).rgb;
#endif
}
)"