-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglow.glsl
44 lines (35 loc) · 1.15 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
#version 330
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
uniform int showOldTrails;
// Output fragment color
out vec4 finalColor;
// NOTE: Add here your custom variables
const vec2 size = vec2(600, 700); // render size
const float samples = 3.5; // pixels per axis; higher = bigger glow, worse performance
const float quality = 1.5; // lower = smaller glow, better quality
void main()
{
// Texel color fetching from texture sampler
vec4 source = texture(texture0, fragTexCoord);
finalColor = source;
if (showOldTrails == 1) {
vec4 sum = vec4(0);
vec2 sizeFactor = vec2(1)/size*quality;
const int range = 2;
for (int x = -range; x <= range; x++)
{
for (int y = -range; y <= range; y++)
{
sum += texture(texture0, fragTexCoord + vec2(x, y)*sizeFactor);
}
}
// Calculate final fragment color
finalColor = ((sum/(samples*samples)) + source);
finalColor = vec4(finalColor.rgb, 1.);
}
}