Skip to content

Instantly share code, notes, and snippets.

@mrange
Last active April 9, 2019 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrange/d7f6529ad9b7a9b3aacaae7813b76792 to your computer and use it in GitHub Desktop.
Save mrange/d7f6529ad9b7a9b3aacaae7813b76792 to your computer and use it in GitHub Desktop.
2d effects
#version 150
in VertexData
{
vec4 v_position;
vec3 v_normal;
vec2 v_texcoord;
} inData;
out vec4 fragColor;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
uniform vec2 iResolution;
uniform float iTime;
uniform float iTimeDelta;
uniform int iFrame;
uniform vec4 iMouse;
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;
uniform sampler2D iChannel2;
uniform sampler2D iChannel3;
uniform vec4 iDate;
uniform float iSampleRate;
void mainImage(out vec4, in vec2);
void main(void) { mainImage(fragColor,inData.v_texcoord * iResolution.xy); }
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#define TOLERANCE 0.001
#define MAX_RAY_MARCHES 150
#define PI 3.141592654
#define TAU (2.0*PI)
const float fadeInTime = 2.0;
const float fadeOutTime = 28.0;
const float apexTime = 30.0;
vec3 saturate(vec3 a) { return clamp(a, 0.0, 1.0); }
vec2 saturate(vec2 a) { return clamp(a, 0.0, 1.0); }
float saturate(float a) { return clamp(a, 0.0, 1.0); }
float noise(in vec3 x)
{
vec3 p = floor(x);
vec3 f = fract(x);
f = f*f*(3.0-2.0*f);
vec2 uv = (p.xy+vec2(37.0,17.0)*p.z) + f.xy;
vec2 rg = textureLod( iChannel0, (uv+ 0.5)/256.0, 0.0 ).yx;
return mix( rg.x, rg.y, f.z );
}
void pR(inout vec2 p, float a)
{
p = cos(a)*p + sin(a)*vec2(p.y, -p.x);
}
vec3 heightShade()
{
float time = iTime/apexTime;
return mix(vec3(1.0, 0.5, 0.5), vec3(1.0), min(1.0, time));
}
vec3 getSkyColor(vec3 rayDir)
{
vec3 lightPos1 = 100.0*vec3(0.0, -0.15, 1.0);
vec3 lightPos2 = 100.0*vec3(0.4, -0.25, 1.0);
float time = iTime/apexTime;
float a = 0.5*time;
float sky = atan(rayDir.y/rayDir.z)*2.0/PI;
pR(lightPos1.yz, a);
pR(lightPos2.yz, a);
vec3 lightDir1 = normalize(lightPos1);
vec3 lightDir2 = normalize(lightPos2);
vec3 heightmod = heightShade();
vec3 lightCol1 = heightmod*vec3(8.0,7.0,6.0)/8.0;
vec3 lightCol2 = heightmod*vec3(8.0,6.0,7.0)/8.0;
float lf1 = max(dot(rayDir, lightDir1), 0.0);
float lf2 = max(dot(rayDir, lightDir2), 0.0);
vec3 final = vec3(0.0);
final += mix(0.5*heightmod, heightmod*vec3(0.0, 0.4, 1.5), pow(min(1.0, abs(1.5*sky)), 1.0));
final += lightCol1*pow(lf1, mix(4.0, 75.0, time));
final += lightCol2*pow(lf2, 75.0)/4.0;
final += 4.0*lightCol1 * pow(lf1, 100.0);
final += 4.0*lightCol2 * pow(lf2, 3200.0);
return final;
}
float noise2(in vec3 p)
{
p /=3.0;
vec3 q = p;
float f;
f = 0.50000*noise(q);
q = q*2.02;
f += 0.25000*noise(q);
q = q*2.03;
f += 0.12500*noise(q);
return clamp(1.0 - p.y - 2.1 + 2.0*f, 0.0, 1.0);
}
vec4 cloudMarch(in vec3 ro, in vec3 rd)
{
float t = 1.0;
vec4 sum = vec4(0.0);
vec3 heightmod = sqrt(heightShade());
for (int i = 0; i < MAX_RAY_MARCHES; i++)
{
vec3 p = ro + rd*t;
float den = noise2(p);
vec4 col = vec4(heightmod*mix(vec3(1.0,0.9,0.8), vec3(0.4,0.15,0.1), den) + 0.05*sin(p), den);
col.a *= 0.6;
col.rgb *= col.a;
sum = sum + col*(1.0 - sum.a);
t += 0.3;
}
return sum;
}
vec3 render(in vec3 ro, in vec3 rd)
{
vec3 skyCol = saturate(getSkyColor(rd));
vec4 col = cloudMarch(ro, rd);
return skyCol*(pow(1.0 - col.a, 0.2)) + col.xyz;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
vec2 q=fragCoord.xy/iResolution.xy;
vec2 p = -1.0 + 2.0*q;
p.x *= iResolution.x/iResolution.y;
float ctime = iTime*11.0;
vec3 ro = vec3(0.0, 0.0, ctime);
vec3 ww = normalize(ro + vec3(0.0, 0.0, 1.0));
vec3 uu = normalize(cross( vec3(0.0,1.0,0.0), ww ));
vec3 vv = normalize(cross(ww,uu));
vec3 rd = normalize(p.x*uu + p.y*vv + 2.5*ww);
vec3 col = render(ro, rd);
col = clamp(col, 0., 1.);
col = pow(col, vec3(0.416667))*1.055 - 0.055; //sRGB
float fadeIn = smoothstep(0.0, fadeInTime, iTime);
float fadeOut = smoothstep(fadeOutTime, fadeOutTime + 2.0, iTime);
fragColor = vec4(col*fadeIn + fadeOut, 1.0);
}
#version 150
in VertexData
{
vec4 v_position;
vec3 v_normal;
vec2 v_texcoord;
} inData;
out vec4 fragColor;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
uniform vec2 iResolution;
uniform float iTime;
uniform float iTimeDelta;
uniform int iFrame;
uniform vec4 iMouse;
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;
uniform sampler2D iChannel2;
uniform sampler2D iChannel3;
uniform vec4 iDate;
uniform float iSampleRate;
void mainImage(out vec4, in vec2);
void main(void) { mainImage(fragColor,inData.v_texcoord * iResolution.xy); }
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#define MANDELBROT_ZOOM_START 5.0
void pR(inout vec2 p, in float a)
{
p = cos(a)*p + sin(a)*vec2(p.y, -p.x);
}
vec2 pMod2(inout vec2 p, in vec2 size)
{
vec2 c = floor((p + size*0.5)/size);
p = mod(p + size*0.5,size) - size*0.5;
return c;
}
vec3 mandelbrot(in float time, in vec2 p)
{
vec3 col = vec3(0.0);
if(-p.y + 1.0> time)
{
return col;
}
float ztime = (time - MANDELBROT_ZOOM_START)*step(MANDELBROT_ZOOM_START, time);
float zoo = 0.64 + 0.36*cos(.07*ztime);
float coa = cos(0.15*(1.0-zoo)*ztime);
float sia = sin(0.15*(1.0-zoo)*ztime);
zoo = pow(zoo,8.0);
vec2 xy = vec2( p.x*coa-p.y*sia, p.x*sia+p.y*coa);
vec2 c = vec2(-.745,.186) + xy*zoo;
const float B = 10.0;
float l = 0.0;
vec2 z = vec2(0.0);
vec2 zn = vec2(2.1, 0.0);
float zo = 2.99;
vec2 zc = vec2(1.0);
pR(zc, ztime);
float dcc = 1e20;
float dll = 1e20;
for(int i = 0; i < 256; ++i)
{
float re2 = z.x*z.x;
float im2 = z.y*z.y;
float reim= z.x*z.y;
if(re2 + im2 > (B*B)) break;
z = vec2(re2 - im2, 2.0*reim) + c;
vec2 zm = z;
pMod2(zm, vec2(5));
float l2c = dot(zm - zc, zm - zc);
float l2l = dot(zm, zn) + zo;
dcc = min(dcc, l2c);
dll = min(dll, abs(l2l));
l += 1.0;
}
float sl = l - log2(log2(dot(z,z))) + 4.0;
vec3 dc = vec3(pow(abs(1.0 - dcc), 20.0));
vec3 dl = 0.5*vec3(pow(abs(1.0 - dll), 10.0));
vec3 gc = 0.5 + 0.5*cos(3.0 + sl*0.15 + vec3(0.1,0.5,0.9));
return gc + dl*smoothstep(40.4, 40.6, time) + dc*smoothstep(33.8, 34.0, time);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
vec2 p = (-iResolution.xy + 2.0*fragCoord.xy)/iResolution.y;
vec3 col = 0.5*(mandelbrot(iTime, p) + mandelbrot(iTime - 1.0/120.0, p));
fragColor = vec4(col, 1.0);
}
#version 150
in VertexData
{
vec4 v_position;
vec3 v_normal;
vec2 v_texcoord;
} inData;
out vec4 fragColor;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
uniform vec2 iResolution;
uniform float iTime;
uniform float iTimeDelta;
uniform int iFrame;
uniform vec4 iMouse;
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;
uniform sampler2D iChannel2;
uniform sampler2D iChannel3;
uniform vec4 iDate;
uniform float iSampleRate;
void mainImage(out vec4, in vec2);
void main(void) { mainImage(fragColor,inData.v_texcoord * iResolution.xy); }
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Based of https://www.shadertoy.com/view/4sX3Rn
// Raymarching explained: http://9bitscience.blogspot.com/2013/07/raymarching-distance-fields_14.html
// Distance Estimators: www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
#define TOLERANCE 0.001
#define NORM_OFF 0.0001
#define MAX_RAY_LENGTH 50.0
#define MAX_RAY_MARCHES 70
#define MAX_SRAY_MARCHES 40
#define PI 3.141592654
#define TAU (2.0*PI)
#define BOXSIZE 5.0
#define FADE_BOX_ROTATE_BEGIN 10.0
#define FADE_BOX_ROTATE_END 20.0
vec3 saturate(in vec3 a) { return clamp(a, 0.0, 1.0); }
vec2 saturate(in vec2 a) { return clamp(a, 0.0, 1.0); }
float saturate(in float a) { return clamp(a, 0.0, 1.0); }
float maxComp(in vec3 p)
{
return max(p.x,max(p.y,p.z));
}
float maxComp(in vec2 p)
{
return max(p.x, p.y);
}
void rot(inout vec2 v, in float a)
{
float c = cos(a);
float s = sin(a);
v.xy = vec2(v.x*c + v.y*s, -v.x*s + v.y*c);
}
float fOpUnionRound(float a, float b, float r)
{
vec2 u = max(vec2(r - a,r - b), vec2(0));
return max(r, min (a, b)) - length(u);
}
float softMin(in float a, in float b, in float k)
{
float res = exp( -k*a ) + exp( -k*b );
return -log( res )/k;
}
float sdSphere(in vec3 p, in float r)
{
return length(p) - r;
}
float sdBox(in vec3 p, in vec3 b)
{
vec3 di = abs(p) - b;
float mc = maxComp(di);
return min(mc,length(max(di,0.0)));
}
float sdSoftBox(in vec3 p, in float r)
{
p *= p;
p *= p;
p *= p;
return pow(p.x + p.y + p.z, 1.0/8.0) - r;
}
float sdCross(in vec3 p)
{
float da = maxComp(abs(p.xy));
float db = maxComp(abs(p.yz));
float dc = maxComp(abs(p.zx));
return min(da,min(db,dc))-1.0;
}
float sdPlane(in vec3 p, in vec3 n, in float m)
{
return dot(p, n) + m;
}
float sdMengerCube(in vec3 offs, in mat4 t, in vec3 p)
{
const float s = 3.;
float d = 1e5;
float amp = 1./s; // Analogous to layer amplitude.
for(int i=0; i<5; i++){
p = abs(p);
p.xy += step(p.x, p.y)*(p.yx - p.xy);
p.xz += step(p.x, p.z)*(p.zx - p.xz);
p.yz += step(p.y, p.z)*(p.zy - p.yz);
p = p*s + offs*(1. - s);
p = (t*vec4(p, 1.0)).xyz;
p.z -= step(p.z, offs.z*(1. - s)*.5)*offs.z*(1. - s);
p = abs(p);
d = min(d, max(max(p.x, p.y), p.z)*amp);
amp /= s;
}
return d - 0.038;
}
mat4 mscale(vec3 s)
{
return mat4(
s.x, 0.0, 0.0, 0.0,
0.0, s.y, 0.0, 0.0,
0.0, 0.0, s.z, 0.0,
0.0, 0.0, 0.0, 1.0);
}
mat4 mrotX(in float a)
{
float c = cos(a);
float s = sin(a);
return mat4(
c,-s, 0, 0,
s, c, 0, 0,
0, 0, 1, 0,
0, 0, 0, 0);
}
mat4 mrotY(in float a)
{
float c = cos(a);
float s = sin(a);
return mat4(
c, 0,-s, 0,
0, 1, 0, 0,
s, 0, c, 0,
0, 0, 0, 1);
}
mat4 mrotZ(in float a)
{
float c = cos(a);
float s = sin(a);
return mat4(
1, 0, 0, 0,
0, c,-s, 0,
0, s, c, 0,
0, 0, 0, 1);
}
mat4 mtrans(in vec3 t)
{
return mat4(
1, 0, 0, t.x,
0, 1, 0, t.y,
0, 0, 1, t.z,
0, 0, 0, 1);
}
float map(in vec3 p, out int m)
{
rot(p.xz, -iTime*TAU/120);
float a2 = iTime/sqrt(2.0);
float a3 = iTime/sqrt(3.0);
float a5 = iTime/sqrt(5.0);
float br = smoothstep(FADE_BOX_ROTATE_BEGIN, FADE_BOX_ROTATE_END, iTime);
vec3 bp = p - vec3(0.0, -BOXSIZE*br - 0.0, 0.0);
rot(bp.xy, mix(a2, 0.0, br));
rot(bp.xz, mix(-a3, 0.0, br));
rot(bp.yz, mix(a5, 0.0, br));
float bd = sdSoftBox(bp, BOXSIZE);
vec3 mp = p - vec3(0.0, mix(50.0, 1.0*sin(a2) + 1, br), 0.0);
rot(mp.xy, a2);
rot(mp.xz, -a3);
rot(mp.yz, a5);
mat4 t = mrotX(0.2*sin(10*a5))*mrotY(0.3*(0.5 + sin(0.0*a3)))*mrotZ(0.3*sin(0*a2));
// mat4 t = mtrans(vec3(0.0));
vec3 offs = vec3(9.0, 9.0 - 1.0*(1.0 + sin(a2)), 9.0);
rot(offs.yz, 0.00*sin(iTime));
float md = sdMengerCube(offs, t, 9.0*mp)/9.0;
float d = fOpUnionRound(bd, md, 0.3);
if (abs(d - bd) < 0.05)
{
m = 1;
}
else
{
m = 0;
}
return d;
}
float rayMarch(in vec3 ro, in vec3 rd, out int mat, out int iter)
{
float t = 0.0;
float distance;
int i;
for (i = 0; i < MAX_RAY_MARCHES; i++)
{
distance = map(ro + rd*t, mat);
if (distance < TOLERANCE || t > MAX_RAY_LENGTH) break;
t += distance;
}
iter = i;
if (abs(distance) > 100.0*TOLERANCE) return MAX_RAY_LENGTH;
return t;
}
vec3 normal(in vec3 pos)
{
vec3 eps = vec3(NORM_OFF,0.0,0.0);
vec3 nor;
int mat;
nor.x = map(pos+eps.xyy, mat) - map(pos-eps.xyy, mat);
nor.y = map(pos+eps.yxy, mat) - map(pos-eps.yxy, mat);
nor.z = map(pos+eps.yyx, mat) - map(pos-eps.yyx, mat);
return normalize(nor);
}
float softShadow(in vec3 pos, in vec3 ld, in float ll, in float mint, in float k)
{
const float minShadow = 0.25;
float res = 1.0;
float t = mint;
int mat;
for (int i=0; i<MAX_SRAY_MARCHES; i++)
{
float distance = map(pos + ld*t, mat);
res = min(res, k*distance/t);
if (ll <= t) break;
if(res <= minShadow) break;
t += max(mint*0.2, distance);
}
return clamp(res,minShadow,1.0);
}
const vec3 lightPos1 = 100.0*vec3(-0.3, 0.15, 1.0);
const vec3 lightPos2 = 100.0*vec3(-0.33, -0.2, -1.0);
vec3 skyColor(vec3 rayDir)
{
rot(rayDir.xz, iTime*TAU/120);
vec3 lightDir1 = normalize(lightPos1);
vec3 lightDir2 = normalize(lightPos2);
vec3 lightCol1 = vec3(8.0/8.0,7.0/8.0,6.0/8.0);
vec3 lightCol2 = vec3(8.0/8.0,6.0/8.0,7.0/8.0);
float ld1 = max(dot(lightDir1, rayDir), 0.0);
float ld2 = max(dot(lightDir2, rayDir), 0.0);
vec3 final = vec3(0.125);
if ((rayDir.y > abs(rayDir.x)*1.0) && (rayDir.y > abs(rayDir.z*0.25))) final = vec3(2.0)*rayDir.y;
float roundBox = length(max(abs(rayDir.xz/max(0.0,rayDir.y))-vec2(0.9, 4.0),0.0))-0.1;
final += vec3(0.8)* pow(saturate(1.0 - roundBox*0.5), 6.0);
final += 1.0*pow(lightCol1, vec3(2.0, 1.5, 1.5)) * pow(ld1, 8.0);
final += 1.0*lightCol1 * pow(ld1, 200.0);
final += 1.0*pow(lightCol2, vec3(2.0, 1.5, 1.5)) * pow(ld2, 8.0);
final += 1.0*lightCol2 * pow(ld2, 200.0);
return final;
}
vec3 render(in vec3 ro, in vec3 rd)
{
const vec3 lightPos = 40.0*vec3(1.5, 3.0, 1.0);
// background color
vec3 color = vec3(0.5, 0.8, 1.0);
int mat = 0;
int iter = 0;
float t = rayMarch(ro,rd, mat, iter);
vec3 pos = ro + t*rd;
vec3 nor = vec3(0.0, 1.0, 0.0);
float ndif = 1.0;
float nspe = 75.0;
float nref = 0.8;
if (t < MAX_RAY_LENGTH)
{
// Ray intersected object
nor = normal(pos);
float d2 = abs(dot(-rd, nor));
switch(mat)
{
case 0:
color = vec3(0.75);
ndif = 1.0;
nspe = 10.0;
nref = 1.0;
break;
case 1:
color = vec3(0.9) + abs(nor.zxy)*0.1;
ndif = 1.0;
nref = 0.7;
break;
default:
color = nor*nor;
break;
}
}
else
{
// Ray intersected sky
return skyColor(rd);
}
vec3 ref = reflect(rd, nor);
vec3 rcol = skyColor(ref);
vec3 lv = lightPos - pos;
float ll2 = dot(lv, lv);
float ll = sqrt(ll2);
vec3 ld = lv / ll;
float sha = softShadow(pos, ld, ll, 0.01, 64.0);
float dif = max(dot(nor,ld),0.0);
float occ = (MAX_RAY_MARCHES + MAX_RAY_MARCHES - iter) / float(2.0*MAX_RAY_MARCHES);
float spe = pow(max(dot(reflect(-ld, nor), -rd), 0.), nspe);
float bac = max(0.4 + 0.6*dot(nor,vec3(-ld.x,ld.y,-ld.z)),0.0);
float lin = mix(0.2, 1.0, pow(dif,ndif)*occ*sha + 0.3*bac*(0.5+0.5*occ));
vec3 col = mix(rcol, lin*color + spe*sha, nref);
return col;
}
vec3 postProcess(in vec3 col, in vec2 q)
{
col=pow(clamp(col,0.0,1.0),vec3(0.45));
col=col*0.6+0.4*col*col*(3.0-2.0*col); // contrast
col=mix(col, vec3(dot(col, vec3(0.33))), -0.4); // satuation
col*=0.5+0.5*pow(19.0*q.x*q.y*(1.0-q.x)*(1.0-q.y),0.7); // vigneting
return col;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
vec2 q=fragCoord.xy/iResolution.xy;
vec2 p = -1.0 + 2.0*q;
p.x *= iResolution.x/iResolution.y;
float br = smoothstep(FADE_BOX_ROTATE_BEGIN, FADE_BOX_ROTATE_END, iTime);
vec3 ro = mix(10.0, 3.0, br)*vec3(2.0, 1.0, 0.2);
vec3 la = mix(vec3(0.0, 0.0, 0.0), vec3(0.0, 1.5, 0.0), br);
vec3 up = vec3(0.0, 1.0, 0.0);
rot(ro.xz, -0.6);
// rot(ro.yz, (iMouse.y + 1.0)/300);
vec3 ww = normalize(la - ro);
vec3 uu = normalize(cross(up, ww ));
vec3 vv = normalize(cross(ww,uu));
vec3 rd = normalize(p.x*uu + p.y*vv + 2.5*ww);
vec3 col = render(ro, rd);
fragColor = vec4(col,1.0);
}
#version 150
in VertexData
{
vec4 v_position;
vec3 v_normal;
vec2 v_texcoord;
} inData;
out vec4 fragColor;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
uniform vec2 iResolution;
uniform float iTime;
uniform float iTimeDelta;
uniform int iFrame;
uniform vec4 iMouse;
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;
uniform sampler2D iChannel2;
uniform sampler2D iChannel3;
uniform vec4 iDate;
uniform float iSampleRate;
void mainImage(out vec4, in vec2);
void main(void) { mainImage(fragColor,inData.v_texcoord * iResolution.xy); }
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Font rendering macros (ASCII codes)
#define _SPACE 32
#define _EXCLAMATION 33
#define _COMMA 44
#define _DASH 45
#define _PERIOD 46
#define _SLASH 47
#define _COLON 58
#define _AT 64
#define _A 65
#define _B 66
#define _C 67
#define _D 68
#define _E 69
#define _F 70
#define _G 71
#define _H 72
#define _I 73
#define _J 74
#define _K 75
#define _L 76
#define _M 77
#define _N 78
#define _O 79
#define _P 80
#define _Q 81
#define _R 82
#define _S 83
#define _T 84
#define _U 85
#define _V 86
#define _W 87
#define _X 88
#define _Y 89
#define _Z 90
#define _a 97
#define _b 98
#define _c 99
#define _d 100
#define _e 101
#define _f 102
#define _g 103
#define _h 104
#define _i 105
#define _j 106
#define _k 107
#define _l 108
#define _m 109
#define _n 110
#define _o 111
#define _p 112
#define _q 113
#define _r 114
#define _s 115
#define _t 116
#define _u 117
#define _v 118
#define _w 119
#define _x 120
#define _y 121
#define _z 122
#define _0 48
#define _1 49
#define _2 50
#define _3 51
#define _4 52
#define _5 53
#define _6 54
#define _7 55
#define _8 56
#define _9 57
const int numLetters = 253;
const int letterArray[numLetters] = int[numLetters](
_I,_M,_P,_U,_L,_S,_E,_EXCLAMATION,_SPACE,_DASH,_SPACE,
_I,_t,_SPACE,_i,_s,_SPACE,_t,_i,_m,_e,_SPACE,_f,_o,_r,_SPACE,_t,_h,_e,_SPACE,_I,_M,_P,_U,_L,_S,_E,_SPACE,
_DASH,_SPACE,_i,_n,_v,_i,_t,_i,_o,_n,_a,_t,_i,_o,_n,_a,_l,_SPACE,_o,_n,_l,_y,_SPACE,_DASH,_SPACE,_2,_0,_1,_9,_PERIOD,_SPACE,
_2,_0,_1,_8,_SPACE,_w,_a,_s,_SPACE,_a,_SPACE,_g,_r,_e,_a,_t,_SPACE,_s,_u,_c,_c,_e,_s,_s,_SPACE,
_a,_n,_d,_SPACE,_2,_0,_1,_9,_SPACE,_d,_e,_s,_e,_r,_v,_e,_s,_SPACE,_a,_SPACE,_w,_o,_r,_t,_h,_y,_SPACE,
_r,_e,_p,_e,_a,_t,_PERIOD,_SPACE,
_S,_o,_SPACE,_f,_e,_l,_l,_o,_w,_SPACE,_h,_a,_c,_k,_e,_r,_s,_COMMA,_SPACE,_p,_i,_c,_k,_SPACE,_u,_p,_SPACE,
_y,_o,_u,_r,_SPACE,_c,_o,_m,_p,_u,_t,_e,_r,_s,_COMMA,_SPACE,_k,_e,_y,_b,_o,_a,_r,_d,_s,_SPACE,_a,_n,_d,_SPACE,
_j,_o,_y,_s,_t,_i,_c,_k,_s,_SPACE,_a,_n,_d,_SPACE,_t,_r,_a,_v,_e,_l,_SPACE,_t,_o,_SPACE,
_G,_o,_t,_h,_e,_n,_b,_u,_r,_g,_SPACE,_i,_n,_SPACE,_M,_a,_y,_PERIOD,_SPACE,
_B,_e,_SPACE,_t,_h,_e,_r,_e,_SPACE,_o,_r,_SPACE,_b,_e,_SPACE,_s,_q,_u,_a,_r,_e,_EXCLAMATION,_EXCLAMATION,_EXCLAMATION
);
vec4 sampleText(in vec2 uv, int start, int count, bool repeat) {
float fl = floor(uv + 0.5).x;
float cursorPos = fl;
int arrayPos = int(cursorPos);
if (arrayPos < 0) {
return vec4(0.0, 0.0, 0.0, 1.0);
}
if (!repeat && arrayPos >= count) {
return vec4(0.0, 0.0, 0.0, 1.0);
}
arrayPos %= count;
arrayPos += start;
int letter = letterArray[arrayPos];
vec2 lp = vec2(letter % 16, 15 - letter/16);
vec2 uvl = lp + fract(uv+0.5)-0.5;
// Sample the font texture. Make sure to not use mipmaps.
// Add a small amount to the distance field to prevent a strange bug on some gpus. Slightly mysterious. :(
vec2 tp = (uvl+0.5)*(1.0/16.0);
return texture(iChannel2, tp, -100.0) + vec4(0.0, 0.0, 0.0, 0.000000001);
}
vec3 scrollText(vec2 uv, float time, vec3 fontColor, vec3 glowColor, vec3 background) {
vec3 col = background;
const float appearTime = 6.0;
vec2 p = uv + vec2(time, 0.0);
if (abs(p.y) > 0.5)
{
return col;
}
vec4 samp = sampleText(p, 0, numLetters, true);
float dist = samp.w;
col += glowColor*(1.0 - smoothstep(0.55, 0.66, dist));
if (step(0.55, dist) == 0.0) {
col = vec3(0.0);
}
if (step(0.5, dist) == 0.0) {
col = fontColor;
}
return col;
}
float pMod1(inout float p, in float size)
{
float halfsize = size*0.5;
float c = floor((p + halfsize)/size);
p = mod(p + halfsize, size) - halfsize;
return c;
}
vec2 pMod2(inout vec2 p, in vec2 size)
{
vec2 c = floor((p + size*0.5)/size);
p = mod(p + size*0.5,size) - size*0.5;
return c;
}
void pR(inout vec2 p, in float a)
{
p = cos(a)*p + sin(a)*vec2(p.y, -p.x);
}
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;
}
float linex(in vec2 p, in float b)
{
float d = abs(p.y) - b;
return min(d,0.0) + max(d,0.0);
}
float liney(in vec2 p, in float b)
{
float d = abs(p.x) - b;
return min(d,0.0) + max(d,0.0);
}
float box(in vec2 p, in vec2 b)
{
vec2 d = abs(p) - b;
return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}
float circle(in vec2 p, in float r)
{
return length(p) - r;
}
float hyper(in vec2 p, in float r)
{
return length(p) + r;
}
const vec3 color = vec3(1.125, 1.25, 1.5);
const vec3 fontColor = vec3(1.15, 1.1, 1.1);
const vec3 glowColor = vec3(1.5, 1.25, 1.125);
#define DISABLE 0.0
#define BOUNCESTART 0.0
#define BOUNCEDONE 30.0
#define DISTSTART 5.0
#define DISTDONE 20.0
#define LAYERSTART 12.0
#define LAYERDONE 40.0
#define LAYERCOUNT 6
#define ROTSTART 9.0
#define ROTDONE 20.0
#define TRANSSTART 0.0
#define TRANSDONE 30.0
vec3 layer(in vec2 p, in int layer, in float time)
{
layer += 3;
float s = 0.2/float(layer + 1);
const float timeFactor = 0.3;
float tm = time*timeFactor;
pR(p, mix(0.0, tm + 100.0*s*float(layer) - timeFactor*ROTSTART, smoothstep(ROTSTART, ROTDONE, time)));
p += mix(vec2(0.0), -s*200.0*vec2(cos(sqrt(2.0)*tm), sin(tm)) + s*vec2(1.0), smoothstep(TRANSSTART, TRANSDONE, time));
vec2 sp = toSmith(p);
sp += mix(vec2(0.0), -0.5*(2.0+ sin(tm))*mix(p, vec2(1.0), sin(tm*0.1)*sin(tm*0.1)), smoothstep(DISTSTART, DISTDONE, time));
p = fromSmith(sp);
vec2 scp = p;
float row = pMod1(scp.y, 4.0*s);
scp *= 1.0/s;
scp += vec2(-row*4.0, -0.5);
pMod2(p, vec2(4.0*s));
float d = 1E20;
d = min(d, liney(p, s*0.1));
d = min(d, linex(p, s*0.1));
d = min(d, circle(p, s*0.6));
d = max(d, -circle(p, s*0.4));
vec3 col = vec3(0.0);
if (d < 0.0)
{
col = pow(color, vec3(-layer));
}
col = scrollText(scp, time, pow(fontColor, vec3(-layer)), pow(glowColor, vec3(-layer)), col);
return col;
}
vec3 mobiusScrollText(in vec2 p, float time)
{
p *= mix(0.1, 5.0*(2.0 + sin(time*0.1)), smoothstep(BOUNCESTART, BOUNCEDONE, time));
float lp = (LAYERDONE - LAYERSTART) / LAYERCOUNT;
vec3 col = layer(p, 0, time);
for (int i = 1; i < LAYERCOUNT; ++i)
{
float lf = smoothstep(LAYERSTART + lp*(i - 1), LAYERSTART + lp*(i - 1 + 0.5), time);
col += lf*layer(p, i, time);
}
return col;
}
#define AA 2
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
vec3 col = vec3(0.0);
for( int m=0; m<AA; m++ )
for( int n=0; n<AA; n++ )
{
vec2 p = (-iResolution.xy + 2.0*(fragCoord.xy+vec2(float(m),float(n))/float(AA)))/iResolution.y;
col += mobiusScrollText(p, iTime - 3);
}
fragColor = vec4(col/(AA*AA),1.0);
}
#version 150
in VertexData
{
vec4 v_position;
vec3 v_normal;
vec2 v_texcoord;
} inData;
out vec4 fragColor;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
uniform vec2 iResolution;
uniform float iTime;
uniform float iTimeDelta;
uniform int iFrame;
uniform vec4 iMouse;
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;
uniform sampler2D iChannel2;
uniform sampler2D iChannel3;
uniform vec4 iDate;
uniform float iSampleRate;
void mainImage(out vec4, in vec2);
void main(void) { mainImage(fragColor,inData.v_texcoord * iResolution.xy); }
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Based of https://www.shadertoy.com/view/4sX3Rn
// Raymarching explained: http://9bitscience.blogspot.com/2013/07/raymarching-distance-fields_14.html
// Distance Estimators: www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
#define TOLERANCE 0.001
#define NORM_OFF 0.001
#define MAX_RAY_LENGTH 6.0
#define MAX_RAY_MARCHES 70
#define PI 3.141592654
#define TAU (2.0*PI)
#define BOXSIZE 0.2
#define PERIOD 15.0
#define CURRENT_PERIOD int(iTime/PERIOD)
#define TIME_IN_PERIOD mod(iTime,PERIOD)
#define FADE_BOX_ROTATE_BEGIN 10.0
#define FADE_BOX_ROTATE_END 20.0
vec3 saturate(in vec3 a) { return clamp(a, 0.0, 1.0); }
vec2 saturate(in vec2 a) { return clamp(a, 0.0, 1.0); }
float saturate(in float a) { return clamp(a, 0.0, 1.0); }
float rand(vec3 r)
{
return fract(sin(dot(r.xy,vec2(1.38984*sin(r.z),1.13233*cos(r.z))))*653758.5453);
}
vec3 toSpherical(vec3 p)
{
float l = length(p);
return vec3(length(p), acos(p.z/l), atan(p.y, p.x));
}
vec3 toRectangular(vec3 p)
{
float l = length(p);
return vec3(p.x*sin(p.y)*cos(p.z), p.x*sin(p.y)*sin(p.z), p.x*cos(p.y));
}
vec3 mod3(inout vec3 p, vec3 size)
{
vec3 c = floor((p + size*0.5)/size);
p = mod(p + size*0.5, size) - size*0.5;
return c;
}
float maxComp(in vec3 p)
{
return max(p.x,max(p.y,p.z));
}
float maxComp(in vec2 p)
{
return max(p.x, p.y);
}
void rot(inout vec2 v, in float a)
{
float c = cos(a);
float s = sin(a);
v.xy = vec2(v.x*c + v.y*s, -v.x*s + v.y*c);
}
float unionRound(float a, float b, float r)
{
vec2 u = max(vec2(r - a,r - b), vec2(0));
return max(r, min (a, b)) - length(u);
}
float softMin(in float a, in float b, in float k)
{
float res = exp( -k*a ) + exp( -k*b );
return -log( res )/k;
}
float softMin2(in float a, in float b, in float k)
{
if (a*a + b*b > 4.0)
{
return min(a, b);
}
else
{
return softMin(a, b, k);
}
}
float sdSphere(in vec3 p, in float r)
{
return length(p) - r;
}
float sdBox(in vec3 p, in vec3 b)
{
vec3 di = abs(p) - b;
float mc = maxComp(di);
return min(mc,length(max(di,0.0)));
}
float sdSoftBox(in vec3 p, in float r)
{
p *= p;
p *= p;
p *= p;
return pow(p.x + p.y + p.z, 1.0/8.0) - r;
}
float sdCross(in vec3 p)
{
float da = maxComp(abs(p.xy));
float db = maxComp(abs(p.yz));
float dc = maxComp(abs(p.zx));
return min(da,min(db,dc))-1.0;
}
float sdPlane(in vec3 p, in vec3 n, in float m)
{
return dot(p, n) + m;
}
float sdHoleyBox(in vec3 p)
{
vec3 bp = p;
float bd = sdSoftBox(bp, BOXSIZE);
mod3(bp, vec3(0.62*BOXSIZE));
float msd = sdSphere(bp, 0.38*BOXSIZE);
float hbd = max(bd, -msd);
return hbd;
}
mat4 mscale(vec3 s)
{
return mat4(
s.x, 0.0, 0.0, 0.0,
0.0, s.y, 0.0, 0.0,
0.0, 0.0, s.z, 0.0,
0.0, 0.0, 0.0, 1.0);
}
mat4 mrotX(in float a)
{
float c = cos(a);
float s = sin(a);
return mat4(
c,-s, 0, 0,
s, c, 0, 0,
0, 0, 1, 0,
0, 0, 0, 0);
}
mat4 mrotY(in float a)
{
float c = cos(a);
float s = sin(a);
return mat4(
c, 0,-s, 0,
0, 1, 0, 0,
s, 0, c, 0,
0, 0, 0, 1);
}
mat4 mrotZ(in float a)
{
float c = cos(a);
float s = sin(a);
return mat4(
1, 0, 0, 0,
0, c,-s, 0,
0, s, c, 0,
0, 0, 0, 1);
}
mat4 mtrans(in vec3 t)
{
return mat4(
1, 0, 0, t.x,
0, 1, 0, t.y,
0, 0, 1, t.z,
0, 0, 0, 1);
}
void nerdRotate(inout vec3 p)
{
float a2 = 2.0*iTime/sqrt(2.0);
float a3 = 1.0*iTime/sqrt(3.0);
float a5 = 0.5*iTime/sqrt(5.0);
rot(p.yz, a5);
rot(p.xy, -a3);
rot(p.xz, -a2);
}
float theCube(in vec3 p, out int m)
{
vec3 bp = p;
float bd = sdSoftBox(bp, BOXSIZE);
float d = bd;
m = 1;
return d;
}
float nerdBalls(in vec3 p, out int m)
{
float a2 = TAU*iTime/sqrt(2.0);
float a3 = TAU*iTime/sqrt(3.0);
float d = MAX_RAY_LENGTH;
for (int i = 0; i < 7; ++i)
{
vec3 sp = p;
rot(sp.yz, i);
sp += 0.75*BOXSIZE*sin(a2/3 + i*a3/20.0);
float d1 = sdSphere(sp, BOXSIZE*0.25);
d = softMin(d, d1, 20);
}
m = 1;
return d;
}
float nerdCube(in vec3 p, out int m)
{
vec3 bp = p;
float hbd = sdHoleyBox(bp);
float d = hbd;
m = 1;
return d;
}
float impulseCube(in vec3 p, in float celld, in float celll, out int m)
{
vec3 bp = p;
float cs = BOXSIZE*0.8;
float cd = max(length(p.xy) - cs*0.3, sdSphere(bp, 1.2*BOXSIZE));
float hbd = min(max(sdSoftBox(bp, BOXSIZE), -sdCross(bp/cs)*cs), cd);
float bbd = sdBox(bp, vec3(cs));
vec3 rbp = toSpherical(bp);
rbp.y += TIME_IN_PERIOD*0.5;
bp = toRectangular(rbp);
vec3 cell = mod3(bp, vec3(cs*celld));
float id = sdSoftBox(bp, cs*celll);
float mbd = max(bbd, id);
float d = unionRound(hbd, mbd, BOXSIZE*0.15);
if (abs(hbd - d) < 0.01)
{
m = 2;
}
else
{
m = 1;
}
return d;
}
float map(in vec3 p, out int m)
{
const float scale = BOXSIZE;
p *= scale;
float d = MAX_RAY_LENGTH;
int period = CURRENT_PERIOD%5;
// period = 3;
nerdRotate(p);
switch(period)
{
case 0:
d = theCube(p, m);
break;
case 1:
d = nerdCube(p, m);
break;
case 2:
d = nerdBalls(p, m);
break;
case 3:
d = impulseCube(p, 0.1, 0.048, m);
break;
case 4:
d = impulseCube(p, 0.1, 0.01, m);
break;
}
return d/scale;
}
float rayMarch(in vec3 ro, in vec3 rd, out int mat, out int iter)
{
float t = 0.0;
float distance;
int i;
for (i = 0; i < MAX_RAY_MARCHES; i++)
{
distance = map(ro + rd*t, mat);
if (distance < TOLERANCE || t > MAX_RAY_LENGTH) break;
t += distance;
}
iter = i;
if (abs(distance) > 100.0*TOLERANCE) return MAX_RAY_LENGTH;
return t;
}
vec3 normal(in vec3 pos)
{
vec3 eps = vec3(NORM_OFF,0.0,0.0);
vec3 nor;
int mat;
nor.x = map(pos+eps.xyy, mat) - map(pos-eps.xyy, mat);
nor.y = map(pos+eps.yxy, mat) - map(pos-eps.yxy, mat);
nor.z = map(pos+eps.yyx, mat) - map(pos-eps.yyx, mat);
return normalize(nor);
}
const vec3 lightPos1 = 100.0*vec3(-0.3, 0.15, 1.0);
const vec3 lightPos2 = 100.0*vec3(-0.33, -0.2, -1.0);
const vec3 lightCol1 = vec3(8.0/8.0,7.0/8.0,6.0/8.0);
const vec3 lightCol2 = vec3(8.0/8.0,6.0/8.0,7.0/8.0);
vec3 skyColor(vec3 rayDir)
{
vec3 lightDir1 = normalize(lightPos1);
vec3 lightDir2 = normalize(lightPos2);
float ld1 = max(dot(lightDir1, rayDir), 0.0);
float ld2 = max(dot(lightDir2, rayDir), 0.0);
vec3 final = vec3(0.125);
if ((rayDir.y > abs(rayDir.x)*1.0) && (rayDir.y > abs(rayDir.z*0.25))) final = vec3(2.0)*rayDir.y;
float roundBox = length(max(abs(rayDir.xz/max(0.0,rayDir.y))-vec2(0.9, 4.0),0.0))-0.1;
final += vec3(0.8)* pow(saturate(1.0 - roundBox*0.5), 6.0);
final += 1.0*pow(lightCol1, vec3(2.0, 1.5, 1.5)) * pow(ld1, 8.0);
final += 1.0*lightCol1 * pow(ld1, 200.0);
final += 1.0*pow(lightCol2, vec3(2.0, 1.5, 1.5)) * pow(ld2, 8.0);
final += 1.0*lightCol2 * pow(ld2, 200.0);
return final;
}
vec3 render(in vec3 ro, in vec3 rd)
{
// background color
vec3 color = vec3(0.5, 0.8, 1.0);
int mat = 0;
int iter = 0;
float t = rayMarch(ro,rd, mat, iter);
vec3 pos = ro + t*rd;
vec3 nor = vec3(0.0, 1.0, 0.0);
float ndif = 1.0;
float nref = 0.8;
if (t < MAX_RAY_LENGTH)
{
// Ray intersected object
nor = normal(pos);
float d2 = abs(dot(-rd, nor));
switch(mat)
{
case 0:
color = mix(vec3(1.0), nor*nor, 0.5);
ndif = 0.75;
nref = 0.7;
break;
case 1:
color = vec3(0.9) + abs(nor.zxy)*0.1;
ndif = 0.75;
nref = 0.7;
break;
case 2:
color = vec3(0.25) + abs(nor.zxy)*0.05;
ndif = 0.5;
nref = 0.9;
break;
default:
color = nor*nor;
break;
}
}
else
{
// Ray intersected sky
return skyColor(rd);
}
vec3 ref = reflect(rd, nor);
vec3 rcol = skyColor(ref);
vec3 ld0 = vec3(0.0, 1.0, 0.0);
vec3 lv1 = lightPos1 - pos;
float ll1 = length(lv1);
vec3 ld1 = lv1 / ll1;
vec3 lv2 = lightPos2 - pos;
float ll2 = length(lv2);
vec3 ld2 = lv2 / ll2;
int rmat = 0;
int riter = 0;
float st = rayMarch(pos + ref*10.0*TOLERANCE, ref, rmat, riter);
float sha1 = pow(st/MAX_RAY_LENGTH, 0.2);
float sha2 = st < MAX_RAY_LENGTH ? 0.0 : 1.0;
float dif0 = pow(max(dot(nor,ld0),0.0), ndif);
float dif1 = pow(max(dot(nor,ld1),0.0), ndif);
float dif2 = pow(max(dot(nor,ld2),0.0), ndif);
float occ = (MAX_RAY_MARCHES + MAX_RAY_MARCHES - iter) / float(2.0*MAX_RAY_MARCHES);
// float spe = pow(max(dot(reflect(-ld, nor), -rd), 0.), nspe);
// float bac = max(0.4 + 0.6*dot(nor,vec3(-ld.x,ld.y,-ld.z)),0.0);
// float lin = mix(0.2, 1.0, pow(dif,ndif)*occ + 0.3*bac*(0.5+0.5*occ));
float bac = 0.2;
vec3 col0 = mix(vec3(1.0), dif0*vec3(1.0), 0.8);
vec3 col1 = mix(vec3(1.0), dif1*lightCol1, 0.8);
vec3 col2 = mix(vec3(1.0), dif2*lightCol2, 0.8);
// nref = 1.0;
vec3 col = mix(rcol*sha2, color*(col0 + col1 + col2)/2.0, nref);
return col;
}
vec3 postProcess(in vec3 col, in vec2 q)
{
col=pow(clamp(col,0.0,1.0),vec3(0.45));
col=col*0.6+0.4*col*col*(3.0-2.0*col); // contrast
col=mix(col, vec3(dot(col, vec3(0.33))), -0.4); // satuation
col*=0.5+0.5*pow(19.0*q.x*q.y*(1.0-q.x)*(1.0-q.y),0.7); // vigneting
return col;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
vec2 q=fragCoord.xy/iResolution.xy;
vec2 p = -1.0 + 2.0*q;
p.x *= iResolution.x/iResolution.y;
float br = smoothstep(FADE_BOX_ROTATE_BEGIN, FADE_BOX_ROTATE_END, iTime);
br = 0.0;
vec3 ro = mix(1.5, 1.0, br)*vec3(2.0, 1.0, 0.2);
vec3 la = mix(vec3(0.0, 0.0, 0.0), vec3(0.0, 1.5/BOXSIZE, 0.0), br);
vec3 up = vec3(0.0, 1.0, 0.0);
rot(ro.xz, TAU*iTime/30.0);
// rot(ro.xz, (iMouse.x + 1.0)/300);
vec3 ww = normalize(la - ro);
vec3 uu = normalize(cross(up, ww ));
vec3 vv = normalize(cross(ww,uu));
vec3 rd = normalize(p.x*uu + p.y*vv + 2.5*ww);
vec3 col = render(ro, rd);
float fadeIn = 1.0 - smoothstep(0.0, 0.75, TIME_IN_PERIOD);
float fadeOut = smoothstep(PERIOD - 0.25, PERIOD, TIME_IN_PERIOD);
fragColor = vec4(mix(col, vec3(1.0), fadeOut + fadeIn),1.0);
}
#version 150
in VertexData
{
vec4 v_position;
vec3 v_normal;
vec2 v_texcoord;
} inData;
out vec4 fragColor;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
uniform vec2 iResolution;
uniform float iTime;
uniform float iTimeDelta;
uniform int iFrame;
uniform vec4 iMouse;
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;
uniform sampler2D iChannel2;
uniform sampler2D iChannel3;
uniform vec4 iDate;
uniform float iSampleRate;
void mainImage(out vec4, in vec2);
void main(void) { mainImage(fragColor,inData.v_texcoord * iResolution.xy); }
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Font rendering macros (ASCII codes)
#define _SPACE 32
#define _EXCLAMATION 33
#define _COMMA 44
#define _DASH 45
#define _PERIOD 46
#define _SLASH 47
#define _COLON 58
#define _AT 64
#define _A 65
#define _B 66
#define _C 67
#define _D 68
#define _E 69
#define _F 70
#define _G 71
#define _H 72
#define _I 73
#define _J 74
#define _K 75
#define _L 76
#define _M 77
#define _N 78
#define _O 79
#define _P 80
#define _Q 81
#define _R 82
#define _S 83
#define _T 84
#define _U 85
#define _V 86
#define _W 87
#define _X 88
#define _Y 89
#define _Z 90
#define _a 97
#define _b 98
#define _c 99
#define _d 100
#define _e 101
#define _f 102
#define _g 103
#define _h 104
#define _i 105
#define _j 106
#define _k 107
#define _l 108
#define _m 109
#define _n 110
#define _o 111
#define _p 112
#define _q 113
#define _r 114
#define _s 115
#define _t 116
#define _u 117
#define _v 118
#define _w 119
#define _x 120
#define _y 121
#define _z 122
#define _0 48
#define _1 49
#define _2 50
#define _3 51
#define _4 52
#define _5 53
#define _6 54
#define _7 55
#define _8 56
#define _9 57
const int numLetters = 38;
const int letterArray[numLetters] = int[numLetters](
_I,_M,_P,_U,_L,_S,_E,_EXCLAMATION,_SPACE,
_DASH,_SPACE,
_S,_U,_M,_M,_E,_R,_SPACE
,_2,_0,_1,_9,_SPACE,
_DASH,_SPACE,
_J,_u,_s,_t,_SPACE,
_D,_O,_SPACE,
_I,_T,_EXCLAMATION,_EXCLAMATION,_SPACE
);
vec4 sampleText(in vec2 uv, int start, int count, bool repeat) {
float fl = floor(uv + 0.5).x;
float cursorPos = fl;
int arrayPos = int(cursorPos);
if (arrayPos < 0) {
return vec4(0.0, 0.0, 0.0, 1.0);
}
if (!repeat && arrayPos >= count) {
return vec4(0.0, 0.0, 0.0, 1.0);
}
arrayPos %= count;
arrayPos += start;
int letter = letterArray[arrayPos];
vec2 lp = vec2(letter % 16, 15 - letter/16);
vec2 uvl = lp + fract(uv+0.5)-0.5;
// Sample the font texture. Make sure to not use mipmaps.
// Add a small amount to the distance field to prevent a strange bug on some gpus. Slightly mysterious. :(
vec2 tp = (uvl+0.5)*(1.0/16.0);
return texture(iChannel2, tp, -100.0) + vec4(0.0, 0.0, 0.0, 0.000000001);
}
vec3 scrollText(vec2 uv, float time, vec3 fontColor, vec3 glowColor, vec3 background) {
vec3 col = background;
const float appearTime = 6.0;
vec2 p = uv + vec2(time, 0.0);
if (abs(p.y) > 0.5)
{
return col;
}
vec4 samp = sampleText(p, 0, numLetters, true);
float dist = samp.w;
col += glowColor*(1.0 - smoothstep(0.55, 0.66, dist));
if (step(0.55, dist) == 0.0) {
col = vec3(0.0);
}
if (step(0.5, dist) == 0.0) {
col = fontColor;
}
return col;
}
float pMod1(inout float p, in float size)
{
float halfsize = size*0.5;
float c = floor((p + halfsize)/size);
p = mod(p + halfsize, size) - halfsize;
return c;
}
vec2 pMod2(inout vec2 p, in vec2 size)
{
vec2 c = floor((p + size*0.5)/size);
p = mod(p + size*0.5,size) - size*0.5;
return c;
}
void pR(inout vec2 p, in float a)
{
p = cos(a)*p + sin(a)*vec2(p.y, -p.x);
}
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;
}
float linex(in vec2 p, in float b)
{
float d = abs(p.y) - b;
return min(d,0.0) + max(d,0.0);
}
float liney(in vec2 p, in float b)
{
float d = abs(p.x) - b;
return min(d,0.0) + max(d,0.0);
}
float box(in vec2 p, in vec2 b)
{
vec2 d = abs(p) - b;
return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}
float circle(in vec2 p, in float r)
{
return length(p) - r;
}
float hyper(in vec2 p, in float r)
{
return length(p) + r;
}
const vec3 color = vec3(1.125, 1.25, 1.5);
const vec3 fontColor = vec3(1.15, 1.1, 1.1);
const vec3 glowColor = vec3(1.5, 1.25, 1.125);
#define DISABLE 0.0
#define BOUNCESTART 0.0
#define BOUNCEDONE 30.0
#define DISTSTART 5.0
#define DISTDONE 20.0
#define LAYERSTART 15.0
#define LAYERDONE 40.0
#define LAYERCOUNT 6
#define ROTSTART 9.0
#define ROTDONE 20.0
#define TRANSSTART 0.0
#define TRANSDONE 30.0
vec3 layer(in vec2 p, in int layer, in float time)
{
layer += 3;
float s = 0.2/float(layer + 1);
const float timeFactor = 0.3;
float tm = time*timeFactor;
pR(p, mix(0.0, tm + 100.0*s*float(layer) - timeFactor*ROTSTART, smoothstep(ROTSTART, ROTDONE, time)));
p += mix(vec2(0.0), -s*200.0*vec2(cos(sqrt(2.0)*tm), sin(tm)) + s*vec2(1.0), smoothstep(TRANSSTART, TRANSDONE, time));
vec2 sp = toSmith(p);
sp += mix(vec2(0.0), -0.5*(2.0+ sin(tm))*mix(p, vec2(1.0), sin(tm*0.1)*sin(tm*0.1)), smoothstep(DISTSTART, DISTDONE, time));
p = fromSmith(sp);
vec2 scp = p;
pMod1(scp.y, 4.0*s);
scp *= 1.0/s;
scp += vec2(0.0, -0.5);
pMod2(p, vec2(4.0*s));
float d = 1E20;
d = min(d, liney(p, s*0.1));
d = min(d, linex(p, s*0.1));
d = min(d, circle(p, s*0.6));
d = max(d, -circle(p, s*0.4));
vec3 col = vec3(0.0);
if (d < 0.0)
{
col = pow(color, vec3(-layer));
}
col = scrollText(scp, time, pow(fontColor, vec3(-layer)), pow(glowColor, vec3(-layer)), col);
return col;
}
vec3 mobiusScrollText(in vec2 p, float time)
{
p *= mix(0.1, 5.0*(2.0 + sin(time*0.1)), smoothstep(BOUNCESTART, BOUNCEDONE, time));
float lp = (LAYERDONE - LAYERSTART) / LAYERCOUNT;
vec3 col = layer(p, 0, time);
for (int i = 1; i < LAYERCOUNT; ++i)
{
float lf = smoothstep(LAYERSTART + lp*(i - 1), LAYERSTART + lp*(i - 1 + 0.5), time);
col += lf*layer(p, i, time);
}
return col;
}
#define AA 2
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
vec3 col = vec3(0.0);
for( int m=0; m<AA; m++ )
for( int n=0; n<AA; n++ )
{
vec2 p = (-iResolution.xy + 2.0*(fragCoord.xy+vec2(float(m),float(n))/float(AA)))/iResolution.y;
col += mobiusScrollText(p, iTime - 3);
}
fragColor = vec4(col/(AA*AA),1.0);
}
#version 150
in VertexData
{
vec4 v_position;
vec3 v_normal;
vec2 v_texcoord;
} inData;
out vec4 fragColor;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
uniform vec2 iResolution;
uniform float iTime;
uniform float iTimeDelta;
uniform int iFrame;
uniform vec4 iMouse;
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;
uniform sampler2D iChannel2;
uniform sampler2D iChannel3;
uniform vec4 iDate;
uniform float iSampleRate;
void mainImage(out vec4, in vec2);
void main(void) { mainImage(fragColor,inData.v_texcoord * iResolution.xy); }
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
float pMod1(inout float p, in float size)
{
float halfsize = size*0.5;
float c = floor((p + halfsize)/size);
p = mod(p + halfsize, size) - halfsize;
return c;
}
vec2 pMod2(inout vec2 p, in vec2 size)
{
vec2 c = floor((p + size*0.5)/size);
p = mod(p + size*0.5,size) - size*0.5;
return c;
}
void pR(inout vec2 p, in float a)
{
p = cos(a)*p + sin(a)*vec2(p.y, -p.x);
}
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;
}
float box(in vec2 p, in vec2 b)
{
vec2 d = abs(p) - b;
return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}
float circle(in vec2 p, in float r)
{
return length(p) - r;
}
float hyper(in vec2 p, in float r)
{
return length(p) + r;
}
const vec3 color = vec3(1.125, 1.25, 1.5);
vec3 layer(in vec2 p, in int l)
{
l = l + 3;
float s = 0.2/(l + 1);
float tm = iTime*0.3;
p += s*200*vec2(cos(sqrt(2.0)*tm), sin(tm)) + s*vec2(1.0);
vec2 sp = toSmith(p);
sp += -0.5*(2.0+ sin(tm))*mix(p, vec2(1.0), sin(tm*0.1)*sin(tm*0.1));
p = fromSmith(sp);
pMod2(p, vec2(4.0*s));
if (box(p, vec2(s)) < 0.0)
{
return 0.90*pow(color, vec3(-l));
}
else
{
return vec3(0.0);
}
}
vec3 effect(in vec2 p)
{
vec3 col = vec3(0.0);
p *= 1*(2.0 + sin(iTime*0.1));
for (int i = 0; i < 20; ++i)
{
col += layer(p, i);
}
return col;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
vec2 q =fragCoord.xy/iResolution.xy;
vec2 uv = fragCoord/iResolution.xy;
vec2 p = -1.0 + 2.0*q;
p.x *= iResolution.x/iResolution.y;
vec3 col = effect(p);
fragColor = vec4(col,1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment