Skip to content

Instantly share code, notes, and snippets.

@mrange
Last active August 10, 2025 13:04
Show Gist options
  • Save mrange/61e6ac781e3a4c32a14ccc5b19f23000 to your computer and use it in GitHub Desktop.
Save mrange/61e6ac781e3a4c32a14ccc5b19f23000 to your computer and use it in GitHub Desktop.
Bonzomatic Prelude
// -----------------------------------------------------------------------------
#version 430 core
// -----------------------------------------------------------------------------
uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)
uniform float fFrameTime; // duration of the last frame, in seconds
uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
uniform sampler1D texFFTIntegrated; // this is continually increasing
uniform sampler2D texPreviousFrame; // screenshot of the previous frame
uniform sampler2D texChecker;
uniform sampler2D texNoise;
uniform sampler2D texTex1;
uniform sampler2D texTex2;
uniform sampler2D texTex3;
uniform sampler2D texTex4;
layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything
#define iTime fGlobalTime
#define iResolution vec3(v2Resolution,1)
// -----------------------------------------------------------------------------
float hash(float co) {
return fract(sin(co*12.9898) * 13758.5453);
}
float hash(vec2 co) {
return fract(sin(dot(co.xy ,vec2(12.9898,58.233))) * 13758.5453);
}
float hash(vec3 r) {
return fract(sin(dot(r.xy,vec2(1.38984*sin(r.z),1.13233*cos(r.z))))*653758.5453);
}
float segmenty(vec2 p) {
float
d0 = length(p)
, d1 = abs(p.x)
;
return p.y > 0. ? d0 : d1;
}
vec3 bars(vec3 col) {
col = mix(col,vec3(0), isnan(col));
const float ZZ = 0.0125;
vec2
r = v2Resolution
, C = gl_FragCoord.xy
, p = (C + C - r) / r.y
, q
;
float
t = fGlobalTime
, aa = sqrt(2.) / r.y
;
p.y += 0.25;
q = (1. + p) * 0.5;
// Draw frequency bars
if (abs(p.x) < 1.5 - ZZ * 3.) {
float
x = q.x
, n = round(x / ZZ) * ZZ
;
vec2 c = q;
c.x -= n;
x = n;
x = clamp(x * 0.5 + 0.125, 0., 1.);
float f = texture(texFFTSmoothed, x).x;
x += 1./16.;
f *= f * x * x * 3e4;
f = log2(f) / 10. + 0.6;
c.y -= 0.5;
c.y = abs(c.y) - f * 0.3;
col = mix(
col
, vec3(0)
, smoothstep(aa, -aa, segmenty(c) - ZZ * 0.4-aa*2.)
);
col = mix(
col
, (1. + sin(-t + abs(p.y) + 2. * p.x + vec3(0, 1, 2))) * (1.25 + sign(p.y))
, smoothstep(aa, -aa, segmenty(c) - ZZ * 0.4)
);
}
// Horizontal line at y=0
if (abs(p.y) < 2. * aa) {
col = vec3(2);
}
// Bottom half tint
if (p.y < 0.) {
col += -0.01 * vec3(1, 3, 21) * p.y;
}
// Final color processing
col = sqrt(tanh(col));
return col;
}
void mainImage(out vec4 O, vec2 C);
void main(void) {
vec4 O=vec4(1);
mainImage(O, gl_FragCoord.xy);
O.w = 1.;
out_color = O;
}
// -----------------------------------------------------------------------------
void mainImage(out vec4 O, vec2 C) {
O.xyz = bars(O.xyz);
}
// -----------------------------------------------------------------------------
#version 430 core
// -----------------------------------------------------------------------------
uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)
uniform float fFrameTime; // duration of the last frame, in seconds
uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
uniform sampler1D texFFTIntegrated; // this is continually increasing
uniform sampler2D texPreviousFrame; // screenshot of the previous frame
uniform sampler2D texChecker;
uniform sampler2D texNoise;
uniform sampler2D texTex1;
uniform sampler2D texTex2;
uniform sampler2D texTex3;
uniform sampler2D texTex4;
layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything
#define iTime fGlobalTime
#define iResolution vec3(v2Resolution,1)
// -----------------------------------------------------------------------------
float hash(vec2 co) {
return fract(sin(dot(co.xy ,vec2(12.9898,58.233))) * 13758.5453);
}
float segmenty(vec2 p) {
float
d0 = length(p)
, d1 = abs(p.x)
;
return p.y > 0. ? d0 : d1;
}
vec3 bars() {
const float ZZ = 0.0125;
vec2
r = v2Resolution
, C = gl_FragCoord.xy
, p = (C + C - r) / r.y
, q
;
float
t = fGlobalTime
, aa = sqrt(2.) / r.y
;
vec3
col = vec3(0);
;
p.y += 0.25;
q = (1. + p) * 0.5;
// Draw frequency bars
if (abs(p.x) < 1.5 - ZZ * 3.) {
float
x = q.x
, n = round(x / ZZ) * ZZ
;
vec2 c = q;
c.x -= n;
x = n;
x = clamp(x * 0.5 + 0.125, 0., 1.);
float f = texture(texFFTSmoothed, x).x;
x += 1./16.;
f *= f * x * x * 3e4;
f = log2(f) / 10. + 0.6;
c.y -= 0.5;
c.y = abs(c.y) - f * 0.3;
col = mix(
col
, (1. + sin(-t + abs(p.y) + 2. * p.x + vec3(0, 1, 2))) * (1.25 + sign(p.y))
, smoothstep(aa, -aa, segmenty(c) - ZZ * 0.4)
);
}
// Horizontal line at y=0
if (abs(p.y) < 2. * aa) {
col = vec3(2);
}
// Bottom half tint
if (p.y < 0.) {
col += -0.01 * vec3(1, 3, 21) * p.y;
}
// Final color processing
col = sqrt(tanh(col));
return col;
}
void mainImage(out vec4 O, vec2 C);
void main(void) {
vec4 O=vec4(1);
mainImage(O, gl_FragCoord.xy);
O.w = 1.;
out_color = O;
}
// -----------------------------------------------------------------------------
vec2 toSmith(vec2 p) {
// z = (p + 1)/(-p + 1)
// (x,y) = ((1+x)*(1-x)-y*y,2y)/((1-x)*(1-x) + y*y)
float d = (1.0 - p.x)*(1.0 - p.x) + p.y*p.y;
float x = (1.0 + p.x)*(1.0 - p.x) - p.y*p.y;
float y = 2.0*p.y;
return vec2(x,y)/d;
}
vec2 fromSmith(vec2 p) {
// z = (p - 1)/(p + 1)
// (x,y) = ((x+1)*(x-1)+y*y,2y)/((x+1)*(x+1) + y*y)
float d = (p.x + 1.0)*(p.x + 1.0) + p.y*p.y;
float x = (p.x + 1.0)*(p.x - 1.0) + p.y*p.y;
float y = 2.0*p.y;
return vec2(x,y)/d;
}
vec2 offset() {
return sin(.5*iTime*vec2(1,sqrt(2.)))*cos(iTime/11.);
}
float zoom() {
return 3.+2.*sin(iTime/10.);
}
vec2 forward(vec2 p) {
p += offset();
p *= zoom();
return fromSmith(p);
}
vec2 reverse(vec2 p) {
return toSmith(p)/zoom()-offset();
}
void mainImage(out vec4 O, vec2 C) {
vec4 o,T,Q;
vec2
p = (C+C-iResolution.xy)/iResolution.y
, op = p
, q
, n = normalize(cos(iTime*vec2(5,6)/10.))
, c = .5*cos(iTime*vec2(7,8)/10.)
, N = vec2(n.y, -n.x)
, l
, t
;
float sz = 2./iResolution.y,I = 1.+dot(p,p),Z;
p = forward(p);
Z = length(op-p)+1.;
Q = 1.+sin(6.*length(op)+Z+iTime+vec4(0,1,2,0));
l = p - c;
float d = dot(n,l), D = dot(N,l),x=abs(.5*D);
t = .95*N*D+n*d*.9;
t += c;
q = (reverse(t)*iResolution.y+iResolution.xy)/2./iResolution.xy;
o = texture(texPreviousFrame,q)*vec4(1.)*.995;
if (abs(d)<sz*50.) {
// *100.
float f = texture(texFFT,fract(x)).x,F;
F = f;
x += 1./16.;
f *= f * x * x * 3e4;
f = log2(f) / 10. + 0.6;
// T = vec4(f,0.01,F,0)*8.;
T = (1.+sin(iTime+10.*F+vec4(0,1,2,0)))*f;
T.xyz *= T.w;
// T *= smoothstep(1., .5,x);
o += tanh(T);
}
o -= 0.01*Q*Z;
if (length(op) < 0.5*sin(iTime)) {
o += 0.1*sin(6.*iTime+length(op)*10.);
}
O = o;
}
// -----------------------------------------------------------------------------
#version 430 core
// -----------------------------------------------------------------------------
uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)
uniform float fFrameTime; // duration of the last frame, in seconds
uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
uniform sampler1D texFFTIntegrated; // this is continually increasing
uniform sampler2D texPreviousFrame; // screenshot of the previous frame
uniform sampler2D texChecker;
uniform sampler2D texNoise;
uniform sampler2D texTex1;
uniform sampler2D texTex2;
uniform sampler2D texTex3;
uniform sampler2D texTex4;
layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything
#define iTime fGlobalTime
#define iResolution vec3(v2Resolution,1)
// -----------------------------------------------------------------------------
float hash(vec2 co) {
return fract(sin(dot(co.xy ,vec2(12.9898,58.233))) * 13758.5453);
}
float segmenty(vec2 p) {
float
d0 = length(p)
, d1 = abs(p.x)
;
return p.y > 0. ? d0 : d1;
}
vec3 bars() {
const float ZZ = 0.0125;
vec2
r = v2Resolution
, C = gl_FragCoord.xy
, p = (C + C - r) / r.y
, q
;
float
t = fGlobalTime
, aa = sqrt(2.) / r.y
;
vec3
col = vec3(0);
;
p.y += 0.25;
q = (1. + p) * 0.5;
// Draw frequency bars
if (abs(p.x) < 1.5 - ZZ * 3.) {
float
x = q.x
, n = round(x / ZZ) * ZZ
;
vec2 c = q;
c.x -= n;
x = n;
x = clamp(x * 0.5 + 0.125, 0., 1.);
float f = texture(texFFTSmoothed, x).x;
x += 1./16.;
f *= f * x * x * 3e4;
f = log2(f) / 10. + 0.6;
c.y -= 0.5;
c.y = abs(c.y) - f * 0.3;
col = mix(
col
, (1. + sin(-t + abs(p.y) + 2. * p.x + vec3(0, 1, 2))) * (1.25 + sign(p.y))
, smoothstep(aa, -aa, segmenty(c) - ZZ * 0.4)
);
}
// Horizontal line at y=0
if (abs(p.y) < 2. * aa) {
col = vec3(2);
}
// Bottom half tint
if (p.y < 0.) {
col += -0.01 * vec3(1, 3, 21) * p.y;
}
return col;
}
void mainImage(out vec4 O, vec2 C);
void main(void) {
vec4 O=vec4(1);
mainImage(O, gl_FragCoord.xy);
O.w = 1.;
out_color = O;
}
// -----------------------------------------------------------------------------
float length8(vec3 p) {
p *= p;
p *= p;
return pow(dot(p,p),1./8.);
}
float length8(vec2 p) {
p *= p;
p *= p;
return pow(dot(p,p),1./8.);
}
float length4(vec2 p) {
p *= p;
return pow(dot(p,p),1./4.);
}
void rot(inout vec2 p, float a) {
float c=cos(a),s=sin(a);
p = vec2(c*p.x+s*p.y,-s*p.x+c*p.y);
}
float torus(vec3 p, vec2 t) {
vec2 q = vec2(length(p.xz)-t.x,p.y);
return length8(q)-t.y;
}
float ttorus(vec3 p, vec2 t) {
vec2 q = vec2(length(p.xz)-t.x,p.y);
float a = atan(p.x,p.z);
rot(q.xy,4.*a+iTime);
return length8(q)-t.y;
}
float ref(inout vec3 p, vec3 r) {
float d = dot(p, r);
p -= r*min(0., d)*2.;
return d < 0. ? 0. : 1.;
}
float ball(vec3 p, vec2 t) {
const vec3
r0=normalize(vec3(1,-1,0))
, r1=normalize(vec3(0,-1,1))
;
p = abs(p);
ref(p,r0);
ref(p,r1);
return torus(p,t);
}
float tball(vec3 p, vec2 t) {
const vec3
r0=normalize(vec3(1,-1,0))
, r1=normalize(vec3(0,-1,1))
;
p = abs(p);
ref(p,r0);
ref(p,r1);
return ttorus(p,t);
}
vec3 g_rot;
float g_gd;
float df(vec3 p) {
vec3 rot = g_rot;
p.y -= 0.3;
p = rot*dot(p,rot)-cross(p,rot);
vec3 P = 100.*p;
float I = pow((.5+.5*sin(P.x)*sin(P.y)*sin(P.z)),8)/200;
float d = length8(p) - 1.;
float D = ball_(p,vec2(1,0.1));
float T = D;
d += -I;
d = max(d, 0.1-D);
d = min(d, (T));
g_gd = min(g_gd, T);
return d;
}
vec3 normal(vec3 p) {
vec2 eps = vec2(1e-3,0);
return normalize(vec3(
df(p+eps.xyy)-df(p-eps.xyy)
, df(p+eps.yxy)-df(p-eps.yxy)
, df(p+eps.yyx)-df(p-eps.yyx)
));
}
vec3 renderSky(vec3 col, vec3 ro, vec3 rd) {
float t0 = (5.-ro.y)/rd.y;
float t1 = (-5.-ro.y)/rd.y;
//col += 0.01*vec3(3,2,1)/(1.00001-dot(rd, normalize(vec3(1,1,-1))));
if (t0 > 0.) {
vec3 p = t0*rd;
float d = length8(p.xz)-3.;
col += vec3(1,2,9)/2.*smoothstep(.2, 0., d)*(4.+d);
}
if (t1 > 0.) {
vec3 p = t1*rd;
float d = length(p.xz)-2.;
col += vec3(3,0,9)/9.*exp(-2.*d);
}
return col;
}
vec3 render(vec3 col, vec3 ro, vec3 rd,float noise) {
float z=noise;
col = renderSky(col, ro, rd);
g_rot = normalize(sin(iTime+vec3(0,1,2)));
g_gd = 1E3;
for(float i=0.;++i<77.;) {
vec3 p = z*rd+ro;
float s = p.y+1.25;
p.y = abs(s)-1.25;
float d = df(p);
if (d<1e-3) {
float gd = g_gd;
vec3 n = normal(p);
vec3 r = reflect(rd,n);
float fre = 1.+dot(rd,n);
fre *= fre;
//col = vec3(1.-i/80.);
col = vec3(0);
col += fre*renderSky(vec3(0),p,r);
col += vec3(1,1,9)*pow((0.5+.5*n.y),4.)/30.;
if (s < 0.) {
col *= vec3(1,2,3)/8.;
}
col += 2e-3*vec3(1,2,9)/max(gd, 1e-3);
break;
}
z += d;
}
return col;
}
vec3 effect(vec3 col, vec2 p,float noise) {
vec3 ro = vec3(0,0,-4);
vec3 rd = normalize(vec3(p,1));
col = render(col, ro, rd,noise);
col = sqrt(tanh(col));
return col;
}
void mainImage(out vec4 O, vec2 C) {
vec3 col = bars();
col = effect(col, (C-.5*iResolution.xy)/iResolution.y,fract(dot(C,sin(C))));
O = vec4(col,1);
}
// -----------------------------------------------------------------------------
#version 430 core
// -----------------------------------------------------------------------------
uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)
uniform float fFrameTime; // duration of the last frame, in seconds
uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
uniform sampler1D texFFTIntegrated; // this is continually increasing
uniform sampler2D texPreviousFrame; // screenshot of the previous frame
uniform sampler2D texChecker;
uniform sampler2D texNoise;
uniform sampler2D texTex1;
uniform sampler2D texTex2;
uniform sampler2D texTex3;
uniform sampler2D texTex4;
layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything
#define iTime fGlobalTime
#define iResolution vec3(v2Resolution,1)
// -----------------------------------------------------------------------------
float hash(vec2 co) {
return fract(sin(dot(co.xy ,vec2(12.9898,58.233))) * 13758.5453);
}
float segmenty(vec2 p) {
float
d0 = length(p)
, d1 = abs(p.x)
;
return p.y > 0. ? d0 : d1;
}
vec3 bars() {
const float ZZ = 0.0125;
vec2
r = v2Resolution
, C = gl_FragCoord.xy
, p = (C + C - r) / r.y
, q
;
float
t = fGlobalTime
, aa = sqrt(2.) / r.y
;
vec3
col = vec3(0);
;
p.y += 0.25;
q = (1. + p) * 0.5;
// Draw frequency bars
if (abs(p.x) < 1.5 - ZZ * 3.) {
float
x = q.x
, n = round(x / ZZ) * ZZ
;
vec2 c = q;
c.x -= n;
x = n;
x = clamp(x * 0.5 + 0.125, 0., 1.);
float f = texture(texFFTSmoothed, x).x;
x += 1./16.;
f *= f * x * x * 3e4;
f = log2(f) / 10. + 0.6;
c.y -= 0.5;
c.y = abs(c.y) - f * 0.3;
col = mix(
col
, (1. + sin(-t + abs(p.y) + 2. * p.x + vec3(0, 1, 2))) * (1.25 + sign(p.y))
, smoothstep(aa, -aa, segmenty(c) - ZZ * 0.4)
);
}
// Horizontal line at y=0
if (abs(p.y) < 2. * aa) {
col = vec3(2);
}
// Bottom half tint
if (p.y < 0.) {
col += -0.01 * vec3(1, 3, 21) * p.y;
}
return col;
}
void mainImage(out vec4 O, vec2 C);
void main(void) {
vec4 O=vec4(1);
mainImage(O, gl_FragCoord.xy);
O.w = 1.;
out_color = O;
}
// -----------------------------------------------------------------------------
const float PI = acos(-1.);
float length8(vec4 p) {
p *= p;
p *= p;
return pow(dot(p,p),1./8.);
}
float length8(vec3 p) {
p *= p;
p *= p;
return pow(dot(p,p),1./8.);
}
float length8(vec2 p) {
p *= p;
p *= p;
return pow(dot(p,p),1./8.);
}
float length4(vec4 p) {
p *= p;
return pow(dot(p,p),1./4.);
}
float length4(vec3 p) {
p *= p;
return pow(dot(p,p),1./4.);
}
float length4(vec2 p) {
p *= p;
return pow(dot(p,p),1./4.);
}
void rot(inout vec2 p, float a) {
float c=cos(a),s=sin(a);
p = vec2(c*p.x+s*p.y,-s*p.x+c*p.y);
}
float torus(vec3 p, vec2 t) {
vec2 q = vec2(length(p.xz)-t.x,p.y);
return length(q)-t.y;
}
float ttorus(vec3 p, vec2 t) {
vec2 q = vec2(length(p.xz)-t.x,p.y);
float a = atan(p.x,p.z);
rot(q.xy,4.*a+iTime);
return length(q)-t.y;
}
float ref(inout vec3 p, vec3 r) {
float d = dot(p, r);
p -= r*min(0., d)*2.;
return d < 0. ? 0. : 1.;
}
float ball(vec3 p, vec2 t) {
const vec3
r0=normalize(vec3(1,-1,0))
, r1=normalize(vec3(0,-1,1))
;
p = abs(p);
ref(p,r0);
ref(p,r1);
return torus(p,t);
}
float pmin(float a, float b, float k) {
float h = clamp(0.5+0.5*(b-a)/k, 0.0, 1.0);
return mix(b, a, h) - k*h*(1.0-h);
}
float pmax(float a, float b, float k) {
return -pmin(-a, -b, k);
}
vec3 g_rot;
float g_gd;
vec3 rotate(vec3 p) {
/*
rot(p.xz, 0.5*PI);
rot(p.zy, 0.*PI);
return p;
*/
vec3 rot = g_rot;
return rot*dot(p,rot)-cross(p,rot);;
}
float df_(vec3 p) {
float d = 1E3;
float Z = 1.25;
float gd = 1E3;
for (float i = 0.;i < 1; ++i) {
p = rotate(p);
float O = length8(p) - Z;
d = pmax(d, .15*Z-O,.1*Z);
gd = min(gd, max(max(d, O-.25*Z), .2*Z-O));
d = min(d, O);
p = abs(p);
p -= .5*Z;
Z *= .4;
}
g_gd = min(g_gd,gd);
return d;
}
float df(vec3 p) {
p = rotate(p);
float d = 1E3;
float O = length4(p) - 1.3;
float I = length(p) - 1.;
d = O;
/*
d = pmax(d, -I,.7);
d = min(d, I);
*/
// d = max(d, .1-I);
//g_gd = min(g_gd, I);
//d = min(d, I);
return d;
}
vec3 normal(vec3 p) {
vec2 eps = vec2(1e-3,0);
return normalize(vec3(
df(p+eps.xyy)-df(p-eps.xyy)
, df(p+eps.yxy)-df(p-eps.yxy)
, df(p+eps.yyx)-df(p-eps.yyx)
));
}
vec3 renderSky(vec3 col, vec3 ro, vec3 rd) {
float t0 = (5.-ro.y)/rd.y;
float t1 = (-5.-ro.y)/rd.y;
//col += 0.01*vec3(3,2,1)/(1.00001-dot(rd, normalize(vec3(1,1,-1))));
if (t0 > 0.) {
vec3 p = t0*rd;
float d = length4(p.xz)-3.;
col += vec3(1,2,9)/2.*smoothstep(1., 0., d+.5)*(4+d);
}
if (t1 > 0.) {
vec3 p = t1*rd;
float d = length(p.xz);
col += vec3(1,0,6)*exp(-2.*d);
}
return col;
}
float rayMarch(vec3 ro, vec3 rd, float initt) {
const float MaxIter = 77.;
float
t = initt
, mind = 1E3
, mint = initt
, i
;
for(i=0.;i<MaxIter;++i) {
vec3 p = t*rd+ro;
float d = df(p);
if (d < 1e-3) break;
if (t > 10.) break;
if (d < mind) {
mind = d;
mint = t;
}
t+=d;
}
if (i == MaxIter) {
return mint;
}
return t;
}
vec3 prevFrame(vec2 p) {
// rot(p, iTime+3.*length(p));
// p = -p;
p.x *= iResolution.y/iResolution.x;
p *= .4;
p += .5;
vec4 t = texture(texPreviousFrame, p);
vec3 col = (t.xyz*t.xyz)*t.w;
col *= vec3(6,4,8)/9.;
col -= vec3(6,4,8).xzy*.005;
return col;
}
#define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a))
vec3 render(vec3 col, vec3 ro, vec3 rd,float noise) {
float z=noise;
col = renderSky(col, ro, rd);
g_rot = normalize(sin(.4*iTime+vec3(0,1,2)));
g_gd = 1E3;
float t = rayMarch(ro, rd, 0.);
if (t< 10.) {
vec3 p = ro+rd*t;
float gd = g_gd;
vec3 n = normal(p);
vec3 r = reflect(rd,n);
float fre = 1.+dot(rd,n);
fre *= fre;
vec3 U = rotate(p);
vec3 N = rotate(n);
/*
vec2 u =
N.x*U.yz*vec2(1,-sign(N.x))*ROT(-sign(N.x)*PI*.5)
+ N.y*vec2(sign(N.y),1)*U.xz*ROT(PI*0.)
+ N.z*U.yx*vec2(1,sign(N.z))*ROT(-sign(N.z)*PI*.5)
;
*/
vec2 u =
N.x*U.zy
+ N.y*U.xz*vec2(1,-1)
- N.z*U.yx
;
//vec2 u = N.x*U.yz*ROT(1.)+N.y*U.xz*ROT(PI*.5)+N.z*U.yx*vec2(1,-1)*ROT(PI*.5);
col = vec3(0);
col += fre*renderSky(vec3(0),p,r);
col += vec3(1,1,9)*pow((0.5+.5*n.y),4.)/30.;
col += 1e-3*vec3(1,2,9)/max(gd, 1e-3);
const float L = .5;
float l;
l = length(u)+.1*iTime;
l -= round(l/L)*L;
col = mix(col, prevFrame(u), smoothstep(L*.26,L*.24,l)*smoothstep(-L*.26,-L*.24,l));
l -= .25*L;
col += 2e-5*vec3(9,2,1)/max(l*l, 1e-5);
l -= -.5*L;
col += 2e-5*vec3(9,2,1).zyx/max(l*l, 1e-5);
}
return col;
}
vec3 effect(vec3 col, vec2 p,float noise) {
vec3 ro = vec3(0,0,-4);
vec3 rd = normalize(vec3(p,1));
col = render(col, ro, rd,noise);
// col -= 0.04*vec3(2,1,3)*length(.25+p);;
col = sqrt(tanh(col));
return col;
}
void mainImage(out vec4 O, vec2 C) {
vec3 col = bars();
col = effect(col, (C-.5*iResolution.xy)/iResolution.y,fract(dot(C,sin(C))));
O = vec4(col,1);
}

