Rice Terraces
by MusicBar, progress bar
Terraced rice hills in the morning haze, ripe gold up to the playhead where a farmer in a conical hat carries the harvest home and young green beyond, with wind waves rolling across the rice to the music and white egrets flying over.
How it installs, its SHA-256 and its code
Click Apply: MusicBar downloads it, checks its SHA-256 and puts it on the taskbar, or just puts it on if it already has it. Needs MusicBar 1.8 or newer.
SHA-256 9a3004d2d77640d6cee24627a9d4e0c66f1cb7d5a05ff92f47578c08ca89af56
//! name: Rice Terraces
//! author: MusicBar
//! kind: progress
//! description: Terraced rice hills step up through the morning haze, ripe gold up to the playhead where a farmer carries the harvest and young green beyond, the rice rippling in wind waves that follow the music.
float hash1(float n) { return frac(sin(n * 127.1 + 311.7) * 43758.5453); }
float hash2(float2 p) { return frac(sin(dot(p, float2(127.1, 311.7))) * 43758.5453); }
float vnoise(float2 p)
{
float2 i = floor(p), f = frac(p);
f = f * f * (3.0 - 2.0 * f);
return lerp(lerp(hash2(i), hash2(i + float2(1, 0)), f.x), lerp(hash2(i + float2(0, 1)), hash2(i + float2(1, 1)), f.x), f.y);
}
float sdSeg(float2 p, float2 a, float2 b) { float2 pa = p - a, ba = b - a; return length(pa - ba * saturate(dot(pa, ba) / dot(ba, ba))); }
float ellipse(float2 p, float2 r) { float k0 = length(p / r); return k0 * (k0 - 1.0) / max(length(p / (r * r)), 0.0001); }
// Lays a color over what is there (premultiplied light, and how much of the pixel it covers).
void layer(inout float3 acc, inout float cover, float3 rgb, float a)
{
a = saturate(a);
acc = rgb * a + acc * (1.0 - a);
cover = a + cover * (1.0 - a);
}
// A row of round hills, one per cell with its own height and width: the skyline over X, the height of the
// hill that makes it (so the terraces can follow that hill's curve) and where across that hill X is.
float3 hills(float X, float cellW, float seed, float hMin, float hMax)
{
float c = floor(X / cellW);
float3 best = float3(0.0, hMax, 0.0);
for (int i = -1; i <= 1; i++)
{
float ci = c + i;
float h = lerp(hMin, hMax, hash1(ci * 7.3 + seed));
float dx = (X - (ci + 0.5 + 0.3 * (hash1(ci * 5.7 + seed) - 0.5)) * cellW) / (cellW * (0.42 + 0.25 * hash1(ci * 3.1 + seed)));
float r = h * pow(saturate(1.0 - dx * dx), 0.5);
best = r > best.x ? float3(r, h, dx) : best;
}
return best;
}
// The terraced face of a hill: steps follow its curve down from the top; each is a field of rice with a
// bright bund at its lip and a dark wall below. The morning sun comes from the left.
float4 terraces(float X, float y, float3 hill, float bandH, float ripe, float gust, float aa)
{
float T = (y - hill.x) / bandH + 10.0; // steps counted down from the skyline
float f = frac(T);
float field = hash1(floor(T) * 3.7 + hill.y * 91.0); // each paddy ripens a little differently
float3 gold = lerp(float3(0.95, 0.7, 0.22), colorA.rgb, 0.4) * lerp(float3(1.05, 1.0, 0.9), float3(0.95, 0.98, 1.1), field);
float3 green = lerp(float3(0.36, 0.72, 0.26), colorB.rgb, 0.4) * (0.9 + 0.2 * field);
float3 crop = lerp(green, gold, ripe);
float tex = 0.78 + 0.3 * vnoise(float2(X * 55.0, T * 3.0)) * vnoise(float2(X * 9.0, T * 7.0 + 3.0));
float sun = 0.82 + 0.3 * saturate(0.5 - 0.6 * hill.z);
float3 col = crop * tex * sun * (0.55 + 0.45 * f) * (1.0 + gust);
col = lerp(col, lerp(float3(0.2, 0.25, 0.1), float3(0.32, 0.2, 0.08), ripe), smoothstep(0.2, 0.17, f));
col = lerp(col, crop * 1.25 + 0.15, smoothstep(aa / bandH * 1.2, 0.0, abs(f - 0.2)));
return float4(col, smoothstep(-aa, aa, hill.x - y) * step(0.0, y));
}
float4 main(float2 uv : TEXCOORD) : COLOR
{
float u = size.y;
float2 px = float2(uv.x * size.x, (1.0 - uv.y) * u); // pixels, y up the screen so the hills always stand
float head = progress * size.x;
float X = px.x / u;
float aa = 1.0 / u;
float d = (px.x - head) / u; // bar heights ahead of the playhead
float ripe = smoothstep(0.5, -0.5, d);
float3 acc = float3(0, 0, 0);
float cover = 0;
// Wind waves rolling across the rice, harder when the song is loud and with a gust on the beat.
float spec = spectrum(frac(X * 0.031) * 0.8);
float wind = sin(X * 2.4 - time * 3.0 + px.y / u * 2.0 + 0.8 * sin(X * 0.37 + time * 0.3));
float gust = (smoothstep(0.3, 1.0, wind) - 0.4 * smoothstep(-0.3, -1.0, wind)) * (0.2 + 0.3 * level + 0.4 * spec + 0.6 * beat);
// Far hills, pale in the haze, standing on the mist.
float yF = px.y / u - 0.22;
float3 hF = hills(X, 1.9, 17.0, 0.3, 0.6);
float4 far = terraces(X * 1.3, yF, hF, 0.075, ripe, gust * 0.5, aa);
layer(acc, cover, lerp(far.rgb, float3(0.86, 0.9, 0.92), 0.4), far.a * lerp(0.25, 0.5, ripe));
// Morning haze drifting between the hills.
float mist = vnoise(float2(X * 0.9 - time * 0.06, px.y / u * 2.5)) * 0.6 + vnoise(float2(X * 2.1 - time * 0.1, px.y / u * 5.0)) * 0.4;
float3 hazeC = lerp(float3(1.0, 0.97, 0.93), colorC.rgb, 0.2);
layer(acc, cover, hazeC, smoothstep(0.3, 0.8, mist) * exp(-pow((px.y / u - 0.3) / 0.16, 2.0)) * lerp(0.25, 0.4, ripe));
// The near hills, terraced from the footpath up.
float yN = px.y / u - 0.07;
float3 hN = hills(X + 1.1, 2.6, 3.0, 0.32, 0.68);
float4 near = terraces(X, yN, hN, 0.1, ripe, gust, aa);
layer(acc, cover, colorA.rgb * 0.1, smoothstep(-aa, aa, hN.x + 0.02 - yN) * step(0.0, yN) * lerp(0.2, 0.5, ripe));
layer(acc, cover, near.rgb, near.a * lerp(0.38, 0.95, ripe));
// Rice heads fringing each hilltop, swaying in the wind: heavy and gold on the played side.
float sway = 0.3 * wind * (0.4 + level);
float tx = frac(X * 40.0 + sway * (yN - hN.x) * 30.0);
float tuft = smoothstep(aa, -aa, yN - hN.x - 0.03 * (0.6 + 0.4 * sin(X * 23.0))) * step(hN.x - 0.005, yN) * step(abs(tx - 0.5), 0.3);
layer(acc, cover, lerp(lerp(float3(0.5, 0.85, 0.35), colorB.rgb, 0.4), lerp(float3(1, 0.82, 0.35), colorA.rgb, 0.4), ripe) * (1.0 + gust + 0.5 * beat), tuft * lerp(0.5, 0.95, ripe));
// The footpath along the bottom, and a soft mist along the foot of the hills.
layer(acc, cover, float3(0.45, 0.32, 0.2), smoothstep(aa, -aa, abs(px.y / u - 0.035) - 0.035) * lerp(0.3, 0.75, ripe));
layer(acc, cover, hazeC, exp(-px.y / u / 0.12) * smoothstep(0.2, 0.9, mist) * 0.25);
// White egrets flying over the fields, legs trailing, wings beating slowly.
float ec = floor((X - time * 0.3) / 6.5);
float eh = hash1(ec * 4.1 + 2.0);
float2 e = float2(X - time * 0.3 - (ec + 0.5 + 0.3 * (eh - 0.5)) * 6.5, px.y / u - (0.76 + 0.12 * eh) - 0.02 * sin(time * 1.5 + eh * 9.0));
float flap = sin(time * 4.5 + eh * 20.0);
float dEg = min(ellipse(e, float2(0.085, 0.022)), length(e - float2(0.085, 0.016)) - 0.019);
float dBill = sdSeg(e, float2(0.095, 0.016), float2(0.15, 0.008)) - 0.006;
float dEgLeg = sdSeg(e, float2(-0.05, -0.006), float2(-0.17, -0.014)) - 0.006;
float2 wa = e - float2(-0.01, 0.012), wb = float2(-0.07, 0.17 * flap);
float wh = saturate(dot(wa, wb) / dot(wb, wb));
float dWing = length(wa - wb * wh) - lerp(0.04, 0.008, wh);
float dBird = min(min(dEg, dWing), min(dBill, dEgLeg));
layer(acc, cover, float3(0.2, 0.22, 0.25), smoothstep(aa, -aa, dBird - aa * 1.2) * 0.8);
layer(acc, cover, float3(0.25, 0.22, 0.2), smoothstep(aa, -aa, dEgLeg));
layer(acc, cover, float3(1.0, 0.8, 0.25), smoothstep(aa, -aa, dBill));
layer(acc, cover, float3(0.97, 0.97, 0.95) * (0.8 + 0.2 * saturate(e.y / 0.03 + 0.5)), smoothstep(aa, -aa, min(dEg, dWing)));
// The farmer at the playhead: a conical hat, a shoulder pole bouncing with her steps, two baskets of golden rice.
float g = time * 5.0;
float bob = 0.015 * abs(sin(g));
float2 f = float2(px.x - head, px.y) / u - float2(0.0, 0.05 + bob);
float flex = 0.035 + 0.015 * sin(g * 2.0) + 0.06 * beat;
float poleY = 0.37 - flex * f.x * f.x / 0.07;
float dPole = max(abs(f.y - poleY) - 0.013, abs(f.x) - 0.3);
float bx = f.x < 0.0 ? -0.27 : 0.27;
float by = 0.14 - flex + 0.012 * sin(g * 2.0 + step(0.0, f.x) * 1.5);
float2 bq = f - float2(bx, by);
float dRope = max(abs(abs(bq.x) - 0.065 + bq.y * 0.25) - 0.006, max(bq.y - (poleY - by), -bq.y));
float dBasket = max(length(bq / float2(1.0, 0.6)) - 0.09, bq.y - 0.02);
float sheaf = max(abs(bq.x + 0.012 * sin(bq.y * 30.0 + g)) - 0.06 + bq.y * 0.3, max(-bq.y, bq.y - 0.1));
float lstep = 0.06 * sin(g);
float dLegs = min(sdSeg(f, float2(0.0, 0.17), float2(lstep, 0.0)), sdSeg(f, float2(0.0, 0.17), float2(-lstep, 0.0))) - 0.022;
float dBody = min(sdSeg(f, float2(0.0, 0.17), float2(0.01, 0.33)) - 0.05, length(f - float2(0.015, 0.39)) - 0.04);
float dArm = sdSeg(f, float2(0.01, 0.31), float2(0.1, poleY - 0.01)) - 0.017;
float2 hq = f - float2(0.015, 0.4);
float dHat = max((abs(hq.x) * 0.66 + hq.y - 0.11) * 0.83, -hq.y);
float dAll = min(min(min(dPole, dBasket), min(dLegs, dBody)), min(dHat, sheaf));
layer(acc, cover, float3(1.0, 0.95, 0.8), exp(-max(dAll, 0.0) / 0.08) * 0.22);
layer(acc, cover, float3(0.12, 0.08, 0.04), smoothstep(aa, -aa, min(min(dPole, dRope), dAll) - aa * 1.3) * 0.85);
layer(acc, cover, float3(0.55, 0.38, 0.2), smoothstep(aa, -aa, dRope));
layer(acc, cover, lerp(float3(1, 0.82, 0.35), colorA.rgb, 0.4) * (0.8 + 0.25 * sin(bq.x * 140.0)), smoothstep(aa, -aa, sheaf));
layer(acc, cover, float3(0.6, 0.43, 0.22) * (0.75 + 0.3 * step(0.5, frac(bq.y * 40.0))), smoothstep(aa, -aa, dBasket));
layer(acc, cover, float3(0.1, 0.09, 0.1), smoothstep(aa, -aa, dLegs));
float3 shirt = lerp(float3(0.42, 0.26, 0.2), colorC.rgb, 0.3) * (0.7 + 0.45 * saturate(f.x / 0.05 + 0.5));
layer(acc, cover, shirt, smoothstep(aa, -aa, min(dBody, dArm)));
layer(acc, cover, float3(0.85, 0.63, 0.45), smoothstep(aa, -aa, length(f - float2(0.035, 0.385)) - 0.028));
layer(acc, cover, float3(0.66, 0.5, 0.26), smoothstep(aa, -aa, dPole));
float3 hatC = float3(0.98, 0.92, 0.75) * (0.7 + 0.3 * saturate(hq.x / 0.2 + 0.6)) * (0.9 + 0.1 * step(0.5, frac(hq.y * 50.0)));
layer(acc, cover, hatC, smoothstep(aa, -aa, dHat));
return paint(acc / max(cover, 0.001), cover);
}