slightly better?
authorJohn Tsiombikas <nuclear@mutantstargoat.com>
Wed, 10 Aug 2016 22:18:52 +0000 (01:18 +0300)
committerJohn Tsiombikas <nuclear@mutantstargoat.com>
Wed, 10 Aug 2016 22:18:52 +0000 (01:18 +0300)
sdr/glink.p.glsl
src/fs.cc

index 0c51278..372af7f 100644 (file)
+uniform float tsec, phase;
+
+float cnoise(vec2 p);
+float fbm(vec2 p, int octaves);
+
 void main()
 {
        const vec3 color = vec3(0.2, 0.4, 1.0);
 
 void main()
 {
        const vec3 color = vec3(0.2, 0.4, 1.0);
 
+       float tm = tsec + phase;
+
        vec2 uv = gl_TexCoord[0].st;
        vec2 pt = uv * vec2(2.0) - vec2(1.0);
 
        vec2 uv = gl_TexCoord[0].st;
        vec2 pt = uv * vec2(2.0) - vec2(1.0);
 
+       float pulse = fbm(vec2(uv.y * 50.0 - tm * 0.5, 0.0), 2);
+
        float d_horiz = abs(pt.x);
        float d_vert = max(abs(pt.y), 0.0);
 
        float d_horiz = abs(pt.x);
        float d_vert = max(abs(pt.y), 0.0);
 
-       float beam_sharpness = 80.0 * min(uv.y + 0.3, 1.0);
-       float beam_intensity = 6.0 * (1.0 - uv.y);
+       float beam_sharpness = 80.0 * clamp(pow(uv.y, 0.5), 0.0, 1.0) * (pulse * 0.5 + 1.0);
+       float beam_intensity = 6.0 * min(0.01 / (uv.y * uv.y) - 0.0004, 1.0);
 
        float glow_u = pow(1.0 - smoothstep(0.0, 1.0, d_horiz), beam_sharpness) * beam_intensity;
 
        float glow_u = pow(1.0 - smoothstep(0.0, 1.0, d_horiz), beam_sharpness) * beam_intensity;
-       float glow_v = 1.0 - smoothstep(0.8, 1.0, d_vert);
+       float glow_v = 1.0 - smoothstep(0.98, 1.0, d_vert);
 
        float glow = glow_u * glow_v;
 
        gl_FragColor.rgb = color * glow;// + vec3(0.0, 1.0, 0.0) * step(0.99, max(abs(pt.x), abs(pt.y)));
        gl_FragColor.a = 1.0;
 }
 
        float glow = glow_u * glow_v;
 
        gl_FragColor.rgb = color * glow;// + vec3(0.0, 1.0, 0.0) * step(0.99, max(abs(pt.x), abs(pt.y)));
        gl_FragColor.a = 1.0;
 }
