|
@@ -0,0 +1,78 @@
|
|
1
|
+#version 120
|
|
2
|
+
|
|
3
|
+uniform sampler2D texture;
|
|
4
|
+uniform sampler2D desktop;
|
|
5
|
+uniform vec2 screenSize;
|
|
6
|
+uniform float time;
|
|
7
|
+
|
|
8
|
+varying vec2 uvCoord;
|
|
9
|
+
|
|
10
|
+vec2 getDesktopUV( vec2 uv ) {
|
|
11
|
+ // Desktop image is upside-down, blame X11 lmao
|
|
12
|
+ uv.y = -uv.y;
|
|
13
|
+ return uv;
|
|
14
|
+}
|
|
15
|
+
|
|
16
|
+const float pi = 3.14159265f;
|
|
17
|
+
|
|
18
|
+void main() {
|
|
19
|
+ float sigma = 5;
|
|
20
|
+ float numBlurPixelsPerSide = 2.0f;
|
|
21
|
+ float blurMultiplier = 2.0f;
|
|
22
|
+
|
|
23
|
+ vec2 tc = uvCoord.xy;
|
|
24
|
+ vec2 p = -1.0 + 2.0 * tc;
|
|
25
|
+ float len = length(p);
|
|
26
|
+ vec2 offset = (p/len)*cos(len*12.0-time*4.0)*0.005;
|
|
27
|
+
|
|
28
|
+ // Incremental Gaussian Coefficent Calculation (See GPU Gems 3 pp. 877 - 889)
|
|
29
|
+ float blurSize = 1.f/screenSize.x*blurMultiplier;
|
|
30
|
+ vec2 blurMultiplyVec = vec2(0.0f, 1.0f);
|
|
31
|
+ vec3 incrementalGaussian;
|
|
32
|
+ incrementalGaussian.x = 1.0f / (sqrt(2.0f * pi) * sigma);
|
|
33
|
+ incrementalGaussian.y = exp(-0.5f / (sigma * sigma));
|
|
34
|
+ incrementalGaussian.z = incrementalGaussian.y * incrementalGaussian.y;
|
|
35
|
+
|
|
36
|
+ vec4 avgValue = vec4(0.0f, 0.0f, 0.0f, 0.0f);
|
|
37
|
+ float coefficientSum = 0.0f;
|
|
38
|
+
|
|
39
|
+ // Take the central sample first...
|
|
40
|
+ vec4 color = texture2D( desktop, getDesktopUV( uvCoord.xy ) + offset );
|
|
41
|
+ avgValue += color * incrementalGaussian.x;
|
|
42
|
+ coefficientSum += incrementalGaussian.x;
|
|
43
|
+ incrementalGaussian.xy *= incrementalGaussian.yz;
|
|
44
|
+
|
|
45
|
+ // Go through the remaining 8 vertical samples (4 on each side of the center)
|
|
46
|
+ for (float i = 1.0f; i <= numBlurPixelsPerSide; i++) {
|
|
47
|
+ vec2 uv = (uvCoord.xy - i * blurSize * blurMultiplyVec);
|
|
48
|
+ color = texture2D( desktop, getDesktopUV( uv ) + offset );
|
|
49
|
+ avgValue += color * incrementalGaussian.x;
|
|
50
|
+ uv = (uvCoord.xy + i * blurSize * blurMultiplyVec);
|
|
51
|
+ color = texture2D( desktop, getDesktopUV( uv ) + offset );
|
|
52
|
+ avgValue += color * incrementalGaussian.x;
|
|
53
|
+ coefficientSum += 2 * incrementalGaussian.x;
|
|
54
|
+ incrementalGaussian.xy *= incrementalGaussian.yz;
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ //Reset
|
|
58
|
+ blurSize = 1.f/screenSize.x*blurMultiplier;
|
|
59
|
+ blurMultiplyVec = vec2(1.0f, 0.0f);
|
|
60
|
+ incrementalGaussian.x = 1.0f / (sqrt(2.0f * pi) * sigma);
|
|
61
|
+ incrementalGaussian.y = exp(-0.5f / (sigma * sigma));
|
|
62
|
+ incrementalGaussian.z = incrementalGaussian.y * incrementalGaussian.y;
|
|
63
|
+
|
|
64
|
+ // Go through the remaining 8 horizontal samples (4 on each side of the center)
|
|
65
|
+ for (float i = 1.0f; i <= numBlurPixelsPerSide; i++) {
|
|
66
|
+ vec2 uv = (uvCoord.xy - i * blurSize * blurMultiplyVec);
|
|
67
|
+ vec4 color = texture2D( desktop, getDesktopUV( uv ) + offset );
|
|
68
|
+ avgValue += color * incrementalGaussian.x;
|
|
69
|
+ uv = (uvCoord.xy + i * blurSize * blurMultiplyVec);
|
|
70
|
+ color = texture2D( desktop, getDesktopUV( uv ) + offset );
|
|
71
|
+ avgValue += color * incrementalGaussian.x;
|
|
72
|
+ coefficientSum += 2 * incrementalGaussian.x;
|
|
73
|
+ incrementalGaussian.xy *= incrementalGaussian.yz;
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ vec4 rect = texture2D(texture,uvCoord);
|
|
77
|
+ gl_FragColor = (avgValue / coefficientSum)*rect;
|
|
78
|
+}
|