Neon City
của Zu Phạm, visualizer
A glittering neon city at night, a butterfly scattering stardust, and something hidden in the city. Can you spot it?
57 lượt tải
Tải file, 31.9 KB
Cách cài, mã SHA-256 và mã nguồn
Bấm Áp dụng: MusicBar tự tải về, kiểm tra mã SHA-256 rồi mặc lên taskbar; có rồi thì mặc luôn. Cần MusicBar 1.8 trở lên.
SHA-256 427905e5dc218045654fd784081e8c283c6eb82ec6b119b890c855eec177c37f
//! name: Neon City
//! author: Zu Phạm
//! kind: visualizer
//! description: Neon city at night with glowing lights and a flying butterfly shedding tiny falling dust.
// Original code by Inigo Quilez (2021), licensed under the MIT License.
// Use, modification, and redistribution are permitted under its terms.
// When redistributing, include the original copyright notice and full MIT License.
// Provided "AS IS", without warranty or liability.
#define CAM_DIR float3(-0.666667, -0.333333, -0.666667)
#define CAM_DIST 9.0
#define CITY_SPEED 0.4
#define WINDOW_A float3(0.0, 0.0, 1.7)
#define WINDOW_B float3(0.6, 1.8, 2.4)
#define FOG_OFFSET 7.0
#define FOG_DENSITY 0.7
#define FOG_COLOR float3(0.25, 0.0, 0.3)
#define LIGHT_HEIGHT 0.0
#define LIGHT_SPEED 0.15
#define LIGHT_HIDDEN_GLOW 0.25
#define LIGHT_A float3(0.7, 0.35, 0.15)
#define LIGHT_B float3(0.95, 0.7, 0.5)
#define SIGN_A float3(0.0, 0.0, 1.8)
#define SIGN_B float3(3.4, 3.4, 3.4)
#define TAU 6.283185
#define VIEW_TAN 0.7
#define VIEW_SHIFT 0.0
#define SPEC_Z0 -0.5
#define SPEC_Z1 6.0
#define SPEC_JITTER 0.08
#define SPEC_MIN 0.9
#define SPEC_GAIN 2.5
#define FLY_D0 10.2
#define FLY_AZ 2.2
#define FLY_AX 4.4
#define FLY_SPEED 0.55
#define FLY_OMEGA 0.30
#define FLY_SIZE_VAR 0.15
#define FLY_DNEAR 8.0
#define FLY_K 0.95
#define FLY_FORESHORT (-CAM_DIR.z)
#define FLY_RISE 0.55
#define FLY_LAG 0.35
#define FLY_EPOCH 30.0
#define FLY_SIGHTING_PERIOD 45.0
#define FLY_SIGHTING_LENGTH_MIN 18.0
#define FLY_SIGHTING_LENGTH_MAX 32.0
#define FLY_SIGHTING_FADE 0.8
#define FLY_EXIT 2.4
#define FLY_VK 3.0
#define FLAP_RATE 1.25
#define FLAP_LIFT 0.09
#define FLAP_SURGE 0.9
#define FLY_B2_PROB 0.55
#define FLY_B2_OFFSET 37.3
#define FLY_B2_SIZE 0.85
#define BF_S 3.0
#define DUST_N 12
#define DUST_DT 0.18
#define DUST_LIFE 1.6
#define TEXT_CELL float2(24.0, 9.0)
#define TEXT_SIGN_HASH float4(0.5, 0.0, 0.75, 0.9)
float2 wrapCell(float2 b)
{
return b - 512.0 * floor(b / 512.0);
}
float hash1(float p)
{
float3 p3 = frac(p * float3(5.3983, 5.4427, 6.9371));
p3 += dot(p3, p3.yzx + 19.19);
return frac((p3.x + p3.y) * p3.z);
}
float hash1(float2 p2)
{
p2 = frac(p2 * float2(5.3983, 5.4427));
p2 += dot(p2.yx, p2.xy + float2(21.5351, 14.3137));
return frac(p2.x * p2.y * 95.4337);
}
float hash1(float2 p2, float p)
{
float3 p3 = frac(float3(5.3983 * p2.x, 5.4427 * p2.y, 6.9371 * p));
p3 += dot(p3, p3.yzx + 19.19);
return frac((p3.x + p3.y) * p3.z);
}
float2 hash2(float2 p2, float p)
{
float3 p3 = frac(float3(5.3983 * p2.x, 5.4427 * p2.y, 6.9371 * p));
p3 += dot(p3, p3.yzx + 19.19);
return frac((p3.xx + p3.yz) * p3.zy);
}
float3 hash3(float2 p2)
{
float3 p3 = frac(float3(p2.xyx) * float3(5.3983, 5.4427, 6.9371));
p3 += dot(p3, p3.yxz + 19.19);
return frac((p3.xxy + p3.yzz) * p3.zyx);
}
float4 hash4(float2 p2)
{
float4 p4 = frac(p2.xyxy * float4(5.3983, 5.4427, 6.9371, 7.1283));
p4 += dot(p4, p4.yxwz + 19.19);
return frac((p4.xxxy + p4.yyzz + p4.zwww) * p4.wzyx);
}
float4 signParams(float2 hb)
{
float isCell = step(abs(hb.x - TEXT_CELL.x) + abs(hb.y - TEXT_CELL.y), 0.5);
return lerp(hash4(hb), TEXT_SIGN_HASH, isCell);
}
float vnoise(float2 p)
{
float2 i = floor(p);
float2 f = frac(p);
float2 u = f * f * (3.0 - 2.0 * f);
return lerp(lerp(hash1(i + float2(0.0, 0.0)),
hash1(i + float2(1.0, 0.0)), u.x),
lerp(hash1(i + float2(0.0, 1.0)),
hash1(i + float2(1.0, 1.0)), u.x), u.y);
}
float3 boxHit(float3 eye, float3 ri, float3 ray, float3 side, float3 lo, float3 hi)
{
float3 wall = lerp(hi, lo, side);
float3 t = (wall - eye) * ri;
float3 dm = step(t.zxy, t) * step(t.yzx, t);
float maxT = dot(dm, t);
float maxFace = dm.x - dm.y;
float3 p = eye + maxT * ray;
dm += step(lo, p) * step(p, hi);
float hit = step(0.5, dm.x * dm.y * dm.z);
return float3(maxT, maxFace, hit);
}
float4 castRay(float3 eye, float3 ray, float2 center)
{
float2 block = floor(eye.xy);
float3 ri = 1.0 / ray;
float3 rs = sign(ray);
float3 side = 0.5 + 0.5 * rs;
float2 ris = ri.xy * rs.xy;
float2 dis = (block - eye.xy + 0.5 + rs.xy * 0.5) * ri.xy;
float4 result = float4(100.0, 0.0, 0.0, 1.0);
[loop]
for (int i = 0; i < 16; ++i)
{
float2 hb = wrapCell(block);
float d = dot(block - center, CAM_DIR.xy);
float height = 3.0 * hash1(hb) - 1.0 + 1.5 * d - 0.1 * d * d;
float2 lo0 = block;
float2 loX = float2(0.45, 0.45);
float2 hi0 = block + 0.55;
float2 hiX = float2(0.45, 0.45);
float dist = 500.0;
float face = 0.0;
{
float4 signHash = signParams(hb);
float2 sc = float2(0.2, -0.4) + float2(0.6, -0.8) * signHash.xy;
float width = 0.06 + 0.1 * signHash.w;
float3 lo = float3(sc.x - width, 0.55, -100.0);
float3 hi = float3(sc.x + width, 0.99, sc.y + width + height);
float s = step(0.5, signHash.z);
lo = float3(block, 0.0) + lerp(lo, lo.yxz, s);
hi = float3(block, 0.0) + lerp(hi, hi.yxz, s);
float3 h = boxHit(eye, ri, ray, side, lo, hi);
if (h.z > 0.5 && h.x < dist)
{
dist = h.x;
face = h.y;
}
}
[unroll]
for (int j = 0; j < 5; ++j)
{
float top = height - 0.4 * float(j);
float3 lo = float3(lo0 + loX * hash2(hb, float(j)), -100.0);
float3 hi = float3(hi0 + hiX * hash2(hb, float(j) + 0.5), top);
float3 h = boxHit(eye, ri, ray, side, lo, hi);
if (h.z > 0.5 && h.x < dist)
{
dist = h.x;
face = h.y;
}
}
if (dist < 400.0)
{
result = float4(dist, height, face, 1.0);
break;
}
float2 stepDim = step(dis.xy, dis.yx);
dis += stepDim * ris;
block += stepDim * rs.xy;
}
return result;
}
float3 window(float z, float2 pos, float2 id, float px)
{
float windowSize = 0.03 + 0.12 * hash1(id + 0.1);
float windowProb = 0.3 + 0.8 * hash1(id + 0.2);
float depth = z / windowSize;
float lv = floor(depth);
float3 colorA = lerp(WINDOW_A, WINDOW_B, hash3(id));
float3 colorB = lerp(WINDOW_A, WINDOW_B, hash3(id + 0.1));
float3 color = lerp(colorA, colorB, hash1(id, lv));
float noise = vnoise(20.0 * pos + 100.0 * hash1(lv));
float ne = clamp(10.0 * px, 0.015, 0.08);
color *= 0.15 + 0.95 * smoothstep(0.33 - ne, 0.33 + ne, noise);
float onOff = step(0.08, hash1(id, lv + 0.3 + floor(time * 0.15)));
color *= step(windowProb, hash1(id, lv + 0.1)) * onOff;
float f = depth - lv;
float wa = clamp(0.7 * px / windowSize, 0.02, 0.25);
float windowGlow = smoothstep(0.10, 0.10 + 2.0 * wa, f)
* (1.0 - smoothstep(0.90 - 2.0 * wa, 0.90, f));
return color * (0.85 * windowGlow);
}
float3 addLight(float3 eye, float3 ray, float res, float tm, float height)
{
float2 q = eye.xy + ((height - eye.z) / ray.z) * ray.xy;
float row = floor(q.x + 0.5);
float rowH = row - 512.0 * floor(row / 512.0);
tm += hash1(rowH);
float col = floor(0.125 * q.y - tm);
float colH = col - 64.0 * floor(col / 64.0);
float pos = 0.4 + 0.4 * cos(tm + TAU * hash1(float2(rowH, colH)));
float3 lightPos = float3(row, 8.0 * (col + tm + pos), height);
float3 lightDir = float3(0.0, 1.0, 0.0);
float3 w = eye - lightPos;
float a = dot(ray, ray);
float b = dot(ray, lightDir);
float c = dot(lightDir, lightDir);
float d = dot(ray, w);
float e = dot(lightDir, w);
float D = a * c - b * b;
float s = (b * e - c * d) / D;
float t = (a * e - b * d) / D;
t = max(t, 0.0001);
float dist = distance(eye + s * ray, lightPos + t * lightDir);
float mask = 1.0 - smoothstep(res, res + 0.12, s);
float light = min(1.0 / pow(160.0 * dist * dist / t + 14.0 * t * t, 0.75), 2.6);
float shaft = 0.35 * exp(-1.8 * dist) * saturate(1.0 - t * 0.15);
float fog = exp(-FOG_DENSITY * max(s - FOG_OFFSET, 0.0));
float3 color = lerp(LIGHT_A, LIGHT_B, hash3(float2(rowH, colH)));
return (mask * light + lerp(LIGHT_HIDDEN_GLOW, 1.0, mask) * shaft) * fog * color;
}
#define SEG(x0, y0, x1, y1) gd = min(gd, segDist(gq, float2(x0, y0), float2(x1, y1)))
float segDist(float2 p, float2 a, float2 b)
{
float2 pa = p - a;
float2 ba = b - a;
float h = saturate(dot(pa, ba) / max(dot(ba, ba), 0.0001));
return length(pa - ba * h);
}
float hanGlyph(float gi, float2 gq, float gpx)
{
float gd = 100.0;
if (abs(gi - 4.0) < 0.5)
gi = 1.0;
if (gi < 0.5)
{
SEG(2.5, 3.6, 13.5, 3.6);
SEG(5.8, 1.5, 5.8, 5.4);
SEG(10.2, 1.5, 10.2, 5.4);
SEG(3.0, 6.6, 13.0, 6.6);
SEG(4.5, 6.6, 4.5, 11.4);
SEG(11.5, 6.6, 11.5, 11.4);
SEG(8.0, 6.6, 8.0, 11.4);
SEG(4.5, 9.0, 11.5, 9.0);
SEG(4.5, 11.4, 11.5, 11.4);
SEG(6.5, 11.4, 3.0, 14.5);
SEG(9.5, 11.4, 13.0, 14.5);
}
else if (gi < 1.5)
{
SEG(3.2, 2.6, 5.0, 4.0);
SEG(2.4, 6.6, 4.4, 8.0);
SEG(2.2, 13.4, 5.4, 9.6);
SEG(10.5, 1.8, 10.5, 10.5);
SEG(8.0, 4.4, 6.8, 6.8);
SEG(13.0, 4.4, 14.0, 6.8);
SEG(13.5, 8.0, 7.5, 14.5);
}
else if (gi < 2.5)
{
SEG(9.0, 3.0, 12.0, 6.5);
}
else if (gi < 3.5)
{
SEG(4.5, 1.8, 12.5, 1.8);
SEG(4.5, 1.8, 4.5, 7.4);
SEG(12.5, 1.8, 12.5, 7.4);
SEG(4.5, 4.6, 12.5, 4.6);
SEG(4.5, 7.4, 12.5, 7.4);
SEG(2.5, 9.6, 13.5, 9.6);
SEG(8.2, 7.4, 8.2, 12.4);
SEG(8.2, 11.6, 3.0, 14.6);
SEG(8.2, 11.6, 13.5, 14.6);
}
else if (gi < 5.5)
{
SEG(2.5, 1.8, 13.5, 1.8);
SEG(2.5, 1.8, 2.5, 5.2);
SEG(13.5, 1.8, 13.5, 5.2);
SEG(2.5, 5.2, 13.5, 5.2);
SEG(6.2, 1.8, 6.2, 5.2);
SEG(9.8, 1.8, 9.8, 5.2);
SEG(5.0, 6.8, 2.8, 9.0);
SEG(2.8, 9.0, 5.6, 9.0);
SEG(5.6, 9.0, 3.2, 11.2);
SEG(4.2, 11.0, 4.2, 14.6);
SEG(2.6, 12.4, 3.4, 13.4);
SEG(5.8, 12.4, 5.0, 13.4);
SEG(11.8, 6.6, 9.4, 8.0);
SEG(11.2, 6.8, 11.2, 14.6);
SEG(9.2, 9.4, 13.8, 9.4);
SEG(9.2, 11.2, 13.8, 11.2);
SEG(9.2, 13.0, 13.8, 13.0);
SEG(8.0, 8.4, 7.2, 10.6);
SEG(7.7, 9.6, 7.7, 14.6);
}
else if (gi < 6.5)
{
SEG(3.0, 3.2, 13.0, 3.2);
SEG(8.0, 1.5, 8.0, 5.0);
SEG(4.8, 5.0, 11.2, 5.0);
SEG(4.8, 5.0, 4.8, 7.3);
SEG(11.2, 5.0, 11.2, 7.3);
SEG(4.8, 7.3, 11.2, 7.3);
SEG(4.5, 8.8, 11.5, 8.8);
SEG(4.5, 8.8, 4.5, 12.4);
SEG(11.5, 8.8, 11.5, 12.4);
SEG(4.5, 12.4, 11.5, 12.4);
SEG(4.5, 10.6, 11.5, 10.6);
SEG(6.5, 12.4, 3.8, 14.6);
SEG(9.5, 12.4, 12.2, 14.6);
}
else if (gi < 7.5)
{
SEG(3.6, 3.6, 7.0, 3.6);
SEG(5.3, 2.0, 5.3, 6.8);
SEG(2.8, 6.8, 7.8, 6.8);
SEG(5.3, 6.8, 5.3, 10.0);
SEG(5.3, 10.0, 2.8, 12.4);
SEG(3.2, 13.4, 13.8, 13.4);
SEG(8.5, 4.6, 13.8, 4.6);
SEG(8.8, 7.2, 13.8, 7.2);
SEG(12.0, 2.2, 12.0, 11.0);
SEG(12.0, 11.0, 10.6, 12.0);
SEG(10.2, 2.8, 8.8, 10.8);
SEG(13.0, 3.0, 13.8, 3.8);
}
else
{
SEG(2.5, 3.0, 13.5, 3.0);
SEG(8.0, 1.5, 8.0, 6.0);
SEG(3.5, 6.0, 12.5, 6.0);
SEG(3.5, 6.0, 3.5, 14.5);
SEG(12.5, 6.0, 12.5, 14.5);
SEG(5.5, 8.2, 10.5, 8.2);
SEG(8.0, 6.0, 8.0, 8.2);
SEG(5.5, 10.4, 10.5, 10.4);
SEG(5.5, 10.4, 5.5, 13.2);
SEG(10.5, 10.4, 10.5, 13.2);
SEG(5.5, 13.2, 10.5, 13.2);
SEG(8.0, 8.2, 8.0, 13.2);
}
float r = max(0.85, 0.8 * gpx);
float e = max(0.4 * gpx, 0.05);
return 1.0 - smoothstep(r - e, r + e, gd);
}
float3 addSign(float3 color, float3 pos, float side, float2 id, float tw, float px)
{
float4 signHash = signParams(id);
float s = step(0.5, signHash.z);
if ((s - 0.5) * side < 0.1)
return color;
float2 center = float2(0.2, -0.4) + float2(0.6, -0.8) * signHash.xy;
float2 p = lerp(pos.xz, pos.yz, s);
float isText = step(abs(id.x - TEXT_CELL.x) + abs(id.y - TEXT_CELL.y), 0.5);
float halfWidth = lerp(0.04 + 0.06 * signHash.w, 0.85 * (0.06 + 0.1 * signHash.w), isText);
float charCount = lerp(floor(1.0 + 8.0 * hash1(id + 0.5)), 9.0, isText);
float second = 0.0;
if (center.y - p.y > 2.0 * halfWidth * (charCount + 1.0))
{
second = 1.0;
center.y -= 2.0 * halfWidth * (charCount + 1.5 + 5.0 * hash1(id + 0.6));
charCount = floor(2.0 + 12.0 * hash1(id + 0.7));
id += 0.05;
}
float3 signColor = lerp(SIGN_A, SIGN_B, hash3(id + 0.5)) * (1.0 + 0.6 * beat);
float3 outlineColor = lerp(SIGN_A, SIGN_B, hash3(id + 0.6));
float flash = 6.0 - 24.0 * hash1(id + 0.8);
flash *= step(3.0, flash);
float beatFlick = 1.0 + 2.5 * beat;
flash = smoothstep(0.1, 0.5, 0.5 + 0.5 * cos(flash * tw * beatFlick));
float useText = isText * (1.0 - second);
flash = lerp(flash, 1.0, useText);
float2 halfSize = float2(halfWidth, halfWidth * charCount);
float tpx = px / halfWidth;
center.y -= halfSize.y;
float outline = length(max(abs(p - center) - halfSize, 0.0)) / halfWidth;
color *= smoothstep(0.1, 0.1 + max(0.1, 2.0 * tpx), outline);
float2 charPos = 0.5 * (p - center + halfSize) / halfWidth;
float2 cell = floor(charPos);
float2 charId = id + 0.05 + 0.1 * floor(charPos);
float flicker = hash1(charId);
flicker = step(0.93, flicker);
flicker = 1.0 - flicker * step(0.96, hash1(charId, tw));
flicker = lerp(flicker, 1.0, useText);
float charBright = 0.7 + 0.3 * sin(tw * (1.5 + 3.0 * hash1(charId + 0.2)) + hash1(charId) * TAU);
float glyph = -3.5 + 8.0 * vnoise(id + 6.0 * charPos);
charPos = frac(charPos);
float ca = max(0.04, 0.6 * tpx);
glyph *= smoothstep(0.15, 0.15 + 2.0 * ca, charPos.x) * (1.0 - smoothstep(0.85 - 2.0 * ca, 0.85, charPos.x));
glyph *= smoothstep(0.15, 0.15 + 2.0 * ca, charPos.y) * (1.0 - smoothstep(0.85 - 2.0 * ca, 0.85, charPos.y));
if (useText > 0.5)
{
float gx = lerp(1.0 - charPos.x, charPos.x, s);
glyph = hanGlyph(charCount - 1.0 - cell.y, float2(gx, 1.0 - charPos.y) * 16.0, 8.0 * tpx);
}
color = lerp(color, signColor * charBright, flash * flicker * step(outline, 0.01) * clamp(glyph, 0.0, 1.0));
float fa0 = 0.08;
float fa1 = max(0.46, fa0 + 2.2 * tpx);
float fe = max(0.03, 0.5 * tpx);
outline = smoothstep(fa0 - fe, fa0 + fe, outline) * (1.0 - smoothstep(fa1 - fe, fa1 + fe, outline));
return lerp(color, outlineColor, flash * outline);
}
float gmod(float x, float y)
{
return x - y * floor(x / y);
}
float3 trackMin(float3 v, float d)
{
if (d < v.x) v = float3(d, v.x, v.y);
else if (d < v.y) v = float3(v.x, d, v.y);
else if (d < v.z) v = float3(v.x, v.y, d);
return v;
}
float4 butterfly(float2 p, float aa)
{
p.x = abs(p.x) + 0.00001;
p.y *= 0.9;
float4 col = float4(0.0, 0.0, 0.0, 0.0);
float a = atan2(p.x, p.y);
float r = length(p);
if (p.y < 0.0)
{
float f = 0.6 + 0.01 * sin(24.0 * a);
float w = 1.1 * a - 0.8;
f *= sin(w) * sin(w);
float th = f + 0.001;
float th2 = th;
float3 wcol = lerp(float3(210.0, 119.0, 40.0) / 255.0,
float3(232.0, 79.0, 12.0) / 255.0, smoothstep(0.0, 0.7, r));
wcol *= 1.5;
wcol *= 1.0 + 0.1 * sin(17.0 * p.x + float3(0.0, 0.0, 4.0))
* sin(23.0 * p.y + float3(0.0, 0.0, 4.0));
float2 q = p;
q.xy += 0.02 * sin(q.yx * 12.0);
q.y = min(q.y, 0.0);
float3 v = float3(10.0, 10.0, 10.0);
v = trackMin(v, length(q - float2(0.29, -0.20)));
v = trackMin(v, length(q - float2(0.10, -0.30)));
v = trackMin(v, length(q - float2(0.20, -0.26)));
v = trackMin(v, length(q - float2(0.28, -0.29)));
v = trackMin(v, length(q - float2(0.34, -0.27)));
v = trackMin(v, length(q - float2(0.38, -0.24)));
v = trackMin(v, length(q - float2(0.39, -0.20)));
v = trackMin(v, length(q - float2(0.38, -0.15)));
v = trackMin(v, length(q - float2(0.35, -0.08)));
v.y -= v.x;
v.z -= v.x;
float g = 1.25 * v.y * v.z / max(v.y + v.z, 0.001);
wcol *= smoothstep(0.0, max(0.01, aa), g);
th -= 0.05 * (1.0 - smoothstep(0.0, 0.05, g)) - 0.02;
wcol *= smoothstep(max(0.02, aa * 0.8), max(0.03, aa * 1.6), (th - r) * th);
q = float2(gmod(a, 0.2) - 0.1, (r - th + 0.025) * 3.1415 * 0.5);
float d = length(q) - max(0.015, aa * 1.1);
wcol = lerp(wcol, float3(1.0, 1.0, 1.0), 1.0 - smoothstep(0.0, max(0.005, aa), d));
wcol *= smoothstep(0.01, max(0.03, aa * 1.2), length(p - float2(0.235, -0.2)));
d = r - (th + th2) * 0.5;
col = float4(wcol, smoothstep(0.0, 2.0 * aa, -d));
}
if (a < 2.2)
{
float f = 0.65 + 0.015 * sin(24.0 * a);
float w = a * (3.1416 / 2.356);
float th = f * sin(w) * sin(w) + 0.001;
float th2 = th;
th += 0.25 * exp2(-50.0 * (w - 1.4) * (w - 1.4));
float3 wcol = lerp(float3(0.7, 0.5, 0.2),
float3(0.8, 0.2, 0.0), smoothstep(0.0, 1.0, r));
wcol *= 1.4;
wcol *= 1.0 + 0.1 * sin(13.0 * p.x + float3(0.0, 0.0, 4.0))
* sin(19.0 * p.y + float3(0.0, 0.0, 4.0));
float3 v = float3(10.0, 10.0, 10.0);
v = trackMin(v, length(p - float2(0.25, 0.2)));
v = trackMin(v, length(p - float2(0.35, 0.0)));
v = trackMin(v, length(p - float2(0.4, 0.1)));
v = trackMin(v, length(p - float2(0.45, 0.2)));
v = trackMin(v, length(p - float2(0.45, 0.3)));
v.y -= v.x;
v.z -= v.x;
float g = 2.0 * v.y * v.z / max(v.y + v.z, 0.001);
wcol *= smoothstep(0.0, max(0.02, aa * 1.5), g);
th2 -= 0.05 * (1.0 - smoothstep(0.0, 0.05, g));
float isblack = smoothstep(max(0.02, aa * 0.8), max(0.03, aa * 1.6), (th2 - r) * th2);
float2 q = float2(gmod(a, 0.2) - 0.1, (r - th + 0.025) * 3.1415 * 0.5);
float d = length(q) - max(0.015, aa * 1.1);
float ww = 1.0 - smoothstep(0.0, max(0.01, aa), d);
if (r > th2)
{
float cells = 9.0;
float2 cp = p * cells;
float2 qq = frac(cp) - 0.5;
float2 iq = floor(cp);
float cid = iq.x * 111.0 + iq.y * 13.0;
qq += 0.25 * sin(cid * float2(15.0, 17.0) + float2(0.0, 2.0));
float rr = 1.0 + 0.75 * sin(cid * 431.0);
ww = max(ww, 1.0 - smoothstep(0.0, max(0.01, aa * cells), length(qq) - 0.25 * rr));
}
wcol = lerp(wcol, float3(ww, ww, ww), 1.0 - isblack);
d = r - th;
float al = smoothstep(0.0, 2.0 * aa, -d);
col.xyz = lerp(col.xyz, wcol, al);
col.w = 1.0 - (1.0 - col.w) * (1.0 - al);
}
return col;
}
float2 wingPl(float2 p, float wing)
{
float an = 1.55 * (0.5 - 0.5 * cos(12.566371 * wing));
return float2(sign(p.x) * sin(an), -cos(an));
}
float2 proj(float2 p, float wing)
{
float2 pl = wingPl(p, wing);
float3 ro = float3(0.0, 0.085, 2.1);
float3 rd = float3(p.x, p.y, -3.0);
float den = dot(rd.xz, pl);
den = (abs(den) < 0.001) ? 0.001 : den;
float3 pos = ro - rd * (dot(ro.xz, pl) / den);
return float2(length(pos.xz), pos.y);
}
float3 flyPathT(float t)
{
float th = FLY_OMEGA * t + 0.9 * sin(0.21 * t + 1.0) + 0.4 * sin(0.53 * t);
float fx = FLY_AX * (1.0 + 0.25 * sin(0.17 * t + 2.0)) * (sin(th) + 0.12 * sin(1.3 * t + 0.7));
float fn = FLY_AZ * (cos(th) + 0.18 * sin(0.8 * t + 2.0) + 0.5 * sin(0.29 * t + 4.0));
float rise = 0.8 * sin(0.31 * t + 0.8 * sin(0.13 * t)) + 0.3 * sin(0.77 * t + 2.0) + 0.2 * sin(1.37 * t + 5.0);
fx += 0.30 * sin(2.3 * t + 1.0);
fn += 0.25 * sin(1.9 * t + 3.0);
rise += 0.05 * sin(2.7 * t + 0.5);
return float3(fx, fn, FLY_RISE * rise);
}
float flapPhase(float t)
{
float ft = gmod(t, 4.0);
return FLAP_RATE * ft + 0.15 * sin(TAU * ft / 4.0) + 0.06 * sin(3.0 * TAU * ft / 4.0 + 1.0);
}
float flapAmp(float t)
{
float g = sin(0.37 * t) * sin(0.23 * t + 1.0) + 0.35 * sin(0.83 * t + 2.0);
return lerp(0.2, 1.0, smoothstep(-0.3, 0.5, g));
}
float flapPose(float t)
{
return lerp(0.35, cos(12.566371 * flapPhase(t)), flapAmp(t));
}
float3 flyPath(float t)
{
float phi = 12.566371 * flapPhase(t);
float surge = flapAmp(t) * FLAP_SURGE * cos(phi) / (12.566371 * FLAP_RATE);
return flyPathT(FLY_SPEED * t + surge);
}
float3 flyDrift(float t)
{
float3 fwd = normalize(CAM_DIR);
float3 rgt = normalize(cross(fwd, float3(0.0, 0.0, 1.0)));
float3 upv = cross(rgt, fwd);
float3 vrel = float3(CITY_SPEED * CAM_DIR.x, CITY_SPEED * CAM_DIR.y, 0.0);
float tau = gmod(t, FLY_EPOCH) - 0.5 * FLY_EPOCH;
return FLY_LAG * tau * float3(dot(vrel, rgt), dot(vrel, upv), dot(vrel, fwd));
}
float flyExit(float t)
{
float tau = gmod(t, FLY_EPOCH) - 0.5 * FLY_EPOCH;
return FLY_EXIT * sign(tau) * smoothstep(0.25 * FLY_EPOCH, 0.5 * FLY_EPOCH, abs(tau));
}
float4 flyScreen(float t, float prob)
{
float3 f = flyPath(t);
float3 dr = flyDrift(t);
float depth = max(FLY_D0 - f.y + dr.z, 3.0);
float xf = 0.5 + 0.5 * (f.x + dr.x) / (depth * VIEW_TAN);
float barH = 2.0 * VIEW_TAN * depth * size.y / size.x;
float lift = FLAP_LIFT * (1.0 + 0.5 * beat) * flapAmp(t) * cos(12.566371 * flapPhase(t));
float yb = f.z + lift - 0.10 * f.y / FLY_AZ + dr.y / barH;
float sizeVar = 1.0 + FLY_SIZE_VAR * (0.6 * sin(0.53 * t + 1.0) + 0.4 * sin(1.31 * t + 2.0)) + 0.04 * beat;
float k = FLY_K * FLY_DNEAR / depth * sizeVar;
return float4(xf, yb, depth, k);
}
float flyHeading(float t, float depth)
{
const float e = 0.3;
float3 a = flyPathT(FLY_SPEED * (t - e));
float3 b = flyPathT(FLY_SPEED * (t + e));
float3 fwd = normalize(CAM_DIR);
float3 rgt = normalize(cross(fwd, float3(0.0, 0.0, 1.0)));
float3 upv = cross(rgt, fwd);
float3 vrel = float3(CITY_SPEED * CAM_DIR.x, CITY_SPEED * CAM_DIR.y, 0.0);
float3 dv = (1.0 - FLY_LAG) * 2.0 * e * float3(dot(vrel, rgt), dot(vrel, upv), dot(vrel, fwd));
float barH = 2.0 * VIEW_TAN * max(depth, 3.0) * size.y / size.x;
float farV = -(b.y - a.y - dv.z)
+ (b.z - a.z + dv.y / barH) * FLY_VK / FLY_FORESHORT;
return atan2(farV, b.x - a.x + dv.x);
}
float4 drawButterfly(float2 lp, float dp, float psi, float wing)
{
float cs = cos(psi);
float sn = sin(psi);
float2 pw = float2(lp.x, lp.y / FLY_FORESHORT);
float u = pw.x * cs + pw.y * sn;
float v = -pw.x * sn + pw.y * cs;
float2 p = float2(-v, u - 0.22);
float2 pl = wingPl(p, wing);
float2 q = proj(p, wing);
float2 qx = proj(p + float2(sn, cs) * dp, wing);
float2 qy = proj(p + float2(-cs, sn) * (dp / FLY_FORESHORT), wing);
float aa = clamp(length(qx - q) + length(qy - q), 0.004, 0.25);
q = float2(min(q.x, 4.0), clamp(q.y, -4.0, 4.0));
float4 tmp = saturate(butterfly(q, aa));
tmp.xyz *= 0.1 + 0.9 * lerp(1.0, abs(q.y) * 0.5 + min(q.x * 2.0, 1.0), pl.x * pl.x);
tmp.xyz *= saturate(0.25 + 0.75 * (pl.x - pl.y + 1.0));
return tmp;
}
float calcSight(float tt, float prob, float hueShift)
{
float sightEpoch = floor(tt / FLY_SIGHTING_PERIOD);
float sightPhase = gmod(tt, FLY_SIGHTING_PERIOD);
float sightRoll = hash1(gmod(sightEpoch, 512.0) + 19.73 + hueShift);
float maxStart = max(FLY_SIGHTING_PERIOD - FLY_SIGHTING_LENGTH_MAX - 1.0, 1.0);
float sightStart = hash1(gmod(sightEpoch, 512.0) + 31.17 + hueShift) * maxStart;
float sightLen = lerp(FLY_SIGHTING_LENGTH_MIN, FLY_SIGHTING_LENGTH_MAX,
hash1(gmod(sightEpoch, 512.0) + 43.91 + hueShift));
return step(sightRoll, prob)
* smoothstep(sightStart, sightStart + FLY_SIGHTING_FADE, sightPhase)
* (1.0 - smoothstep(sightStart + sightLen - FLY_SIGHTING_FADE,
sightStart + sightLen, sightPhase));
}
float4 butterflyLayer(float2 uv, float tt, float prob, float sizeMul, float hueShift)
{
float bh = size.y;
float4 fl = flyScreen(tt, prob);
float sight = calcSight(tt, prob, hueShift);
float dp = BF_S / (fl.w * sizeMul) / bh;
float2 lp = float2((uv.x - fl.x) * size.x, (0.5 - uv.y - fl.y) * bh) * dp;
float rl = length(lp);
if (rl >= 1.85 || sight < 0.001)
return float4(0.0, 0.0, 0.0, 0.0);
float amp = flapAmp(tt);
float phase = flapPhase(tt);
float hdg = flyHeading(tt, fl.z);
float hdgPrev = flyHeading(tt - 0.5, fl.z);
float bank = clamp((hdg - hdgPrev) * 1.5, -0.3, 0.3);
float psi = hdg + bank
+ 0.08 * amp * sin(12.566371 * phase)
+ 0.12 * sin(1.1 * tt + 0.5);
float wing = acos(clamp(flapPose(tt), -1.0, 1.0)) / 12.566371;
float4 bw = drawButterfly(lp, dp, psi, wing);
float nearness = saturate((12.0 - fl.z) / 6.0);
float edgeBoost = lerp(1.0, 1.3, nearness);
bw.xyz = pow(max(bw.xyz, 0.0), 1.0 / edgeBoost) * edgeBoost;
float blum = dot(bw.xyz, float3(0.3, 0.59, 0.11));
float hueMix = 0.5 + 0.5 * sin(0.7 * tt + hueShift + 2.0 * lp.y + 1.2 * lp.x);
float3 neonCol = lerp(float3(0.10, 0.90, 1.00), float3(1.00, 0.15, 0.85), hueMix);
float3 glow = neonCol * (0.35 + 1.2 * blum);
glow += float3(1.0, 1.0, 1.0) * smoothstep(0.8, 1.0, blum) * 0.35;
bw.xyz = saturate(glow * (1.0 + 0.25 * level + 0.4 * beat));
float fogB = exp(-0.15 * max(fl.z - FOG_OFFSET, 0.0));
bw.xyz = lerp(FOG_COLOR * 1.5, bw.xyz, 0.5 + 0.5 * fogB);
bw.w *= 1.0 - smoothstep(1.55, 1.8, rl);
bw.w *= sight;
if (bw.w > 0.05)
{
float4 flTrail = flyScreen(tt - 0.06, prob);
float2 lpT = float2((uv.x - flTrail.x) * size.x, (0.5 - uv.y - flTrail.y) * bh) * dp;
float rlT = length(lpT);
float trailA = (1.0 - smoothstep(0.5, 1.1, rlT)) * 0.14 * sight * bw.w;
bw.xyz = lerp(neonCol * 0.55, bw.xyz, saturate(bw.w / max(bw.w + trailA, 0.001)));
bw.w = 1.0 - (1.0 - bw.w) * (1.0 - trailA);
}
return bw;
}
float4 dustLayer(float2 uv, float tt, float prob, float sizeMul, float hueShift)
{
float bh = size.y;
float4 fl = flyScreen(tt, prob);
float sight = calcSight(tt, prob, hueShift);
if (sight < 0.001)
return float4(0.0, 0.0, 0.0, 0.0);
float dyu = uv.y - (0.5 - fl.y);
if (abs(fl.y) > 3.3 || abs(uv.x - fl.x) > 0.3 || dyu < -0.55 || dyu > 1.0)
return float4(0.0, 0.0, 0.0, 0.0);
float dp = BF_S / (fl.w * sizeMul) / bh;
float2 lp = float2((uv.x - fl.x) * size.x, (0.5 - uv.y - fl.y) * bh) * dp;
float tw = gmod(tt, DUST_DT * 2048.0);
float id0 = floor(tw / DUST_DT);
float ph0 = tw / DUST_DT - id0;
float3 pm = float3(0.0, 0.0, 0.0);
float aw = 0.0;
float beatBoost = 1.0 + 0.25 * level + 0.35 * beat;
[loop]
for (int k = 0; k < DUST_N; ++k)
{
float a = (ph0 + float(k)) * DUST_DT;
float pid = gmod(id0 - float(k), 2048.0);
float tk = tt - a;
float2 hA = hash2(float2(pid, 3.7), 0.9);
float2 hB = hash2(float2(pid, 8.1), 2.3);
float emit = step(hB.y, 0.28 + 0.55 * flapAmp(tk));
if (emit < 0.5)
continue;
float4 se = flyScreen(tk, prob);
float ang = hA.x * TAU;
float2 eo = float2(cos(ang), sin(ang)) * (sqrt(hA.y) * 0.7);
float2 pp = float2((se.x - fl.x) * size.x, (se.y - fl.y) * bh) * dp + eo;
float upChance = step(0.88, hB.y);
float fall = (0.55 + 0.55 * hB.x) * a * a / (1.0 + 1.1 * a);
pp.y -= fall * (1.0 - 1.7 * upChance);
pp.x += (hB.y - 0.5) * 0.5 * (1.0 - exp(-1.2 * a));
pp.x += 0.025 * sin(1.7 * a + ang * 4.0 + pid) * min(a, 0.7);
pp.y += 0.01 * sin(2.1 * a + pid * 0.7) * min(a, 0.5);
float sizeVar = 0.45 + 1.1 * hA.y;
float rad = sizeVar * dp;
float2 dlt = lp - pp;
float d2 = dot(dlt, dlt);
if (d2 > rad * rad * 20.0)
continue;
float d = sqrt(d2);
float core = 1.0 - smoothstep(rad * 0.4, rad * 1.3, d);
float halo = (0.18 + 0.14 * hA.y) * (1.0 - smoothstep(0.0, rad * (3.0 + 2.0 * hA.y), d));
float life = saturate(1.0 - a / DUST_LIFE);
float fade = life * life * smoothstep(0.0, 0.12, a);
float twk = 0.78 + 0.22 * sin(9.0 * a + 40.0 * hA.x + hB.y * 6.0);
float w = saturate((core + halo) * fade * twk);
float hueMix = 0.5 + 0.5 * sin(0.7 * tk + hueShift + 6.0 * hB.x);
float3 dcol = lerp(float3(0.10, 0.90, 1.00), float3(1.00, 0.15, 0.85), hueMix);
float3 deathCol = float3(0.75, 0.15, 0.85);
dcol = lerp(deathCol, dcol, life * 0.85 + 0.15);
dcol = lerp(dcol, float3(1.0, 1.0, 1.0), 0.40 * core) * beatBoost;
pm += dcol * w;
aw = 1.0 - (1.0 - aw) * (1.0 - w);
}
float alpha = aw * sight;
return float4(saturate(pm / max(aw, 0.001)), alpha);
}
float4 main(float2 uv : TEXCOORD) : COLOR
{
float tw = time - 4096.0 * floor(time / 4096.0);
float2 center = -CITY_SPEED * time * CAM_DIR.xy;
center -= 512.0 * floor(center / 512.0);
float3 eye = float3(center, 0.0) - CAM_DIST * CAM_DIR;
float3 forward = normalize(CAM_DIR);
float3 right = normalize(cross(forward, float3(0.0, 0.0, 1.0)));
float3 up = cross(right, forward);
float2 xy = float2(2.0 * uv.x - 1.0, (1.0 - 2.0 * uv.y) * size.y / size.x) * VIEW_TAN
+ float2(0.0, VIEW_SHIFT);
float3 ray = normalize(xy.x * right + xy.y * up + forward);
float4 res = castRay(eye, ray, center);
float3 p = eye + res.x * ray;
float2 block = floor(p.xy);
float2 hb = wrapCell(block);
float2 pw = hb + (p.xy - block);
float px = 1.4 * res.x * (2.0 * VIEW_TAN / size.x);
float3 color = window(p.z - res.y, pw, hb, px);
float specX = saturate((p.z - SPEC_Z0) / (SPEC_Z1 - SPEC_Z0) + SPEC_JITTER * (hash1(hb + 0.9) - 0.5));
float3 specCol = spectrum(specX);
float satBoost = 1.0 + 0.45 * length(specCol);
float gray = dot(color, float3(0.33, 0.33, 0.33));
color = lerp(float3(gray, gray, gray), color, satBoost);
color *= SPEC_MIN + SPEC_GAIN * specCol;
color = addSign(color, float3(p.xy - block, p.z - res.y), res.z, hb, tw, px);
color = lerp(float3(0.0, 0.0, 0.0), color, abs(res.z));
float heightFog = saturate((p.z + 2.0) / 8.0);
float3 fogCol = lerp(FOG_COLOR, float3(0.12, 0.18, 0.35), heightFog);
float fog = exp(-FOG_DENSITY * max(res.x - FOG_OFFSET, 0.0));
color = lerp(fogCol, color, fog);
float tl = LIGHT_SPEED * time;
float lightGain = 1.05 + 0.55 * level;
color += lightGain * addLight(eye.xyz, ray.xyz, res.x, tl, LIGHT_HEIGHT - 0.6);
color += lightGain * addLight(eye.yxz, ray.yxz, res.x, tl, LIGHT_HEIGHT - 0.4);
color += lightGain * addLight(float3(-eye.xy, eye.z), float3(-ray.xy, ray.z), res.x, tl, LIGHT_HEIGHT - 0.2);
color += lightGain * addLight(float3(-eye.yx, eye.z), float3(-ray.yx, ray.z), res.x, tl, LIGHT_HEIGHT);
color = saturate(color);
float lum = dot(color, float3(0.3, 0.59, 0.11));
float alpha = saturate(0.3 + 2.0 * lum);
float4 b2 = butterflyLayer(uv, time + FLY_B2_OFFSET, FLY_B2_PROB, FLY_B2_SIZE, 2.5);
float4 b1 = butterflyLayer(uv, time, 0.92, 1.0, 0.0);
float4 d2 = dustLayer(uv, time + FLY_B2_OFFSET, FLY_B2_PROB, FLY_B2_SIZE, 2.5);
float4 d1 = dustLayer(uv, time, 0.92, 1.0, 0.0);
float3 pre = d2.xyz * d2.w + color * alpha * (1.0 - d2.w);
alpha = d2.w + alpha * (1.0 - d2.w);
pre = d1.xyz * d1.w + pre * (1.0 - d1.w);
alpha = d1.w + alpha * (1.0 - d1.w);
pre = b2.xyz * b2.w + pre * (1.0 - b2.w);
alpha = b2.w + alpha * (1.0 - b2.w);
pre = b1.xyz * b1.w + pre * (1.0 - b1.w);
alpha = b1.w + alpha * (1.0 - b1.w);
color = pre / max(alpha, 0.001);
float bloomLum = dot(color, float3(0.3, 0.59, 0.11));
float3 bloom = color * smoothstep(0.55, 1.1, bloomLum) * 0.45;
color = saturate(color + bloom);
return paint(color, alpha);
}