PulseCanvas / app · pulsecanvas.ai / Sources / PulseCanvas / Resources / NativeTunnels.metal
| 1 | // PulseCanvas native designs: tunnels (scenes 100–116). Original procedural code; see |
| 2 | // NativeCommon.metal. Every design is a pure function of its uniforms and every audio term |
| 3 | // is zero at zero Chaos. |
| 4 | |
| 5 | // ---------------------------------------------------------------- shared tunnel helpers |
| 6 | // Wrap an angle into [-π, π]. |
| 7 | float tnWrap(float a) { return a - TAU * floor(a / TAU + .5); } |
| 8 | // Smooth Lissajous drift for a vanishing point. |
| 9 | float2 tnDrift(float t, float2 amount) { |
| 10 | return float2(sin(t * .23) + .45 * sin(t * .37 + 2.1), sin(t * .19 + 1.3) + .45 * sin(t * .31 + .4)) / 1.45 * amount; |
| 11 | } |
| 12 | // Bent tube: near walls stay centred while far depths converge on the drifting vanishing |
| 13 | // point. The map is smooth and one-to-one for |vanish| < .5. |
| 14 | float2 tnBend(float2 uv, float2 vanish) { |
| 15 | float2 q = uv - vanish; |
| 16 | return uv - vanish / (1 + 2.5 * dot(q, q)); |
| 17 | } |
| 18 | // Depth fog with the Fog control. |
| 19 | float tnFog(float z, Ctx c, float base) { return exp(-z * (base + c.fog * .15)); } |
| 20 | // Normalized attack level: 0 when quiet, 1 on a strong attack. |
| 21 | float tnAttack(Ctx c) { return smoothstep(.04f, .7f, c.hit); } |
| 22 | |
| 23 | // ---------------------------------------------------------------- 100 Plasma Bore |
| 24 | // A round bore of boiling plasma. Domain-warped noise on the cylinder forms hot filaments |
| 25 | // and colour bands that slide down the curving tube. Bass thickens the near filaments, |
| 26 | // highs crackle on the walls and attacks launch a plasma ring down the bore. |
| 27 | float3 plasmaBore(Ctx c, constant NativeFrame &f) { |
| 28 | float2 vanish = tnDrift(c.t, float2(.36, .24)); |
| 29 | float2 d = tnBend(c.uv, vanish); |
| 30 | float r = max(length(d), 1e-3f), a = atan2(d.y, d.x); |
| 31 | // The bore wall bulges with the bass in rings that roll toward the camera. |
| 32 | float bulge = 1 + c.b.x * .16 * sin((1 / r + c.travel * 2.4) * 1.3 + c.m * 2.5 + 2 * cos(a)); |
| 33 | float z = bulge / r, zw = z + c.travel * 2.4 + c.m * .7; |
| 34 | float scale = 1 / c.size; |
| 35 | float3 p = float3(cos(a) * 1.4, sin(a) * 1.4, zw * .42) * scale; |
| 36 | float3 warp = float3(fbm3(p + float3(0, 0, c.t * .31 + c.m * .3), 3), fbm3(p + float3(4.1, 1.7, -c.t * .27), 3), 0); |
| 37 | float n = fbm3(p * 1.5 + warp * (2.6 + c.b.y * 1.6) + float3(1.3, -.7, -c.t * .45 - c.m * .4), 4); |
| 38 | float near = exp(-z * .6); |
| 39 | float filaments = 1 - abs(sin(n * 11 + c.t * .5 + c.m * .4)); |
| 40 | float ridge = pow(filaments, 8 - 5 * c.b.x * near); |
| 41 | float strands = pow(1 - abs(sin(warp.x * 14 - c.t * .3)), 14.f); |
| 42 | float phase = n * 3.2 + zw * .05 - c.t * .1 + c.b.z * .5; |
| 43 | float cloud = smoothstep(.38f, .72f, n); |
| 44 | float bands = .55 + .45 * sin(zw * 1.3 - c.t * 1.4 + n * 5); |
| 45 | float3 color = paint(phase + .5, f) * .04 + paint(phase, f) * cloud * .3 * bands; |
| 46 | color += paint(phase + .15, f) * ridge * (1.1 + 2.4 * c.b.x * near) * (.6 + .4 * bands); |
| 47 | color += paint(phase + .55, f) * strands * .45; |
| 48 | color += paint(phase + .3, f) * pow(filaments, 30.f) * 1.1; |
| 49 | // High-band crackle: tiny sparks that flicker on the near walls. |
| 50 | float2 sparkCell = float2((a / TAU + .5) * 64, zw * 9); |
| 51 | float sparkHash = hash21(floor(sparkCell) + 17); |
| 52 | float twinkle = pow(.5 + .5 * sin(c.t * 23 * (.5 + sparkHash) + sparkHash * 40), 6.f); |
| 53 | float spark = smoothstep(.32f, 0.f, length(fract(sparkCell) - .5)) * step(.82f, sparkHash); |
| 54 | color += paint(phase + .5, f) * spark * twinkle * c.b.w * 5 * exp(-z * .3); |
| 55 | // Attack: a ring-shaped surge that rides down the tube as the attack decays. |
| 56 | float h = tnAttack(c); |
| 57 | float ringDepth = 1.3 + (1 - h) * 6; |
| 58 | float surge = exp(-pow((z - ringDepth) / (.12 + .1 * ringDepth), 2.f)) * c.hit; |
| 59 | color += paint(.85 + n * .3, f) * surge * (1 + 2.6 * filaments); |
| 60 | float3 core = paint(phase * .3 + .55, f) * .7 + paint(.9, f) * exp(-r * 9) * 1.4; |
| 61 | return mix(core, color, tnFog(z, c, .03) * smoothstep(30.f, 10.f, z)); |
| 62 | } |
| 63 | |
| 64 | // ---------------------------------------------------------------- 101 LED Corridor |
| 65 | // A square corridor tiled with LED matrices. The walls run equalizer columns (left on the |
| 66 | // low band, right on high-mids) under marching chevrons, the ceiling scrolls a slow colour |
| 67 | // field and attacks run a pixel wave down the floor. Dark seams mark every panel. |
| 68 | float3 ledCorridor(Ctx c, constant NativeFrame &f) { |
| 69 | float2 vanish = tnDrift(c.t * .8, float2(.18, .1)); |
| 70 | float2 d = tnBend(c.uv, vanish); |
| 71 | float ax = abs(d.x), ay = abs(d.y); |
| 72 | bool wall = ax > ay; |
| 73 | float z = 1 / max(max(ax, ay), 1e-3f); |
| 74 | // Forward drive: zoom travel plus the music clock, so energetic passages surge ahead. |
| 75 | float drive = c.travel * 3.2 + c.m * .9; |
| 76 | float zw = z + drive; |
| 77 | float across = (wall ? d.y : d.x) * z; |
| 78 | float pitch = .09 * c.size; |
| 79 | float2 cell = float2(across, zw) / pitch; |
| 80 | float2 id = floor(cell), local = fract(cell) - .5; |
| 81 | float centreAcross = (id.x + .5) * pitch, centreDepth = (id.y + .5) * pitch; |
| 82 | float relDepth = centreDepth - drive; |
| 83 | float height01 = centreAcross * .5 + .5; |
| 84 | // Every panel block listens to its own band. |
| 85 | float2 block = floor(float2(id.x / 5, id.y / 6)) + (wall ? (d.x < 0 ? 0 : 40) : (d.y > 0 ? 80 : 120)); |
| 86 | float blockBand = c.b[int(hash21(block) * 3.99)]; |
| 87 | float3 led = 0; |
| 88 | if (wall) { |
| 89 | bool left = d.x < 0; |
| 90 | if (height01 < .66) { |
| 91 | float column = floor(id.y / 4); |
| 92 | float gap = step(2.5f, id.y - column * 4); |
| 93 | float band = left ? c.b.x : c.b.z; |
| 94 | float level = .22 + .14 * sin(c.t * 2.3 + c.m * 1.5 + column * 1.37) + .09 * sin(c.t * 3.9 + column * .71) |
| 95 | + band * (.45 + .4 * hash11(column * 1.71 + (left ? 0 : 50))); |
| 96 | float h = height01 / .66; |
| 97 | float on = (1 - gap) * step(h, level); |
| 98 | float cap = (1 - gap) * step(level, h) * step(h, level + pitch * .75); |
| 99 | led = paint(.04 + h * .8, f) * on * 1.1 + paint(.9, f) * cap * 1.3; |
| 100 | } else { |
| 101 | float row = (centreAcross - .66) / pitch; |
| 102 | float march = fract((id.y + abs(row) * 1.2 - c.t * 7 - c.m * 5) / 9); |
| 103 | led = paint(.72 + .1 * sin(id.y * .05) + c.b.w * .25, f) * step(march, .3f) * step(.7f, height01) * step(height01, .96f) * (1 + c.b.w * 1.8); |
| 104 | } |
| 105 | } else if (d.y > 0) { |
| 106 | float n = noise2(float2(centreAcross * 1.2, centreDepth * .22 - c.t * .25 - c.m * .3)); |
| 107 | led = paint(n * 1.5 + c.t * .03 + centreDepth * .01 + c.b.y * .35, f) * (.25 + .4 * n) * (1 + blockBand * 2.4); |
| 108 | } else { |
| 109 | float lane = step(abs(abs(centreAcross) - .64), pitch * .6); |
| 110 | float dash = step(fract(id.y / 8 - c.t * .9 - c.m * .6), .5); |
| 111 | float arrow = step(fract((id.y + abs(id.x + .5) * 1.2 - c.t * 5 - c.m * 4) / 10), .22) * step(abs(centreAcross), .3f); |
| 112 | led = paint(.55, f) * lane * dash * (.9 + c.b.y * 2.2) + paint(.3 + c.b.x * .3, f) * arrow * (.7 + c.b.x * 2); |
| 113 | float h = tnAttack(c); |
| 114 | float front = 1.7 + (1 - h) * 7; |
| 115 | float wave = c.hit * exp(-pow((relDepth + abs(centreAcross) * .8 - front) / .7, 2.f)); |
| 116 | led += paint(.85 + .1 * centreAcross, f) * wave * 2.4; |
| 117 | } |
| 118 | float panel = 2.4; |
| 119 | float seam = step(fract(centreDepth / panel), pitch / panel * 1.01); |
| 120 | led *= 1 - seam; |
| 121 | float2 fw = fwidth(cell); |
| 122 | float blur = max(fw.x, fw.y); |
| 123 | float dist = length(local); |
| 124 | float aa = blur * .7 + .02; |
| 125 | float resolve = smoothstep(.9f, .35f, blur); |
| 126 | float dotMask = mix(.4f, 1 - smoothstep(.36f - aa, .36f + aa, dist), resolve); |
| 127 | float halo = mix(.4f, exp(-dist * dist * 7), resolve); |
| 128 | // Idle LEDs shimmer with their block's band in waves running down the corridor. |
| 129 | float shimmer = pow(.5 + .5 * sin(relDepth * 1.3 - c.m * 3 + hash21(block) * 6), 2.f); |
| 130 | float3 offLed = paint(.5 + blockBand * .4, f) * .03 * (1 - seam) * (1 + blockBand * 7 * shimmer); |
| 131 | float3 color = deep(.3, f) * .025 * (1 - seam * .8) + (led + offLed) * (dotMask * 1.6 + halo * .3); |
| 132 | float corner = exp(-abs(ax - ay) * z * 40); |
| 133 | color *= 1 - corner * .6; |
| 134 | float3 end = paint(.55, f) * .55 + paint(.85, f) * exp(-max(ax, ay) * 16) * 1.2; |
| 135 | return mix(end, color, tnFog(z, c, .03)); |
| 136 | } |
| 137 | |
| 138 | // ---------------------------------------------------------------- 102 Prism Shaft |
| 139 | // A triangular glass shaft that turns as it flies past. Each face carries thin-film caustic |
| 140 | // lines; panels alternate tint along depth and the three corners burn as bright seams. |
| 141 | // Highs multiply and shimmer the caustics, bass widens the seams, attacks sweep a band of |
| 142 | // refracted light down the faces. |
| 143 | float3 prismShaft(Ctx c, constant NativeFrame &f) { |
| 144 | float2 vanish = tnDrift(c.t * .9, float2(.22, .14)); |
| 145 | float2 d = tnBend(c.uv, vanish); |
| 146 | float r = max(length(d), 1e-3f); |
| 147 | float spin = c.travel * .14 + c.t * .05; |
| 148 | float a = atan2(d.y, d.x) - spin; |
| 149 | const float sector = TAU / 3; |
| 150 | float k = floor(a / sector + .5); |
| 151 | float phi = a - k * sector; |
| 152 | float face = k - 3 * floor(k / 3); |
| 153 | float z = 1 / (r * cos(phi)); |
| 154 | float lateral = tan(phi); |
| 155 | float zw = z + c.travel * 2.6; |
| 156 | float fs = 1 / c.size; |
| 157 | float2 q = float2(lateral * .9, zw * .5) * fs + float2(face * 7.3, 0); |
| 158 | float2 w = float2(fbm2(q * .7 + float2(0, c.t * .06), 3), fbm2(q * .7 + float2(5.2, -c.t * .05), 3)); |
| 159 | float n = fbm2(q * 1.3 + w * 2.2, 3); |
| 160 | float freq = 20 + c.b.w * 14; |
| 161 | float caustic = pow(1 - abs(sin(n * freq + c.t * .6 + c.m * 1.2)), 24.f); |
| 162 | float n2 = fbm2(q * 2.3 - w * 1.5 + float2(c.t * .05, 0), 3); |
| 163 | caustic += .7 * pow(1 - abs(sin(n2 * freq * 1.3 - c.t * .4 + 1.3)), 30.f) * (.35 + c.b.w * 1.2); |
| 164 | float segment = floor(zw / 1.8); |
| 165 | float parity = segment - 2 * floor(segment / 2); |
| 166 | float3 glass = deep(.12 + parity * .3 + face * .13, f) * .2 + paint(.3 + parity * .25 + face * .1, f) * .05; |
| 167 | glass *= .6 + .5 * lateral * lateral / 3; |
| 168 | float sheen = exp(-pow(fract(zw * .12 + lateral * .18 - c.t * .08) - .5, 2.f) * 50); |
| 169 | glass += paint(.75 + face * .08, f) * sheen * .12; |
| 170 | float3 color = glass + filmColor(n * 1.6 + lateral * .12 + zw * .025, f) * caustic * 1.6; |
| 171 | float segDist = abs(fract(zw / 1.8 + .5) - .5) * 1.8; |
| 172 | color += paint(.6 + parity * .2, f) * (1 - smoothstep(0.f, fwidth(zw) * 1.5 + .004f, segDist)) * .6; |
| 173 | float seamDist = r * sin(PI / 3 - abs(phi)); |
| 174 | float seamW = .005 + .012 * c.b.x; |
| 175 | color += paint(.9, f) * (exp(-seamDist / seamW) * 1.5 + exp(-seamDist / (seamW * 8)) * .3); |
| 176 | float h = tnAttack(c); |
| 177 | float bandDepth = 1.4 + (1 - h) * 5; |
| 178 | float band = exp(-pow((z - bandDepth) / (.15 + .08 * bandDepth), 2.f)) * c.hit; |
| 179 | color += mix(paint(.97, f) * 1.4, filmColor(lateral * .25 + zw * .1, f) * 1.6, smoothstep(.2f, 1.6f, abs(lateral))) * band * 1.5; |
| 180 | float3 core = deep(.55, f) * .6 + paint(.85, f) * exp(-r * 7) * 1.2; |
| 181 | return mix(core, color, tnFog(z, c, .03) * smoothstep(40.f, 14.f, z)); |
| 182 | } |
| 183 | |
| 184 | // ---------------------------------------------------------------- 103 Hyperloop |
| 185 | // Riding a glass vacuum tube at speed: support rings flash past, a guide strip glows along |
| 186 | // the deck and a twilight city streaks by outside. Bass pulses the guide strip in segments, |
| 187 | // highs glint on the glass and attacks run a ring of light down the supports ahead. |
| 188 | float3 hyperloop(Ctx c, constant NativeFrame &f) { |
| 189 | float2 vanish = tnDrift(c.t * .7, float2(.14, .06)) + float2(0, .05); |
| 190 | float2 d = tnBend(c.uv, vanish); |
| 191 | float r = max(length(d), 1e-3f), a = atan2(d.y, d.x); |
| 192 | float z = 1 / r; |
| 193 | // Forward drive: zoom travel plus the music clock, so energetic passages surge ahead. |
| 194 | float drive = c.travel * 4.5 + c.m * 1.2; |
| 195 | float zw = z + drive; |
| 196 | // Outside the glass, seen through a shell that ripples with the bass. |
| 197 | float2 view = c.uv + c.b.x * .045 * float2(sin(zw * 2.1 - c.m * 3 + a * 2), cos(zw * 1.7 - c.m * 2.5 + a)) * smoothstep(.3f, 1.2f, r); |
| 198 | float horizon = vanish.y - .03; |
| 199 | float y = view.y - horizon; |
| 200 | float3 outside; |
| 201 | if (y > 0) { |
| 202 | outside = mix(paint(.62, f) * .5, deep(.08, f) * .18, smoothstep(0.f, 1.1f, y)); |
| 203 | outside += paint(.8 + c.b.y * .25, f) * exp(-y * 9) * (.5 + c.b.y * .9); |
| 204 | float sx = view.x * 7 + c.travel * .08; |
| 205 | float tower = hash11(floor(sx) + 3); |
| 206 | float top = .03 + .2 * tower * tower; |
| 207 | if (y < top) { |
| 208 | float2 wc = float2(sx * 4, y * 70); |
| 209 | float windowHash = hash21(floor(wc)); |
| 210 | float window = step(.7f, windowHash) * step(.3f, fract(wc.x)) * step(.35f, fract(wc.y)); |
| 211 | outside = deep(.15, f) * .12 + paint(.75 + tower * .2, f) * window * (.7 + c.b[int(windowHash * 13) & 3] * 2.5); |
| 212 | } |
| 213 | outside += paint(.9, f) * step(.996f, hash21(floor(view * 140))) * smoothstep(.25f, .8f, y) * .6; |
| 214 | } else { |
| 215 | float depth = .55 / max(-y, .004f); |
| 216 | float X = (view.x - vanish.x) * depth; |
| 217 | float Zg = depth + drive; |
| 218 | float2 cellSize = float2(1.4, 3.2); |
| 219 | float2 gid = floor(float2(X, Zg) / cellSize); |
| 220 | float2 h2 = hash22(gid); |
| 221 | float lx = (gid.x + .2 + .6 * h2.x) * cellSize.x; |
| 222 | float lz = (gid.y + .4 * h2.y) * cellSize.y; |
| 223 | float trail = .5 + 1.4 * f.camera.w; |
| 224 | float along = Zg - lz; |
| 225 | float inStreak = smoothstep(0.f, .15f, along) * smoothstep(trail, 0.f, along); |
| 226 | float lateralScreen = abs(X - lx) / depth; |
| 227 | float lamp = (exp(-lateralScreen * 260) + exp(-lateralScreen * 40) * .25) * inStreak * step(.35f, h2.y); |
| 228 | outside = deep(.2, f) * .07 + paint(.6 + c.b.y * .25, f) * exp(y * 14) * (.35 + c.b.y * .6); |
| 229 | outside += paint(h2.x * .8 + .1, f) * lamp * (2.2 + c.b[int(h2.x * 3.99)] * 4) * exp(-depth * .05); |
| 230 | } |
| 231 | float3 color = outside * .85 + paint(.5, f) * .03; |
| 232 | color += paint(.55, f) * .1 * smoothstep(.6f, 2.f, r); |
| 233 | float sheen = exp(-pow(tnWrap(a - 2.1) / .04, 2.f)) + exp(-pow(tnWrap(a - 1.05) / .03, 2.f)) * .6; |
| 234 | color += paint(.8, f) * sheen * (.22 + c.b.z * .6) * (.6 + .4 * sin(zw * .3)); |
| 235 | // Glints on the glass. |
| 236 | float2 gc = float2((a / TAU + .5) * 48, zw * 2); |
| 237 | float gh = hash21(floor(gc) + 5); |
| 238 | float glint = smoothstep(.3f, 0.f, length(fract(gc) - .5)) * step(.86f, gh) * pow(.5 + .5 * sin(c.t * 9 * (.5 + gh) + gh * 30), 8.f); |
| 239 | color += paint(.9, f) * glint * c.b.w * 3.5 * exp(-z * .2); |
| 240 | // Deck and guide strip along the floor. |
| 241 | float floorAngle = tnWrap(a + PI * .5); |
| 242 | float deck = smoothstep(.43f, .4f, abs(floorAngle)); |
| 243 | if (deck > 0) { |
| 244 | float3 deckColor = deep(.3, f) * .08 * (.6 + .4 * step(.1f, fract(zw * .8))); |
| 245 | deckColor += paint(.6, f) * exp(-(.42 - abs(floorAngle)) * r * 90) * .5; |
| 246 | float strip = smoothstep(.05f, .035f, abs(floorAngle)) * step(fract(zw * 1.2), .6f); |
| 247 | float pulse = 1 + c.b.x * 3.5 * pow(.5 + .5 * sin(zw * .7 - c.t * 5 - c.m * 4), 4.f); |
| 248 | deckColor += paint(.7, f) * strip * 1.4 * pulse + paint(.7, f) * exp(-abs(floorAngle) * r * 30) * .25 * pulse; |
| 249 | color = mix(color, deckColor, deck); |
| 250 | } |
| 251 | // Support rings. |
| 252 | for (int k = 0; k < 6; ++k) { |
| 253 | float ribAngle = (float(k) + .5) * TAU / 8 - PI * .5 + TAU / 8; |
| 254 | float ribDist = r * abs(sin(a - ribAngle)); |
| 255 | color += paint(.62, f) * exp(-ribDist / (.002 + .003 * r)) * (.35 + c.b.z * 1.2) * step(0.f, cos(a - ribAngle)); |
| 256 | } |
| 257 | float spacing = 1.5 * c.size; |
| 258 | float ringIndex = floor(zw / spacing + .5); |
| 259 | float dz = zw - ringIndex * spacing; |
| 260 | float fwz = fwidth(zw); |
| 261 | float thick = .11; |
| 262 | float ringMask = 1 - smoothstep(thick * .5 - fwz, thick * .5 + fwz, abs(dz)); |
| 263 | ringMask = mix(ringMask, thick / spacing, smoothstep(.3f * spacing, spacing, fwz)); |
| 264 | float ringZ = ringIndex * spacing - drive; |
| 265 | float ringBand = c.b[int(hash11(ringIndex * 3.3) * 3.99)]; |
| 266 | float h = tnAttack(c); |
| 267 | float front = 2.2 + (1 - h) * 8; |
| 268 | float flash = c.hit * exp(-pow((ringZ - front) / 1.2, 2.f)); |
| 269 | float leds = pow(.5 + .5 * cos(a * 16), 30.f); |
| 270 | float3 ringColor = deep(.6, f) * .25 + paint(.65, f) * .35 * (.5 + .5 * abs(sin(a))); |
| 271 | ringColor += paint(.85 + hash11(ringIndex) * .1, f) * (leds * (.9 + ringBand * 3) + flash * 2.5); |
| 272 | color = mix(color, ringColor, ringMask); |
| 273 | // Each ring's lights wash the glass around it with its own band. |
| 274 | color += paint(.75, f) * exp(-abs(dz) * 8) * (.1 + flash * .5); |
| 275 | color += paint(.6 + ringBand * .3, f) * exp(-abs(dz) * 2.2) * ringBand * .45; |
| 276 | float3 end = paint(.7, f) * .45 + paint(.9, f) * exp(-r * 12) * 1.4; |
| 277 | return mix(end, color, tnFog(z, c, .02)); |
| 278 | } |
| 279 | |
| 280 | // ---------------------------------------------------------------- 104 Barrel Wave |
| 281 | // Inside the curl of a breaking wave. Deep water climbs the face on the right, arcs |
| 282 | // overhead and falls as a thin backlit lip on the left; foam lines stream around the curl |
| 283 | // toward the bright opening ahead. Bass thickens the foam, highs sparkle spray on the water |
| 284 | // and attacks throw a burst of spray off the lip. |
| 285 | float3 barrelWave(Ctx c, constant NativeFrame &f) { |
| 286 | float2 vanish = float2(.16 + .08 * sin(c.t * .13), .07 + .05 * sin(c.t * .19 + 1)); |
| 287 | float2 d = tnBend(c.uv, vanish); |
| 288 | float r = max(length(d), 1e-3f), ang = atan2(d.y, d.x); |
| 289 | // The water surface heaves with the bass in swells that roll down the barrel. |
| 290 | float swell = c.b.x * .11 * sin((1 / r + c.travel * 2.2) * .9 - c.m * 2.5 + ang * 2); |
| 291 | float radius = 1 + .18 * cos(2 * ang + .4) + swell; |
| 292 | float z = radius / r, zw = z + c.travel * 2.2 + c.m * .6; |
| 293 | // Angle around the barrel: rising face (about -1.5) to roof (0.8) to falling lip (π). |
| 294 | // It is unwrapped so its only seam lies inside the trough, which covers it. |
| 295 | float beta = tnWrap(ang - PI * .25); |
| 296 | beta = beta < -2.4 ? beta + TAU : beta; |
| 297 | float cs = 1 / c.size; |
| 298 | // Water thins from the face (right) over the roof to the lip (left). |
| 299 | float thin = smoothstep(-1.5f, 2.5f, beta); |
| 300 | float3 water = mix(deep(.3, f) * .12, paint(.4, f) * .17, smoothstep(-1.5f, 1.2f, beta)); |
| 301 | water = mix(water, paint(.58, f) * .3, smoothstep(1.f, 2.5f, beta)); |
| 302 | water += paint(.75 + c.b.z * .2, f) * pow(thin, 4.f) * (.2 + c.b.z * .6); |
| 303 | water += paint(.5, f) * swell * 1.6; |
| 304 | // Foam streaks flowing around the curl, faster when the music drives. |
| 305 | float s = beta * 1.5 + zw * .2; |
| 306 | float2 fp = float2(s * .7 - c.t * 1.2 - c.m * 1.1, zw * 6) * cs; |
| 307 | float n = fbm2(fp + float2(0, fbm2(fp * float2(.6, .2) + c.t * .15, 2) * 2), 4); |
| 308 | float foam = smoothstep(.6f - .1f * c.b.x, .74f, n); |
| 309 | float lace = exp(-abs(n - .52) * 40) * (.35 + c.b.w * 1.2); |
| 310 | float3 color = water + paint(.85, f) * (foam * (.65 + c.b.y * 1.3) + lace) * (.35 + .45 * thin); |
| 311 | // The flat trough along the bottom. |
| 312 | float trough = max(smoothstep(PI + .1f, PI + .45f, beta), smoothstep(-1.5f, -1.9f, beta)); |
| 313 | float2 tp = float2(d.x * z * 2.5, (zw + c.t * .8) * 1.4) * cs; |
| 314 | float troughFoam = smoothstep(.58f, .76f, fbm2(tp, 4)); |
| 315 | float3 troughColor = deep(.32, f) * .22 + paint(.7, f) * exp(-abs(d.x) * 5) * .2 + paint(.85, f) * troughFoam * .45; |
| 316 | color = mix(color, troughColor, trough); |
| 317 | // Where the falling lip lands in the trough: a band of churning whitewater. |
| 318 | float landing = beta; |
| 319 | float lipEnd = PI + .02 + .14 * sin(zw * .55 - c.t * 1.2) + .07 * sin(zw * 1.7 + c.t * .8); |
| 320 | float churn = fbm2(float2(landing * 5 - c.t * .6, zw * 3 - c.t * 2.2 - c.m * 1.5) * cs, 4); |
| 321 | float white = exp(-pow((landing - lipEnd) / (.3 + c.b.x * .15), 2.f)) * smoothstep(.3f, .6f, churn + .15); |
| 322 | color = mix(color, paint(.82, f) * (.35 + .6 * churn) * (1 + c.b.x * .8), white); |
| 323 | color += paint(.9, f) * exp(-abs(landing - lipEnd + .3) * 12) * .35; |
| 324 | // Spray drifting off the lip. |
| 325 | float2 sc = float2(beta * 9, zw * 4 - c.t * 1.5); |
| 326 | float sh = hash21(floor(sc) + 3); |
| 327 | float drop = smoothstep(.22f, 0.f, length(fract(sc) - .5 - (hash22(floor(sc)) - .5) * .4)); |
| 328 | color += paint(.95, f) * drop * step(.78f, sh) * smoothstep(1.7f, 2.6f, beta) * (1 - white) * (1 - trough) * .7; |
| 329 | // Highs: sparkling glints across the water. |
| 330 | float2 gl = float2(beta * 30, zw * 10); |
| 331 | float glh = hash21(floor(gl)); |
| 332 | color += paint(.95, f) * smoothstep(.3f, 0.f, length(fract(gl) - .5)) * step(.93f, glh) * pow(.5 + .5 * sin(c.t * 11 * glh + glh * 50), 6.f) * c.b.w * 3 * exp(-z * .25); |
| 333 | // Attack: a burst of spray thrown off the lip near the camera. |
| 334 | float h = tnAttack(c); |
| 335 | float burstZone = smoothstep(lipEnd - 1.1, lipEnd - .3, beta) * exp(-z * .4); |
| 336 | float2 bc = float2(beta * 14 + (1 - h) * 3, zw * 7 + (1 - h) * 4); |
| 337 | float bh = hash21(floor(bc) + 9); |
| 338 | float burstDrop = smoothstep(.3f, 0.f, length(fract(bc) - .5)) * step(.55f, bh); |
| 339 | color += (paint(.95, f) * burstDrop * 2.5 + paint(.8, f) * .2) * burstZone * c.hit; |
| 340 | // The barrel's open end ahead: bright sky over the sea, framed by a ragged foamy rim. |
| 341 | float rimDepth = 4.6 + .5 * sin(c.t * .27) + .35 * sin(ang * 3 + c.t * .5) + .2 * sin(ang * 5 - c.t * .8); |
| 342 | float beyond = smoothstep(rimDepth - .2, rimDepth + .2, z); |
| 343 | float2 view = c.uv - vanish; |
| 344 | float horizonY = view.y + .03; |
| 345 | float3 outside = mix(deep(.4, f) * .35 + paint(.6, f) * .25 * step(.6f, noise2(float2(view.x * 60, horizonY * 200 + c.t))), paint(.88, f) * .9, smoothstep(-.004f, .004f, horizonY)); |
| 346 | outside = mix(outside, paint(.55, f) * .5, smoothstep(.02f, .25f, horizonY)); |
| 347 | outside += paint(.95, f) * exp(-length(view - float2(.06, .05)) * 14) * .8; |
| 348 | float3 mist = paint(.6, f) * .25; |
| 349 | color = mix(mist, color, tnFog(z, c, .02)); |
| 350 | color = mix(color, outside, beyond); |
| 351 | color += paint(.9, f) * exp(-abs(z - rimDepth) * 2.5) * .45 * (.6 + .4 * noise2(float2(ang * 4, c.t))); |
| 352 | return color * .78; |
| 353 | } |
| 354 | |
| 355 | // ---------------------------------------------------------------- 105 Magma Tube |
| 356 | // A lava tube: basalt plates split by incandescent cracks, a molten river churning toward |
| 357 | // the viewer along the floor, heat haze and drifting embers. Bass widens the near cracks, |
| 358 | // highs throw embers and attacks make the river spurt. |
| 359 | float3 magmaTube(Ctx c, constant NativeFrame &f) { |
| 360 | float2 uv = c.uv; |
| 361 | // Heat haze shimmers harder on the bass. |
| 362 | float hazeAmount = (.012 + .02 * smoothstep(.3f, -1.f, uv.y)) * (1 + c.b.x * 2.5); |
| 363 | uv += (float2(noise2(uv * 6 + float2(0, -c.t * 2.2 - c.m * 1.5)), noise2(uv * 6 + float2(7.1, -c.t * 1.9))) - .5) * hazeAmount; |
| 364 | float2 vanish = tnDrift(c.t * .7, float2(.24, .12)) + float2(0, .06); |
| 365 | float2 d = tnBend(uv, vanish); |
| 366 | float r = max(length(d), 1e-3f); |
| 367 | float theta = atan2(-d.x, d.y); |
| 368 | float z = 1 / r; |
| 369 | // Forward drive: zoom travel plus the music clock. |
| 370 | float drive = c.travel * 1.8 + c.m * .5; |
| 371 | float zw = z + drive; |
| 372 | float cs = 1 / c.size; |
| 373 | float near = exp(-z * .45); |
| 374 | float floorDistance = PI - abs(theta); |
| 375 | float2 pc = float2(theta * 1.45, zw * 1.45) * cs; |
| 376 | float4 v = voronoi(pc, .85, 0); |
| 377 | float edge = v.y - v.x; |
| 378 | // Each plate's rim burns with its own band; bass widens the near cracks. |
| 379 | float plateBand = c.b[int(hash21(v.zw) * 3.99)]; |
| 380 | float crackW = .035 + .1 * c.b.x * near + .03 * plateBand; |
| 381 | float crack = 1 - smoothstep(crackW * .4f, crackW, edge); |
| 382 | float heat = exp(-edge * (9 - 4 * c.b.x * near - 3.5 * plateBand)); |
| 383 | float flicker = .75 + .25 * noise2(v.zw * 3.1 + c.t * 1.3); |
| 384 | float3 rock = deep(.06, f) * (.08 + .3 * fbm2(pc * 4, 3)) * (.5 + .5 * smoothstep(0.f, .3f, edge)); |
| 385 | float under = smoothstep(2.2f, .6f, floorDistance); |
| 386 | rock += paint(.35, f) * under * .12; |
| 387 | rock += paint(.3, f) * plateBand * .1 * smoothstep(.0f, .25f, edge) * (.5 + .5 * fbm2(pc * 4 + 7, 2)); |
| 388 | float3 color = rock + paint(.34 + .32 * heat + plateBand * .12, f) * (crack * 1.2 + heat * .5) * flicker * (1 + plateBand * 1.4); |
| 389 | float riverHalf = .52 + .07 * sin(zw * .8 + c.t * .4) + .04 * sin(zw * 2.1 - c.t * .7); |
| 390 | float riverMask = smoothstep(riverHalf + .04, riverHalf - .04, floorDistance); |
| 391 | if (riverMask > 0) { |
| 392 | float X = d.x * z; |
| 393 | float2 rp = float2(X * 1.7, (zw + c.t * 1.6 + c.m * 1.2) * .7) * cs; |
| 394 | float2 rw = float2(fbm2(rp * .8 + float2(0, c.t * .3), 3), fbm2(rp * .8 + float2(4.3, -c.t * .25), 3)); |
| 395 | float rn = fbm2(rp * 1.2 + rw * 2.4, 4); |
| 396 | float crust = smoothstep(.45f, .55f, rn); |
| 397 | float3 molten = paint(.3 + .36 * smoothstep(.5f, .2f, rn), f) * (.8 + .7 * smoothstep(.5f, .2f, rn)); |
| 398 | float3 river = mix(molten * (1 + c.b.x * .9), deep(.1, f) * .2 + paint(.35, f) * .15, crust * .9); |
| 399 | color = mix(color, river, riverMask); |
| 400 | } |
| 401 | color += paint(.7, f) * exp(-abs(floorDistance - riverHalf) * 14) * (.6 + c.b.y * 1.2); |
| 402 | // Embers drifting toward the camera. |
| 403 | for (int i = 0; i < 2; ++i) { |
| 404 | float rho = .5 + .3 * float(i); |
| 405 | float ze = rho / r; |
| 406 | if (ze < .3) continue; |
| 407 | float count = 30 + 10 * float(i); |
| 408 | float swirl = theta + c.t * (.12 + .05 * float(i)) + c.m * .1; |
| 409 | float2 ec = float2(swirl / TAU * count, (ze + drive + c.t * .5) * 2.5); |
| 410 | float2 eid = floor(ec); |
| 411 | eid.x -= count * floor(eid.x / count); |
| 412 | float eh = hash21(eid + float(i) * 37); |
| 413 | float2 el = fract(ec) - .5 - (hash22(eid) - .5) * .5; |
| 414 | float density = .05 + .3 * c.b.w; |
| 415 | float ember = smoothstep(.16f, 0.f, length(el)) * smoothstep(density, density - .04f, eh); |
| 416 | color += paint(.8, f) * ember * 2 * smoothstep(.3f, .8f, ze) * exp(-ze * .25); |
| 417 | } |
| 418 | // Attack: lava spurts from vents in the river. |
| 419 | float h = tnAttack(c); |
| 420 | const float ventSpacing = 6; |
| 421 | float base = floor(drive / ventSpacing); |
| 422 | for (int k = 1; k <= 3; ++k) { |
| 423 | float ventDepth = (base + float(k)) * ventSpacing - drive; |
| 424 | if (ventDepth < .6) continue; |
| 425 | float vx = (hash11(base + float(k)) - .5) * .8; |
| 426 | float2 foot = float2(vx, -.9) / ventDepth; |
| 427 | float height = (.3 + .9 * h) / ventDepth; |
| 428 | float2 q = d - foot; |
| 429 | float column = exp(-abs(q.x) / (.06 / ventDepth)) * smoothstep(height, 0.f, q.y) * smoothstep(-.02f / ventDepth, 0.f, q.y); |
| 430 | float splash = exp(-length(q - float2(0, height)) / (.1 / ventDepth)); |
| 431 | color += paint(.75, f) * (column * 2.5 + splash * 1.5) * c.hit; |
| 432 | } |
| 433 | float3 smoke = deep(.3, f) * .3 + paint(.55, f) * exp(-r * 5) * .8; |
| 434 | return mix(smoke, color, tnFog(z, c, .04)); |
| 435 | } |
| 436 | |
| 437 | // ---------------------------------------------------------------- 106 Data Conduit |
| 438 | // A cylindrical circuit board: traces, vias and chips in deep tones, with data packets |
| 439 | // racing along the traces in both directions. Each trace layer's packet density follows |
| 440 | // its own band; attacks fire a broad packet burst out of the vanishing point. |
| 441 | float3 dataConduit(Ctx c, constant NativeFrame &f) { |
| 442 | float2 vanish = tnDrift(c.t * .8, float2(.22, .14)); |
| 443 | float2 d = tnBend(c.uv, vanish); |
| 444 | float r = max(length(d), 1e-3f), a = atan2(d.y, d.x) + c.t * .05; |
| 445 | float z = 1 / r; |
| 446 | const float speed = 3.4, N = 72; |
| 447 | // Forward drive: zoom travel plus the music clock. |
| 448 | float zw = z + c.travel * speed + c.m * .8; |
| 449 | float2 g = float2(a / TAU * N, zw * N / TAU); |
| 450 | float2 cell = floor(g), local = fract(g) - .5; |
| 451 | float cx = cell.x - N * floor(cell.x / N); |
| 452 | float2 fw = fwidth(g); |
| 453 | float blur = smoothstep(.3f, .9f, max(fw.x, fw.y)); |
| 454 | float tw = .09 * c.size; |
| 455 | // Board layout. |
| 456 | float segRow = cell.y - 9 * floor(cell.y / 9); |
| 457 | float laneOn = step(hash11(cx * 1.37 + 2), .58) * step(hash21(float2(cx, floor(cell.y / 9))), .85); |
| 458 | float lane = laneOn * (1 - smoothstep(tw - fw.x, tw + fw.x, abs(local.x))); |
| 459 | float crossRow = step(hash11(cell.y * .731 + 4), .3); |
| 460 | float crossOn = crossRow * step(hash21(float2(floor(cx / 4), cell.y) + 5), .45); |
| 461 | float crossLine = crossOn * (1 - smoothstep(tw - fw.y, tw + fw.y, abs(local.y))); |
| 462 | float viaAt = max(laneOn * step(segRow, .5), laneOn * crossOn); |
| 463 | float viaRing = abs(length(local) - .2); |
| 464 | float via = viaAt * (1 - smoothstep(.07f - fw.x, .07f + fw.x, viaRing)); |
| 465 | float traces = max(max(lane, crossLine), via); |
| 466 | float2 chipLocal = float2(cx - 14 * floor(cx / 14) - 4 + local.x + .5, cell.y - 15 * floor(cell.y / 15) - 5 + local.y + .5); |
| 467 | float chipOn = step(hash21(float2(floor(cx / 14), floor(cell.y / 15)) + 11), .7); |
| 468 | float chipBody = sdBox2(chipLocal - float2(3, 2.5), float2(2.6, 2.0)); |
| 469 | float pinRow = step(abs(abs(chipLocal.y - 2.5) - 2.35), .3) * step(abs(chipLocal.x - 3), 2.3f); |
| 470 | float pins = pinRow * step(abs(fract(chipLocal.x * 2) - .5), .2); |
| 471 | // Each trace layer glows with its own band; board sectors are backlit by theirs. |
| 472 | float layer = floor(hash11(cx * 3.7 + 1) * 4); |
| 473 | float band = c.b[int(layer)]; |
| 474 | float rowBand = c.b[int(hash11(cell.y * .61 + 2) * 3.99)]; |
| 475 | float sectorBand = c.b[int(hash21(float2(floor(cx / 6), floor(cell.y / 6)) + 21) * 3.99)]; |
| 476 | float3 board = deep(.3, f) * .15 * (.85 + .3 * hash21(float2(floor(cx / 2), floor(cell.y / 2)) + 3)) * (1 + sectorBand * 1.6); |
| 477 | float3 copper = deep(.6, f) * .7; |
| 478 | float traceGlow = max(lane * (1 + band * 2.2), max(crossLine * (1 + rowBand * 2.2), via * (1 + band * 1.5))); |
| 479 | float3 color = board + copper * traceGlow * (1 - chipOn * step(chipBody, .4f)); |
| 480 | if (chipOn > 0) { |
| 481 | float bodyMask = 1 - smoothstep(-fw.x, fw.x, chipBody); |
| 482 | float chipBand = c.b[int(hash21(float2(floor(cx / 14), floor(cell.y / 15)) + 5) * 3.99)]; |
| 483 | float3 chip = deep(.12, f) * .12 + paint(.45 + chipBand * .2, f) * exp(-abs(chipBody) * (14 - 7 * chipBand)) * (.45 + chipBand * 1.2); |
| 484 | chip += paint(.35, f) * .2 * step(abs(chipLocal.y - 2.5), .1f) * step(abs(chipLocal.x - 3), 1.4f); |
| 485 | color = mix(color, chip, bodyMask); |
| 486 | color += copper * 1.1 * pins * (1 - bodyMask); |
| 487 | } |
| 488 | // Packets racing along the depth lanes, one band per trace layer; the music clock |
| 489 | // speeds them up. |
| 490 | float dir = hash11(cx * 5.3 + 7) < .5 ? -1 : 1; |
| 491 | float rate = 2 + 3 * hash11(cx * 9.1); |
| 492 | float pos = (g.y - dir * (c.t * 1.5 + c.m * 1.2) * rate) / 6; |
| 493 | float slot = floor(pos), fp = fract(pos); |
| 494 | float density = .22 + .6 * band; |
| 495 | float present = smoothstep(density, density - .1f, hash21(float2(cx, slot))); |
| 496 | float dash = smoothstep(0.f, .03f, fp) * smoothstep(.3f, .22f, fp); |
| 497 | float head = dir > 0 ? smoothstep(.12f, .3f, fp) : smoothstep(.15f, 0.f, fp); |
| 498 | float3 packetColor = paint(.55 + layer * .12, f); |
| 499 | float packet = present * dash * laneOn; |
| 500 | color += packetColor * packet * (exp(-abs(local.x) / (tw * .8)) * (1.5 + head * 1.8) + exp(-abs(local.x) * 5) * .25); |
| 501 | // Packets hopping around the ring traces. |
| 502 | float around = (g.x + (hash11(cell.y) < .5 ? -1 : 1) * (c.t * 3 + c.m * 2.5)) / 4; |
| 503 | float hopId = floor(around) - N / 4 * floor(floor(around) / (N / 4)); |
| 504 | float hop = crossOn * smoothstep(.25f, .15f, abs(fract(around) - .5)) * step(hash21(float2(hopId, cell.y)), .35f); |
| 505 | color += paint(.75, f) * hop * exp(-abs(local.y) / (tw * .8)) * 1.3; |
| 506 | // Attack: a packet burst spreading from the vanishing point. |
| 507 | float h = tnAttack(c); |
| 508 | float front = 1.2 + 5 * h; |
| 509 | float zone = smoothstep(front - .8, front, z) * sqrt(h); |
| 510 | float burst = smoothstep(.55f, 1.f, fract(g.y / 3 + c.t * 4)); |
| 511 | float3 average = board + copper * .3 + packetColor * density * .08; |
| 512 | color = mix(color, average, blur); |
| 513 | color += paint(.85, f) * zone * mix(max(lane, crossLine * .7) * (burst * 3 + .6), .5f, blur); |
| 514 | float3 core = paint(.5, f) * .5 + paint(.85, f) * exp(-r * 9) * 1.2; |
| 515 | return mix(core, color, tnFog(z, c, .03)); |
| 516 | } |
| 517 | |
| 518 | // ---------------------------------------------------------------- 107 Helix Stair |
| 519 | // Looking straight down a deep stairwell while descending the spiral. Each step's edge is a |
| 520 | // strip light, a handrail coils around the open well and the bottom fades into coloured |
| 521 | // mist. Bass rolls a swell of light down the steps, highs glint on the rail and attacks |
| 522 | // light a run of steps. |
| 523 | float3 helixStair(Ctx c, constant NativeFrame &f) { |
| 524 | float2 vanish = tnDrift(c.t * .6, float2(.1, .08)); |
| 525 | float2 d = tnBend(c.uv, vanish); |
| 526 | float r = max(length(d), 1e-4f), a = atan2(d.y, d.x); |
| 527 | const float R = 1, Ri = .4, S = 18; |
| 528 | float P = 1.7 * c.size; |
| 529 | // Descent: zoom travel plus the music clock, so energetic passages hurry down. |
| 530 | float descend = c.travel * .95 + c.m * .3; |
| 531 | float spin = descend / P * TAU * .45 + c.t * .06; |
| 532 | float theta = a + spin; |
| 533 | float stepF = theta * S / TAU; |
| 534 | float s0 = floor(stepF); |
| 535 | float frac = stepF - s0; |
| 536 | float z0 = s0 * P / S - descend; |
| 537 | float zWall = R / r; |
| 538 | float need = max(.18f, Ri / r); |
| 539 | float n = ceil((need - z0) / P); |
| 540 | float zs = z0 + n * P; |
| 541 | float stepId = s0 + n * S; |
| 542 | bool tread = zs * r <= R; |
| 543 | float zSurface = tread ? zs : zWall; |
| 544 | float h = tnAttack(c); |
| 545 | float3 color; |
| 546 | if (tread) { |
| 547 | float rho = zs * r; |
| 548 | float edgeScreen = (1 - frac) * TAU / S * r; |
| 549 | float wave = pow(.5 + .5 * sin(stepId * .42 - c.t * 3.2 - c.m * 3), 4.f); |
| 550 | float run = c.hit * smoothstep(P * (.6 + 2.6 * h), P * .4f, zs); |
| 551 | float stepBand = c.b[int(hash11(stepId * .37) * 3.99)]; |
| 552 | float level = .9 + c.b.x * 1.8 * wave + stepBand * 2.2 + run * 3; |
| 553 | float3 light = paint(stepId * .037 + .1 + stepBand * .2, f); |
| 554 | float plank = smoothstep(.0f, .04f, abs(fract((rho - Ri) / (R - Ri) * 3) - .5)); |
| 555 | float3 treadColor = deep(.25 + stepId * .011, f) * .16 * (.55 + .45 * frac) * (.7 + .3 * plank); |
| 556 | treadColor *= smoothstep(0.f, .25f, frac); |
| 557 | treadColor += light * exp(-(1 - frac) * TAU / S * rho * (30 - 16 * stepBand)) * .25 * level; |
| 558 | treadColor += light * (exp(-edgeScreen / .0035) * 2 + exp(-edgeScreen / .02) * .3) * level; |
| 559 | treadColor += paint(.6, f) * exp(-(rho - Ri) / zs / .006) * .4; |
| 560 | color = treadColor; |
| 561 | } else { |
| 562 | float above = floor((zWall - z0) / P); |
| 563 | float below = z0 + (above + 1) * P - zWall; |
| 564 | float groove = smoothstep(.06f, 0.f, abs(fract(theta * 12 / TAU) - .5) - .44); |
| 565 | float course = smoothstep(.0f, .05f, abs(fract((zWall + descend) * 2.2) - .5) - .42); |
| 566 | float belowId = s0 + (above + 1) * S; |
| 567 | float belowBand = c.b[int(hash11(belowId * .37) * 3.99)]; |
| 568 | float3 wallColor = (deep(.3, f) * .3 + paint(.4, f) * .1) * (1 - groove * .6) * (1 - course * .4); |
| 569 | wallColor += paint(.7 + c.b.z * .2, f) * groove * c.b.z * .5; |
| 570 | wallColor += paint(belowId * .037 + .1 + belowBand * .2, f) * exp(-below * (4 - 2 * belowBand)) * (.5 + belowBand * 1.4); |
| 571 | color = wallColor; |
| 572 | } |
| 573 | const float railHeight = .22; |
| 574 | float ramp = theta * P / TAU - descend - railHeight; |
| 575 | float nr = round((Ri / r - ramp) / P); |
| 576 | float zr = ramp + nr * P; |
| 577 | if (zr > .15 && zr < zSurface + .02) { |
| 578 | float railScreen = abs(r - Ri / zr); |
| 579 | float railW = .02 / zr; |
| 580 | float glint = pow(hash21(float2(floor(theta * 64 / TAU + nr * 64), 3)), 12.f) * pow(.5 + .5 * sin(c.t * 7 + theta * 30), 4.f); |
| 581 | color += paint(.85, f) * (exp(-railScreen / railW) * (1 + glint * c.b.w * 6 + c.b.w * .8) + exp(-railScreen / (railW * 5)) * (.2 + c.b.w * .4)); |
| 582 | } |
| 583 | float mist = 1 - exp(-zSurface * (.05 + c.fog * .14)); |
| 584 | float3 mistColor = paint(.58 + c.b.y * .25, f) * .32 + paint(.85, f) * exp(-r * 7) * .9; |
| 585 | return mix(color, mistColor, mist); |
| 586 | } |
| 587 | |
| 588 | // ---------------------------------------------------------------- 108 Mirror Regress |
| 589 | // An infinity mirror: nested rounded frames in the canvas shape recede forever, each lined |
| 590 | // with an LED strip in its own colour and tilted against its neighbours. Bands drive running |
| 591 | // lights along individual strips; attacks send a ripple of light inward through the frames. |
| 592 | |
| 593 | |
| 594 | // ---------------------------------------------------------------- 109 Laser Bore |
| 595 | // A bore built only of laser light: six fans of beams radiate from the vanishing point and |
| 596 | // counter-rotate, laser rings flash past and haze glows between. Each fan's brightness |
| 597 | // follows a band; attacks splay the uppermost fan open. |
| 598 | float3 laserBore(Ctx c, constant NativeFrame &f) { |
| 599 | float2 vanish = tnDrift(c.t * 1.1, float2(.25, .16)); |
| 600 | float2 d = tnBend(c.uv, vanish); |
| 601 | float r = max(length(d), 1e-3f), a = atan2(d.y, d.x); |
| 602 | float z = 1 / r; |
| 603 | const float speed = 3; |
| 604 | float zw = z + c.travel * speed; |
| 605 | float fog = tnFog(z, c, .02); |
| 606 | float haze = fbm3(float3(cos(a) * 1.5, sin(a) * 1.5, log(r) * 1.4 - c.t * .15), 3); |
| 607 | float3 color = deep(.15, f) * .07 + deep(.6, f) * .3 * haze * haze; |
| 608 | float3 scatter = 0; |
| 609 | for (int i = 0; i < 6; ++i) { |
| 610 | float fi = float(i); |
| 611 | float dir = (i & 1) ? -1.f : 1.f; |
| 612 | float centre = fi * TAU / 6 + dir * (c.t * (.18 + fi * .03) + c.travel * .03); |
| 613 | float top = .5 + .5 * cos(centre - PI * .5); |
| 614 | float spread = (.42 + .1 * sin(c.t * .4 + fi * 1.7)) * (1 + c.hit * 1.6 * pow(top, 4.f)); |
| 615 | const float M = 7; |
| 616 | float local = tnWrap(a - centre); |
| 617 | float spacing = spread / (M - 1); |
| 618 | float j = clamp(round(local / spacing + (M - 1) * .5), 0.f, M - 1); |
| 619 | float beamAngle = (j - (M - 1) * .5) * spacing; |
| 620 | float dist = r * abs(sin(local - beamAngle)); |
| 621 | float width = .0035 * c.size * (.25 + r); |
| 622 | float pulse = .6 + .4 * sin(zw * 1.7 - fi * 1.3 + j * 1.1); |
| 623 | float bright = (.5 + c.b[i & 3] * 1.8) * (.3 + .7 * fog) * pulse; |
| 624 | float3 beam = paint(fi * .17 + j * .02 + .05, f); |
| 625 | color += beam * exp(-dist / width) * 1.4 * bright; |
| 626 | scatter += beam * (exp(-dist / (width * 12 + .02)) + smoothstep(spread * .5f + .12f, spread * .5f - .04f, abs(local)) * .12) * bright; |
| 627 | } |
| 628 | color += scatter * (.07 + .2 * haze); |
| 629 | const float ringSpacing = 2.4; |
| 630 | float ringBase = floor(zw / ringSpacing + .5); |
| 631 | for (int k = -1; k <= 2; ++k) { |
| 632 | float id = ringBase + float(k); |
| 633 | float ringZ = id * ringSpacing - c.travel * speed; |
| 634 | if (ringZ < .2) continue; |
| 635 | float ringR = 1 / ringZ; |
| 636 | float dist = abs(r - ringR); |
| 637 | float width = .005 * ringR + c.px; |
| 638 | float3 ring = paint(hash11(id * 7.1) * .9 + .05, f); |
| 639 | color += ring * (exp(-dist / width) * 1.3 + exp(-dist / (width * 10)) * .2) * smoothstep(16.f, 5.f, ringZ); |
| 640 | } |
| 641 | color += paint(.9, f) * exp(-r * 10) * 1.1 + paint(.6, f) * exp(-r * 3) * .25; |
| 642 | return color; |
| 643 | } |
| 644 | |
| 645 | // ---------------------------------------------------------------- 110 Twist Checker |
| 646 | // A round tube of raised glossy checker tiles whose rings twist with depth and time. Bevels |
| 647 | // catch a sweeping specular light. Bass lifts individual tiles off the wall; attacks flip a |
| 648 | // ring of tiles to bright. |
| 649 | float3 tnCheckerWall(float a, float z, float N, float speed, Ctx c, constant NativeFrame &f) { |
| 650 | // Bass winds the twist tighter; the music clock speeds both twist and travel. |
| 651 | float twist = z * (.3 + .14 * c.b.x) + c.t * .22 + c.m * .15; |
| 652 | float drive = c.travel * speed + c.m * .6; |
| 653 | float zw = z + drive; |
| 654 | float2 uv = float2((a + twist) / TAU * N, zw * N / TAU); |
| 655 | float2 id = floor(uv), l = fract(uv); |
| 656 | float column = id.x - N * floor(id.x / N); |
| 657 | float parity = id.x + id.y - 2 * floor((id.x + id.y) * .5); |
| 658 | float ex = min(l.x, 1 - l.x), ey = min(l.y, 1 - l.y); |
| 659 | float e = min(ex, ey); |
| 660 | float top = smoothstep(0.f, .14f, e); |
| 661 | float2 slope = ex < ey ? float2(l.x < .5 ? -1 : 1, 0) : float2(0, l.y < .5 ? -1 : 1); |
| 662 | float2 lightDir = normalize(float2(cos(c.t * .4), .8)); |
| 663 | float facing = dot(slope, lightDir) * (1 - top); |
| 664 | // The two tones drift along the palette with the low-mid and high-mid bands. |
| 665 | float3 base = parity < .5 ? paint(.16 + c.b.y * .14, f) : paint(.64 + c.b.z * .14, f); |
| 666 | float rowBand = c.b[int(hash11(id.y * .71) * 3.99)]; |
| 667 | float3 color = base * (.27 + .23 * top + .42 * facing) * (.2 + .8 * smoothstep(0.f, .03f, e)) * (1 + rowBand * .5 * top); |
| 668 | float sweep = pow(max(cos(a - c.t * .7 - c.m * .8), 0.f), 18.f) * top; |
| 669 | color += paint(.95, f) * sweep * (.5 + c.b.w * 1.2); |
| 670 | float lift = c.b.x * smoothstep(.5f, .9f, hash21(float2(column, id.y))) * exp(-z * .2) * 1.2; |
| 671 | float side = step(l.y, lift * .45); |
| 672 | color = mix(color * (1 + lift * .9), base * .3, side); |
| 673 | color += paint(.9, f) * exp(-abs(l.y - lift * .45) * 40) * lift * .8; |
| 674 | float h = tnAttack(c); |
| 675 | float rowZ = (id.y + .5) * TAU / N - drive; |
| 676 | float front = 2.4 + 4 * (1 - h); |
| 677 | float flip = c.hit * exp(-pow((rowZ - front) / .5, 2.f)); |
| 678 | color = mix(color, paint(.92 + .08 * parity, f) * 1.6 * (.6 + .4 * top), clamp(flip, 0.f, .85f)); |
| 679 | float blur = smoothstep(.3f, .9f, fwidth(uv.y)); |
| 680 | return mix(color, (paint(.16, f) + paint(.64, f)) * .22, blur); |
| 681 | } |
| 682 | |
| 683 | float3 twistChecker(Ctx c, constant NativeFrame &f) { |
| 684 | float2 vanish = tnDrift(c.t, float2(.3, .2)); |
| 685 | float2 d = tnBend(c.uv, vanish); |
| 686 | float r = max(length(d), 1e-3f), a = atan2(d.y, d.x); |
| 687 | float z = 1 / r; |
| 688 | const float speed = 2.6; |
| 689 | float count = 12 / c.size; |
| 690 | float n0 = 2 * floor(count * .5); |
| 691 | float blend = fract(count * .5); |
| 692 | float3 color = tnCheckerWall(a, z, max(n0, 4.f), speed, c, f); |
| 693 | if (blend > .001) color = mix(color, tnCheckerWall(a, z, max(n0 + 2, 4.f), speed, c, f), blend); |
| 694 | color *= .47 + .38 * smoothstep(3.f, .6f, z); |
| 695 | float3 core = paint(.5, f) * .4 + paint(.85, f) * exp(-r * 8) * 1.1; |
| 696 | return mix(core, color, tnFog(z, c, .03)); |
| 697 | } |
| 698 | |
| 699 | // ---------------------------------------------------------------- 111 Foam Tube |
| 700 | // A tunnel of packed iridescent soap bubbles that drift and wobble: clear centres, swirling |
| 701 | // thin-film colour toward the rims and window highlights. Highs shimmer the small bubbles in |
| 702 | // the gaps, bass swells the near bubbles and attacks pop a ring of bubbles that then regrow. |
| 703 | float tnFoamCells(float2 p, float period, float phase, thread float2 &toSite, thread float2 &cellId, thread float &second) { |
| 704 | float2 cell = floor(p), fr = fract(p); |
| 705 | float first = 8; |
| 706 | second = 8; |
| 707 | for (int y = -1; y <= 1; ++y) for (int x = -1; x <= 1; ++x) { |
| 708 | float2 g = float2(x, y), id = cell + g; |
| 709 | float2 wrapped = float2(id.x - period * floor(id.x / period), id.y); |
| 710 | float2 seed = hash22(wrapped); |
| 711 | float2 site = g + .5 + .36 * sin(phase * (.6 + seed.yx * .8) + seed * TAU); |
| 712 | float2 v = site - fr; |
| 713 | float dd = dot(v, v); |
| 714 | if (dd < first) { second = first; first = dd; toSite = v; cellId = wrapped; } else if (dd < second) second = dd; |
| 715 | } |
| 716 | second = sqrt(second); |
| 717 | return sqrt(first); |
| 718 | } |
| 719 | |
| 720 | float3 tnFoamWall(float a, float z, float N, float speed, Ctx c, constant NativeFrame &f) { |
| 721 | float zw = z + c.travel * speed; |
| 722 | float2 p = float2((a / TAU + .5) * N + c.t * .05, zw * N / TAU + c.t * .12); |
| 723 | float2 toSite, cellId; |
| 724 | float second; |
| 725 | float first = tnFoamCells(p, N, c.t * .8, toSite, cellId, second); |
| 726 | float q = 2 * first / (first + second); |
| 727 | float cellZ = (cellId.y + .5 - c.t * .12) * TAU / N - c.travel * speed; |
| 728 | float h = tnAttack(c); |
| 729 | float front = 1.9 + 4 * (1 - h); |
| 730 | float pop = c.hit * exp(-pow((cellZ - front) / .7, 2.f)); |
| 731 | float swell = c.b.x * exp(-z * .5); |
| 732 | float radius = clamp(.93 + .06 * swell - pop * .8, .05f, 1.f); |
| 733 | float qn = q / radius; |
| 734 | float seed = hash21(cellId); |
| 735 | float3 backdrop = deep(.35 + .15 * sin(zw * .2), f) * .07; |
| 736 | float3 color = backdrop * .6; |
| 737 | if (qn < 1) { |
| 738 | float nz = sqrt(1 - qn * qn); |
| 739 | float thickness = .2 + .7 * (1 - nz) + .35 * noise2(toSite * 3 + seed * 17 + c.t * .3) + c.t * .04 + seed * 2; |
| 740 | float3 film = filmColor(thickness, f); |
| 741 | float fresnel = pow(qn, 9.f); |
| 742 | float swirl = pow(.5 + .5 * sin(thickness * 13 + c.t * .5), 6.f) * (1 - fresnel); |
| 743 | color = backdrop + film * (.03 + 1.1 * fresnel + .14 * swirl); |
| 744 | float2 rel = -toSite / radius; |
| 745 | float2 w0 = rel - float2(-.17, .2); |
| 746 | float window = exp(-dot(w0, w0) * 160) * 1.2 + exp(-dot(rel - float2(.2, -.22), rel - float2(.2, -.22)) * 400) * .4; |
| 747 | color += paint(.95, f) * window * (1 - pop); |
| 748 | } |
| 749 | float rimLine = exp(-abs(qn - 1) * 45); |
| 750 | color += filmColor(seed * 1.7 + c.t * .05 + .4, f) * rimLine * (.55 + pop * 4); |
| 751 | float2 sp = p * 3 + float2(0, c.t * .2); |
| 752 | float2 sid = floor(sp); |
| 753 | sid.x -= 3 * N * floor(sid.x / (3 * N)); |
| 754 | float sh = hash21(sid + 13); |
| 755 | float sr = length(fract(sp) - .5 - (hash22(sid) - .5) * .3) / (.12 + .1 * hash11(sh * 9)); |
| 756 | float small = exp(-abs(sr - 1) * 6) * step(.45f, sh) * smoothstep(.97f, 1.04f, qn); |
| 757 | float shimmer = .35 + c.b.w * 2.5 * pow(.5 + .5 * sin(c.t * 9 + sh * 40), 3.f); |
| 758 | color += filmColor(sh * 2 + c.t * .1, f) * small * shimmer * .8; |
| 759 | float blur = smoothstep(.35f, .9f, fwidth(p.y)); |
| 760 | return mix(color, filmColor(.5, f) * .2, blur); |
| 761 | } |
| 762 | |
| 763 | float3 foamTube(Ctx c, constant NativeFrame &f) { |
| 764 | float2 vanish = tnDrift(c.t * .7, float2(.26, .18)); |
| 765 | float2 d = tnBend(c.uv, vanish); |
| 766 | float r = max(length(d), 1e-3f), a = atan2(d.y, d.x); |
| 767 | float z = 1 / r; |
| 768 | const float speed = 1.5; |
| 769 | float count = 13 / c.size; |
| 770 | float n0 = floor(count); |
| 771 | float blend = fract(count); |
| 772 | float3 color = tnFoamWall(a, z, max(n0, 4.f), speed, c, f); |
| 773 | if (blend > .001) color = mix(color, tnFoamWall(a, z, max(n0 + 1, 4.f), speed, c, f), blend); |
| 774 | float3 core = filmColor(.3 + c.t * .02, f) * .35 + paint(.9, f) * exp(-r * 8); |
| 775 | return mix(core, color, tnFog(z, c, .03)) * .78; |
| 776 | } |
| 777 | |
| 778 | // ---------------------------------------------------------------- 112 Polygon Stack |
| 779 | // A receding stack of thick neon polygon outlines that morph between three and six sides, |
| 780 | // each turned a little further than the one before so the stack twists into a tunnel. Bass |
| 781 | // thickens the near outlines, highs add an echo outline and attacks kick one layer's spin. |
| 782 | // Regular polygon distance (unit circumradius) from polar coordinates. |
| 783 | float tnPolygon(float radius, float a, float sides) { |
| 784 | float sector = TAU / sides; |
| 785 | float local = a - sector * floor(a / sector + .5); |
| 786 | return radius * cos(local) - cos(PI / sides); |
| 787 | } |
| 788 | float tnPolygonMorph(float radius, float a, float sides) { |
| 789 | float n0 = floor(sides); |
| 790 | return mix(tnPolygon(radius, a, n0), tnPolygon(radius, a, n0 + 1), smoothstep(0.f, 1.f, sides - n0)); |
| 791 | } |
| 792 | |
| 793 | float3 polygonStack(Ctx c, constant NativeFrame &f) { |
| 794 | float2 vanish = tnDrift(c.t * .8, float2(.3, .2)); |
| 795 | float r = length(c.uv - vanish); |
| 796 | float haze = fbm2(rot(c.uv - vanish, c.t * .05) * 1.5 + float2(0, -c.travel * .3), 3); |
| 797 | float3 color = deep(.3, f) * (.06 + .06 * haze) + paint(.6, f) * exp(-r * 2.5) * .15; |
| 798 | float3 hot = paint(.95, f) * .06; |
| 799 | const int layers = 22; |
| 800 | for (int k = 0; k < layers; ++k) { |
| 801 | float2 slot = layerSlot(k, layers, c.travel * .19); |
| 802 | float phase = slot.x, id = slot.y; |
| 803 | float fade = layerFade(phase); |
| 804 | if (fade <= 0) continue; |
| 805 | float scale = layerScale(phase, 5); |
| 806 | float2 centre = vanish * (1 - phase) * (1 - phase); |
| 807 | float kick = c.hit * exp(-pow((phase - .72) / .07, 2.f)) * 1.4; |
| 808 | float angle = id * .13 + c.t * .12 + kick; |
| 809 | const float size = 3.2; |
| 810 | float2 q = c.uv - centre; |
| 811 | float sides = 4.5 + 1.5 * sin(id * .61 + c.t * .23); |
| 812 | float dist = tnPolygonMorph(length(q) * scale / size, atan2(q.y, q.x) + angle, sides) * size / scale; |
| 813 | float radius = size / scale; |
| 814 | float width = radius * (.007 + .014 * c.b.x * phase * phase) * c.size + c.px * .5; |
| 815 | if (abs(dist) > width * 26) continue; |
| 816 | float core = 1 - smoothstep(width - c.px, width + c.px, abs(dist)); |
| 817 | float halo = exp(-abs(dist) / (width * 3)); |
| 818 | float echo = exp(-abs(dist + width * 4) / (width * .35 + c.px)) * c.b.w * 1.6; |
| 819 | float3 tint = paint(id * .19 + .05 + phase * .1, f); |
| 820 | color += (tint * (core * .6 + halo * .07 + echo) + hot * core) * fade; |
| 821 | } |
| 822 | return color; |
| 823 | } |
| 824 | |
| 825 | // ---------------------------------------------------------------- 113 Gyroid Caverns |
| 826 | // A raymarched flight through a gyroid lattice with a corridor carved along the camera's |
| 827 | // path. Glowing contour bands wrap the surfaces under soft subsurface light and fog. Bass |
| 828 | // thickens the bands, highs sparkle on the surfaces, attacks send a glow wave outward from |
| 829 | // the camera. |
| 830 | float2 tnCavernPath(float z) { return float2(sin(z * .21) * 1.1 + sin(z * .09) * .7, cos(z * .17) * .9); } |
| 831 | float tnCavern(float3 p, float s, float wall, thread float &g) { |
| 832 | float3 q = p / s; |
| 833 | g = dot(sin(q), cos(q.yzx)); |
| 834 | float shell = (abs(g) - wall) * s * .5; |
| 835 | float tunnel = 1.1 - length(p.xy - tnCavernPath(p.z)); |
| 836 | return max(shell, tunnel); |
| 837 | } |
| 838 | |
| 839 | float3 gyroidCaverns(Ctx c, constant NativeFrame &f) { |
| 840 | float s = .7 * c.size; |
| 841 | // The lattice walls swell with the bass; the flight speeds up with the music clock. |
| 842 | float wall = .22 + .09 * c.b.x; |
| 843 | float zc = c.travel * 1.4 + c.m * .35; |
| 844 | float3 ro = float3(tnCavernPath(zc), zc); |
| 845 | float3 target = float3(tnCavernPath(zc + 2), zc + 2); |
| 846 | float3 rd = cameraRay(c.uv, target - ro, float3(sin(c.t * .13) * .5, 1, 0), 1.1); |
| 847 | float t = .05, glowSum = 0, g = 0; |
| 848 | bool hit = false; |
| 849 | for (int i = 0; i < 72; ++i) { |
| 850 | float3 p = ro + rd * t; |
| 851 | float dd = tnCavern(p, s, wall, g); |
| 852 | glowSum += exp(-max(dd, 0.f) * 14) * .01; |
| 853 | if (dd < .0015 * t) { hit = true; break; } |
| 854 | t += dd * .85; |
| 855 | if (t > 22) break; |
| 856 | } |
| 857 | float3 fogColor = deep(.5, f) * .06 + paint(.55, f) * .05; |
| 858 | float3 color = fogColor; |
| 859 | if (hit) { |
| 860 | float3 p = ro + rd * t; |
| 861 | const float2 e = float2(.004, -.004); |
| 862 | float dummy; |
| 863 | float3 nrm = normalize(e.xyy * tnCavern(p + e.xyy, s, wall, dummy) + e.yyx * tnCavern(p + e.yyx, s, wall, dummy) |
| 864 | + e.yxy * tnCavern(p + e.yxy, s, wall, dummy) + e.xxx * tnCavern(p + e.xxx, s, wall, dummy)); |
| 865 | float3 q = p / s; |
| 866 | float level = dot(cos(q * 1.3), sin(q.zxy * 1.3)); |
| 867 | float contour = abs(fract(level * 1.25 + c.t * .06 + c.m * .15) - .5); |
| 868 | float width = .035 + .06 * c.b.x; |
| 869 | float band = 1 - smoothstep(width * .5f, width, contour); |
| 870 | float bandGlow = exp(-contour * 9); |
| 871 | float diffuse = max(dot(nrm, -rd), 0.f); |
| 872 | float rim = pow(1 - diffuse, 2.f); |
| 873 | float occlusion = clamp(tnCavern(p + nrm * .35, s, wall, dummy) / .35, 0.f, 1.f); |
| 874 | float3 base = deep(.2 + level * .1 + c.b.y * .25, f) * (.05 + .45 * diffuse) * (.3 + .7 * occlusion); |
| 875 | base += paint(.4 + level * .1 + c.b.z * .25, f) * rim * (.3 + c.b.z * .6); |
| 876 | base += paint(.75 + .1 * level, f) * (band * 1.5 + bandGlow * (.25 + .7 * c.b.x)); |
| 877 | float3 sparkCell = floor(p * 9); |
| 878 | float3 sparkOffset = fract(p * 9) - .5 - (hash33(sparkCell) - .5) * .5; |
| 879 | float sparkle = step(.93f, hash31(sparkCell)) * exp(-dot(sparkOffset, sparkOffset) * 60) * pow(.5 + .5 * sin(c.t * 8 + dot(sparkCell, float3(7, 11, 13))), 4.f); |
| 880 | base += paint(.95, f) * sparkle * c.b.w * 4; |
| 881 | float h = tnAttack(c); |
| 882 | float waveDistance = 2.5 + 8 * (1 - h); |
| 883 | base += paint(.9, f) * c.hit * exp(-pow((t - waveDistance) * 2.5, 2.f)) * 1.6; |
| 884 | color = mix(fogColor, base, exp(-t * (.05 + c.fog * .12))); |
| 885 | } |
| 886 | return (color + paint(.6, f) * glowSum * (.5 + c.b.z * .9)) * .88; |
| 887 | } |
| 888 | |
| 889 | // ---------------------------------------------------------------- 114 Spectrum Bore |
| 890 | // A tube built from equalizer bars: every column of the wall extrudes inward to a height set |
| 891 | // by the bands (lows on the floor, highs on the ceiling, mixes between), ring after ring |
| 892 | // receding with travel. Bar faces are segmented like LED meters with bright peak caps. |
| 893 | // With no music the bars still breathe on a slow wave. |
| 894 | float tnBarLevel(float column, float ring, float angle, Ctx c) { |
| 895 | float x = (sin(angle) * .5 + .5) * 3; |
| 896 | int i0 = int(min(floor(x), 2.f)); |
| 897 | float band = mix(c.b[i0], c.b[i0 + 1], x - float(i0)); |
| 898 | float h = hash21(float2(column, ring)); |
| 899 | float breathe = .5 + .5 * sin(c.t * 1.9 + column * .8 + ring * .55); |
| 900 | return .08 + .12 * breathe * (.6 + .4 * h) + band * (.18 + .26 * h); |
| 901 | } |
| 902 | // Attack lift for one ring of bars that rides away from the camera as the attack decays. |
| 903 | float tnBarKick(float ring, float travel, float spacing, Ctx c) { |
| 904 | float front = 1.6 + 5 * (1 - tnAttack(c)); |
| 905 | return c.hit * .22 * exp(-pow((ring * spacing - travel - front) / spacing, 2.f)); |
| 906 | } |
| 907 | |
| 908 | float3 spectrumBore(Ctx c, constant NativeFrame &f) { |
| 909 | float2 vanish = tnDrift(c.t * .9, float2(.24, .15)); |
| 910 | float2 d = tnBend(c.uv, vanish); |
| 911 | float r = max(length(d), 1e-3f), a = atan2(d.y, d.x); |
| 912 | const float columns = 28, spacing = .9, barLength = .5, speed = 2.4, segment = .045; |
| 913 | float travel = c.travel * speed; |
| 914 | float colF = (a + PI) / TAU * columns; |
| 915 | float column = floor(colF); |
| 916 | float fa = colF - column - .5; |
| 917 | float columnAngle = (column + .5) / columns * TAU - PI; |
| 918 | float barHalf = min(.36 * c.size, .48f); |
| 919 | float zWall = 1 / r; |
| 920 | int hitType = 0; |
| 921 | float zHit = zWall, level = 0, ringId = 0; |
| 922 | if (abs(fa) < barHalf) { |
| 923 | float zMin = .3 / r; |
| 924 | float first = floor((zMin + travel) / spacing); |
| 925 | for (int m = 0; m < 10; ++m) { |
| 926 | float ring = first + float(m); |
| 927 | float zs = ring * spacing - travel, ze = zs + barLength; |
| 928 | if (zs > zWall) break; |
| 929 | if (ze < .05) continue; |
| 930 | float lv = tnBarLevel(column, ring, columnAngle, c) + tnBarKick(ring, travel, spacing, c); |
| 931 | float zc = (1 - lv) / r; |
| 932 | if (zc < zs) { |
| 933 | if (zs * r <= 1 && zs > .05) { hitType = 2; zHit = zs; level = lv; ringId = ring; } |
| 934 | break; |
| 935 | } |
| 936 | if (zc <= ze) { hitType = 1; zHit = zc; level = lv; ringId = ring; break; } |
| 937 | } |
| 938 | } |
| 939 | float side = smoothstep(barHalf, barHalf * .6f, abs(fa)); |
| 940 | float3 color; |
| 941 | if (hitType == 1) { |
| 942 | float along = (zHit - (ringId * spacing - travel)) / barLength; |
| 943 | float3 barTint = paint(.05 + level * 1.5, f); |
| 944 | float outline = 1 - smoothstep(.0f, .12f, barHalf - abs(fa)) * 1; |
| 945 | color = barTint * (.05 + .1 * (1 - along)) + barTint * outline * .5 * (1 - along * .6); |
| 946 | color += paint(.95, f) * exp(-along * 30) * .7 + barTint * exp(-(1 - along) * 25) * .3; |
| 947 | } else if (hitType == 2) { |
| 948 | float height = 1 - zHit * r; |
| 949 | float cells = height / segment; |
| 950 | float blur = fwidth(cells); |
| 951 | float lit = smoothstep(.12f, .12f + blur + .05f, fract(cells)) * smoothstep(.92f, .88f - blur, fract(cells)); |
| 952 | lit = mix(lit, .75f, smoothstep(.3f, 1.f, blur)); |
| 953 | float peak = exp(-(level - height) / (segment * .6)); |
| 954 | color = paint(.05 + height * 1.5, f) * (.12 + 1.2 * lit) * (.75 + .25 * side) + paint(.95, f) * peak * lit * .9; |
| 955 | } else { |
| 956 | float zw = zWall + travel; |
| 957 | float ring = floor(zw / spacing); |
| 958 | float u = zw - ring * spacing; |
| 959 | float lvNext = tnBarLevel(column, ring + 1, columnAngle, c); |
| 960 | float lvHere = tnBarLevel(column, ring, columnAngle, c); |
| 961 | float columnLight = smoothstep(.55f, .1f, abs(fa)); |
| 962 | color = deep(.35, f) * .04 * (.6 + .4 * columnLight); |
| 963 | color += paint(.05 + lvNext * 1.5, f) * exp(-(spacing - u) * 6) * .3 * columnLight; |
| 964 | color += paint(.05 + lvHere * 1.5, f) * .06 * step(u, barLength) * columnLight; |
| 965 | color += paint(.5, f) * .1 * exp(-abs(u - barLength) * 30 / max(fwidth(zw) * 8, 1.f)); |
| 966 | } |
| 967 | float3 core = paint(.6, f) * .35 + paint(.85, f) * exp(-r * 8) * 1.1; |
| 968 | return mix(core, color, tnFog(zHit, c, .03)); |
| 969 | } |
| 970 | |
| 971 | // ---------------------------------------------------------------- 115 Ribbon Vortex |
| 972 | // Broad translucent silk ribbons spiral together into a tube, each at its own radius and |
| 973 | // corkscrew rate, folding softly and overlapping in additive light. Bass widens the ribbons, |
| 974 | // highs sparkle along their edges and attacks ripple their edges outward. |
| 975 | |
| 976 | |
| 977 | // ---------------------------------------------------------------- 116 Gate Run |
| 978 | // Flying down an endless avenue of tall lacquered arch gates on a gently curving path over |
| 979 | // a mirror-dark floor, each gate hung with glowing lanterns against a horizon glow. Bass |
| 980 | // swings the lanterns, highs flicker their flames and attacks light a gate's beam trim. |
| 981 | |
| 982 | |
| 983 | // Gate facade at world position (X, Y) on its plane: rgb, opacity and additive lantern glow. |
| 984 | |
| 985 | |
| 986 | #define TUNNEL_EFFECTS(X) X(plasmaBore) X(ledCorridor) X(prismShaft) X(hyperloop) X(barrelWave) X(magmaTube) X(dataConduit) X(helixStair) X(laserBore) X(twistChecker) X(foamTube) X(polygonStack) X(gyroidCaverns) X(spectrumBore) |
| 987 | TUNNEL_EFFECTS(NATIVE_EFFECT) |
| 988 | |
| 989 | // Coaster versions: the same designs riding the roller-coaster course. |
| 990 | NATIVE_COASTER(plasmaBore, 100, false) |
| 991 | NATIVE_COASTER(ledCorridor, 101, true) |
| 992 | NATIVE_COASTER(magmaTube, 105, false) |
| 993 | NATIVE_COASTER(dataConduit, 106, false) |
| 994 | NATIVE_COASTER(helixStair, 107, false) |
| 995 | NATIVE_COASTER(laserBore, 109, false) |
| 996 | NATIVE_COASTER(twistChecker, 110, false) |
| 997 | NATIVE_COASTER(foamTube, 111, false) |
| 998 | NATIVE_COASTER(spectrumBore, 114, false) |