-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ls_Bevel.2.glsl
41 lines (33 loc) · 973 Bytes
/
Ls_Bevel.2.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
// Bevel
// Pass 2: horizontal Gaussian blur
// lewis@lewissaunders.com
uniform sampler2D adsk_results_pass1;
uniform float adsk_result_w, adsk_result_h;
uniform float sigma;
const float pi = 3.141592653589793238462643383279502884197969;
void main() {
vec2 xy = gl_FragCoord.xy;
vec2 px = vec2(1.0) / vec2(adsk_result_w, adsk_result_h);
int support = int(sigma * 3.0);
// Incremental coefficient calculation setup as per GPU Gems 3
vec3 g;
g.x = 1.0 / (sqrt(2.0 * pi) * sigma);
g.y = exp(-0.5 / (sigma * sigma));
g.z = g.y * g.y;
if(sigma == 0.0) {
g.x = 1.0;
}
// Centre sample
vec4 a = g.x * texture2D(adsk_results_pass1, xy * px);
float energy = g.x;
g.xy *= g.yz;
// The rest
for(int i = 1; i <= support; i++) {
a += g.x * texture2D(adsk_results_pass1, (xy - vec2(float(i), 0.0)) * px);
a += g.x * texture2D(adsk_results_pass1, (xy + vec2(float(i), 0.0)) * px);
energy += 2.0 * g.x;
g.xy *= g.yz;
}
a /= energy;
gl_FragColor = a;
}