+
+float fbm(vec2 p, int octaves)
+{
+       float res = 0.0;
+       float freq = 1.0;
+       float scale = 1.0;
+
+       for(int i=0; i<octaves; i++) {
+               res += cnoise(p * freq) * scale;
+               freq *= 2.0;
+               scale *= 0.5;
+       }
+       return res;
+}
+
+//
+// GLSL textureless classic 2D noise "cnoise",
+// with an RSL-style periodic variant "pnoise".
+// Author:  Stefan Gustavson (stefan.gustavson@liu.se)
+// Version: 2011-08-22
+//
+// Many thanks to Ian McEwan of Ashima Arts for the
+// ideas for permutation and gradient selection.
+//
+// Copyright (c) 2011 Stefan Gustavson. All rights reserved.
+// Distributed under the MIT license. See LICENSE file.
+// https://github.com/stegu/webgl-noise
+//
+
+vec4 mod289(vec4 x)
+{
+  return x - floor(x * (1.0 / 289.0)) * 289.0;
+}
+
+vec4 permute(vec4 x)
+{
+  return mod289(((x*34.0)+1.0)*x);
+}
+
+vec4 taylor_inv_sqrt(vec4 r)
+{
+  return 1.79284291400159 - 0.85373472095314 * r;
+}
+
+vec2 fade(vec2 t) {
+  return t*t*t*(t*(t*6.0-15.0)+10.0);
+}
+
+// Classic perlin noise
+float cnoise(vec2 p)
+{
+  vec4 pi = floor(p.xyxy) + vec4(0.0, 0.0, 1.0, 1.0);
+  vec4 pf = fract(p.xyxy) - vec4(0.0, 0.0, 1.0, 1.0);
+  pi = mod289(pi); // To avoid truncation effects in permutation
+  vec4 ix = pi.xzxz;
+  vec4 iy = pi.yyww;
+  vec4 fx = pf.xzxz;
+  vec4 fy = pf.yyww;
+
+  vec4 i = permute(permute(ix) + iy);
+
+  vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ;
+  vec4 gy = abs(gx) - 0.5 ;
+  vec4 tx = floor(gx + 0.5);
+  gx = gx - tx;
+
+  vec2 g00 = vec2(gx.x,gy.x);
+  vec2 g10 = vec2(gx.y,gy.y);
+  vec2 g01 = vec2(gx.z,gy.z);
+  vec2 g11 = vec2(gx.w,gy.w);
+
+  vec4 norm = taylor_inv_sqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
+  g00 *= norm.x;  
+  g01 *= norm.y;  
+  g10 *= norm.z;  
+  g11 *= norm.w;  
+
+  float n00 = dot(g00, vec2(fx.x, fy.x));
+  float n10 = dot(g10, vec2(fx.y, fy.y));
+  float n01 = dot(g01, vec2(fx.z, fy.z));
+  float n11 = dot(g11, vec2(fx.w, fy.w));
+
+  vec2 fade_xy = fade(pf.xy);
+  vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x);
+  float n_xy = mix(n_x.x, n_x.y, fade_xy.y);
+  return 2.3 * n_xy;
+}
index 032fd66..c7df966 100644 (file)
--- a/src/fs.cc
+++ b/src/fs.cc
@@ -137,6 +137,8 @@ void draw_fs()
        }
 
        // draw the directory link lines
        }
 
        // draw the directory link lines
+       glUseProgram(glow_link_sdr);
+       set_uniform_float(glow_link_sdr, "tsec", time_sec);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE);
 
        for(int i=0; i<nchildren; i++) {
        glBlendFunc(GL_SRC_ALPHA, GL_ONE);
 
        for(int i=0; i<nchildren; i++) {
@@ -152,21 +154,22 @@ void draw_fs()
                xform.rotate_y(angle);
                xform.translate(0, -0.3, 0);
 
                xform.rotate_y(angle);
                xform.translate(0, -0.3, 0);
 
-               glUseProgram(glow_link_sdr);
                glPushMatrix();
                glMultMatrixf(xform[0]);
                glDepthMask(0);
 
                glPushMatrix();
                glMultMatrixf(xform[0]);
                glDepthMask(0);
 
+               set_uniform_float(glow_link_sdr, "phase", col * 42.0);
+
                glBegin(GL_QUADS);
                glColor3f(0.2, 0.3, 0.8);
                glTexCoord2f(0, 0);
                glBegin(GL_QUADS);
                glColor3f(0.2, 0.3, 0.8);
                glTexCoord2f(0, 0);
-               glVertex3f(-0.25, 0, 0.05);
+               glVertex3f(-0.2, 0, 0.05);
                glTexCoord2f(1, 0);
                glTexCoord2f(1, 0);
-               glVertex3f(0.25, 0, 0.05);
+               glVertex3f(0.2, 0, 0.05);
                glTexCoord2f(1, 1);
                glTexCoord2f(1, 1);
-               glVertex3f(0.25, 0, -2.0);
+               glVertex3f(0.2, 0, -5.0);
                glTexCoord2f(0, 1);
                glTexCoord2f(0, 1);
-               glVertex3f(-0.25, 0, -2.0);
+               glVertex3f(-0.2, 0, -5.0);
                glColor3f(1, 1, 1);
                glEnd();
                glPopMatrix();
                glColor3f(1, 1, 1);
                glEnd();
                glPopMatrix();