Browse Source

More shaders :)

Arthur Suzuki 2 years ago
parent
commit
f92242eced
3 changed files with 138 additions and 0 deletions
  1. 39 0
      training-20191217/julia.glsl
  2. 44 0
      training-20191217/revolution.glsl
  3. 55 0
      training-20191223/torusTunnel.glsl

+ 39 - 0
training-20191217/julia.glsl

@@ -0,0 +1,39 @@
1
+#version 410 core
2
+
3
+uniform float fGlobalTime; // in seconds
4
+uniform vec2 v2Resolution; // viewport resolution (in pixels)
5
+
6
+uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
7
+uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
8
+uniform sampler1D texFFTIntegrated; // this is continually increasing
9
+
10
+layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything
11
+
12
+//vec2 c = vec2(-0.7,0.44);
13
+vec2 c = vec2(cos(mod(fGlobalTime/5+5,7)),sin(mod(fGlobalTime/5+3,7)));
14
+
15
+int julia(vec2 uv, vec2 c, float zoom, vec2 offset)
16
+{
17
+  int i;
18
+  int iter = 100;
19
+  vec2 z = vec2(3,2)*zoom*uv+offset;
20
+  for(i=0; i<iter; i++) {
21
+    float x = (z.x * z.x - z.y * z.y) + c.x;
22
+    float y = (z.y * z.x + z.x * z.y) + c.y;
23
+    if((x * x + y * y) > 4.0) break;
24
+    z.x = x;
25
+    z.y = y;
26
+  }
27
+  return i;
28
+}
29
+
30
+void main(void)
31
+{
32
+  vec2 uv = vec2(gl_FragCoord.x / v2Resolution.x, gl_FragCoord.y / v2Resolution.y);
33
+  uv -= 0.5;
34
+  uv /= vec2(v2Resolution.y / v2Resolution.x, 1);
35
+  
36
+  int i = julia(uv,c,fGlobalTime/5000,vec2(0.4,0.4));
37
+  vec3 rgb = vec3(1-exp(5-i/3),1-exp(3-i/2),1-exp(1-i));
38
+  out_color = vec4(rgb,1);
39
+}

+ 44 - 0
training-20191217/revolution.glsl

@@ -0,0 +1,44 @@
1
+#version 410 core
2
+
3
+uniform float fGlobalTime; // in seconds
4
+uniform vec2 v2Resolution; // viewport resolution (in pixels)
5
+
6
+uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
7
+uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
8
+uniform sampler1D texFFTIntegrated; // this is continually increasing
9
+
10
+layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything
11
+
12
+vec2 rot(vec2 p, float a)
13
+{
14
+   return p *
15
+          mat2(cos(a),sin(-a),
16
+               sin(a),cos(-a));
17
+}
18
+
19
+float sph(vec3 p, float rad)
20
+{
21
+  p.xz=rot(p.xz, fGlobalTime);
22
+  return length(p)-rad;
23
+}
24
+
25
+void main(void)
26
+{
27
+  vec2 uv = vec2(gl_FragCoord.x / v2Resolution.x, gl_FragCoord.y / v2Resolution.y);
28
+  uv -= 0.5;
29
+  uv /= vec2(v2Resolution.y / v2Resolution.x, 1);
30
+
31
+  vec3 dir = normalize(vec3(uv,1));
32
+  vec3 p0 = vec3(0,0,-3);
33
+  vec3 p = p0;
34
+  
35
+  for(int i=0; i < 64; i++){
36
+    float d=sph(p,1);
37
+    if(abs(d) < 0.01) break;
38
+    p+=d*dir;
39
+  }
40
+  
41
+  vec3 c = vec3(exp(-distance(p,p0))*10);
42
+  
43
+  out_color = vec4(c,1);
44
+}

+ 55 - 0
training-20191223/torusTunnel.glsl

@@ -0,0 +1,55 @@
1
+#version 410 core
2
+
3
+uniform float fGlobalTime; // in seconds
4
+uniform vec2 v2Resolution; // viewport resolution (in pixels)
5
+
6
+uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
7
+uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
8
+uniform sampler1D texFFTIntegrated; // this is continually increasing
9
+
10
+layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything
11
+
12
+vec2 rot(vec2 p, float a)
13
+{
14
+  return mat2(cos(a),sin(-a),
15
+              sin(a),cos(-a)) *p;
16
+}
17
+
18
+float sphere (vec3 p, float r)
19
+{
20
+  return length(p)-r;
21
+}
22
+
23
+float torus(vec3 p, vec2 t)
24
+{
25
+  p.yz=rot(p.yz,3.1416/2);
26
+  vec2 q = vec2(length(p.xz)-t.x, p.y);
27
+  return length(q)-t.y;
28
+}
29
+
30
+float dist(vec3 p)
31
+{
32
+    vec3 g = vec3(p.xy,mod(p.z,1.5) - 1.6);
33
+    //g.yz=rot(g.yz,fGlobalTime);
34
+    float bass = texture(texFFTSmoothed,0.1).r;
35
+    return torus(g,vec2(2+5*bass,0.1+10*bass));
36
+}
37
+
38
+void main(void)
39
+{
40
+  vec2 uv = vec2(gl_FragCoord.x / v2Resolution.x, gl_FragCoord.y / v2Resolution.y);
41
+  uv -= 0.5;
42
+  uv /= vec2(v2Resolution.y / v2Resolution.x, 1);
43
+
44
+  vec3 p0 = vec3(cos(fGlobalTime),sin(fGlobalTime),-3+fGlobalTime*2);
45
+  vec3 d0 = normalize(vec3(uv,1));
46
+  vec3 p=p0;
47
+  for (int i=0;i<64;i++)
48
+  {
49
+    float d = dist(p);
50
+    if(abs(d) < 0.01) break;
51
+    p+=d*d0;
52
+  }
53
+  vec3 c = vec3(exp(-distance(p,p0)*0.01));
54
+  out_color = vec4(c,1);
55
+}