// ----------------------------------------------------------------------------- #version 430 core // -----------------------------------------------------------------------------

uniform float fGlobalTime; // in seconds uniform vec2 v2Resolution; // viewport resolution (in pixels) uniform float fFrameTime; // duration of the last frame, in seconds

uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients uniform sampler1D texFFTIntegrated; // this is continually increasing uniform sampler2D texPreviousFrame; // screenshot of the previous frame uniform sampler2D texChecker; uniform sampler2D texNoise; uniform sampler2D texTex1; uniform sampler2D texTex2; uniform sampler2D texTex3; uniform sampler2D texTex4;

layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything

#define iTime fGlobalTime #define iResolution vec3(v2Resolution,1)

// -----------------------------------------------------------------------------

float hash(vec2 co) { return fract(sin(dot(co.xy ,vec2(12.9898,58.233))) * 13758.5453); }

float segmenty(vec2 p) { float d0 = length(p) , d1 = abs(p.x) ; return p.y > 0. ? d0 : d1; }

vec3 bars() { const float ZZ = 0.0125; vec2 r = v2Resolution , C = gl_FragCoord.xy , p = (C + C - r) / r.y , q ; float t = fGlobalTime , aa = sqrt(2.) / r.y ; vec3 col = vec3(0); ; p.y += 0.25; q = (1. + p) * 0.5; // Draw frequency bars if (abs(p.x) < 1.5 - ZZ * 3.) { float x = q.x , n = round(x / ZZ) * ZZ ; vec2 c = q; c.x -= n; x = n;

    x = clamp(x * 0.5 + 0.125, 0., 1.);
    float f = texture(texFFTSmoothed, x).x;
    x += 1./16.;
    f *= f * x * x * 3e4;
    f = log2(f) / 10. + 0.6;
    
    c.y -= 0.5;
    c.y = abs(c.y) - f * 0.3;
    
    col = mix(
        col
    , (1. + sin(-t + abs(p.y) + 2. * p.x + vec3(0, 1, 2))) * (1.25 + sign(p.y))
    , smoothstep(aa, -aa, segmenty(c) - ZZ * 0.4)
    );
}

