// ╔═════════════╦════════════════╗
// ║ Marco Gomez ║ https://mgz.me ║
// ╚═════════════╩════════════════╝
precision highp float;
uniform sampler2D prgm2Texture;
uniform vec2 resolution;
uniform float time;
void main(void) {
vec2 uv = gl_FragCoord.xy / resolution.xy;
vec4 prgm2 = texture2D(prgm2Texture, uv);
gl_FragColor = vec4(prgm2.xyz, 1.0);
}
// ╔═════════════╦════════════════╗
// ║ Marco Gomez ║ https://mgz.me ║
// ╚═════════════╩════════════════╝
precision highp float;
uniform vec2 resolution;
uniform vec2 mouselerp;
uniform float time;
#define ss(a, b, t) smoothstep(a, b, t)
float dot2 (vec2 v) { return dot(v, v); }
float sdHeart(vec2 p) {
p.x = abs(p.x);
if (p.y + p.x > 1.0) {
return sqrt(dot2(p - vec2(0.25, 0.75))) - sqrt(2.0) / 4.0;
}
return sqrt(
min(
dot2(p - vec2(0.0, 1.0)),
dot2(p - 0.5 * max(p.x + p.y, 0.0))
)
) * sign(p.x - p.y);
}
float smax(float a, float b, float k) {
float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0);
return mix(a, b, h) + k * h * (1.0 - h);
}
mat2 scale(in float sx, in float sy) {
return mat2(1.0 / sx, 0.0, 0.0, 1.0 / sy) * 1.2;
}
vec4 qmulq(vec4 q1, vec4 q2) {
return vec4(
q1.xyz * q2.w + q2.xyz * q1.w + cross(q1.xyz, q2.xyz),
(q1.w * q2.w) - dot(q1.xyz, q2.xyz)
);
}
vec4 aa2q(vec3 axis, float angle) {
return vec4(
normalize(axis) * sin(angle * 0.5),
cos(angle * 0.5)
);
}
vec4 qinv(vec4 q) {
return vec4(-q.xyz, q.w) / dot(q, q);
}
vec3 qmulv(vec4 q, vec3 p) {
return qmulq(q, qmulq(vec4(p, 0.0), qinv(q))).xyz;
}
vec2 raySphere(vec3 rd, vec3 p) {
float l = dot(rd, p);
float det = l * l - dot(p, p) + 1.0;
if (det < 0.0) { return vec2(-1.0); }
float sd = sqrt(det);
return vec2(l - sd, l + sd);
}
struct sphereInfo {
vec3 p1, p2, n1, n2;
vec2 uv1, uv2;
};
sphereInfo GetSphereUvs(vec3 rd, vec2 i, vec2 rot, vec3 s) {
sphereInfo res;
rot *= 6.2831;
vec4 q = aa2q(vec3(cos(rot.x), sin(rot.x), 0.0), rot.y);
vec3 o = qmulv(q, -s) + s;
vec3 d = qmulv(q, rd);
res.p1 = rd * i.x;
vec3 p = o + d * i.x - s;
res.uv1 = vec2(atan(p.x, p.z), p.y);
res.n1 = res.p1 - s;
res.p2 = rd * i.y;
p = o + d * i.y - s;
res.uv2 = vec2(atan(p.x, p.z), p.y);
res.n2 = s - res.p2;
return res;
}
float heart(vec2 uv, float b) {
uv.x *= 0.5;
float shape = smax(sqrt(abs(uv.x)), b, 0.3 * b) * 0.5;
uv.y -= shape * (1.0 - b);
return ss(b, -b, length(uv) - 0.5);
}
vec4 heartCurve(vec3 rd, vec3 p, vec2 rot, float t, float blur) {
vec2 d = raySphere(rd, p);
vec3 light = vec3(0.577, -0.577, -0.577);
vec4 col = vec4(0.0);
if (d.x > 0.0) {
sphereInfo info = GetSphereUvs(rd, d, rot, p);
float sd = length(cross(p, rd));
float edge = ss(1.0, mix(1.0, 0.1, blur), sd);
float backMask = heart(info.uv2, blur) * edge;
float frontMask = heart(info.uv1, blur) * edge;
float frontLight = clamp(dot(light, info.n1), 0.0, 1.0) * 0.8 + 0.2;
float backLight = clamp(dot(light, info.n2) * 0.8 + 0.2, 0.0, 1.0) * 0.9;
col = mix(
vec4(backLight * vec3(1.0, 0.01, 0.01), backMask),
vec4(frontLight * vec3(1.0, 0.01, 0.01), frontMask),
frontMask
);
}
return col;
}
void main(void) {
vec2 uv = (gl_FragCoord.xy / resolution.xy) * 2.0 - 1.0;
uv.x *= resolution.x / resolution.y;
uv.y += 0.2;
vec3 rd = normalize(vec3(vec2(uv.x, uv.y * 0.7 - 0.3), 1.0));
vec2 rot = time * 0.3 * vec2(0.12, 0.18);
vec4 bgCol = vec4(0.0);
for (float i = 0.0; i < 1.0; i += (1.0 / 42.0)) {
float x = (fract(cos(i * 536.3) * 7464.4) - 0.5) * 21.0;
float y = (fract(-time * 0.3 * 0.2 + i * 7.64) - 0.5) * 21.0;
float z = mix(14.0, 2.0, i);
float blur = mix(0.021, 0.3, ss(0.0, 0.3, abs(1.0 - i))) * 0.7;
rot += (fract(sin(i * vec2(536.3, 23.4)) * vec2(764.4, 987.3)) - 0.5);
vec4 heart = heartCurve(rd, vec3(x, y, z), rot, time * 0.3, blur);
bgCol = mix(bgCol, heart, heart.a);
}
vec2 p = uv;
float mt = mod(time, 1.2);
float px = 1.0 + 0.12 * exp(-mt * 3.0) * cos(12.0 * mt);
float py = 1.0 + 0.12 * exp(-mt * 3.0) * sin(12.0 * mt);
p = scale(sqrt(px), py) * p;
p.y += py * 0.21;
float d = sdHeart(p);
vec3 col = vec3(0.0);
if (d < 0.0) {
col += vec3(1.6, 0.3, 0.0);
}
col *= 1.0 + 0.021 * cos(768.0 * abs(d)) * 0.75;
col = (
(d < 0.0)
? vec3(1.6, 0.12, 0.0) + col
: bgCol.xyz + vec3(0.3, 0.05, 0.1) * 1.0 + 0.021 * cos(768.0 * abs(d)) * 0.75);
col *= 1.0 - exp(-6.0 * abs(d));
vec3 ss = mix(col, vec3(2.0, 0.5, 0.5), 1.0 - smoothstep(0.0, 0.021, abs(d)));
col = ss * ss * ss + col * col;
gl_FragColor = vec4(col, 1.0);
}
// ╔═════════════╦════════════════╗
// ║ Marco Gomez ║ https://mgz.me ║
// ╚═════════════╩════════════════╝
precision highp float;
uniform sampler2D prgm1Texture;
uniform vec2 resolution;
uniform float time;
uniform float fft;
const float reinhardAmount = 1.0;
const float contrast = 0.99;
const float brightness = 1.0;
const float amount = 1.0;
const float saturation = 0.7;
const vec2 vignetteSize = vec2(0.21, 0.21);
const float vignetteRoundness = 0.12;
const float vignetteMix = 1.0;
const float vignetteSmoothness = 0.42;
const float W = 1.2;
const float T = 7.5;
float filmicReinhardCurve(float x) {
float q = (T * T + 1.0) * x * x;
return q / (q + x + T * T);
}
vec3 filmicReinhard(vec3 c) {
float w = filmicReinhardCurve(W);
return vec3(
filmicReinhardCurve(c.r),
filmicReinhardCurve(c.g),
filmicReinhardCurve(c.b)
) / w;
}
vec3 ContrastSaturationBrightness(vec3 color, float brt, float sat, float con) {
const float AvgLumR = 0.5;
const float AvgLumG = 0.5;
const float AvgLumB = 0.5;
const vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721);
vec3 AvgLumin = vec3(AvgLumR, AvgLumG, AvgLumB);
vec3 brtColor = color * brt;
vec3 intensity = vec3(dot(brtColor, LumCoeff));
vec3 satColor = mix(intensity, brtColor, sat);
vec3 conColor = mix(AvgLumin, satColor, con);
return conColor;
}
float sdSquare(vec2 point, float width) {
vec2 d = abs(point) - width;
return min(max(d.x, d.y), 0.0) + length(max(d, 0.0));
}
float vignette(vec2 uv, vec2 size, float roundness, float smoothness) {
uv -= 0.5;
float minWidth = min(size.x, size.y);
uv.x = sign(uv.x) * clamp(abs(uv.x) - abs(minWidth - size.x), 0.0, 1.0);
uv.y = sign(uv.y) * clamp(abs(uv.y) - abs(minWidth - size.y), 0.0, 1.0);
float boxSize = minWidth * (1.0 - roundness);
float dist = sdSquare(uv, boxSize) - (minWidth * roundness);
return 1.0 - smoothstep(0.0, smoothness, dist);
}
void main(void) {
vec2 uv = gl_FragCoord.xy / resolution.xy;
vec4 prgm1 = texture2D(prgm1Texture, uv);
vec3 reinhard = filmicReinhard(prgm1.rgb);
vec3 color = prgm1.rgb;
color = mix(prgm1.rgb, reinhard, reinhardAmount);
color = ContrastSaturationBrightness(color, brightness, saturation, contrast);
float v = vignette(uv, vignetteSize, vignetteRoundness, vignetteSmoothness);
vec3 vig = color * v;
color = mix(color, vig, vignetteMix);
color = mix(prgm1.xyz, color, amount);
color = clamp(color, 0.0, 1.0);
gl_FragColor = vec4(color, 1.0);
}