Browse Source

Da Funky Planetarium update :)

Arthur Suzuki 2 years ago
parent
commit
87e3b029d0
2 changed files with 79 additions and 7 deletions
  1. 5 7
      training-20191223/torusTunnel.glsl
  2. 74 0
      training-20191227/planetetarium.glsl

+ 5 - 7
training-20191223/torusTunnel.glsl

@@ -22,17 +22,15 @@ float sphere (vec3 p, float r)
22 22
 
23 23
 float torus(vec3 p, vec2 t)
24 24
 {
25
-  p.yz=rot(p.yz,3.1416/2);
26
-  vec2 q = vec2(length(p.xz)-t.x, p.y);
25
+  vec2 q = vec2(length(p.xy)-t.x, p.z);
27 26
   return length(q)-t.y;
28 27
 }
29 28
 
30
-float dist(vec3 p)
29
+float sceneSDF(vec3 p)
31 30
 {
32 31
     vec3 g = vec3(p.xy,mod(p.z,1.5) - 1.6);
33
-    //g.yz=rot(g.yz,fGlobalTime);
34 32
     float bass = texture(texFFTSmoothed,0.1).r;
35
-    return torus(g,vec2(2+5*bass,0.1+10*bass));
33
+    return torus(g,vec2(2+5*bass,0.12+10*bass));
36 34
 }
37 35
 
38 36
 void main(void)
@@ -46,10 +44,10 @@ void main(void)
46 44
   vec3 p=p0;
47 45
   for (int i=0;i<64;i++)
48 46
   {
49
-    float d = dist(p);
47
+    float d = sceneSDF(p);
50 48
     if(abs(d) < 0.01) break;
51 49
     p+=d*d0;
52 50
   }
53
-  vec3 c = vec3(exp(-distance(p,p0)*0.01));
51
+  vec3 c = vec3(exp(-distance(p,p0)*0.01))*vec3(sin(fGlobalTime),cos(fGlobalTime+3.14159/3),sin(fGlobalTime+2*(3.14159/3)));
54 52
   out_color = vec4(c,1);
55 53
 }

+ 74 - 0
training-20191227/planetetarium.glsl

@@ -0,0 +1,74 @@
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
+float time = fGlobalTime;
13
+float pi = 3.14159;
14
+
15
+vec2 rot(vec2 p,float a)
16
+{
17
+  return
18
+  mat2(cos(a),sin(-a),
19
+       sin(a),cos(-a))
20
+  * p;
21
+}
22
+
23
+vec3 tran(vec3 p, vec3 dep)
24
+{
25
+  return p+dep;
26
+}
27
+
28
+float box(vec3 p, vec3 b, float r)
29
+{
30
+  vec3 q = abs(p) - b;
31
+  return length(max(q,0.0)) + min(max(q.x,max(q.y,q.z)),0.0)-r; 
32
+}
33
+
34
+float sphere(vec3 p, float r)
35
+{
36
+  return length(p)-r;
37
+}
38
+
39
+float torus(vec3 p, vec2 t)
40
+{
41
+  vec2 q = vec2(length(p.xy)-t.x,p.z);
42
+  return length(q)-t.y;
43
+}
44
+
45
+float sceneSDF(vec3 p)
46
+{
47
+  p.xz=rot(p.xz,time/5);
48
+  vec3 x = p; x.xz = rot(x.xz,time/2);
49
+  vec3 y = p; y.zy = rot(y.zy,time/3);
50
+  float dualtorus = min(torus(x,vec2(2,0.1)),torus(y,vec2(1.5,0.1)));
51
+  float plansat = min(sphere(p,0.5),sphere(tran(p,vec3(cos(time),sin(time),0)),0.2));
52
+  return min(dualtorus,plansat);
53
+}
54
+
55
+void main(void)
56
+{
57
+  vec2 uv = vec2(gl_FragCoord.x / v2Resolution.x, gl_FragCoord.y / v2Resolution.y);
58
+  uv -= 0.5;
59
+  uv /= vec2(v2Resolution.y / v2Resolution.x, 1);
60
+
61
+  vec3 p0 = vec3(0,0,-3);
62
+  vec3 dir = normalize(vec3(uv,1));
63
+  vec3 p=p0;
64
+  for(int i=0;i<64;i++)
65
+  {
66
+    float d=sceneSDF(p);
67
+    if(abs(d)<0.01) break;
68
+    p+=d*dir;
69
+  }
70
+
71
+  float obj = exp(-distance(p,p0));
72
+  vec3 color = obj >= 0.01 ? vec3(obj) : vec3(sin(time),sin(time+pi/3),sin(time+2*pi/3))*length(uv);
73
+  out_color = vec4(color,1);
74
+}