-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ls_Bevel.5.glsl
54 lines (46 loc) · 2.19 KB
/
Ls_Bevel.5.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
// Bevel
// Pass 5: gradient detection and actual beveling
// Broadly, we use the gradient vector of the blurred
// image as the X/Y components of a normal vector, which
// we then dot with the light direction.
// To get the sharp edge, we normalize the gradient, then
// use smoothstep() to remove the nasty artifacts where
// it was near zero. This gives us a kinda level-set iso-line
// of the blurred image, which roughly follows the outline of
// the text. It ain't perfect!
//
// This pass outputs the normals of the bevel based on the
// "Height map" input
//
// lewis@lewissaunders.com
uniform sampler2D adsk_results_pass3, adsk_results_pass1;
uniform float adsk_result_w, adsk_result_h;
uniform float sigma, smoothy;
uniform bool normals;
void main() {
vec2 xy = gl_FragCoord.xy;
vec2 px = vec2(1.0) / vec2(adsk_result_w, adsk_result_h);
float fron = texture2D(adsk_results_pass1, xy * px).g;
// Find gradients with X/Y Sobel convolution
vec2 d;
float ksize = sigma/2.0;
d.x = 1.0 * texture2D(adsk_results_pass3, (xy + ksize * vec2(-1.0, -1.0)) * px).g;
d.x += 2.0 * texture2D(adsk_results_pass3, (xy + ksize * vec2(-1.0, 0.0)) * px).g;
d.x += 1.0 * texture2D(adsk_results_pass3, (xy + ksize * vec2(-1.0, +1.0)) * px).g;
d.x += -1.0 * texture2D(adsk_results_pass3, (xy + ksize * vec2(+1.0, -1.0)) * px).g;
d.x += -2.0 * texture2D(adsk_results_pass3, (xy + ksize * vec2(+1.0, 0.0)) * px).g;
d.x += -1.0 * texture2D(adsk_results_pass3, (xy + ksize * vec2(+1.0, +1.0)) * px).g;
d.y = 1.0 * texture2D(adsk_results_pass3, (xy + ksize * vec2(-1.0, -1.0)) * px).g;
d.y += 2.0 * texture2D(adsk_results_pass3, (xy + ksize * vec2( 0.0, -1.0)) * px).g;
d.y += 1.0 * texture2D(adsk_results_pass3, (xy + ksize * vec2(+1.0, -1.0)) * px).g;
d.y += -1.0 * texture2D(adsk_results_pass3, (xy + ksize * vec2(-1.0, +1.0)) * px).g;
d.y += -2.0 * texture2D(adsk_results_pass3, (xy + ksize * vec2( 0.0, +1.0)) * px).g;
d.y += -1.0 * texture2D(adsk_results_pass3, (xy + ksize * vec2(+1.0, +1.0)) * px).g;
d /= ksize;
float len = length(d);
float edge = smoothstep(0.0, smoothy/100.0, len);
d /= len + 0.0001;
vec3 n = vec3(d.x, d.y, 1.0);
n = mix(vec3(0.0, 0.0, 1.0), n, edge);
gl_FragColor = vec4(n, fron);
}