// Horizontal line at y=0
if (abs(p.y) < 2. * aa) {
    col = vec3(2);
}

// Bottom half tint
if (p.y < 0.) {
    col += -0.01 * vec3(1, 3, 21) * p.y;
}

// Final color processing

return col;

}

void mainImage(out vec4 O, vec2 C);

void main(void) { vec4 O=vec4(1); mainImage(O, gl_FragCoord.xy); O.w = 1.; out_color = O;

}

// -----------------------------------------------------------------------------

float length4(vec3 p) { return sqrt(length(p*p)); }

float length4(vec2 p) { return sqrt(length(p*p)); }

float length8(vec3 p) { return sqrt(sqrt(length(ppp*p))); }

float length8(vec2 p) { return sqrt(sqrt(length(ppp*p))); }

vec3 sky(vec3 S, vec3 I) { vec3 col; float t0 = (5.-S.y)/I.y; float t1 = (-5.-S.y)/I.y; if (t0 > 0.) { vec2 p2 = (t0*I+S).xz; float d = length4(p2)-4.; col += (vec3(1,2,3)-d-1.)smoothstep(2.,-2.,d)/2.; } if (t1 > 0.) { vec2 p2 = (t1I+S).xz; float d = length(p2); col += vec3(1,1,2)*exp(-d); } return col; }

