Parcourir la source

added more shader examples

naelstrof il y a 7 ans
Parent
révision
d482546922

+ 27
- 0
shaderexamples/hippie.frag Voir le fichier

@@ -0,0 +1,27 @@
1
+#version 120
2
+
3
+uniform sampler2D texture;
4
+uniform vec2 screenSize;
5
+uniform float time;
6
+
7
+varying vec2 uvCoord;
8
+
9
+const float pi = 3.14159265f;
10
+
11
+vec3 color(float x) {
12
+    return max(min(sin(vec3(x,x+pi*2.0/3.0,x+pi*4.0/3.0))+0.5,1.0),0.0);
13
+}
14
+
15
+void main() {
16
+    vec2 pos = (( gl_FragCoord.xy / screenSize.xy )-0.5)*screenSize.xy/screenSize.x*4.0;
17
+    pos+=normalize(pos);
18
+    pos.xy+=sin(pos.yx*10.0)*0.1;
19
+    float r=(2.0/(dot(pos,pos)*10.0+1.0));
20
+    vec2 rr=vec2(cos(r),sin(r));
21
+    pos=pos.xy*rr.xx+pos.yx*rr.yy*vec2(-1.0,1.0);
22
+    float f=(length(pos)*10.0)+time;
23
+    //f=acos((pos.x/length(pos)*0.5+0.5)*pi);
24
+    f+=sin(atan(pos.y,pos.x)*7.0)*5.0;
25
+    vec4 rect = texture2D(texture,uvCoord);
26
+    gl_FragColor = vec4(color(f),1.f)*rect;
27
+}

+ 12
- 0
shaderexamples/hippie.vert Voir le fichier

@@ -0,0 +1,12 @@
1
+#version 120
2
+
3
+attribute vec2 position;
4
+attribute vec2 uv;
5
+
6
+varying vec2 uvCoord;
7
+
8
+void main()
9
+{
10
+	uvCoord = uv;
11
+	gl_Position = vec4(position,0,1);
12
+}

+ 13
- 0
shaderexamples/invert.frag Voir le fichier

@@ -0,0 +1,13 @@
1
+#version 120
2
+
3
+uniform sampler2D texture;
4
+uniform sampler2D desktop;
5
+
6
+varying vec2 uvCoord;
7
+
8
+void main() {
9
+    vec2 uv = vec2(uvCoord.x, -uvCoord.y);
10
+    vec4 color = texture2D(desktop,uv);
11
+    vec4 rect = texture2D(texture,uvCoord);
12
+    gl_FragColor = vec4( 1.0 - color.rgb, color.a )*rect;
13
+}

+ 12
- 0
shaderexamples/invert.vert Voir le fichier

@@ -0,0 +1,12 @@
1
+#version 120
2
+
3
+attribute vec2 position;
4
+attribute vec2 uv;
5
+
6
+varying vec2 uvCoord;
7
+
8
+void main()
9
+{
10
+	uvCoord = uv;
11
+	gl_Position = vec4(position,0,1);
12
+}

+ 78
- 0
shaderexamples/refract.frag Voir le fichier

@@ -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
+}

+ 12
- 0
shaderexamples/refract.vert Voir le fichier

@@ -0,0 +1,12 @@
1
+#version 120
2
+
3
+attribute vec2 position;
4
+attribute vec2 uv;
5
+
6
+varying vec2 uvCoord;
7
+
8
+void main()
9
+{
10
+	uvCoord = uv;
11
+	gl_Position = vec4(position,0,1);
12
+}