#version 300 es
// ╔═════════════╦════════════════╗
// ║ Marco Gomez ║ https://mgz.me ║
// ╚═════════════╩════════════════╝
precision highp float;
uniform sampler2D textTexture;
uniform vec4 date;
uniform vec2 resolution;
uniform float framerate;
uniform int frame;
uniform float time;
uniform float deltatime;
uniform vec2 mouselerp;
uniform vec2 mouse;
uniform float fft; // The average of all 512 values
/*
uniform float fftLow; // The average of the first (lower) third of the fft values Array
uniform float fftMid; // The average of the second (mid) third of the fft values Array
uniform float fftHigh; // The average of the third (high) third of the fft values Array
uniform float fftLowerHalf; // The average of the lower half of the fft values Array
uniform float fftUpperHalf; // The average of the upper half of the fft values Array
*/
uniform float fftNormalized;
/*
uniform float fftLowNormalized;
uniform float fftMidNormalized;
uniform float fftHighNormalized;
uniform float fftLowerHalfNormalized;
uniform float fftUpperHalfNormalized;
*/
out vec4 fragColor;
const float PI = acos(-1.0);
const int _ = 32;
/*
const int _EQ = 61, _GT = 62, _QUEST = 63, _AT = 64;
const int _EXCL = 33, _QUOTE = 34, _SHARP = 35, _DOLLAR = 36, _PERCENT = 37, _AMPER = 38;
*/
const int _SQUOTE = 39, _LPAR = 40, _RPAR = 41, _ASTERISK = 42, _PLUS = 43, _COMMA = 44;
const int _MINUS = 45, _DOT = 46, _SLASH = 47, _COLON = 58, _SEMICOLON = 59, _LT = 60;
const int _0 = 48, _1 = 49, _2 = 50, _3 = 51, _4 = 52, _5 = 53, _6 = 54, _7 = 55, _8 = 56, _9 = 57;
const int _A = 65, _B = 66, _C = 67, _D = 68, _E = 69, _F = 70, _G = 71, _H = 72, _I = 73;
const int _J = 74, _K = 75, _L = 76, _M = 77, _N = 78, _O = 79, _P = 80, _Q = 81, _R = 82;
const int _S = 83, _T = 84, _U = 85, _V = 86, _W = 87, _X = 88, _Y = 89, _Z = 90;
const int _a = 97, _b = 98, _c = 99, _d = 100, _e = 101, _f = 102, _g = 103, _h = 104, _i = 105;
const int _j = 106, _k = 107, _l = 108, _m = 109, _n = 110, _o = 111, _p = 112, _q = 113, _r = 114;
const int _s = 115, _t = 116, _u = 117, _v = 118, _w = 119, _x = 120, _y = 121, _z = 122;
/*
const int _alpha = 128, _beta = 129, _gamma = 130, _delta = 131, _epsilon = 132, _theta = 133;
const int _lambda = 134, _mu = 135, _xi = 136, _pi = 137, _rho = 138, _sigma = 139;
const int _tau = 140, _phi = 141, _psi = 142, _omega = 143;
const int _GAMMA = 144, _DELTA = 145, _THETA = 146, _LAMBDA = 147, _PI = 148, _SIGMA = 149;
const int _PHI = 150, _PSI = 151, _OMEGA = 152;
*/
const int[] wX = int[](_x);
const int[] wXSpace = int[](_,_x,_);
const int[] wSlash = int[](_SLASH);
const int[] wColon = int[](_COLON);
const int[] wFPS = int[](_,_f,_p,_s);
const int[] wSysTime = int[](_,_,_,_s,_y,_s,_t,_e,_m,_,_t,_i,_m,_e,_COLON,_);
const int[] wDate = int[](_,_,_,_,_,_,_,_,_,_,_d,_a,_t,_e,_COLON,_);
const int[] wResolution = int[](_,_,_,_,_r,_e,_s,_o,_l,_u,_t,_i,_o,_n,_COLON,_);
const int[] wFrameRate = int[](_,_,_,_,_,_f,_r,_a,_m,_e,_r,_a,_t,_e,_COLON,_);
const int[] wFrame = int[](_,_,_,_,_,_,_,_,_,_f,_r,_a,_m,_e,_COLON,_);
const int[] wTime = int[](_,_,_,_,_,_,_,_,_,_,_t,_i,_m,_e,_COLON,_);
const int[] wDeltaTime = int[](_,_,_,_,_,_d,_e,_l,_t,_a,_t,_i,_m,_e,_COLON,_);
const int[] wMouseLerp = int[](_,_,_,_,_,_m,_o,_u,_s,_e,_l,_e,_r,_p,_COLON,_);
const int[] wMouse = int[](_,_,_,_,_,_,_,_,_,_m,_o,_u,_s,_e,_COLON,_);
const int[] wFFT = int[](_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_f,_f,_t,_COLON,_);
const int[] wFFTNormalized = int[](_,_,_,_,_,_,_,_,_,_,_,_f,_f,_t,_N,_o,_r,_m,_a,_l,_i,_z,_e,_d,_COLON,_);
#define R resolution
uint hash(uint x) {
x += (x << 10u);
x ^= (x >> 6u);
x += (x << 3u);
x ^= (x >> 11u);
x += (x << 15u);
return x;
}
uint hash(uvec2 v) { return hash(v.x ^ hash(v.y) ); }
uint hash(uvec3 v) { return hash(v.x ^ hash(v.y) ^ hash(v.z) ); }
uint hash(uvec4 v) { return hash(v.x ^ hash(v.y) ^ hash(v.z) ^ hash(v.w)); }
float floatConstruct(uint m) {
const uint ieeeMantissa = 0x007FFFFFu; // binary32 mantissa bitmask
const uint ieeeOne = 0x3F800000u; // 1.0 in IEEE binary32
m &= ieeeMantissa; // Keep only mantissa bits (fractional part)
m |= ieeeOne; // Add fractional part to 1.0
float f = uintBitsToFloat(m); // Range [1:2]
return f - 1.0; // Range [0:1]
}
float random(float x) { return floatConstruct(hash(floatBitsToUint(x))); }
float random(vec2 v) { return floatConstruct(hash(floatBitsToUint(v))); }
float random(vec3 v) { return floatConstruct(hash(floatBitsToUint(v))); }
float random(vec4 v) { return floatConstruct(hash(floatBitsToUint(v))); }
int powInt(int a, int b) {
int r = 1;
for (int i = 0; i++ < b; r *= a);
return r;
}
int intLog(int x, int base) {
if (x < 1) { return 0; }
int res = 0;
for(;x >= base; res++) { x /= base; }
return res;
}
float periodicDirac(float x, float period, float s) {
return pow(abs(cos(x * (PI / period))), s);
}
struct PrintPosition { vec2 uv, pos, resolution; float scale; };
struct PrintStyle{ vec3 charColor, outlineColor; float outlineSize; };
PrintStyle NewPrintStyle(vec3 col1, vec3 col2, float w) { return PrintStyle(col1, col2, w); }
PrintStyle NewPrintStyle(vec3 col1, vec3 col2) { return PrintStyle(col1, col2, 0.05); }
PrintStyle NewPrintStyle(vec3 col) { return PrintStyle(col, col, 0.0); }
#define nextLine(p) p.pos.y -= scale * 1.5, p = PrintPosition((gl_FragCoord.xy - p.pos * resolution.xy) / (p.scale * resolution.x), p.pos, resolution.xy, p.scale);
void writeChar(int char, PrintStyle style, float w, float xOffset, inout PrintPosition p, inout vec3 color) {
vec2 uv = p.uv; uv.x += xOffset;
float outlineSize = style.outlineSize;
if (uv.x > 0.0 && uv.x < w && uv.y > 0.0 && uv.y < 1.0) {
vec4 t = texture(textTexture, (uv + vec2(char % 16, 15 - char / 16)) / 16.0);
color = mix(color, style.outlineColor, smoothstep(0.0, -1.0 / p.resolution.y, t.a - outlineSize - 0.5));
color = mix(color, style.charColor, t.r);
}
uv.x -= w; p.uv = uv;
}
float defaultChW = 0.8,
defaultChOff = 0.3;
void writeStandardChar(int char, PrintStyle style, inout PrintPosition p, inout vec3 color) {
writeChar(char, style, defaultChW, defaultChOff, p, color);
}
#define writeText(text, style, p, color) {\
int chars_per_line = int((1.0 - p.pos.x) / (p.scale * (defaultChW - defaultChOff)));\
for (int i = 0; i < text.length(); i++) {\
writeStandardChar(text[i], style, p, color);\
if ((i + 1) % chars_per_line == 0) { nextLine(p); }\
}\
}
#define writeWord(word, style, p, color)\
for (int i = 0; i < word.length(); i++)\
writeStandardChar(word[i], style, p, color);
void writeNumber(float number, int minIntDigits, int decDigits, PrintStyle style, inout PrintPosition p, inout vec3 color) {
if (isnan(number)) {
PrintStyle NaN_style = PrintStyle(vec3(0.0), vec3(1.0, 0.0, 0.0), 0.05);
writeWord(int[](_N,_a,_N), NaN_style, p, color);
} else if (isinf(number)) {
PrintStyle Inf_style = PrintStyle(vec3(0.0), vec3(0.0, 0.5, 1.0), 0.05);
writeWord(int[](_I,_n,_f), Inf_style, p, color);
} else {
if (number < -0.001 && number != 0.0) {
writeStandardChar(_MINUS, style, p, color);
}
float decimal_digits_factor = float(powInt(10, decDigits));
int rounded_number = int(round(abs(number) * decimal_digits_factor));
int int_part = rounded_number / int(decimal_digits_factor);
int int_digits = 1 + intLog(int_part, 10);
for (int i = 0; i++ < minIntDigits - int_digits;) {
writeStandardChar(_0, style, p, color);
}
int digits = int_digits + decDigits;
for (int x = powInt(10, digits); digits > 0; digits--) {
if (digits == decDigits) {
writeChar(_DOT, style, 0.65, 0.45, p, color);
}
writeStandardChar(_0 + rounded_number / (x /= 10), style, p, color);
rounded_number %= x;
}
}
}
void writeNumber(int number, int minIntDigits, PrintStyle style, inout PrintPosition p, inout vec3 color) {
writeNumber(float(number), minIntDigits, 0, style, p, color);
}
#define WriteChar(char, style) writeStandardChar(char, style, p, color)
#define WriteText(text, style) writeText(text, style, p, color)
#define WW(word, style) writeWord(word, style, p, color)
#define WN(number, minIntDigits, decDigits, style) writeNumber(number, minIntDigits, decDigits, style, p, color)
float truchet(vec2 uv) {
uv *= vec2(5.0 / 3.0, 1.0);
uv *= 24.0;
uv.y -= floor(time * 1.755);
vec2 gv = fract(uv) - 0.5;
vec2 id = floor(uv);
float width = 0.15;
float r = random(id);
if (r < 0.5) { gv.x *= -1.0; }
float mask = smoothstep(0.01, -0.01, abs(gv.x + gv.y) - width);
return mask;
}
float sdBox(vec2 p, vec2 b) {
vec2 d = abs(p) - b;
return min(max(d.x, d.y), 0.0) + length(max(d, 0.0));
}
void main(void) {
float t = time * 1e3;
vec2 uv = gl_FragCoord.xy / resolution.xy;
float px = 1.0 / resolution.x;
const vec4 rates = vec4(240.0, 144.0, 120.0, 60.0);
vec4 d = abs(rates - framerate);
float refresh = (
(d.x < d.y && d.x < d.z && d.x < d.w)
? rates.x
: (d.y < d.z && d.y < d.w)
? rates.y
: (d.z < d.w)
? rates.z
: rates.w
);
float trp = truchet(uv) * 0.6;
vec3 rp = vec3(gl_FragCoord.xy, t);
float rnd = random(rp);
vec3 color = vec3(0.0);
if (uv.x < 0.5) {
color = clamp((vec3(rnd * uv.x) * 0.4) + mix(trp, trp * rnd, 0.1), 0.0, 1.0) * 0.9;
} else if (uv.x > 0.499 && uv.x < 0.501) {
color = vec3(0.5);
} else if (uv.x > 0.501 && uv.y < 10.0 / resolution.y) {
color = vec3(0.1) * rnd;
color += (
1.0 - smoothstep(
px,
0.0,
sdBox(
uv - vec2(0.0, 0.01),
vec2(refresh * (deltatime / 2000.0) + 0.25, 0.01)
)
)
);
}
PrintPosition p;
vec2 pos = vec2(320.0, 335.0) / vec2(640.0, 360.0);
float scale = 1.0 / 35.0;
p = PrintPosition((gl_FragCoord.xy - pos * resolution.xy) / (scale * resolution.x), pos, resolution.xy, scale);
PrintStyle wt = NewPrintStyle(vec3(1.0), vec3(0.0));
float h = floor(date.w / 3600.0);
float m = mod(floor(date.w / 60.0), 60.0);
float s = mod(date.w, 60.0);
WW(wSysTime, wt);
WN(h, 2, 0, wt); WW(wColon, wt);
WN(m, 2, 0, wt); WW(wColon, wt);
WN(s, 2, 2, wt);
nextLine(p); nextLine(p);
WW(wDate, wt);
WN(date.x, 4, 0, wt); WW(wSlash, wt);
WN(date.y, 2, 0, wt); WW(wSlash, wt);
WN(date.z, 2, 0, wt); WW(wColon, wt);
WN(date.w, 5, 2, wt);
nextLine(p);
WW(wResolution, wt);
WN(resolution.x, 2, 0, wt); WW(wX, wt); WN(resolution.y, 2, 0, wt); nextLine(p);
WW(wFrameRate, wt); WN(framerate, 3, 2, wt); nextLine(p);
WW(wFrame, wt); WN(float(frame), 1, 0, wt); nextLine(p);
WW(wTime, wt); WN(time, 1, 2, wt); nextLine(p);
WW(wDeltaTime, wt); WN(deltatime, 1, 2, wt); nextLine(p);
nextLine(p);
WW(wMouseLerp, wt); WN(mouselerp.x, 1, 2, wt); WW(wXSpace, wt); WN(mouselerp.y, 1, 2, wt); nextLine(p);
WW(wMouse, wt); WN(mouse.x, 1, 2, wt); WW(wXSpace, wt); WN(mouse.y, 1, 2, wt); nextLine(p);
nextLine(p);
WW(wFFT, wt); WN(fft, 1, 2, wt); nextLine(p);
WW(wFFTNormalized, wt); WN(fftNormalized, 1, 2, wt); nextLine(p);
pos = vec2(477.0, 10.0) / vec2(640.0, 360.0);
p = PrintPosition((gl_FragCoord.xy - pos * resolution.xy) / (scale * resolution.x), pos, resolution.xy, scale);
WW(int[](19,_), wt);
WN(refresh, 3, 0, wt);
WW(wFPS, wt);
fragColor = vec4(vec3(0.0, color.x, 0.0), 1.0);
}
#version 300 es
// ╔═════════════╦════════════════╗
// ║ Marco Gomez ║ https://mgz.me ║
// ╚═════════════╩════════════════╝
precision highp float;
uniform sampler2D prgm1Texture;
uniform vec2 resolution;
uniform vec2 mouselerp;
uniform float time;
out vec4 fragColor;
#define textureInput prgm1Texture
#define ss smoothstep
const float PI = acos(-1.0);
const float TAU = PI * 2.0;
const vec2 hashv2 = vec2(12.9898, 78.233);
const float hashS = 43758.5453123;
const int blurIter = 8;
const float blurSize = 0.07;
const float width = 0.49;
const float height = 0.3;
float gaussian(float z, float u, float o) {
return (
(1.0 / (o * sqrt(TAU))) *
(exp(-(((z - u) * (z - u)) / (2.0 * (o * o)))))
);
}
vec3 gaussgrain(float t) {
vec2 ps = vec2(1.0) / resolution.xy;
vec2 uv = gl_FragCoord.xy * ps;
float seed = dot(uv, hashv2);
float noise = fract(sin(seed) * hashS + t);
noise = gaussian(noise, 0.0, 0.5);
return vec3(noise);
}
float rand(vec2 co) {
return fract(sin(dot(co.xy, hashv2)) * hashS);
}
vec2 CurvedSurface(vec2 uv, float r) {
return r * uv / sqrt(r * r - dot(uv, uv));
}
vec2 crtCurve(vec2 uv, float r, bool content) {
uv = CurvedSurface(uv, 1.5);
if (content) { uv *= 0.5 / vec2(width, height); }
uv.x -= mouselerp.x * 0.125;
return uv;
}
float roundSquare(vec2 p, vec2 b, float r) {
return length(max(abs(p) - b, 0.0)) - r;
}
float rs(vec2 uv, float r) {
return roundSquare(uv, vec2(width, height) + r, 0.05);
}
vec2 borderReflect(vec2 p, float r) {
float eps = 0.0001;
vec2 epsx = vec2(eps, 0.0);
vec2 epsy = vec2(0.0, eps);
vec2 b = (1.0 + vec2(r, r)) * 0.5;
r /= 3.0;
p -= 0.5;
vec2 normal = vec2(
roundSquare(p - epsx, b, r) - roundSquare(p + epsx, b, r),
roundSquare(p - epsy, b, r) - roundSquare(p + epsy, b, r)
) / eps;
float d = roundSquare(p, b, r);
p += 0.5;
return p + d * normal;
}
vec2 normalizeAndFix() {
vec2 uv = (gl_FragCoord.xy / resolution.xy) * 2.0 - 1.0;
float targetAR = 16.0 / 9.0;
float ar = resolution.x / resolution.y;
uv.x *= ar;
uv *= (
ar < targetAR &&
resolution.x < 800.0 &&
resolution.x < resolution.y
) ? 1.1 : 0.55;
return uv;
}
void main(void) {
float s = 0.0021;
vec4 color = vec4(0.02, 0.02, 0.03, 0.0);
const vec4 multColor = vec4(0.21);
const float ambient = 0.12;
vec4 bezel = vec4(0.5);
vec2 uv = normalizeAndFix();
vec2 suv = gl_FragCoord.xy / resolution.xy;
float gs = 1.0;
float grid = (
(mod(floor((suv.x) * resolution.x / gs), 2.0) == 0.0 ? 1.0 : 0.0) *
(mod(floor((suv.y) * resolution.y / gs), 2.0) == 0.0 ? 1.0 : 0.0)
);
vec2 uvC = crtCurve(uv, 1., true) + 0.5;
vec2 uvS = crtCurve(uv, 1., false);
vec2 uvE = crtCurve(uv, 1.25, false);
color += (max(0.0, ambient - 0.25 * distance(uvS, vec2(0.0))) * ss(s, -s, rs(uvS, 0.0)));
color += (bezel * ambient * 0.7 * ss(-s, s, rs(uvS, 0.0)) * ss(s, -s, rs(uvE, 0.05)));
color -= (bezel * ss(-s * 2.0, s * 10.0, rs(uvE, 0.05)) * ss(s * 2.0, -s * 2.0, rs(uvE, 0.05)));
color += (bezel * ambient * ss(-s, s, rs(uvE, 0.05)) * ss(s, -s, rs(uvE, 0.15)));
for (int i = 0; i < blurIter; i++) {
vec2 uvR = borderReflect(uvC + (vec2(rand(uvC + float(i)), rand(uvC + float(i) + 0.1)) - 0.5) * blurSize, 0.05);
color += (
(multColor - bezel * ambient) *
texture(textureInput, uvR) / float(blurIter) *
ss(-s, s, rs(uvS, 0.0)) *
ss(s, -s, rs(uvE, 0.05))
);
}
vec4 prgmMipMaps = texture(textureInput, uvC, 3.0) + texture(textureInput, uvC, 4.0) + texture(textureInput, uvC, 5.0);
color += (prgmMipMaps * ss(0.0, -s * 20.0, rs(uvS, -0.05)) * 0.5);
color += (
max(0.0, (1.0 - 2.0 * gl_FragCoord.y / resolution.y)) * vec4(0.1, 0.1, 0.1, 0.0) *
ss(-0.3, 0.3, roundSquare(uvC - vec2(0.5, 0.0), vec2(width + 0.2, height), 0.1)) *
ss(-s * 2.0, s * 2.0, roundSquare(uvE, vec2(width, height) + 0.15, 0.05))
) * 1.5;
if (
uvC.x > 0.0 &&
uvC.x < 1.0 &&
uvC.y > 0.0 &&
uvC.y < 1.0
) {
color += texture(textureInput, uvC);
color = mix(color, color * grid, 0.25);
}
vec3 g = gaussgrain(time) * 0.015;
color.xyz += g;
fragColor = color;
fragColor.a = 1.0;
}