mat2 R; float X; float G; float df(vec3 p) { float d = 1E3,i,ia; for (i=0.;i<6.;++i) { vec3 ip = p; ia = -iTime+i*.2+.3p.x; ip.y += sin(ia); ip.z += -.5i; ip.yz = mat2(cos(.6cos(ia)+iTime+p.x+vec4(0,11,33,0))); float id = length4(ip.yz)-0.2; if (id < d) { d = id; X = i; } }

p -= vec3(0,0,-1); p.xz*= R; p.xy*= R; float cd = length8(p)-.7; float gd = length(p)-.5; cd = max(cd,0.3-gd); cd = min(cd, gd); if (cd < d) { d = cd; X = 10.; } G=min(G,gd);

return d; } float rayMarch(vec3 S,vec3 I) { float i,z,d; vec3 p; for(;++i<77.;z+=.8d) { p = zI+S; d = df(p); if (z > 9.) break; if (d < 1e-4) break; }

return z; }

vec3 normal(vec3 p) { vec2 E=vec2(1e-2,0); return normalize(vec3( df(p+E.xyy)-df(p-E.xyy) , df(p+E.yxy)-df(p-E.yxy) , df(p+E.yyx)-df(p-E.yyx) )); }

void mainImage(out vec4 O, vec2 C) { O.xyz = bars(); float d,z,F,x,g; R=mat2(cos(.6iTime+vec4(0,11,33,0))); vec3 r=iResolution , p , I=normalize(vec3(C-.5r.xy,r.y)) , S=vec3(0,0,-4) , n ; G = 1e3; X = 1e3; z = rayMarch(S,I); x = X; g = G; if (z < 9.) { p = S+I*z; n = normal(p); F = 1.+dot(I,n); F *= F; F = mix(.6,1.,F); r = reflect(I,n); O.xyz = 0.; O.xyz += Fsky(p,r); O.xyz += vec3(0,1,9)pow(.5n.y+.5,4.)/18.; O.xyz = 1.2+sin(-.5z+x+vec3(5,1,2)); O.xyz = 1.; O.xyz += 0.003vec3(1,2,3)/max(g,1e-3); }

O.xyz = sqrt(tanh(O.xyz)); }

