-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathglow.glsl
90 lines (67 loc) · 2.28 KB
/
glow.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#START_VERTEX
#version 140
/**
-------------- glow vertex shader -------------
author: Richman Stewart
simple vertex shader that sets the position
to the specified matrix and position while
passing the vertex colour and tex coords
to the fragment shader
**/
in vec2 a_position;
in vec2 a_tex_coord;
in vec4 a_colour;
uniform mat4 matrix;
out vec4 v_colour;
out vec2 tex_coord;
void main() {
v_colour = a_colour;
tex_coord = a_tex_coord;
gl_Position = matrix * vec4(a_position, 0, 1);
}
#END_VERTEX
#START_FRAGMENT
#version 140
/**
------------ one pass glow shader ------------
author: Richman Stewart
applies a gaussian glow horizontally and vertically
behind the original texture
------------------ use ------------------------
glow_size - defines the spread x and y
glow_colour - the colour of the glow
glow_intensity - glow intensity
**/
in vec4 v_colour;
in vec2 tex_coord;
out vec4 pixel;
uniform sampler2D t0;
uniform float glow_size = .5;
uniform vec3 glow_colour = vec3(0, 0, 0);
uniform float glow_intensity = 1;
uniform float glow_threshold = .5;
void main() {
pixel = texture(t0, tex_coord);
if (pixel.a <= glow_threshold) {
ivec2 size = textureSize(t0, 0);
float uv_x = tex_coord.x * size.x;
float uv_y = tex_coord.y * size.y;
float sum = 0.0;
for (int n = 0; n < 9; ++n) {
uv_y = (tex_coord.y * size.y) + (glow_size * float(n - 4.5));
float h_sum = 0.0;
h_sum += texelFetch(t0, ivec2(uv_x - (4.0 * glow_size), uv_y), 0).a;
h_sum += texelFetch(t0, ivec2(uv_x - (3.0 * glow_size), uv_y), 0).a;
h_sum += texelFetch(t0, ivec2(uv_x - (2.0 * glow_size), uv_y), 0).a;
h_sum += texelFetch(t0, ivec2(uv_x - glow_size, uv_y), 0).a;
h_sum += texelFetch(t0, ivec2(uv_x, uv_y), 0).a;
h_sum += texelFetch(t0, ivec2(uv_x + glow_size, uv_y), 0).a;
h_sum += texelFetch(t0, ivec2(uv_x + (2.0 * glow_size), uv_y), 0).a;
h_sum += texelFetch(t0, ivec2(uv_x + (3.0 * glow_size), uv_y), 0).a;
h_sum += texelFetch(t0, ivec2(uv_x + (4.0 * glow_size), uv_y), 0).a;
sum += h_sum / 9.0;
}
pixel = vec4(glow_colour, (sum / 9.0) * glow_intensity);
}
}
#END_FRAGMENT