// -----------------------------------------------------------------------------
#version 430 core
// -----------------------------------------------------------------------------
uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)
uniform float fFrameTime; // duration of the last frame, in seconds
uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
uniform sampler1D texFFTIntegrated; // this is continually increasing
uniform sampler2D texPreviousFrame; // screenshot of the previous frame
uniform sampler2D texChecker;
uniform sampler2D texNoise;
uniform sampler2D texTex1;
uniform sampler2D texTex2;
uniform sampler2D texTex3;
uniform sampler2D texTex4;
layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything
#define iTime fGlobalTime
#define iResolution vec3(v2Resolution,1)
// -----------------------------------------------------------------------------
float hash(vec2 co) {
return fract(sin(dot(co.xy ,vec2(12.9898,58.233))) * 13758.5453);
}
float hash(vec3 r) {
return fract(sin(dot(r.xy,vec2(1.38984*sin(r.z),1.13233*cos(r.z))))*653758.5453);
}
float segmenty(vec2 p) {
float
d0 = length(p)
, d1 = abs(p.x)
;
return p.y > 0. ? d0 : d1;
}
vec3 bars() {
const float ZZ = 0.0125;
vec2
r = v2Resolution
, C = gl_FragCoord.xy
, p = (C + C - r) / r.y
, q
;
float
t = fGlobalTime
, aa = sqrt(2.) / r.y
;
vec3
col = vec3(0);
;
p.y += 0.25;
q = (1. + p) * 0.5;
// Draw frequency bars
if (abs(p.x) < 1.5 - ZZ * 3.) {
float
x = q.x
, n = round(x / ZZ) * ZZ
;
vec2 c = q;
c.x -= n;
x = n;
x = clamp(x * 0.5 + 0.125, 0., 1.);
float f = texture(texFFTSmoothed, x).x;
x += 1./16.;
f *= f * x * x * 3e4;
f = log2(f) / 10. + 0.6;
c.y -= 0.5;
c.y = abs(c.y) - f * 0.3;
col = mix(
col
, (1. + sin(-t + abs(p.y) + 2. * p.x + vec3(0, 1, 2))) * (1.25 + sign(p.y))
, smoothstep(aa, -aa, segmenty(c) - ZZ * 0.4)
);
}
// Horizontal line at y=0
if (abs(p.y) < 2. * aa) {
col = vec3(2);
}
// Bottom half tint
if (p.y < 0.) {
col += -0.01 * vec3(1, 3, 21) * p.y;
}
// Final color processing
col = sqrt(tanh(col));
return col;
}
void mainImage(out vec4 O, vec2 C);
void main(void) {
vec4 O=vec4(1);
mainImage(O, gl_FragCoord.xy);
O.w = 1.;
out_color = O;
}
// -----------------------------------------------------------------------------
void mainImage(out vec4 O, vec2 C) {
float i,d,z,F,H,L,k,W;
vec4 o,p,X,Y,Z,N,P;
vec2 r=iResolution.xy, q2=C/r,p2=(-1.+2.*q2)*r.xy/r.y;
p2 *= .9;
p2 *= mat2(cos(0.3*(length(p2))+vec4(0,11,33,0)));
q2 = (p2*r.y/r.xy+1.)/2.;
//o.xyz = bars();
for(;++i<77.;) {
p = vec4(z*normalize(vec3(C-.5*r, r.y)),0.2);
p.z -= 3.;
W = length(p)-2.5;
mat2 R = mat2(cos(.3*iTime+.5*p.z+vec4(0,11,33,0)));
// p.xy *= R;
k = 6./dot(p,p);
p.xz *= R;
p.xy *= R;
p *= k;
p.xw *= R;
p.wy *= R;
p.zw *= R;
p += .3*iTime;
Y=p;
N = round(p);
H = hash(N.xyz+123.4);
p -= N;
X = p;
X *= X;
X *= X;
d = pow(dot(X,X),1./8.)-.25;
X = sin(50.*p);
d -= pow(.5+.5*X.x*X.y*X.z*X.w, 8.)*.1;
Z = Y;
Z -= N;
// Z.xy *= R;
// Z = abs(Z);
L = length(Z.xy)-.05+.03*sin(3*iTime+6.*Y.z);
d = max(d, .05-L);
d = min(d, L);
d /= k;
d = max(d,W);
d = abs(d)+1e-3;
// d = length(p) - 1.;
p = 1.+sin(iTime+log2(k)+vec4(2,1,0,2));
o += p.w*p/d;
o += 6.*vec4(1,2,3,0)*k*k*k*pow(1.-sqrt(fract(iTime*114./60.)),4.);
z += .7*d;
}
P = texture(texPreviousFrame,q2);
P.xyz = P.xyz*vec3(7,8,9)/9.;
O = tanh(o/1e4);
}
// -----------------------------------------------------------------------------
#version 430 core
// -----------------------------------------------------------------------------
uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)
uniform float fFrameTime; // duration of the last frame, in seconds
uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
uniform sampler1D texFFTIntegrated; // this is continually increasing
uniform sampler2D texPreviousFrame; // screenshot of the previous frame
uniform sampler2D texChecker;
uniform sampler2D texNoise;
uniform sampler2D texTex1;
uniform sampler2D texTex2;
uniform sampler2D texTex3;
uniform sampler2D texTex4;
layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything
#define iTime fGlobalTime
#define iResolution vec3(v2Resolution,1)
// -----------------------------------------------------------------------------
float hash(float co) {
return fract(sin(co*12.9898) * 13758.5453);
}
float hash(vec2 co) {
return fract(sin(dot(co.xy ,vec2(12.9898,58.233))) * 13758.5453);
}
float hash(vec3 r) {
return fract(sin(dot(r.xy,vec2(1.38984*sin(r.z),1.13233*cos(r.z))))*653758.5453);
}
float segmenty(vec2 p) {
float
d0 = length(p)
, d1 = abs(p.x)
;
return p.y > 0. ? d0 : d1;
}
vec3 bars(vec3 col) {
col = mix(col,vec3(0), isnan(col));
const float ZZ = 0.0125;
vec2
r = v2Resolution
, C = gl_FragCoord.xy
, p = (C + C - r) / r.y
, q
;
float
t = fGlobalTime
, aa = sqrt(2.) / r.y
;
p.y += 0.25;
q = (1. + p) * 0.5;
// Draw frequency bars
if (abs(p.x) < 1.5 - ZZ * 3.) {
float
x = q.x
, n = round(x / ZZ) * ZZ
;
vec2 c = q;
c.x -= n;
x = n;
x = clamp(x * 0.5 + 0.125, 0., 1.);
float f = texture(texFFTSmoothed, x).x;
x += 1./16.;
f *= f * x * x * 3e4;
f = log2(f) / 10. + 0.6;
c.y -= 0.5;
c.y = abs(c.y) - f * 0.3;
col = mix(
col
, vec3(0)
, smoothstep(aa, -aa, segmenty(c) - ZZ * 0.4-aa*2.)
);
col = mix(
col
, (1. + sin(-t + abs(p.y) + 2. * p.x + vec3(0, 1, 2))) * (1.25 + sign(p.y))
, smoothstep(aa, -aa, segmenty(c) - ZZ * 0.4)
);
}
// Horizontal line at y=0
if (abs(p.y) < 2. * aa) {
col = vec3(2);
}
// Bottom half tint
if (p.y < 0.) {
col += -0.01 * vec3(1, 3, 21) * p.y;
}
// Final color processing
col = sqrt(tanh(col));
return col;
}
void mainImage(out vec4 O, vec2 C);
void main(void) {
vec4 O=vec4(1);
mainImage(O, gl_FragCoord.xy);
O.w = 1.;
out_color = O;
}
// -----------------------------------------------------------------------------
void mainImage(out vec4 O, vec2 C) {
float i,d,z,k,L;
vec4 o,p,X,Y,S;
for(vec2 r=iResolution.xy;++i<77.;z+=.7*d) {
mat2 R = mat2(cos(0.3*iTime+vec4(0,11,33,0)));
p = vec4(z*normalize(vec3(C-.5*r,r.y)),0);
p.z -= 6.;
Y = p;
L = length(p) - 3.;
p.xw *= R;
p.wy *= R;
p.zw *= R;
k = 9./dot(p,p);
p *= k;
p += iTime-length(Y);
p -= round(p);
X = p;
X *= X;
X *= X;
d = pow(dot(X,X),.125)-.4;
d /= k;
d = max(d,L);
d = abs(d) + 1e-3;
p = 1.+sin(iTime+2.*log2(k)+vec4(0,1,2,0));
o += p.w/d*p;
}
O += o/2e4;
O.xyz = bars(O.xyz*O.xyz);
}
// -----------------------------------------------------------------------------
#version 430 core
// -----------------------------------------------------------------------------
uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)
uniform float fFrameTime; // duration of the last frame, in seconds
uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
uniform sampler1D texFFTIntegrated; // this is continually increasing
uniform sampler2D texPreviousFrame; // screenshot of the previous frame
uniform sampler2D texChecker;
uniform sampler2D texNoise;
uniform sampler2D texTex1;
uniform sampler2D texTex2;
uniform sampler2D texTex3;
uniform sampler2D texTex4;
layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything
#define iTime fGlobalTime
#define iResolution vec3(v2Resolution,1)
// -----------------------------------------------------------------------------
float hash(float co) {
return fract(sin(co*12.9898) * 13758.5453);
}
float hash(vec2 co) {
return fract(sin(dot(co.xy ,vec2(12.9898,58.233))) * 13758.5453);
}
float hash(vec3 r) {
return fract(sin(dot(r.xy,vec2(1.38984*sin(r.z),1.13233*cos(r.z))))*653758.5453);
}
float segmenty(vec2 p) {
float
d0 = length(p)
, d1 = abs(p.x)
;
return p.y > 0. ? d0 : d1;
}
vec3 bars(vec3 col) {
col = mix(col,vec3(0), isnan(col));
const float ZZ = 0.0125;
vec2
r = v2Resolution
, C = gl_FragCoord.xy
, p = (C + C - r) / r.y
, q
;
float
t = fGlobalTime
, aa = sqrt(2.) / r.y
;
p.y += 0.25;
q = (1. + p) * 0.5;
// Draw frequency bars
if (abs(p.x) < 1.5 - ZZ * 3.) {
float
x = q.x
, n = round(x / ZZ) * ZZ
;
vec2 c = q;
c.x -= n;
x = n;
x = clamp(x * 0.5 + 0.125, 0., 1.);
float f = texture(texFFTSmoothed, x).x;
x += 1./16.;
f *= f * x * x * 3e4;
f = log2(f) / 10. + 0.6;
c.y -= 0.5;
c.y = abs(c.y) - f * 0.3;
col = mix(
col
, mix(col, (1. + sin(-t + abs(p.y) + 2. * p.x + vec3(0, 1, 2))) * (1.25 + sign(p.y)), 1.)
, smoothstep(aa, -aa, segmenty(c) - ZZ * 0.45)
);
col = mix(
col
, col/3.
, smoothstep(aa, -aa, abs(segmenty(c) - ZZ * 0.45)-aa)
);
}
// Horizontal line at y=0
if (abs(p.y) < 2. * aa) {
col = vec3(2);
}
// Bottom half tint
if (p.y < 0.) {
col += -0.01 * vec3(1, 3, 21) * p.y;
}
// Final color processing
col = sqrt(tanh(col));
return col;
}
void mainImage(out vec4 O, vec2 C);
void main(void) {
vec4 O=vec4(1);
mainImage(O, gl_FragCoord.xy);
O.w = 1.;
out_color = O;
}
// -----------------------------------------------------------------------------
void mainImage(out vec4 O, vec2 C) {
float i,d,z;
vec4 o,p,X,Y,S,N;
for(vec2 r=iResolution.xy;++i<77;z+=.7*d) {
p = vec4(z*normalize(vec3(C-.5*r,r.y)),0.25);
p.z +=iTime;
mat2 R = mat2(cos(.3*iTime+.3*p.z+vec4(0,11,33,0)));
p.xy *= R;
Y = p;
p.xy -= .5;
N = round(p);
p -= N;
p.xw *= R;
p.wy *= R;
p.zw *= R;
X = p;
X *= X;
X *= X;
d = pow(dot(X,X),.125)-.3;
X = sin(66.*Y);
d += X.x*X.y*X.z*X.w*5e-2;
d = abs(d)+1e-3;
p = 1.+sin(3.*Y.x+.5*Y.z+vec4(0,1,2,0));
o += p.w/d*p;
}
O = (o/1e4);
O.xyz = bars(O.xyz*O.xyz);
}
// -----------------------------------------------------------------------------
#version 430 core
// -----------------------------------------------------------------------------
uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)
uniform float fFrameTime; // duration of the last frame, in seconds
uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
uniform sampler1D texFFTIntegrated; // this is continually increasing
uniform sampler2D texPreviousFrame; // screenshot of the previous frame
uniform sampler2D texChecker;
uniform sampler2D texNoise;
uniform sampler2D texTex1;
uniform sampler2D texTex2;
uniform sampler2D texTex3;
uniform sampler2D texTex4;
layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything
#define iTime fGlobalTime
#define iResolution vec3(v2Resolution,1)
// -----------------------------------------------------------------------------
float hash(float co) {
return fract(sin(co*12.9898) * 13758.5453);
}
float hash(vec2 co) {
return fract(sin(dot(co.xy ,vec2(12.9898,58.233))) * 13758.5453);
}
float hash(vec3 r) {
return fract(sin(dot(r.xy,vec2(1.38984*sin(r.z),1.13233*cos(r.z))))*653758.5453);
}
float segmenty(vec2 p) {
float
d0 = length(p)
, d1 = abs(p.x)
;
return p.y > 0. ? d0 : d1;
}
vec3 bars(vec3 col) {
col = mix(col,vec3(0), isnan(col));
const float ZZ = 0.0125;
vec2
r = v2Resolution
, C = gl_FragCoord.xy
, p = (C + C - r) / r.y
, q
;
float
t = fGlobalTime
, aa = sqrt(2.) / r.y
;
p.y += 0.5;
q = (1. + p) * 0.5;
// Draw frequency bars
if (abs(p.x) < 1.5 - ZZ * 3.) {
float
x = q.x
, n = round(x / ZZ) * ZZ
;
vec2 c = q;
c.x -= n;
x = n;
x = clamp(x * 0.5 + 0.125, 0., 1.);
float f = texture(texFFTSmoothed, x).x;
x += 1./16.;
f *= f * x * x * 3e4;
f = log2(f) / 10. + 0.6;
c.y -= 0.5;
c.y = abs(c.y) - f * 0.3;
col = mix(
col
, vec3(0)
, smoothstep(aa, -aa, segmenty(c) - ZZ * 0.4-aa*2.)
);
col = mix(
col
, (1. + sin(-t + abs(p.y) + 2. * p.x + vec3(0, 1, 2))) * (1.25 + sign(p.y))
, smoothstep(aa, -aa, segmenty(c) - ZZ * 0.4)
);
}
// Horizontal line at y=0
if (abs(p.y) < 2. * aa) {
col = vec3(2);
}
// Bottom half tint
if (p.y < 0.) {
col += -0.01 * vec3(1, 3, 21) * p.y;
}
// Final color processing
col = sqrt(tanh(col));
return col;
}
void mainImage(out vec4 O, vec2 C);
void main(void) {
vec4 O=vec4(1);
mainImage(O, gl_FragCoord.xy);
O.w = 1.;
out_color = O;
}
// -----------------------------------------------------------------------------
vec3 path(float z) {
return vec3(3.*sin(vec2(1,sqrt(.5))*z/9.),z);
}
vec3 dpath(float z) {
float e = 2e-1;
return (path(z+e)-path(z-e))/(2.*e);
}
vec3 ddpath(float z) {
float e =3e-1;
return (dpath(z+e)-dpath(z-e))/(2.*e);
}
// License: CC0, author: Mårten Rånge, found: https://github.com/mrange/glsl-snippets
vec4 alphaBlend(vec4 back, vec4 front) {
// Based on: https://en.wikipedia.org/wiki/Alpha_compositing
float w = front.w + back.w*(1.0-front.w);
vec3 xyz = (front.xyz*front.w + back.xyz*back.w*(1.0-front.w))/w;
return w > 0.0 ? vec4(xyz, w) : vec4(0.0);
}
const float PI=acos(-1.),TAU=2.*PI;
// License: MIT, author: Inigo Quilez, found: https://www.iquilezles.org/www/articles/smin/smin.htm
float pmin(float a, float b, float k) {
float h = clamp(0.5+0.5*(b-a)/k, 0.0, 1.0);
return mix(b, a, h) - k*h*(1.0-h);
}
// License: CC0, author: Mårten Rånge, found: https://github.com/mrange/glsl-snippets
float pmax(float a, float b, float k) {
return -pmin(-a, -b, k);
}
// License: CC0, author: Mårten Rånge, found: https://github.com/mrange/glsl-snippets
float pabs(float a, float k) {
return pmax(a, -a, k);
}
// License: CC0, author: Mårten Rånge, found: https://github.com/mrange/glsl-snippets
vec2 toPolar(vec2 p) {
return vec2(length(p), atan(p.y, p.x));
}
vec2 toRect(vec2 p) {
return vec2(p.x*cos(p.y), p.x*sin(p.y));
}
float modMirror1(inout float p, float size) {
float halfsize = size*0.5;
float c = floor((p + halfsize)/size);
p = mod(p + halfsize,size) - halfsize;
p *= mod(c, 2.0)*2.0 - 1.0;
return c;
}
// License: CC0, author: Mårten Rånge, found: https://github.com/mrange/glsl-snippets
float smoothKaleidoscope(inout vec2 p, float sm, float rep) {
vec2 hp = p;
vec2 hpp = toPolar(hp);
float rn = modMirror1(hpp.y, TAU/rep);
float sa = PI/rep - pabs(PI/rep - abs(hpp.y), sm);
hpp.y = sign(hpp.y)*(sa);
hp = toRect(hpp);
p = hp;
return rn;
}
float length4(vec2 p) {
return sqrt(length(p*p));
}
void mainImage(out vec4 o, vec2 C) {
float
i
, d
, z=iTime*.5
, aa = 1e-3
, H
, D
, BPM=114.
, T=iTime*114./60.
, F=fract(T)
, B=floor(T)+F
, ZZ
, W
;
vec2
r=iResolution.xy
, p=(2.*C-r)/r.y
, q
;
vec3
O = path(z)
, S = normalize(path(z+7.)-O)
, Z = normalize(dpath(z))
, X = normalize(cross(Z,vec3(0,1,0)-1.*ddpath(z)))
, Y = cross(X,Z)
, I = normalize(p.x*X+p.y*Y+(1.5+0.5*length(p))*Z)
, P
, N
;
vec4 R;
z = 0.+fract(-z)/I.z;
for(
o-=o
; ++i < 7.
; z += 1./I.z
) {
P = O+z*I;
P.xy -= path(P.z).xy;
H = hash(round(P.z));
ZZ = (0.5+H)*1.5;
W = .05+.1*fract(7669.*H);
q = P.xy;
// N=ddpath(P.z);
// q *= mat2(cos(atan(N.y, N.x)/8.+vec4(0,11,33,0)));
D = 0.25-length4(q);
aa=length(fwidth(P.xy));
P.xy *= mat2(cos(.5*iTime*(-1.+2.*fract(8667.*H))+vec4(0,11,33,0)));
smoothKaleidoscope(P.xy, .1, 32.);
P.xy *= mat2(cos(.125*iTime*fract(7667.*H)+vec4(0,11,33,0)));
P.xy += .25*iTime*fract(3667.*H);
N = round(P/ZZ)*ZZ;
H = hash(N);
// P.xy -= .5;
q = P.xy;
q -= N.xy;
if (H >= 0.5) {
q = vec2(q.y,-q.x);
}
d = 1e3;
d = min(d, abs(length4(q-.5*ZZ)-.5*ZZ)-W);
d = min(d, abs(length4(q+.5*ZZ)-.5*ZZ)-W);
d = min(d, -.025-D);
D = max(D, d-.025);
R.xyz = vec3(2.*smoothstep(aa,-aa,-d));
R.w = (smoothstep(aa,-aa,D)*smoothstep(7., 3., z));
o = alphaBlend(R,o);
}
R = vec4(vec3(4e-3*sqrt(1.-F)/(1.001-dot(I,S))),1);
o = alphaBlend(R,o);
o.xyz *= o.w;
o.xyz = bars(o.xyz);
}
// -----------------------------------------------------------------------------
#version 430 core
// -----------------------------------------------------------------------------
uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)
uniform float fFrameTime; // duration of the last frame, in seconds
uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
uniform sampler1D texFFTIntegrated; // this is continually increasing
uniform sampler2D texPreviousFrame; // screenshot of the previous frame
uniform sampler2D texChecker;
uniform sampler2D texNoise;
uniform sampler2D texTex1;
uniform sampler2D texTex2;
uniform sampler2D texTex3;
uniform sampler2D texTex4;
layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything
#define iTime fGlobalTime
#define iResolution vec3(v2Resolution,1)
// -----------------------------------------------------------------------------
float hash(float co) {
return fract(sin(co*12.9898) * 13758.5453);
}
float hash(vec2 co) {
return fract(sin(dot(co.xy ,vec2(12.9898,58.233))) * 13758.5453);
}
float hash(vec3 r) {
return fract(sin(dot(r.xy,vec2(1.38984*sin(r.z),1.13233*cos(r.z))))*653758.5453);
}
float segmenty(vec2 p) {
float
d0 = length(p)
, d1 = abs(p.x)
;
return p.y > 0. ? d0 : d1;
}
vec3 bars(vec3 col) {
col = mix(col,vec3(0), isnan(col));
const float ZZ = 0.0125;
vec2
r = v2Resolution
, C = gl_FragCoord.xy
, p = (C + C - r) / r.y
, q
;
float
t = fGlobalTime
, aa = sqrt(2.) / r.y
;
p.y += 0.5;
q = (1. + p) * 0.5;
// Draw frequency bars
if (abs(p.x) < 1.5 - ZZ * 3.) {
float
x = q.x
, n = round(x / ZZ) * ZZ
;
vec2 c = q;
c.x -= n;
x = n;
x = clamp(x * 0.5 + 0.125, 0., 1.);
float f = texture(texFFTSmoothed, x).x;
x += 1./16.;
f *= f * x * x * 3e4;
f = log2(f) / 10. + 0.6;
c.y -= 0.5;
c.y = abs(c.y) - f * 0.3;
col = mix(
col
, vec3(0)
, smoothstep(aa, -aa, segmenty(c) - ZZ * 0.4-aa*2.)
);
col = mix(
col
, (1. + sin(-t + abs(p.y) + 2. * p.x + vec3(0, 1, 2))) * (1.25 + sign(p.y))
, smoothstep(aa, -aa, segmenty(c) - ZZ * 0.4)
);
}
// Horizontal line at y=0
if (abs(p.y) < 2. * aa) {
col = vec3(2);
}
// Bottom half tint
if (p.y < 0.) {
col += -0.01 * vec3(1, 3, 21) * p.y;
}
// Final color processing
col = sqrt(tanh(col));
return col;
}
void mainImage(out vec4 O, vec2 C);
void main(void) {
vec4 O=vec4(1);
mainImage(O, gl_FragCoord.xy);
O.w = 1.;
out_color = O;
}
// -----------------------------------------------------------------------------
// Simple planes
const float NoPlanes=7.;
vec3 path(float z) {
return vec3(3.*sin(vec2(1,sqrt(.5))*z/9.),z);
}
vec3 dpath(float z) {
float e = 2e-1;
return (path(z+e)-path(z-e))/(2.*e);
}
vec3 ddpath(float z) {
float e =3e-1;
return (dpath(z+e)-dpath(z-e))/(2.*e);
}
vec4 alphaBlend(vec4 back, vec4 front) {
// Based on: https://en.wikipedia.org/wiki/Alpha_compositing
float w = front.w + back.w*(1.0-front.w);
vec3 xyz = (front.xyz*front.w + back.xyz*back.w*(1.0-front.w))/w;
return w > 0.0 ? vec4(xyz, w) : vec4(0.0);
}
float length4(vec2 p) {
return sqrt(length(p*p));
}
vec4 plane0(vec3 P,float z) {
float
d=length4(P.xy)-.25
, aa=length(fwidth(P.xy))
;
vec4 R=vec4(
vec3(mix(0.001/pow(dot(P.xy,P.xy),2.),2.,smoothstep(aa,-aa,d-.01)))
, smoothstep(aa,-aa,-d)*smoothstep(NoPlanes, NoPlanes-4., z)
);
return R;
}
void mainImage(out vec4 o, vec2 C) {
float
i
, z=iTime*.5
, BPM=114.
, T=iTime*114./60.
, F=fract(T)
, B=floor(T)+F
;
vec2
r=iResolution.xy
, p=(2.*C-r)/r.y
;
vec3
O = path(z)
, S = normalize(path(z+NoPlanes)-O)
, Z = normalize(dpath(z))
, X = normalize(cross(Z,vec3(0,1,0)-1.*ddpath(z)))
, Y = cross(X,Z)
, I = normalize(p.x*X+p.y*Y+2.*Z)
, P
;
vec4 R;
z = fract(-z)/I.z;
o = vec4(0);
for(
float i = 0.
; i < NoPlanes
; ++i
) {
P = O+z*I;
P.xy -= path(P.z).xy;
R = plane0(P,z);
o = alphaBlend(R,o);
z += 1./I.z;
}
R = vec4(vec3(4e-3*sqrt(1.-F)/(1.001-dot(I,S))),1);
o = alphaBlend(R,o);
o.xyz *= o.w;
o.xyz = bars(o.xyz);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment