PulseCanvas / app · pulsecanvas.ai / Sources / PulseCanvas / Resources / NativeWormholes.metal
| 1 | // PulseCanvas native designs: tunnels and wormholes (scenes 117–133). Original procedural |
| 2 | // code; see NativeCommon.metal. Every design is a pure function of its uniforms and every |
| 3 | // audio term is zero at zero Chaos. |
| 4 | |
| 5 | // ---------------------------------------------------------------- shared tube helpers |
| 6 | // Centreline offset of the bending tubes (in tube radii) at world depth z. |
| 7 | float2 whPath(float z, float bend) { |
| 8 | return bend * float2(sin(z * .21) + .45 * sin(z * .13 + 1.7), .75 * cos(z * .17) + .35 * sin(z * .09 + .4)); |
| 9 | } |
| 10 | // Screen offset of the bent tube centre at view depth d, for a camera riding the axis at |
| 11 | // world depth zc and looking along the local tangent. |
| 12 | float2 whCentre(float zc, float d, float bend, float lens) { |
| 13 | float2 slope = whPath(zc + .5, bend) - whPath(zc - .5, bend); |
| 14 | return (whPath(zc + d, bend) - whPath(zc, bend) - slope * d) * lens / max(d, 1e-3f); |
| 15 | } |
| 16 | // Lateral offset of the view ray from the bent tube centre at view depth d. |
| 17 | float2 whLateral(float2 uv, float d, float2 base, float2 slope, float zc, float bend, float lens) { |
| 18 | return uv * d / lens - (whPath(zc + d, bend) - base - slope * d); |
| 19 | } |
| 20 | // View of a bending tube of the given radius: the first depth at which the view ray |
| 21 | // leaves the tube, found by a geometric march and a short bisection so the far throat |
| 22 | // stays stable. x = angle around the axis, y = world depth of the wall, z = view depth, |
| 23 | // w = screen radius of the wall circle at that depth. |
| 24 | float4 whTube(float2 uv, float zc, float bend, float lens, float radius) { |
| 25 | float2 base = whPath(zc, bend), slope = whPath(zc + .5, bend) - whPath(zc - .5, bend); |
| 26 | // Start the march near the straight-tube answer when the ray is still inside there. |
| 27 | float guess = .5 * lens * radius / max(length(uv), 1e-3f); |
| 28 | float d = length(whLateral(uv, guess, base, slope, zc, bend, lens)) < radius ? min(guess, 60.f) : .04 * radius; |
| 29 | float lo = 0, hi = 80; |
| 30 | for (int i = 0; i < 26; ++i) { |
| 31 | if (length(whLateral(uv, d, base, slope, zc, bend, lens)) >= radius) { hi = d; break; } |
| 32 | lo = d; |
| 33 | d *= 1.35; |
| 34 | if (d > 80) break; |
| 35 | } |
| 36 | if (hi < 80) { |
| 37 | for (int i = 0; i < 7; ++i) { |
| 38 | float mid = .5 * (lo + hi); |
| 39 | if (length(whLateral(uv, mid, base, slope, zc, bend, lens)) >= radius) hi = mid; else lo = mid; |
| 40 | } |
| 41 | } |
| 42 | d = min(.5 * (lo + hi), 80.f); |
| 43 | float2 lateral = whLateral(uv, d, base, slope, zc, bend, lens); |
| 44 | return float4(atan2(lateral.y, lateral.x), zc + d, d, lens * radius / d); |
| 45 | } |
| 46 | float whWrap(float a) { return a - TAU * floor(a / TAU + .5); } |
| 47 | // Value noise and fbm that repeat every `period` cells in x, for seamless angles. |
| 48 | float whNoiseP(float2 p, float period) { |
| 49 | float2 i = floor(p), fr = fract(p), u = fr * fr * (3 - 2 * fr); |
| 50 | float x0 = i.x - period * floor(i.x / period); |
| 51 | float x1 = x0 + 1 < period ? x0 + 1 : 0.f; |
| 52 | return mix(mix(hash21(float2(x0, i.y)), hash21(float2(x1, i.y)), u.x), |
| 53 | mix(hash21(float2(x0, i.y + 1)), hash21(float2(x1, i.y + 1)), u.x), u.y); |
| 54 | } |
| 55 | float whFbmP(float2 p, float period, int octaves) { |
| 56 | float sum = 0, amplitude = .5; |
| 57 | for (int i = 0; i < octaves; ++i) { |
| 58 | sum += amplitude * whNoiseP(p, period); |
| 59 | p = p * 2 + float2(0, 1.37); |
| 60 | period *= 2; |
| 61 | amplitude *= .5; |
| 62 | } |
| 63 | return sum; |
| 64 | } |
| 65 | // Voronoi that repeats every `period` cells in x. x = nearest distance, y = second |
| 66 | // distance, zw = nearest cell id; toSite receives the offset to the nearest site. |
| 67 | float4 whVoronoiP(float2 p, float period, float jitter, thread float2 &toSite) { |
| 68 | float2 cell = floor(p), fr = fract(p), winner = 0; |
| 69 | float first = 8, second = 8; |
| 70 | toSite = 0; |
| 71 | for (int y = -1; y <= 1; ++y) for (int x = -1; x <= 1; ++x) { |
| 72 | float2 g = float2(x, y), id = cell + g; |
| 73 | id.x -= period * floor(id.x / period); |
| 74 | float2 delta = g + .5 + jitter * (hash22(id) - .5) - fr; |
| 75 | float dist = length(delta); |
| 76 | if (dist < first) { second = first; first = dist; winner = id; toSite = delta; } else second = min(second, dist); |
| 77 | } |
| 78 | return float4(first, second, winner); |
| 79 | } |
| 80 | // Distance fog weight (1 near, 0 far). |
| 81 | float whFog(float d, Ctx c, float base, float range) { return exp(-d * (base + c.fog * range)); } |
| 82 | |
| 83 | // ---------------------------------------------------------------- 117 Storm Eye |
| 84 | // Flying down the eye of a storm: a dense outer cloud wall and two sparse inner wisp |
| 85 | // shells in polar coordinates, lit softly from the calm, bright eye ahead. Attacks fire |
| 86 | // branching lightning inside the nearby cloud banks and light only the cloud around each |
| 87 | // bolt; highs bring fine rain. At zero Chaos the clouds keep a soft inner glow. |
| 88 | // Periodic fbm returning the full sum and the sum of its three broadest octaves. |
| 89 | float2 stormFbm(float2 p, int octaves) { |
| 90 | float sum = 0, broad = 0, amplitude = .5, period = 8; |
| 91 | for (int i = 0; i < octaves; ++i) { |
| 92 | sum += amplitude * whNoiseP(p, period); |
| 93 | if (i == 2) broad = sum; |
| 94 | p = p * 2 + float2(0, 1.37); |
| 95 | period *= 2; |
| 96 | amplitude *= .5; |
| 97 | } |
| 98 | return float2(sum, broad); |
| 99 | } |
| 100 | float2 stormWarp(float2 w, float t) { |
| 101 | return (float2(whFbmP(w * .5 + float2(0, t * .04), 4, 2), whFbmP(w * .5 + float2(2, 5.3 - t * .03), 4, 2)) - .5) * 2.8; |
| 102 | } |
| 103 | float stormJag(float s, float seed, float t) { |
| 104 | float x = s * 4 + seed * 7, k = floor(x), fr = x - k; |
| 105 | float coarse = mix(hash11(k + seed * 13), hash11(k + 1 + seed * 13), fr) - .5; |
| 106 | float y = s * 13 + seed * 3, j = floor(y), fy = y - j; |
| 107 | float fine = mix(hash11(j + seed * 29), hash11(j + 1 + seed * 29), fy) - .5; |
| 108 | float wobble = mix(sin(t * 7 + k * 1.7 + seed), sin(t * 7 + (k + 1) * 1.7 + seed), fr); |
| 109 | return coarse + fine * .45 + .12 * wobble; |
| 110 | } |
| 111 | // Distance from `local` (wall offset from the bolt centre) to a forked bolt. |
| 112 | float stormBolt(float2 local, float seed, float t) { |
| 113 | float angle = PI * .5 + (hash11(seed * 1.7) - .5) * 1.5; |
| 114 | float2 dir = float2(cos(angle), sin(angle)), nrm = float2(-dir.y, dir.x); |
| 115 | float len = .75 + hash11(seed + 3.1) * .45; |
| 116 | float s = dot(local, dir) / len, sc = clamp(s, -1.f, 1.f); |
| 117 | float main = length(float2((s - sc) * len, dot(local, nrm) - stormJag(sc, seed, t) * .26 * len)); |
| 118 | float s0 = (hash11(seed + 5.3) - .5) * .9; |
| 119 | float2 origin = dir * s0 * len + nrm * stormJag(s0, seed, t) * .26 * len; |
| 120 | float turn = (hash11(seed + 8.9) > .5 ? 1 : -1) * (.5 + hash11(seed + 2.2) * .4); |
| 121 | float2 bdir = float2(dir.x * cos(turn) - dir.y * sin(turn), dir.x * sin(turn) + dir.y * cos(turn)); |
| 122 | float blen = len * .55; |
| 123 | float2 bl = local - origin; |
| 124 | float bs = dot(bl, bdir) / blen, bsc = clamp(bs, 0.f, 1.f); |
| 125 | float branch = length(float2((bs - bsc) * blen, dot(bl, float2(-bdir.y, bdir.x)) - stormJag(bsc, seed + 17, t) * .2 * blen * bsc)); |
| 126 | return min(main, branch * 1.25); |
| 127 | } |
| 128 | float3 stormEye(Ctx c, constant NativeFrame &f) { |
| 129 | const float lens = 1.05, rowGap = 1.9; |
| 130 | // The music clock adds to the forward motion, so energetic passages speed it up. |
| 131 | float zc = c.travel * 1.6 + c.m * 1.2; |
| 132 | float4 tube = whTube(c.uv, zc, .45, lens, 1); |
| 133 | float a = tube.x, r = tube.w; |
| 134 | float3 eye = paint(.78, f) * .5 + paint(.95, f) * .1; |
| 135 | float3 color = 0; |
| 136 | float transmit = 1; |
| 137 | for (int s = 0; s < 3; ++s) { |
| 138 | float radius = s == 0 ? .5 : (s == 1 ? .74 : 1.f); |
| 139 | float d = min(lens * radius / max(r, 1e-3f), 80.f); |
| 140 | float z = zc + d; |
| 141 | // Fine cloud detail dissolves into the haze once it is smaller than a pixel. |
| 142 | float foot = c.px * d * d / lens * 1.25 / c.size; |
| 143 | float calm = smoothstep(.08f, .5f, foot); |
| 144 | float2 w = float2(a / TAU * 8 + float(s) * 2, z * 1.25 / c.size + float(s) * 17.3); |
| 145 | int octaves = s == 2 ? 6 : 3 + s; |
| 146 | // One warp serves both samples; the lighting sample needs only the broad octaves. |
| 147 | float2 warped = w + stormWarp(w, c.t + c.m * 2); |
| 148 | float2 sample = stormFbm(warped, octaves); |
| 149 | float dens = mix(sample.x, .5f, calm); |
| 150 | float ahead = mix(whFbmP(warped + float2(0, .3), 8, 3) + sample.x - sample.y, .5f, calm); |
| 151 | float rim = clamp((dens - ahead) * 5, -1.f, 1.f); |
| 152 | float cover = s == 2 ? 1.f : smoothstep(s == 0 ? .6f : .52f, s == 0 ? .8f : .72f, dens) * (s == 0 ? .75f : .9f); |
| 153 | float body = smoothstep(.2f, .85f, dens); |
| 154 | float3 cloud = mix(deep(.3 + dens * .2, f) * .18, paint(.2 + dens * .45, f) * .42, body); |
| 155 | cloud *= .45 + .9 * max(rim, 0.f) + .25 * body; |
| 156 | cloud += paint(.75, f) * pow(max(rim, 0.f), 3.f) * body * (.35 + c.b.z * 1.4); |
| 157 | // Soft inner glow drifting through the banks (always on, never music driven). |
| 158 | float pocket = smoothstep(.55f, .9f, whNoiseP(w * .5 + float2(0, -c.t * .1), 4)); |
| 159 | // Low and low-mid bands swell the glow pockets in their own halves of the storm. |
| 160 | float pocketBand = mix(c.b.x, c.b.y, step(0.f, sin(a))); |
| 161 | cloud += paint(.62 + dens * .2, f) * pocket * body * (.55 + .45 * sin(c.t * .9 + w.y * .7) + pocketBand * 2.2) * .3; |
| 162 | // Lightning in the nearest cloud cells (rows x four sectors): each bolt lights only |
| 163 | // its own neighbourhood of cloud. |
| 164 | float row = floor(z / rowGap); |
| 165 | float sector = floor((a + PI) / TAU * 4); |
| 166 | for (int k = -1; k <= 1; ++k) for (int m = -1; m <= 1; ++m) { |
| 167 | float id = row + float(k), boltZ = (id + .5) * rowGap, gap = boltZ - zc; |
| 168 | float cell = sector + float(m); |
| 169 | cell -= 4 * floor(cell / 4); |
| 170 | float seed = id * 4 + cell; |
| 171 | float strength = c.hit * step(.55f, hash11(seed * 3.7)) * smoothstep(.2f, 1.2f, gap) * (1 - smoothstep(5.f, 7.5f, gap)); |
| 172 | if (strength <= 0) continue; |
| 173 | strength *= .8 + .2 * sin(c.t * 31 + seed * 5); |
| 174 | float boltAngle = (cell + .2 + .6 * hash11(seed * 7.1)) / 4 * TAU - PI; |
| 175 | float3 offset = float3(whWrap(a - boltAngle), z - boltZ, (1 - radius) * 1.3); |
| 176 | // Compact light pool: every bolt that can reach this pixel is evaluated. |
| 177 | float reach = max(1 - length(offset * float3(1, .6, 1)), 0.f); |
| 178 | float pool = reach * reach * strength; |
| 179 | cloud += paint(.86, f) * pool * (.3 + body) * 1.2; |
| 180 | if (s == 2 && length(offset.xy) < 1.9) { |
| 181 | float width = max(c.px * d * d / lens, .006f); |
| 182 | float bolt = stormBolt(float2(offset.x * radius, offset.y), seed, c.t); |
| 183 | cloud += (paint(.96, f) * exp(-bolt / (width * 1.5)) + paint(.82, f) * exp(-bolt * 7) * .45) * strength * 2.4; |
| 184 | } |
| 185 | } |
| 186 | float clear = whFog(d, c, .05, .1); |
| 187 | cloud = mix(eye * (.3 + .7 * smoothstep(.2f, .9f, dens)), cloud, clear); |
| 188 | color += transmit * cover * cloud; |
| 189 | transmit *= 1 - cover; |
| 190 | } |
| 191 | color += paint(.88, f) * .3 * exp(-r * 5); |
| 192 | // Fine rain streaks driven by the highs. |
| 193 | if (c.b.w > .001) { |
| 194 | float rain = 0; |
| 195 | for (int layer = 0; layer < 2; ++layer) { |
| 196 | float scale = 9 + float(layer) * 6; |
| 197 | float2 p = c.uv * scale; |
| 198 | p.x += p.y * .22; |
| 199 | float column = floor(p.x), within = fract(p.x) - .5; |
| 200 | float seed = hash11(column + float(layer) * 41); |
| 201 | float y = fract(p.y * .12 + c.t * (1.4 + float(layer) * .6) + seed); |
| 202 | rain += exp(-within * within * 900) * smoothstep(0.f, .05f, y) * (1 - smoothstep(.05f, .22f, y)) * step(.45f, seed); |
| 203 | } |
| 204 | color += paint(.92, f) * rain * c.b.w * .7; |
| 205 | } |
| 206 | return color * .85; |
| 207 | } |
| 208 | |
| 209 | // ---------------------------------------------------------------- 118 Sonar Pipe |
| 210 | // Inside a brushed-metal pipe: fine circumferential grain, long anisotropic highlights, |
| 211 | // seams with rivets, and sonar pings (thin bright rings with trailing ripples) racing |
| 212 | // along the pipe in both directions so their ripples interfere. Bass strengthens the |
| 213 | // outbound pings, each attack launches a fresh ping from the camera, highs shimmer. |
| 214 | float sonarWave(float x, float spacing, float width, float outbound) { |
| 215 | float fr = fract(x); |
| 216 | float behind = (outbound > 0 ? 1 - fr : fr) * spacing; |
| 217 | float nearest = min(fr, 1 - fr) * spacing; |
| 218 | return exp(-nearest * nearest / (width * width)) + exp(-behind * .9) * cos(behind * 9) * .7; |
| 219 | } |
| 220 | float3 sonarPipe(Ctx c, constant NativeFrame &f) { |
| 221 | const float lens = 1.1; |
| 222 | // The music clock adds to the forward motion, so energetic passages speed it up. |
| 223 | float zc = c.travel * 1.5 + c.m * 1.0; |
| 224 | float4 tube = whTube(c.uv, zc, .3, lens, 1); |
| 225 | float a = tube.x, z = tube.y, d = tube.z; |
| 226 | float foot = c.px * d * d / lens; |
| 227 | float sharp = exp(-foot * 40); |
| 228 | // Brushed grain: fine lines running around the pipe. |
| 229 | float grain = whNoiseP(float2(a / TAU * 3, z * 170), 3) * .45 + whNoiseP(float2(a / TAU * 5 + .5, z * 55), 5) * .35 + whNoiseP(float2(a / TAU * 2, z * 9), 2) * .2; |
| 230 | grain = mix(.5, grain, sharp * .8 + .2 * exp(-foot * 6)); |
| 231 | // Seams every 1.25 with a rivet row on each side. |
| 232 | float seamZ = z - round(z / 1.25) * 1.25; |
| 233 | float seam = 1 - smoothstep(.006f, .014f + foot, abs(seamZ)); |
| 234 | float lip = smoothstep(.012f, .022f, abs(seamZ)) * (1 - smoothstep(.022f, .05f, abs(seamZ))); |
| 235 | float cellAngle = (floor(a / TAU * 16) + .5) * TAU / 16; |
| 236 | float2 rivet = float2(whWrap(a - cellAngle), (abs(seamZ) - .085) / clamp(d, .5f, 2.5f)); |
| 237 | float rivetR = length(rivet) / .032; |
| 238 | float dome = sqrt(max(1 - rivetR * rivetR, 0.f)); |
| 239 | float rivetLit = dome > 0 ? (.25 + .75 * max(dot(normalize(float3(rivet / .032, dome)), normalize(float3(-.4, .6, .7))), 0.f)) : 0.f; |
| 240 | float rivetSpec = dome > 0 ? pow(max(dot(normalize(float3(rivet / .032, dome)), normalize(float3(-.3, .45, .85))), 0.f), 24.f) : 0.f; |
| 241 | float rivetEdge = smoothstep(1.f + foot * 30, 1.f, rivetR); |
| 242 | // Anisotropic highlights: long streaks along the pipe, broken into rings by the grain. |
| 243 | float streak = pow(max(cos(a - 1.75), 0.f), 14.f) + .55 * pow(max(cos(a + 1.35), 0.f), 8.f); |
| 244 | float aniso = streak * (.25 + 1.6 * grain * grain) * (.45 + .55 * smoothstep(.3f, 3.f, d)); |
| 245 | float plate = hash11(round(z / 1.25) * 3.1); |
| 246 | float3 metal = mix(deep(.2, f), paint(.28 + plate * .06, f), .45) * (.07 + .24 * grain) * (.85 + .3 * plate); |
| 247 | metal += paint(.5 + grain * .25, f) * aniso * .85; |
| 248 | metal *= 1 - seam * .85; |
| 249 | metal += paint(.6, f) * lip * .1; |
| 250 | metal = mix(metal, paint(.45, f) * rivetLit * .5 + paint(.95, f) * rivetSpec * .6, rivetEdge * sharp); |
| 251 | // Sonar pings: an outbound and an inbound train interfere. |
| 252 | float spacing = 2.6 * c.size, width = .028; |
| 253 | float widthEff = max(width, foot * .8); |
| 254 | float outbound = sonarWave((z - c.t * 2.4 - c.m * 2.5) / spacing, spacing, widthEff, 1) * (1 + c.b.x * 2.2); |
| 255 | float inbound = sonarWave((z + c.t * 1.5 + c.m * 1.5) / (spacing * 1.47) + .31, spacing * 1.47, widthEff, -1) * (.8 + c.b.z * 1.6); |
| 256 | float field = (outbound + inbound) * mix(1.f, width / widthEff, .7f); |
| 257 | float ring = (field * field * .4 + max(field, 0.f) * .6) * smoothstep(.25f, 1.1f, d); |
| 258 | // A fresh ping rides out from the camera as each attack envelope decays. |
| 259 | float pingZ = zc + .7 + (1 - c.hit) * 9; |
| 260 | float behindPing = pingZ - z; |
| 261 | float ping = exp(-pow((z - pingZ) / widthEff, 2.f)) * 2 + step(0.f, behindPing) * exp(-behindPing * 1.2) * max(cos(behindPing * 9), 0.f) * .8; |
| 262 | ping *= c.hit * c.hit; |
| 263 | float shimmer = pow(whNoiseP(float2(a / TAU * 160, z * 140 + c.t * 5), 160), 10.f) * sharp * c.b.w * 2 * (.15 + aniso * 2.5); |
| 264 | float clear = whFog(d, c, .03, .09); |
| 265 | float3 color = metal * (.4 + .6 * clear); |
| 266 | color += paint(.8 + clamp(ring, 0.f, 2.f) * .08, f) * ring * .4 * (.35 + .65 * clear); |
| 267 | color += paint(.6, f) * max(ring, 0.f) * (aniso + .15) * .5; |
| 268 | color += paint(.95, f) * ping * 1.4 * (.5 + .5 * clear); |
| 269 | color += paint(.9, f) * shimmer * clear; |
| 270 | color = mix(deep(.2, f) * .1, color, .2 + .8 * clear); |
| 271 | return color * .78; |
| 272 | } |
| 273 | |
| 274 | // ---------------------------------------------------------------- 119 Cube Helix |
| 275 | // Raymarched glossy cubes strung on a double helix around the flight path, each spinning |
| 276 | // on its own axis, faces painted from the palette with a rim light, two faint glowing |
| 277 | // rails tracing the strands, and dark space with stars beyond. Bass swells the cubes |
| 278 | // nearest the camera, highs glint along their edges and attacks flip them over. |
| 279 | constant float helixRadius = 1.15, helixGap = .42, helixTwist = .38; |
| 280 | float3 helixCentre(float i, float strand, float t) { |
| 281 | float angle = i * helixTwist + strand * PI + t * .25; |
| 282 | return float3(helixRadius * cos(angle), helixRadius * sin(angle), i * helixGap); |
| 283 | } |
| 284 | // Spin of one cube: returns the two rotation angles (xy plane, then yz plane). |
| 285 | float2 helixSpin(float id, Ctx c) { |
| 286 | float seed = hash11(id * 1.37); |
| 287 | float flip = c.hit * 1.7 * (seed > .5 ? 1 : -1); |
| 288 | return float2(c.t * (.45 + seed * .8) + seed * 6.3 + flip, c.t * (.3 + seed * .5) + seed * 3.1 + flip * .6); |
| 289 | } |
| 290 | float helixSize(float i, Ctx c, float zc) { |
| 291 | float bass = c.b.x * .55 * exp(-max(i * helixGap - zc, 0.f) * .35); |
| 292 | return min(.15 * c.size, .3f) * (1 + bass); |
| 293 | } |
| 294 | float helixField(float3 p, Ctx c, float zc, thread float &which, thread float &rail) { |
| 295 | float best = 1e3; |
| 296 | float base = round(p.z / helixGap); |
| 297 | for (int k = -1; k <= 1; ++k) for (int s = 0; s < 2; ++s) { |
| 298 | float i = base + float(k), id = i * 2 + float(s); |
| 299 | float3 q = p - helixCentre(i, float(s), c.t + c.m * 1.2); |
| 300 | float2 spin = helixSpin(id, c); |
| 301 | q.xy = rot(q.xy, spin.x); |
| 302 | q.yz = rot(q.yz, spin.y); |
| 303 | float size = helixSize(i, c, zc); |
| 304 | float dist = sdBox(q, float3(size - .025)) - .025; |
| 305 | if (dist < best) { best = dist; which = id; } |
| 306 | } |
| 307 | rail = 1e3; |
| 308 | for (int s = 0; s < 2; ++s) { |
| 309 | float angle = p.z / helixGap * helixTwist + float(s) * PI + (c.t + c.m * 1.2) * .25; |
| 310 | rail = min(rail, length(p.xy - helixRadius * float2(cos(angle), sin(angle)))); |
| 311 | } |
| 312 | return best; |
| 313 | } |
| 314 | float3 cubeHelix(Ctx c, constant NativeFrame &f) { |
| 315 | // The music clock adds to the forward motion, so energetic passages speed it up. |
| 316 | float zc = c.travel * 1.8 + c.m * 1.4; |
| 317 | float3 ro = float3(sin(c.t * .23) * .12, cos(c.t * .19) * .12, zc); |
| 318 | float3 forward = float3(sin(c.t * .11) * .12, cos(c.t * .13) * .1, 1); |
| 319 | float3 rd = cameraRay(c.uv, forward, float3(sin(c.t * .07) * .4, 1, 0), 1.15); |
| 320 | // Background: faint nebula and stars. |
| 321 | float2 sky = rd.xy / max(rd.z, .05f); |
| 322 | float cloud = fbm2(sky * 1.3 + c.t * .01, 3); |
| 323 | float3 color = mix(paint(.97, f) * .07, paint(.03, f) * .06, smoothstep(.35f, .7f, cloud)) + paint(.8, f) * .04 * smoothstep(.55f, .8f, fbm2(sky * 2.1 + 4.2, 3)); |
| 324 | for (int layer = 0; layer < 2; ++layer) { |
| 325 | float2 g = sky * (18 + float(layer) * 23); |
| 326 | float2 cell = floor(g); |
| 327 | float h = hash21(cell + float(layer) * 31); |
| 328 | float2 at = hash22(cell + 7) - .5; |
| 329 | float star = exp(-length(fract(g) - .5 - at * .6) * 16) * step(.9f, h); |
| 330 | color += paint(.85 + h * .1, f) * star * (.5 + .5 * sin(c.t * (1 + h * 3) + h * 40)) * .8; |
| 331 | } |
| 332 | // March only through the annulus that holds the helix. |
| 333 | float2 o = ro.xy, dxy = rd.xy; |
| 334 | float a2 = dot(dxy, dxy), b = dot(o, dxy); |
| 335 | float margin = .5; |
| 336 | float inner = helixRadius - margin, outer = helixRadius + margin; |
| 337 | float tIn = (-b + sqrt(max(b * b - a2 * (dot(o, o) - inner * inner), 0.f))) / max(a2, 1e-5f); |
| 338 | float tOut = (-b + sqrt(max(b * b - a2 * (dot(o, o) - outer * outer), 0.f))) / max(a2, 1e-5f); |
| 339 | tIn = max(tIn, 0.f); |
| 340 | tOut = min(tOut, 32.f); |
| 341 | float travel = tIn, which = 0, rail = 9, railGlow = 0; |
| 342 | float3 glowSum = 0; |
| 343 | bool hit = false; |
| 344 | for (int i = 0; i < 56 && travel < tOut; ++i) { |
| 345 | float3 p = ro + rd * travel; |
| 346 | float d = helixField(p, c, zc, which, rail); |
| 347 | float fade = whFog(travel, c, .02, .07); |
| 348 | glowSum += paint(hash11(which * 1.37) * 1.1, f) * exp(-d * 9) * .022 * fade; |
| 349 | railGlow += exp(-rail * 30) * .05 * fade; |
| 350 | if (d < .002 * (1 + travel * .5)) { hit = true; break; } |
| 351 | travel += max(d * .9, .01f); |
| 352 | } |
| 353 | color += glowSum * (1 + c.b.y * 1.5) + paint(.8, f) * railGlow * (1 + c.b.z * 3); |
| 354 | if (hit) { |
| 355 | float3 p = ro + rd * travel; |
| 356 | float i = floor(which * .5), strand = which - i * 2; |
| 357 | float3 q = p - helixCentre(i, strand, c.t + c.m * 1.2); |
| 358 | float2 spin = helixSpin(which, c); |
| 359 | q.xy = rot(q.xy, spin.x); |
| 360 | q.yz = rot(q.yz, spin.y); |
| 361 | float size = helixSize(i, c, zc); |
| 362 | float3 aq = abs(q); |
| 363 | float3 nl = aq.x > aq.y && aq.x > aq.z ? float3(sign(q.x), 0, 0) : (aq.y > aq.z ? float3(0, sign(q.y), 0) : float3(0, 0, sign(q.z))); |
| 364 | float face = dot(nl, float3(1, 2, 3)) + 3; |
| 365 | float3 n = nl; |
| 366 | n.yz = rot(n.yz, -spin.y); |
| 367 | n.xy = rot(n.xy, -spin.x); |
| 368 | // Edge factor: the second largest coordinate approaches the half size. |
| 369 | float second = max(min(aq.x, aq.y), min(max(aq.x, aq.y), aq.z)); |
| 370 | float edge = smoothstep(size * .78, size * .98, second); |
| 371 | float seed = hash11(which * 1.37); |
| 372 | float3 albedo = paint(seed * 1.1 + face * .05 + c.t * .015, f); |
| 373 | float3 key = normalize(float3(.45, .75, -.45)); |
| 374 | float diffuse = max(dot(n, key), 0.f); |
| 375 | float3 r = reflect(rd, n); |
| 376 | float spec = pow(max(dot(r, key), 0.f), 40.f); |
| 377 | float rim = pow(1 - max(dot(n, -rd), 0.f), 3.f); |
| 378 | float3 env = deep(.3 + r.y * .2, f) * .4 + paint(.8, f) * pow(max(r.z, 0.f), 6.f) * .5; |
| 379 | float3 cube = albedo * (.2 + .9 * diffuse) + env * .2 + paint(.95, f) * spec * .8 + albedo * rim * .45; |
| 380 | cube += paint(.9, f) * edge * (.12 + c.b.w * 1.4 * (.6 + .4 * sin(c.t * 13 + seed * 50))); |
| 381 | float fade = whFog(travel, c, .02, .07); |
| 382 | color = mix(color, cube, fade) + glowSum * .5; |
| 383 | } |
| 384 | return color; |
| 385 | } |
| 386 | |
| 387 | // ---------------------------------------------------------------- 120 Phyllo Tube |
| 388 | // Glowing beads set on the golden angle along the inside of a tube, so they form the |
| 389 | // interlocking 13 and 21 spirals of a sunflower head unrolled around the walls. The |
| 390 | // lattice turns as you travel; bead size swells and shrinks along the depth index. |
| 391 | // Each band brightens its own family of spiral arms; attacks swell two arms. |
| 392 | float3 phylloTube(Ctx c, constant NativeFrame &f) { |
| 393 | const float lens = 1.0, alpha = .381966, rise = .016; |
| 394 | // The music clock adds to the forward motion, so energetic passages speed it up. |
| 395 | float zc = c.travel * 1.3 + c.m * 1.0; |
| 396 | float4 tube = whTube(c.uv, zc, .3, lens, 1); |
| 397 | float a = tube.x, z = tube.y, d = tube.z; |
| 398 | float foot = c.px * d * d / lens; |
| 399 | // Beads are round on screen: depth offsets are measured in view-scaled units. |
| 400 | float squash = clamp(d, .35f, 2.2f); |
| 401 | float2 p = float2((a / TAU - c.t * .035 - c.m * .04) * TAU, z); |
| 402 | float2 A = float2((13 * alpha - 5) * TAU, 13 * rise), B = float2((21 * alpha - 8) * TAU, 21 * rise); |
| 403 | float det = A.x * B.y - A.y * B.x; |
| 404 | float2 lattice = float2(p.x * B.y - p.y * B.x, A.x * p.y - A.y * p.x) / det; |
| 405 | float2 base = floor(lattice); |
| 406 | float3 color = deep(.3 + z * .01, f) * .08 * (.6 + .4 * whNoiseP(float2(a / TAU * 16, z * 3), 16)); |
| 407 | // Faint grooves along one spiral family. |
| 408 | float groove = abs(fract(lattice.y) - .5) * length(B) * .9; |
| 409 | color += paint(.35, f) * exp(-groove / max(.012f, foot)) * .08; |
| 410 | float best = 1e3; |
| 411 | float3 halo = 0; |
| 412 | for (int j = -1; j <= 1; ++j) for (int i = -1; i <= 1; ++i) { |
| 413 | float2 id = base + float2(i, j); |
| 414 | float n = 13 * id.x + 21 * id.y; |
| 415 | float2 offset = p - (id.x * A + id.y * B); |
| 416 | offset.y /= squash; |
| 417 | float arm = n - 13 * floor(n / 13); |
| 418 | int family = int(arm) % 4; |
| 419 | float swell = .62 + .38 * sin(n * TAU / 233 + 1.3); |
| 420 | float hitArm = (arm == 0 || arm == 7) ? c.hit : 0.f; |
| 421 | float radius = min(.075 * c.size * swell * (1 + hitArm * .6), .16f); |
| 422 | float dist = length(offset); |
| 423 | float lit = 1 + c.b[family] * 1.8 + hitArm * 1.6; |
| 424 | float3 tint = paint(fract(n * .0021 - c.t * .05) * 2 + arm * .02, f); |
| 425 | halo += tint * exp(-max(dist - radius, 0.f) / (.03 + foot * .3)) * .2 * lit; |
| 426 | float edgeWidth = foot / squash + .004; |
| 427 | if (dist < radius + edgeWidth && dist < best) { |
| 428 | best = dist; |
| 429 | float2 nxy = offset / radius; |
| 430 | float nz = sqrt(max(1 - dot(nxy, nxy), 0.f)); |
| 431 | // Lit from the camera side with a cool rim. |
| 432 | float diffuse = max(dot(float3(nxy, nz), normalize(float3(-.45, .55, .8))), 0.f); |
| 433 | float spec = exp(-dot(nxy - float2(-.32, .38), nxy - float2(-.32, .38)) * 26); |
| 434 | float rim = pow(1 - nz, 3.f); |
| 435 | float edge = smoothstep(radius + edgeWidth, radius - edgeWidth, dist); |
| 436 | float3 sphere = tint * (.18 + .85 * diffuse) * lit + paint(.97, f) * spec * .8 + paint(fract(n * .0021) * 2 + .4, f) * rim * .35; |
| 437 | color = mix(color, sphere, edge); |
| 438 | } |
| 439 | } |
| 440 | color += halo; |
| 441 | // Far beads blur into the glow of their spirals. |
| 442 | float clear = whFog(d, c, .03, .1) * exp(-foot * 2); |
| 443 | float3 far = paint(.55 + sin(c.t * .2) * .1, f) * .3; |
| 444 | return mix(far, color, clear) + paint(.85, f) * .3 * exp(-tube.w * 6); |
| 445 | } |
| 446 | |
| 447 | // ---------------------------------------------------------------- 121 Tesla Tube |
| 448 | // A dark ribbed metal tube studded with electrode knobs. Plasma arcs crackle between |
| 449 | // neighbouring electrodes as jagged glowing strokes that light the metal around them. |
| 450 | // Bass wakes more arcs and brightens them, highs spit corona sparks around the knobs and |
| 451 | // attacks fire a large arc straight across the tunnel a few metres ahead. |
| 452 | float teslaJag(float s, float seed, float t) { |
| 453 | float x = s * 7, k = floor(x), fr = x - k; |
| 454 | float a0 = hash11(k + seed * 17) - .5 + .25 * sin(t * 23 + k * 2.1 + seed); |
| 455 | float a1 = hash11(k + 1 + seed * 17) - .5 + .25 * sin(t * 23 + (k + 1) * 2.1 + seed); |
| 456 | float y = s * 19, j = floor(y), fy = y - j; |
| 457 | float f0 = (hash11(j + seed * 31) - .5) * sin(t * 17 + j + seed); |
| 458 | float f1 = (hash11(j + 1 + seed * 31) - .5) * sin(t * 17 + j + 1 + seed); |
| 459 | return mix(a0, a1, fr) + mix(f0, f1, fy) * .35; |
| 460 | } |
| 461 | // Distance from p to a jagged arc from a to b. |
| 462 | float teslaArc(float2 p, float2 a, float2 b, float seed, float t) { |
| 463 | float2 ab = b - a; |
| 464 | float len = max(length(ab), 1e-3f); |
| 465 | float2 dir = ab / len, nrm = float2(-dir.y, dir.x); |
| 466 | float s = dot(p - a, dir) / len, sc = clamp(s, 0.f, 1.f); |
| 467 | float offset = teslaJag(sc, seed, t) * .22 * len * sin(PI * sc); |
| 468 | return length(float2((s - sc) * len, dot(p - a, nrm) - offset)); |
| 469 | } |
| 470 | float3 teslaTube(Ctx c, constant NativeFrame &f) { |
| 471 | const float lens = 1.05, rowGap = 1.6, perRing = 6, ribGap = .4; |
| 472 | // The music clock adds to the forward motion, so energetic passages speed it up. |
| 473 | float zc = c.travel * 1.4 + c.m * 1.0; |
| 474 | float4 tube = whTube(c.uv, zc, .32, lens, 1); |
| 475 | float a = tube.x, r = tube.w; |
| 476 | // Ribs push the wall inward; refine the depth once against the ribbed radius. |
| 477 | float rib = pow(.5 + .5 * cos((zc + tube.z) * TAU / ribGap), 2.f); |
| 478 | float d = tube.z * (1 - .07 * rib); |
| 479 | float z = zc + d; |
| 480 | float phase = z * TAU / ribGap; |
| 481 | rib = pow(.5 + .5 * cos(phase), 2.f); |
| 482 | float foot = c.px * d * d / lens; |
| 483 | float sharp = exp(-foot * 10); |
| 484 | float facing = -sin(phase); // > 0 on the rib flank that faces the camera |
| 485 | float3 color = deep(.12, f) * .1 + paint(.2, f) * .03; |
| 486 | // Low-mids run a glow wave along the ribs. |
| 487 | float ribWave = c.b.y * pow(.5 + .5 * sin(z * .8 - c.t * 3 - c.m * 3), 2.f); |
| 488 | float ribLight = mix(.35f, .6f + .9 * max(facing, 0.f) * rib + .25 * rib, sharp) * (1 + ribWave * 2.2); |
| 489 | color += mix(deep(.25, f), paint(.3, f), .3) * ribLight * .18; |
| 490 | color += paint(.55, f) * pow(max(cos(a - 1.8), 0.f), 14.f) * pow(rib, 3.f) * .35 * sharp; |
| 491 | // Electrodes and the arcs between them. |
| 492 | float row = floor(z / rowGap); |
| 493 | float arcs = 0, glowLight = 0, corona = 0; |
| 494 | float3 knobColor = 0; |
| 495 | float knobMask = 0; |
| 496 | float squash = clamp(d, .35f, 2.5f); |
| 497 | for (int k = -1; k <= 1; ++k) { |
| 498 | float rowId = row + float(k); |
| 499 | float rowZ = rowId * rowGap; |
| 500 | float shift = fmod(fabs(rowId), 2.f) * .5; |
| 501 | float column = round(a / TAU * perRing - shift); |
| 502 | for (int i = -1; i <= 1; ++i) { |
| 503 | float colId = column + float(i); |
| 504 | float wrapped = colId - perRing * floor(colId / perRing); |
| 505 | float angle = (colId + shift) / perRing * TAU; |
| 506 | float2 local = float2(whWrap(a - angle), z - rowZ); |
| 507 | float seed = hash21(float2(wrapped, rowId)); |
| 508 | // Bass wakes more arcs; each arc also brightens with its own band. |
| 509 | float band = c.b[int(fract(seed * 7.3) * 3.99)]; |
| 510 | float wake = .5 + .5 * sin(c.t * (.6 + seed * .8) + c.m * (.8 + seed) + seed * 40) + c.b.x * .9; |
| 511 | float near = exp(-foot * 6) * smoothstep(7.f, 3.5f, d); |
| 512 | float on = smoothstep(.55f, .8f, wake) * (.75 + .25 * sin(c.t * 37 + seed * 9)) * (1 + c.b.x * .5 + band * 1.2) * near; |
| 513 | // Knob: a polished dome, round on screen. |
| 514 | float2 kl = float2(local.x, local.y / squash) / .085; |
| 515 | float kr = length(kl); |
| 516 | float kz = sqrt(max(1 - kr * kr, 0.f)); |
| 517 | float edge = smoothstep(1 + foot * 12, 1.f, kr) * sharp * smoothstep(9.f, 4.f, d); |
| 518 | float3 n = float3(kl, kz); |
| 519 | float spec = pow(max(dot(n, normalize(float3(-.35, .45, .82))), 0.f), 18.f); |
| 520 | float3 knob = deep(.3, f) * .3 + paint(.5, f) * spec * .9 + paint(.85, f) * on * (.6 + .4 * kz); |
| 521 | knobColor += knob * edge; |
| 522 | knobMask = max(knobMask, edge); |
| 523 | float ring = exp(-max(kr - 1, 0.f) * 3) * (1 - edge); |
| 524 | glowLight += ring * on * .5 * near; |
| 525 | corona += pow(max(sin(atan2(kl.y, kl.x) * 7 + c.t * 9 + seed * 30), 0.f), 8.f) * exp(-abs(kr - 1.4) * 4) * c.b.w * near; |
| 526 | // Arc to the next electrode around the ring, or to the next row. |
| 527 | float2 target = hash11(seed * 9 + 1) > .45 ? float2(TAU / perRing, 0) : float2(TAU / perRing * .5 * (hash11(seed * 3) > .5 ? 1 : -1), rowGap); |
| 528 | if (on > .001) { |
| 529 | float dist = teslaArc(local, 0, target, seed * 13 + rowId, c.t); |
| 530 | float width = max(.007f, foot * .6); |
| 531 | arcs += (exp(-dist / width) + exp(-dist * 30) * .3) * on; |
| 532 | glowLight += exp(-dist * 9) * on; |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | color = mix(color, knobColor, knobMask); |
| 537 | color += paint(.72, f) * glowLight * .2 + paint(.6, f) * glowLight * glowLight * .06; |
| 538 | color += paint(.92, f) * arcs * 1.2 + paint(.97, f) * corona * .7; |
| 539 | // Attack: a big arc jumps straight across the tunnel a few metres ahead. |
| 540 | if (c.hit > .001) { |
| 541 | float first = ceil((zc + 1.5) / rowGap); |
| 542 | for (int k = 0; k < 3; ++k) { |
| 543 | float rowId = first + float(k); |
| 544 | float gap = rowId * rowGap - zc; |
| 545 | float window = smoothstep(1.5f, 2.5f, gap) * (1 - smoothstep(4.5f, 6.f, gap)); |
| 546 | if (window <= 0) continue; |
| 547 | float2 centre = whCentre(zc, gap, .32, lens); |
| 548 | float angle = hash11(rowId * 1.3) * TAU; |
| 549 | float span = PI * (.75 + .3 * hash11(rowId * 2.9)); |
| 550 | float2 s0 = centre + lens / gap * float2(cos(angle), sin(angle)); |
| 551 | float2 s1 = centre + lens / gap * float2(cos(angle + span), sin(angle + span)); |
| 552 | float dist = teslaArc(c.uv, s0, s1, rowId * 3.3, c.t); |
| 553 | float strength = c.hit * window; |
| 554 | color += (paint(.95, f) * exp(-dist / (c.px * 2.5)) + paint(.75, f) * exp(-dist * 12) * .6) * strength * 1.8; |
| 555 | } |
| 556 | } |
| 557 | float clear = whFog(d, c, .03, .09); |
| 558 | return mix(deep(.25, f) * .12 + paint(.7, f) * .06, color, clear) + paint(.75, f) * .15 * exp(-r * 4); |
| 559 | } |
| 560 | |
| 561 | // ---------------------------------------------------------------- 122 Fold Tunnel |
| 562 | // An origami tube in a twisted, Kresling-like fold: rings of vertices alternate between |
| 563 | // mountain and valley radii and each ring turns a little against the last, so the wall is |
| 564 | // a spiral of flat triangles, each with its own lighting, crisp crease lines and a paper |
| 565 | // grain. The folds breathe slowly; bass deepens them and each attack unfolds a ring of |
| 566 | // facets just ahead, which flattens and glows through. |
| 567 | constant float foldColumns = 15; // a multiple of 3 keeps the vertex levels seamless |
| 568 | float foldDepth(float row, Ctx c, float zc, float rowH) { |
| 569 | float breathe = .2 + .09 * sin(c.t * .55 + c.m * .8 + row * .29); |
| 570 | float gap = row * rowH - zc; |
| 571 | float unfold = c.hit * smoothstep(1.f, 2.f, gap) * (1 - smoothstep(3.2f, 4.6f, gap)); |
| 572 | return breathe * (1 + c.b.x * .8) * (1 - unfold * .95); |
| 573 | } |
| 574 | // Vertex levels cycle through three radii so the three corners of every facet differ. |
| 575 | float foldRadius(float2 v, Ctx c, float zc, float rowH) { |
| 576 | float k = v.x + 2 * v.y; |
| 577 | float level = k - 3 * floor(k / 3); |
| 578 | return 1 - foldDepth(v.y, c, zc, rowH) * level * .5; |
| 579 | } |
| 580 | // Facet containing (angle, z): the three vertex lattice ids and barycentric weights. |
| 581 | void foldFacet(float angle, float z, float rowH, thread float2 &v0, thread float2 &v1, thread float2 &v2, thread float3 &w, thread bool &upper) { |
| 582 | float y = z / rowH; |
| 583 | float x = angle / TAU * foldColumns - y * .32; // each ring twists against the last |
| 584 | float2 lat = float2(x - .5 * y, y); |
| 585 | float2 cell = floor(lat), uv = lat - cell; |
| 586 | upper = uv.x + uv.y > 1; |
| 587 | if (!upper) { v0 = cell; v1 = cell + float2(1, 0); v2 = cell + float2(0, 1); w = float3(1 - uv.x - uv.y, uv.x, uv.y); } |
| 588 | else { v0 = cell + 1; v1 = cell + float2(0, 1); v2 = cell + float2(1, 0); w = float3(uv.x + uv.y - 1, 1 - uv.x, 1 - uv.y); } |
| 589 | } |
| 590 | float3 foldVertex(float2 v, float rowH, Ctx c, float zc) { |
| 591 | float angle = (v.x + .82 * v.y) / foldColumns * TAU; |
| 592 | float radius = foldRadius(v, c, zc, rowH); |
| 593 | return float3(radius * cos(angle), radius * sin(angle), v.y * rowH); |
| 594 | } |
| 595 | float3 foldTunnel(Ctx c, constant NativeFrame &f) { |
| 596 | const float lens = 1.05, bend = .35; |
| 597 | float rowH = .4 * c.size; |
| 598 | // The music clock adds to the forward motion, so energetic passages speed it up. |
| 599 | float zc = c.travel * 1.35 + c.m * .8; |
| 600 | float4 tube = whTube(c.uv, zc, bend, lens, 1); |
| 601 | float a = tube.x, d0 = tube.z; |
| 602 | float2 v0, v1, v2; |
| 603 | float3 w; |
| 604 | bool upper; |
| 605 | // One damped refinement gives near facets some parallax without unstable jumps. |
| 606 | foldFacet(a, zc + d0, rowH, v0, v1, v2, w, upper); |
| 607 | float radius = w.x * foldRadius(v0, c, zc, rowH) + w.y * foldRadius(v1, c, zc, rowH) + w.z * foldRadius(v2, c, zc, rowH); |
| 608 | float d = d0 * mix(1.f, radius, exp(-d0 * .8)); |
| 609 | float z = zc + d; |
| 610 | foldFacet(a, z, rowH, v0, v1, v2, w, upper); |
| 611 | float3 p0 = foldVertex(v0, rowH, c, zc), p1 = foldVertex(v1, rowH, c, zc), p2 = foldVertex(v2, rowH, c, zc); |
| 612 | float3 centroid = (p0 + p1 + p2) / 3; |
| 613 | float3 n = normalize(cross(p1 - p0, p2 - p0)); |
| 614 | if (dot(n, centroid * float3(1, 1, 0)) > 0) n = -n; |
| 615 | // Lights: a headlamp at the camera, a key from above ahead and a low fill. |
| 616 | float3 toCamera = normalize(float3(0, 0, zc) - centroid); |
| 617 | float head = max(dot(n, toCamera), 0.f); |
| 618 | float key = max(dot(n, normalize(float3(.3, -.8, -.5))), 0.f); |
| 619 | float fill = max(dot(n, normalize(float3(-.6, .5, -.6))), 0.f); |
| 620 | float column = v0.x - foldColumns * floor(v0.x / foldColumns); |
| 621 | float facetId = hash21(float2(column + (upper ? 31 : 0), v0.y)); |
| 622 | float3 tint = paint(facetId * .9 + v0.y * .02 + c.t * .01, f); |
| 623 | tint = mix(tint, paint(.97, f), .45 * hash11(facetId * 17)); |
| 624 | float foot = c.px * d * d / lens; |
| 625 | float grain = mix(1.f, .9f + .2 * noise2(float2(a * 70, z * 60)), exp(-foot * 30)); |
| 626 | float3 color = tint * (.18 + .5 * head + .5 * key * key + .3 * fill) * grain; |
| 627 | // Distant facets shrink below a pixel: settle them to their average shade. |
| 628 | color = mix(tint * .5, color, exp(-foot / rowH * 1.5)); |
| 629 | // Creases: distance to the nearest facet edge in lattice units. |
| 630 | float edgeDist = min(min(w.x, w.y), w.z); |
| 631 | float crease = (1 - smoothstep(0.f, max(.03f, foot / rowH * 1.5), edgeDist)) * exp(-foot / rowH * 2); |
| 632 | float valley = upper ? 1.f : 0.f; |
| 633 | color *= 1 - crease * (.35 + .25 * valley); |
| 634 | color += paint(.95, f) * crease * .12 * (1 - valley) * (head + key) * (1 + c.b.z * 4); |
| 635 | // Low-mids light the paper from behind along a slow band of rows. |
| 636 | float glowRow = pow(.5 + .5 * sin(v0.y * .5 - c.t * .8), 6.f); |
| 637 | color += tint * glowRow * c.b.y * .5; |
| 638 | // Light glowing through facets that are unfolding on an attack. |
| 639 | float gap = v0.y * rowH - zc; |
| 640 | float unfold = c.hit * smoothstep(1.f, 2.f, gap) * (1 - smoothstep(3.2f, 4.6f, gap)); |
| 641 | color += paint(.75 + facetId * .2, f) * unfold * .9; |
| 642 | float clear = whFog(d, c, .035, .1); |
| 643 | float3 haze = deep(.35, f) * .12 + paint(.7, f) * .06; |
| 644 | return (mix(haze, color, clear) + paint(.85, f) * .28 * exp(-tube.w * 5)) * .54; |
| 645 | } |
| 646 | |
| 647 | // ---------------------------------------------------------------- 123 Vector Tube |
| 648 | // A retro vector-display tunnel: glowing wireframe hoops and longitudinal beams with |
| 649 | // phosphor bloom and a slight beam jitter, the tube twisting and bending, with wireframe |
| 650 | // pyramids and cubes tumbling inside. Pure line art on black. Each band lights its own |
| 651 | // set of longitudinal beams; attacks fire a polygon ring burst down the tube. |
| 652 | float vectorBeam(float dist, float width) { |
| 653 | return exp(-dist * dist / (width * width)) + exp(-dist / (width * 7)) * .22; |
| 654 | } |
| 655 | // Screen position of a point at tube-local offset `local` and view depth d. |
| 656 | float2 vectorProject(float3 local, float zc, float bend, float lens) { |
| 657 | float d = max(local.z - zc, .05f); |
| 658 | return whCentre(zc, d, bend, lens) + local.xy * lens / d; |
| 659 | } |
| 660 | float3 vectorTube(Ctx c, constant NativeFrame &f) { |
| 661 | const float lens = 1.0, bend = .55, hoopGap = .9, beams = 16; |
| 662 | // The music clock adds to the forward motion, so energetic passages speed it up. |
| 663 | float zc = c.travel * 2 + c.m * 1.5; |
| 664 | float2 jitter = float2(noise2(float2(c.t * 37, 1.3)), noise2(float2(5.1, c.t * 41))) - .5; |
| 665 | float2 uv = c.uv + jitter * c.px * 1.2; |
| 666 | float4 tube = whTube(uv, zc, bend, lens, 1); |
| 667 | float a = tube.x, z = tube.y, d = tube.z, r = tube.w; |
| 668 | float width = c.px * (.8 + .7 * c.size); |
| 669 | float clear = whFog(d, c, .02, .06); |
| 670 | float3 color = 0; |
| 671 | // Hoops. |
| 672 | float dz = z - round(z / hoopGap) * hoopGap; |
| 673 | float hoopSpacing = hoopGap * r / d; |
| 674 | float hoopFade = smoothstep(c.px * 4, c.px * 14, hoopSpacing) * clear; |
| 675 | float hoopIndex = round(z / hoopGap); |
| 676 | float major = fmod(fabs(hoopIndex), 4.f) < .5 ? 1.f : 0.f; |
| 677 | color += paint(.55 + major * .1, f) * vectorBeam(fabs(dz) * r / d, width * (1 + major * .5)) * hoopFade * (.55 + major * .5); |
| 678 | // Longitudinal beams, twisting along the tube and over time. |
| 679 | float twist = z * .14 + c.t * .18 + c.m * .25; |
| 680 | float slot = (a - twist) / TAU * beams; |
| 681 | float beamId = round(slot); |
| 682 | float beamDist = fabs(slot - beamId) * TAU / beams * r; |
| 683 | float wrapped = beamId - beams * floor(beamId / beams); |
| 684 | int family = int(wrapped) % 4; |
| 685 | float beamSpacing = TAU / beams * r; |
| 686 | float beamFade = smoothstep(c.px * 4, c.px * 16, beamSpacing) * clear; |
| 687 | float level = .5 + c.b[family] * 2.2; |
| 688 | color += paint(.08 + float(family) * .22, f) * vectorBeam(beamDist, width) * beamFade * level; |
| 689 | // Far tube glow where lines merge. |
| 690 | color += paint(.6, f) * .1 * exp(-r * 6); |
| 691 | // Tumbling wireframe solids. |
| 692 | float first = floor((zc + .4) / 3); |
| 693 | for (int k = 0; k < 4; ++k) { |
| 694 | float id = first + float(k); |
| 695 | float objZ = (id + .5) * 3; |
| 696 | float gap = objZ - zc; |
| 697 | if (gap < .35) continue; |
| 698 | float seed = hash11(id * 3.17); |
| 699 | float place = seed * TAU; |
| 700 | float3 centre = float3(.56 * cos(place), .56 * sin(place), objZ); |
| 701 | float size = .24 + .06 * hash11(seed * 9); |
| 702 | float2 screenCentre = vectorProject(centre, zc, bend, lens); |
| 703 | float reach = size * 1.9 * lens / max(gap - size * 1.8, .05f); |
| 704 | if (length(uv - screenCentre) > reach + c.px * 30) continue; |
| 705 | float spinA = c.t * (.5 + seed) + seed * 7, spinB = c.t * (.35 + seed * .4) + seed * 3; |
| 706 | bool cube = hash11(seed * 5.3) > .45; |
| 707 | float3 verts[8]; |
| 708 | for (int v = 0; v < 8; ++v) { |
| 709 | float3 corner; |
| 710 | if (cube) corner = float3(v & 1 ? 1 : -1, v & 2 ? 1 : -1, v & 4 ? 1 : -1); |
| 711 | else corner = v < 4 ? float3(v == 0 || v == 3 ? -1 : 1, -.8, v < 2 ? -1 : 1) : float3(0, 1.2, 0); |
| 712 | corner *= size; |
| 713 | corner.xy = rot(corner.xy, spinA); |
| 714 | corner.yz = rot(corner.yz, spinB); |
| 715 | verts[v] = corner + centre; |
| 716 | } |
| 717 | float best = 1e3; |
| 718 | if (cube) { |
| 719 | for (int e = 0; e < 12; ++e) { |
| 720 | int axis = e / 4, rest = e % 4; |
| 721 | int lo = axis == 0 ? (rest << 1) : (axis == 1 ? ((rest & 1) | ((rest & 2) << 1)) : rest); |
| 722 | int hi = lo | (1 << axis); |
| 723 | best = min(best, sdSegment(uv, vectorProject(verts[lo], zc, bend, lens), vectorProject(verts[hi], zc, bend, lens))); |
| 724 | } |
| 725 | } else { |
| 726 | for (int e = 0; e < 4; ++e) { |
| 727 | float2 base0 = vectorProject(verts[e], zc, bend, lens); |
| 728 | best = min(best, sdSegment(uv, base0, vectorProject(verts[(e + 1) % 4], zc, bend, lens))); |
| 729 | best = min(best, sdSegment(uv, base0, vectorProject(verts[4], zc, bend, lens))); |
| 730 | } |
| 731 | } |
| 732 | float fade = smoothstep(.35f, 1.f, gap) * whFog(gap, c, .02, .06); |
| 733 | color += paint(.82 + seed * .15, f) * vectorBeam(best, width * 1.2) * fade * 1.2; |
| 734 | } |
| 735 | // Attack: a polygon ring bursts out of the tube ahead and rushes past. |
| 736 | if (c.hit > .001) { |
| 737 | float ringD = .7 + (1 - c.hit) * 6; |
| 738 | float2 q = uv - whCentre(zc, ringD, bend, lens); |
| 739 | float radius = .82 * lens / ringD; |
| 740 | float angle = atan2(q.y, q.x) + c.t * .5; |
| 741 | float sector = TAU / 12; |
| 742 | float local = angle - sector * floor(angle / sector) - sector * .5; |
| 743 | float polygon = length(q) * cos(local) - radius * cos(sector * .5); |
| 744 | float spoke = fabs(local) * length(q); |
| 745 | float burst = vectorBeam(fabs(polygon), width * 1.5) + vectorBeam(spoke, width) * smoothstep(radius * .5, radius, length(q)) * (1 - smoothstep(radius, radius * 1.35, length(q))) * step(fabs(local), .2f); |
| 746 | color += paint(.95, f) * burst * c.hit * 1.6; |
| 747 | } |
| 748 | return color; |
| 749 | } |
| 750 | |
| 751 | // ---------------------------------------------------------------- 124 Orbital Corridor |
| 752 | // A space-station corridor, traced analytically: an octagonal hull with octagonal frames |
| 753 | // every few metres, inset wall panels, recessed light strips in the corners, a floor |
| 754 | // grating, a ceiling light panel, and windows on the right showing a banded planet and |
| 755 | // stars. Bass sends a travelling chase along the light strips, attacks light up panels |
| 756 | // just ahead, and highs blink the status lights. |
| 757 | float2 orbitalNormal(int i) { float a = float(i) * PI * .25; return float2(cos(a), sin(a)); } |
| 758 | // Exit distance from inside an octagonal prism of apothem `apothem`; face receives the index. |
| 759 | float orbitalExit(float2 o, float2 dxy, float apothem, thread int &face) { |
| 760 | float best = 1e4; |
| 761 | face = 0; |
| 762 | for (int i = 0; i < 8; ++i) { |
| 763 | float2 n = orbitalNormal(i); |
| 764 | float den = dot(dxy, n); |
| 765 | if (den > 1e-4) { |
| 766 | float t = (apothem - dot(o, n)) / den; |
| 767 | if (t < best) { best = t; face = i; } |
| 768 | } |
| 769 | } |
| 770 | return best; |
| 771 | } |
| 772 | float3 orbitalSpace(float3 rd, Ctx c, constant NativeFrame &f) { |
| 773 | float3 color = deep(.2 + rd.y * .1, f) * .05; |
| 774 | float2 g = float2(atan2(rd.z, rd.x), rd.y) * 60; |
| 775 | float h = hash21(floor(g)); |
| 776 | color += paint(.85 + h * .1, f) * step(.93f, h) * exp(-length(fract(g) - .5) * 9) * 1.2; |
| 777 | float3 planetDir = normalize(float3(1, -.3, .75)); |
| 778 | float3 e1 = normalize(cross(planetDir, float3(0, 1, 0))), e2 = cross(e1, planetDir); |
| 779 | float span = .42; |
| 780 | float2 disk = float2(dot(rd, e1), dot(rd, e2)) / span; |
| 781 | float rr = dot(disk, disk); |
| 782 | float facing = dot(rd, planetDir); |
| 783 | if (facing > 0) { |
| 784 | float3 sun = normalize(float3(-.55, .45, .7)); |
| 785 | float atmosphere = exp(-fabs(sqrt(rr) - 1) * 18) * .5; |
| 786 | if (rr < 1) { |
| 787 | float3 n = float3(disk, sqrt(1 - rr)); |
| 788 | float lit = max(dot(n, sun), 0.f); |
| 789 | float bands = disk.y * 7 + .35 * sin(disk.x * 5 + disk.y * 9 + c.t * .05) + fbm2(float2(disk.x * 3 + c.t * .02, disk.y * 12), 3) * 1.5; |
| 790 | float3 surface = mix(paint(.25 + .1 * sin(bands), f), paint(.65 + .15 * sin(bands * 1.7), f), .5 + .5 * sin(bands * 2.3)); |
| 791 | color = surface * (.04 + lit * .9) + paint(.8, f) * pow(1 - n.z, 3.f) * lit * .6; |
| 792 | } |
| 793 | color += paint(.75, f) * atmosphere * (.3 + max(dot(normalize(disk + 1e-4), normalize(sun.xy)), 0.f)); |
| 794 | } |
| 795 | return color; |
| 796 | } |
| 797 | float3 orbitalCorridor(Ctx c, constant NativeFrame &f) { |
| 798 | const float apothem = 1, frameApothem = .84, halfFrame = .09; |
| 799 | float bay = 2.4 * c.size; |
| 800 | // The music clock adds to the forward drift, so energetic passages speed the flight. |
| 801 | float zc = c.travel * 1.6 + c.m * 1.2; |
| 802 | float3 ro = float3(sin(c.t * .21) * .12, -.1 + sin(c.t * .17) * .05, zc); |
| 803 | float3 rd = cameraRay(c.uv, float3(sin(c.t * .09) * .12, sin(c.t * .07) * .05, 1), float3(sin(c.t * .13) * .06, 1, 0), 1.05); |
| 804 | int face, frameFace; |
| 805 | float tWall = min(orbitalExit(ro.xy, rd.xy, apothem, face), 80.f); |
| 806 | float tFrame = orbitalExit(ro.xy, rd.xy, frameApothem, frameFace); |
| 807 | float zFrame = ro.z + rd.z * tFrame; |
| 808 | float slab = zFrame - round(zFrame / bay) * bay; |
| 809 | int kind = 0; // 0 wall, 1 frame soffit, 2 frame front face |
| 810 | float t = tWall; |
| 811 | if (tFrame < tWall && fabs(slab) < halfFrame) { kind = 1; t = tFrame; } |
| 812 | else if (tFrame < tWall) { |
| 813 | float front = ceil((zFrame + halfFrame) / bay) * bay - halfFrame; |
| 814 | float tFront = (front - ro.z) / max(rd.z, 1e-4f); |
| 815 | if (tFront < tWall) { kind = 2; t = tFront; } |
| 816 | } |
| 817 | float3 p = ro + rd * t; |
| 818 | int id = kind == 1 ? frameFace : face; |
| 819 | float2 n2 = orbitalNormal(id); |
| 820 | float u = dot(p.xy, float2(-n2.y, n2.x)); |
| 821 | float bayIndex = floor((p.z + halfFrame) / bay); |
| 822 | float lz = p.z + halfFrame - bayIndex * bay; // 0..bay within the bay, frame at both ends |
| 823 | float3 normal = kind == 2 ? float3(0, 0, -1) : float3(-n2, 0); |
| 824 | float foot = c.px * t; |
| 825 | float3 light = normalize(float3(-p.x * .6, .85 - p.y, -.3)); |
| 826 | float diffuse = .3 + .7 * max(dot(normal, light), 0.f); |
| 827 | float3 metal = mix(deep(.25, f), paint(.3, f), .35); |
| 828 | float3 color = metal * .12 * diffuse; |
| 829 | float3 glowAdd = 0; |
| 830 | if (kind == 0) { |
| 831 | float panelZ = lz / (bay * .5); |
| 832 | float panelId = floor(panelZ); |
| 833 | float2 cellLocal = float2(u / .36, fract(panelZ) * 2 - 1); |
| 834 | float seed = hash31(float3(float(id), bayIndex, panelId)); |
| 835 | float inset = sdBox2(cellLocal, float2(.86, .82)); |
| 836 | float groove = 1 - smoothstep(0.f, .05f + foot * 4, fabs(inset)); |
| 837 | float bevel = smoothstep(-.12f, 0.f, inset) * (inset < 0 ? 1.f : 0.f); |
| 838 | if (id == 6) { |
| 839 | // Floor grating with a dim glow beneath. |
| 840 | float2 grid = float2(u * 16, p.z * 8); |
| 841 | float2 bars = abs(fract(grid) - .5); |
| 842 | float hole = smoothstep(.32f, .26f, max(bars.x * .9, bars.y * 1.4)); |
| 843 | hole *= exp(-foot * 6); |
| 844 | // The glow under the grating rides a travelling wave that the bass feeds. |
| 845 | float underWave = .6 + .4 * sin(p.z * .7 - c.t - c.m * 2); |
| 846 | color = mix(metal * .16 * diffuse, deep(.4, f) * .12 + paint(.35, f) * (.08 + c.b.x * .45) * underWave, hole); |
| 847 | color += paint(.6, f) * .04 * (1 - smoothstep(.02f, .04f, fabs(fabs(u) - .2))); |
| 848 | } else if (id == 2) { |
| 849 | // Ceiling light panel, broken at each frame. |
| 850 | float strip = smoothstep(.2f, .17f, fabs(u)) * smoothstep(.1f, .25f, lz) * smoothstep(bay - .1f, bay - .25f, lz); |
| 851 | // Low-mids send a slow swell along the ceiling panels. |
| 852 | float swell = pow(.5 + .5 * sin(p.z * .5 - c.t * 2), 4.f) * c.b.y; |
| 853 | color = metal * .12 * diffuse + paint(.82, f) * strip * (.75 + c.b.y * .8 + swell * 1.5); |
| 854 | } else if (id == 0 && fabs(u) < .3 && lz > .25 && lz < bay - .25) { |
| 855 | // Window onto the planet. |
| 856 | float edge = min(.3 - fabs(u), min(lz - .25, bay - .25 - lz)); |
| 857 | float rim = 1 - smoothstep(0.f, .025f + foot * 2, edge); |
| 858 | color = orbitalSpace(rd, c, f) * (1 - rim) + paint(.5, f) * rim * .25; |
| 859 | } else { |
| 860 | color = metal * (.1 + .07 * seed) * diffuse * (1 - groove * .7) + paint(.4, f) * bevel * .05 * diffuse; |
| 861 | // Status lights blink smoothly; highs make them flicker brighter. |
| 862 | float2 ledAt = float2(.6, .55); |
| 863 | float led = exp(-length((cellLocal - ledAt) * float2(1, .9)) * 22); |
| 864 | float blink = pow(.5 + .5 * sin(c.t * (1.3 + seed * 3) + c.m * 2 + seed * 40), 6.f); |
| 865 | glowAdd += paint(fract(seed * 7) < .5 ? .15f : .55f, f) * led * blink * (.4 + c.b.w * 3.5) * step(.3f, seed); |
| 866 | // Attack: panels just ahead glow from inside. |
| 867 | float gap = p.z - zc; |
| 868 | float open = c.hit * step(.55f, seed) * smoothstep(.8f, 2.f, gap) * (1 - smoothstep(4.5f, 7.f, gap)); |
| 869 | glowAdd += paint(.7 + seed * .25, f) * open * (inset < 0 ? .9f : 0.f) * (.6 + .4 * smoothstep(0.f, -.6f, inset)); |
| 870 | // Every wall panel is backlit and pulses with its own band. |
| 871 | float panelBand = c.b[int(fract(seed * 5.3) * 3.99)]; |
| 872 | glowAdd += paint(.5 + seed * .35, f) * panelBand * .2 * (inset < 0 ? .4 + .6 * smoothstep(0.f, -.5f, inset) : 0.f); |
| 873 | } |
| 874 | // Recessed light strips along the corners of the diagonal faces. |
| 875 | if (id % 2 == 1) { |
| 876 | float strip = smoothstep(.375f, .395f, fabs(u)); |
| 877 | float chase = pow(.5 + .5 * sin(p.z * 1.4 - c.t * 5 - c.m * 3), 10.f); |
| 878 | glowAdd += paint(.5 + float(id) * .04, f) * strip * (.5 + c.b.x * .9 + chase * c.b.x * 3); |
| 879 | } |
| 880 | } else if (kind == 1) { |
| 881 | float lip = smoothstep(halfFrame - .02f, halfFrame, fabs(slab)); |
| 882 | color = metal * .22 * diffuse + paint(.6, f) * lip * (.25 + c.b.w * 1.2); |
| 883 | float bolt = exp(-length(float2(fract(u * 6) - .5, slab * 6)) * 12); |
| 884 | color += paint(.9, f) * bolt * .25 * exp(-foot * 8); |
| 885 | } else { |
| 886 | // Frame front face: brushed ring with a glowing inner edge. |
| 887 | float2 q = p.xy; |
| 888 | float oct = 0; |
| 889 | for (int i = 0; i < 8; ++i) oct = max(oct, dot(q, orbitalNormal(i))); |
| 890 | float inner = 1 - smoothstep(0.f, .025f + foot * 2, oct - frameApothem); |
| 891 | float outer = 1 - smoothstep(0.f, .02f + foot * 2, apothem - oct); |
| 892 | color = metal * (.18 + .08 * sin(oct * 80)) * diffuse + paint(.7, f) * inner * (.7 + c.b.z * 1.5) + paint(.4, f) * outer * .2; |
| 893 | float marks = step(.5f, fract((atan2(q.y, q.x) / TAU) * 32)) * smoothstep(.9f, .92f, oct) * (1 - smoothstep(.95f, .97f, oct)); |
| 894 | color += paint(.15, f) * marks * .25; |
| 895 | } |
| 896 | // Attack: a wave of light runs down the corridor along the strips and frames. |
| 897 | float waveZ = zc + .5 + (1 - c.hit) * 12; |
| 898 | float lightWave = c.hit * exp(-pow((p.z - waveZ) * 1.4, 2.f)); |
| 899 | glowAdd += paint(.9, f) * lightWave * (kind == 0 ? .35f : .8f); |
| 900 | color += glowAdd; |
| 901 | float clear = whFog(t, c, .02, .07); |
| 902 | float3 haze = deep(.35, f) * .1 + paint(.7, f) * .1 * exp(-length(c.uv) * 1.5); |
| 903 | return mix(haze, color, clear); |
| 904 | } |
| 905 | |
| 906 | // ---------------------------------------------------------------- 125 Mirrorball Tunnel |
| 907 | // A tube lined with small square mirror tiles, each tilted a little differently, so every |
| 908 | // tile catches its own reflection of a roaming spotlight environment and glints on its |
| 909 | // own, while coloured light spots sweep around the walls. Bass brightens the spots, highs |
| 910 | // sparkle individual tiles and each attack sends a wave of glints racing down the tube. |
| 911 | float3 mirrorballTunnel(Ctx c, constant NativeFrame &f) { |
| 912 | const float lens = 1.05; |
| 913 | // The music clock adds to the forward motion, so energetic passages speed it up. |
| 914 | float zc = c.travel * 1.5 + c.m * 1.0; |
| 915 | float4 tube = whTube(c.uv, zc, .35, lens, 1); |
| 916 | float a = tube.x, z = tube.y, d = tube.z, r = tube.w; |
| 917 | float columns = clamp(floor(44 / c.size + .5), 16.f, 96.f); |
| 918 | float tileH = TAU / columns; |
| 919 | float spin = c.t * .05; |
| 920 | float2 g = float2((a / TAU - spin) * columns, z / tileH); |
| 921 | float2 cell = floor(g), local = fract(g); |
| 922 | float column = cell.x - columns * floor(cell.x / columns); |
| 923 | float seed = hash21(float2(column, cell.y)); |
| 924 | float2 tilt = (hash22(float2(column, cell.y) + 3.7) - .5) * .32; |
| 925 | float centreAngle = (cell.x + .5) / columns * TAU + spin * TAU; |
| 926 | float3 inward = -float3(cos(centreAngle), sin(centreAngle), 0); |
| 927 | float3 tangent = float3(-sin(centreAngle), cos(centreAngle), 0); |
| 928 | float3 n = normalize(inward + tangent * tilt.x + float3(0, 0, 1) * tilt.y); |
| 929 | float3 view = normalize(float3(cos(a), sin(a), d)); |
| 930 | float3 refl = reflect(view, n); |
| 931 | // Reflected environment: a dim gradient and five roaming spotlights. |
| 932 | float3 env = deep(.3 + refl.z * .25, f) * .14; |
| 933 | float spotBoost = 1 + c.b.x * 1.6; |
| 934 | for (int k = 0; k < 5; ++k) { |
| 935 | float fk = float(k); |
| 936 | float around = (c.t + c.m * .8) * (.35 + fk * .08) * (k % 2 == 0 ? 1 : -1) + fk * 1.26; |
| 937 | float3 dir = normalize(float3(cos(around), sin(around), .6 * sin(c.t * .37 + fk * 2.1))); |
| 938 | env += paint(fk * .21 + .05, f) * pow(max(dot(refl, dir), 0.f), 22.f) * 1.8 * (spotBoost + c.b[k % 4] * .8); |
| 939 | } |
| 940 | // Light pools sweeping over the walls. |
| 941 | float3 pool = 0; |
| 942 | for (int m = 0; m < 3; ++m) { |
| 943 | float fm = float(m); |
| 944 | float centre = (c.t + c.m * .8) * (.45 + fm * .17) * (m == 1 ? -1 : 1) + fm * 2.1; |
| 945 | float depth = 2.2 + 1.3 * sin(c.t * .31 + fm * 1.7) + fm * .8; |
| 946 | float2 offset = float2(whWrap(a - centre), (z - zc - depth) * .55); |
| 947 | pool += paint(.15 + fm * .3, f) * exp(-dot(offset, offset) * 5) * spotBoost; |
| 948 | } |
| 949 | float poolLevel = dot(pool, float3(.33)); |
| 950 | // Highs sparkle single tiles; attacks send a glint wave down the tube. |
| 951 | float twinkle = pow(.5 + .5 * sin(c.t * (5 + seed * 7) + seed * 60), 24.f) * c.b.w * 3; |
| 952 | float waveZ = zc + .3 + (1 - c.hit) * 7; |
| 953 | float wave = c.hit * exp(-pow((z - waveZ) * 1.6, 2.f)); |
| 954 | float glint = dot(env, float3(.33)); |
| 955 | float3 tile = env * (.55 + .9 * glint) + pool * (.5 + glint * 2.5) + mix(env, paint(.95, f), .5) * (twinkle + wave * 2.5); |
| 956 | tile *= .85 + .3 * seed; |
| 957 | // Bevelled edges and dark grout between tiles. |
| 958 | float2 edge = min(local, 1 - local); |
| 959 | float edgeMin = min(edge.x, edge.y); |
| 960 | float foot = c.px * d * d / lens / tileH; |
| 961 | float grout = smoothstep(.04f, .09f + foot, edgeMin); |
| 962 | float3 color = mix(deep(.4, f) * .05 + pool * .08, tile, grout); |
| 963 | float star = (twinkle + wave * 2) * exp(-min(fabs(local.x - .5), fabs(local.y - .5)) * 30) * exp(-length(local - .5) * 4); |
| 964 | color += paint(.95, f) * star * .6; |
| 965 | // Tiles smaller than a few pixels blend into their average glow. |
| 966 | float tilePixels = tileH * r / d / c.px; |
| 967 | float3 farGlow = paint(a / TAU * 2 + c.t * .06, f) * .22 + deep(.3, f) * .06; |
| 968 | float3 average = env * .5 + pool * .8 + farGlow + paint(.9, f) * wave * 1.2; |
| 969 | color = mix(average, color, smoothstep(2.f, 5.f, tilePixels)); |
| 970 | float clear = whFog(d, c, .03, .09); |
| 971 | return mix(farGlow, color, clear) + paint(.9, f) * .25 * exp(-r * 7); |
| 972 | } |
| 973 | |
| 974 | // ---------------------------------------------------------------- 126 Fractal Throat |
| 975 | // Raymarched: a kaleidoscopic folded-box fractal (abs folds, sorting folds and rotations) |
| 976 | // repeating along the flight path, with a winding corridor carved through it. Sharp |
| 977 | // crystalline edges glow in orbit-trap colours and the far throat sinks into deep fog. |
| 978 | // Bass swells the fold glow; attacks spark the edges nearest the camera. |
| 979 | |
| 980 | |
| 981 | // ---------------------------------------------------------------- 127 Chroma Pipe |
| 982 | // Inside a polished chrome pipe. The wall mirrors a dark surround laced with neon stripe |
| 983 | // bands, and gentle dents in the metal bend the reflection into liquid, curving bands, |
| 984 | // with sharp specular glints on the dents. Chromatic rings, split into three palette |
| 985 | // channels, travel along the pipe and glint in the chrome. Bass deepens the dents so the |
| 986 | // stripes bend harder, highs sharpen and multiply the rings, and each attack emits a |
| 987 | // bright split ring from the camera. |
| 988 | float3 chromaEnvironment(float3 dir, Ctx c, constant NativeFrame &f) { |
| 989 | // Neon stripe bands around the reflected direction, on black. |
| 990 | float around = atan2(dir.y, dir.x) / TAU; |
| 991 | float stripe = around * 6 + dir.z * 2.6 - c.t * .22 - c.m * .35; |
| 992 | float id = floor(stripe); |
| 993 | id -= 6 * floor(id / 6); |
| 994 | float band = fract(stripe); |
| 995 | float neon = exp(-pow((band - .5) / .16, 2.f)); |
| 996 | float core = exp(-pow((band - .5) / .045, 2.f)); |
| 997 | float3 color = paint(id * .19 + .03, f) * (neon * (.9 + c.b[int(id) % 4] * 1.2) + core * .5); |
| 998 | color += paint(.6, f) * .05 * (.5 + .5 * dir.z); |
| 999 | return color; |
| 1000 | } |
| 1001 | float3 chromaRings(float z, Ctx c, constant NativeFrame &f, float width) { |
| 1002 | float split = .07 * c.size; |
| 1003 | float3 total = 0; |
| 1004 | for (int train = 0; train < 2; ++train) { |
| 1005 | float spacing = train == 0 ? 2.4f : 1.2f; |
| 1006 | float level = train == 0 ? 1.f : c.b.w * 1.4; |
| 1007 | if (level < .001) continue; |
| 1008 | float phase = (z - (c.t + c.m * 1.2) * (train == 0 ? 1.6f : 2.3f)) / spacing + (train == 0 ? 0.f : .37f); |
| 1009 | float dist = (fract(phase + .5) - .5) * spacing; |
| 1010 | float w = width * (1 - .45 * c.b.w); |
| 1011 | total += (paint(.02, f) * exp(-pow((dist + split) / w, 2.f)) + paint(.5, f) * exp(-pow(dist / w, 2.f)) + paint(.8, f) * exp(-pow((dist - split) / w, 2.f))) * level; |
| 1012 | } |
| 1013 | return total; |
| 1014 | } |
| 1015 | float3 chromaPipe(Ctx c, constant NativeFrame &f) { |
| 1016 | const float lens = 1.05; |
| 1017 | // The music clock adds to the forward motion, so energetic passages speed it up. |
| 1018 | float zc = c.travel * 1.6 + c.m * 1.0; |
| 1019 | float4 tube = whTube(c.uv, zc, .3, lens, 1); |
| 1020 | float a = tube.x, z = tube.y, d = tube.z, r = tube.w; |
| 1021 | float foot = c.px * d * d / lens; |
| 1022 | float sharp = exp(-foot * 4); |
| 1023 | float3 view = normalize(float3(cos(a), sin(a), d)); |
| 1024 | // Dents: a smooth height field around and along the pipe; bass deepens it. |
| 1025 | float depth = (.22 + c.b.x * .5) * sharp; |
| 1026 | float phaseA = a * 3 + sin(z * .9 + c.t * .4) * 1.5; |
| 1027 | float phaseZ = z * 2.1 - c.t * .6 + sin(a * 2 + z * .5) * .8; |
| 1028 | float dA = cos(phaseA) * sin(phaseZ) * 3, dZ = sin(phaseA) * cos(phaseZ) * 2.1; |
| 1029 | float3 inward = -float3(cos(a), sin(a), 0), tangent = float3(-sin(a), cos(a), 0); |
| 1030 | float3 n = normalize(inward + (tangent * dA + float3(0, 0, 1) * dZ) * depth); |
| 1031 | float3 refl = reflect(view, n); |
| 1032 | float3 color = chromaEnvironment(refl, c, f); |
| 1033 | // The rings show up in the chrome where the reflection crosses them. |
| 1034 | float t2 = -2 * dot(float2(cos(a), sin(a)), refl.xy) / max(dot(refl.xy, refl.xy), 1e-4f); |
| 1035 | float z2 = z + refl.z * min(t2, 30.f); |
| 1036 | color += chromaRings(z2, c, f, .05 * c.size) * .5; |
| 1037 | float fresnel = .6 + .4 * pow(1 - max(dot(-view, n), 0.f), 3.f); |
| 1038 | color *= fresnel; |
| 1039 | float glint = pow(max(dot(refl, normalize(float3(.25, .45, 1))), 0.f), 60.f) + pow(max(dot(refl, normalize(float3(-.5, -.3, 1))), 0.f), 90.f); |
| 1040 | color += paint(.95, f) * glint * (.7 + c.b.z * 1.5) * sharp; |
| 1041 | // Far down the pipe the reflections blur into a soft average. |
| 1042 | color = mix(paint(.5 + .1 * sin(c.t * .2), f) * .18, color, exp(-foot * 1.5)); |
| 1043 | // Seams on the chrome give scale. |
| 1044 | float seam = 1 - smoothstep(.004f, .012f + foot, fabs(z - round(z / 1.6) * 1.6)); |
| 1045 | color *= 1 - seam * .7; |
| 1046 | // The rings glow on the wall itself. |
| 1047 | float width = .05 * c.size; |
| 1048 | color += chromaRings(z, c, f, max(width, foot * .8)) * min(1.f, width / max(foot * .8, 1e-4f)) * .9; |
| 1049 | float pingZ = zc + .7 + (1 - c.hit) * 8; |
| 1050 | float dz = z - pingZ, split = .09; |
| 1051 | float w = max(.06f, foot); |
| 1052 | color += (paint(.02, f) * exp(-pow((dz + split) / w, 2.f)) + paint(.5, f) * exp(-pow(dz / w, 2.f)) + paint(.8, f) * exp(-pow((dz - split) / w, 2.f))) * c.hit * 2.2; |
| 1053 | float clear = whFog(d, c, .03, .08); |
| 1054 | return (mix(paint(.55, f) * .1 + deep(.3, f) * .08, color, clear) + paint(.9, f) * .2 * exp(-r * 6)) * .68; |
| 1055 | } |
| 1056 | |
| 1057 | // ---------------------------------------------------------------- 128 Coral Burrow |
| 1058 | // An undersea burrow: lumpy walls of porous coral (corallite cells with raised rims) |
| 1059 | // rippled by caustic light, set with bioluminescent polyps (glowing discs ringed by |
| 1060 | // swaying tentacles) and glowing plankton drifting past. Bass opens the polyps, highs |
| 1061 | // make the plankton twinkle and each attack flashes a ring of polyps just ahead. |
| 1062 | |
| 1063 | |
| 1064 | // ---------------------------------------------------------------- 129 Rainbow Slide |
| 1065 | // Riding down a translucent waterslide tube in sunshine. The rider sits low in the tube, |
| 1066 | // banked turns roll the view, helical panels of saturated colour glow with the sun |
| 1067 | // shining through the plastic, flanged seams ring each section, and a sheet of water |
| 1068 | // with bright foam rushes along the bottom. Bass splashes the water higher up the walls, |
| 1069 | // highs spit droplets and attacks throw spray across the camera side. |
| 1070 | float2 slidePath(float z) { return float2(sin(z * .19) * 1.4 + sin(z * .083) * .8, cos(z * .15) * .7); } |
| 1071 | float3 rainbowSlide(Ctx c, constant NativeFrame &f) { |
| 1072 | const float lens = .95, sit = .38; |
| 1073 | float radius = c.size; |
| 1074 | // The music clock adds to the forward motion, so energetic passages speed it up. |
| 1075 | float zc = c.travel * 1.9 + c.m * 1.5; |
| 1076 | // Bank into the turns: lateral curvature rolls the rider and the water up the wall. |
| 1077 | float curve = slidePath(zc + 1.2).x - 2 * slidePath(zc).x + slidePath(zc - 1.2).x; |
| 1078 | float bank = clamp(-curve * 1.6, -1.f, 1.f); |
| 1079 | float2 uv = rot(c.uv, -bank); |
| 1080 | float2 down = float2(sin(bank), -cos(bank)); |
| 1081 | float2 cam = down * sit * radius; |
| 1082 | float2 slope = slidePath(zc + .5) - slidePath(zc - .5); |
| 1083 | float d = 2, angle = 0; |
| 1084 | float2 wall = 0; |
| 1085 | for (int i = 0; i < 3; ++i) { |
| 1086 | float2 centre = (slidePath(zc + d) - slidePath(zc) - slope * d) * lens / max(d, 1e-3f); |
| 1087 | float2 v = (uv - centre) / lens; |
| 1088 | float vv = max(dot(v, v), 1e-6f), vc = dot(v, cam); |
| 1089 | d = (-vc + sqrt(max(vc * vc - vv * (dot(cam, cam) - radius * radius), 0.f))) / vv; |
| 1090 | d = min(d, 70.f); |
| 1091 | wall = cam + v * d; |
| 1092 | } |
| 1093 | angle = atan2(wall.y, wall.x); |
| 1094 | float z = zc + d; |
| 1095 | float foot = c.px * d * d / lens; |
| 1096 | float sharp = exp(-foot * 6); |
| 1097 | // Helical colour panels with flanged seams. |
| 1098 | float section = 1.1; |
| 1099 | float stripe = angle / TAU * 6 + z / section * .35; |
| 1100 | float id = floor(stripe); |
| 1101 | id -= 6 * floor(id / 6); |
| 1102 | float segment = floor(z / section); |
| 1103 | float3 panel = paint(id < 4.5 ? id * .25 : .375f, f); // palette stops stay pure |
| 1104 | float edge = fract(stripe); |
| 1105 | float joint = (1 - smoothstep(0.f, .04f + foot * 3, edge)) + (1 - smoothstep(1.f, .96f - foot * 3, edge)); |
| 1106 | panel *= 1 - joint * .55 * sharp; |
| 1107 | // Moulded ribs inside each panel catch the light. |
| 1108 | float rib = pow(.5 + .5 * cos(fract(z / section) * TAU * 3), 12.f) * sharp; |
| 1109 | panel *= .85 + .3 * rib; |
| 1110 | // Sun through the plastic: the side facing the sun glows, with a soft hot spot. |
| 1111 | float2 outward = wall / radius; |
| 1112 | float2 sunDir = normalize(float2(.45, .9)); |
| 1113 | float through = .15 + .85 * pow(max(dot(outward, sunDir) * .5 + .5, 0.f), 2.f); |
| 1114 | float hotspot = exp(-pow(whWrap(angle - atan2(sunDir.y, sunDir.x) - .3 * sin(z * .2)), 2.f) * 6) * (.6 + .4 * sin(z * .9 - c.t * .5)); |
| 1115 | float ripple = whNoiseP(float2(angle / TAU * 24, z * 2 + c.t * .4), 24); |
| 1116 | float caustic = pow(1 - fabs(whNoiseP(float2(angle / TAU * 16, z * 1.4 - c.t * .8), 16) * 2 - 1), 6.f) * sharp; |
| 1117 | // Low-mids pulse light through the panels section by section; high-mids sharpen the caustics. |
| 1118 | float sectionPulse = pow(.5 + .5 * sin(segment * 1.3 - c.t * 3), 4.f) * c.b.y; |
| 1119 | float3 color = panel * (.08 + .8 * through + hotspot * .4 + caustic * (.35 + c.b.z * .8) * through + sectionPulse * .6) + panel * ripple * .08 * sharp; |
| 1120 | float sheen = pow(max(cos(angle - 2.3), 0.f), 90.f) + pow(max(cos(angle + .6), 0.f), 120.f) * .6; |
| 1121 | color += mix(panel, paint(.97, f), .5) * sheen * .35 * sharp; |
| 1122 | float seamZ = z - round(z / section) * section; |
| 1123 | float flange = (1 - smoothstep(.018f, .03f + foot, fabs(seamZ))) * sharp; |
| 1124 | color = mix(color, panel * .15 + paint(.95, f) * .2 * through, flange * .8); |
| 1125 | float bolts = exp(-length(float2(whWrap(angle - (floor(angle / TAU * 16) + .5) * TAU / 16) * radius, seamZ)) * 60) * sharp; |
| 1126 | color += paint(.97, f) * bolts * .4; |
| 1127 | // Water sheet along the bottom (which tilts with the bank), with foam at its edges. |
| 1128 | float waterAngle = atan2(down.y, down.x); |
| 1129 | float off = fabs(whWrap(angle - waterAngle)); |
| 1130 | float slosh = .5 + .12 * sin(z * .6 - c.t * 1.3) + .08 * sin(z * 1.7 + c.t * 2.1); |
| 1131 | float reach = slosh + c.b.x * .55 * (.6 + .4 * sin(z * 2.3 - c.t * 4)); |
| 1132 | float water = smoothstep(reach, reach - .08f, off); |
| 1133 | float flow = z * 2.2 - zc * 2.6 - c.t * 2; |
| 1134 | float streaks = whNoiseP(float2(angle / TAU * 60, flow), 60) * .6 + whNoiseP(float2(angle / TAU * 20, flow * .4), 20) * .4; |
| 1135 | streaks = mix(.5f, streaks, sharp); |
| 1136 | float foam = smoothstep(.12f, 0.f, fabs(off - reach)) * (.5 + .5 * whNoiseP(float2(angle / TAU * 40, flow * 1.5), 40)); |
| 1137 | float glitter = pow(whNoiseP(float2(angle / TAU * 90, flow * 3 + c.t), 90), 14.f) * sharp; |
| 1138 | float3 spray = mix(paint(.0, f), paint(.5, f), .35); |
| 1139 | float3 waterColor = panel * .25 + paint(.0, f) * .14 + spray * (pow(streaks, 4.f) * .8 + glitter * 1.6); |
| 1140 | color = mix(color, waterColor, water * .85); |
| 1141 | color += spray * foam * .6 * sharp; |
| 1142 | float clear = whFog(d, c, .02, .06); |
| 1143 | color = mix(paint(.8, f) * .22 + paint(.3, f) * .06, color, clear * exp(-foot * .8) + (1 - exp(-foot * .8)) * 0); |
| 1144 | // Droplets in the air (highs) and spray across the camera side (attacks). |
| 1145 | if (c.b.w > .001) { |
| 1146 | float2 q = uv * 7 + float2(0, c.t * 2.5); |
| 1147 | float2 cell = floor(q); |
| 1148 | float h = hash21(cell); |
| 1149 | float2 at = hash22(cell + 4.1) - .5; |
| 1150 | float drop = exp(-pow(length(fract(q) - .5 - at * .7) / .045, 2.f)) * step(.86f, h); |
| 1151 | color += paint(.97, f) * drop * c.b.w * 1.4; |
| 1152 | } |
| 1153 | if (c.hit > .001) { |
| 1154 | float spray = 0; |
| 1155 | for (int k = 0; k < 9; ++k) { |
| 1156 | float seed = hash11(float(k) * 7.31 + 2); |
| 1157 | float dirAngle = -PI * .5 + (seed - .5) * 2.6; |
| 1158 | float2 at = float2(0, -1.05) + float2(cos(dirAngle), sin(dirAngle) * .5 + .6) * (.25 + (1 - c.hit) * (.6 + seed * .5)); |
| 1159 | at.x *= c.extent.x; |
| 1160 | float size = .04 + .05 * hash11(seed * 13); |
| 1161 | float rr = length(uv - at) / size; |
| 1162 | spray += (smoothstep(1.f, .85f, rr) * .25 + exp(-pow((rr - .85) / .12, 2.f)) * .9); |
| 1163 | } |
| 1164 | color += paint(.95, f) * spray * c.hit * c.hit * 1.2; |
| 1165 | } |
| 1166 | return color * .62; |
| 1167 | } |
| 1168 | |
| 1169 | // ---------------------------------------------------------------- 130 Pulse Arteries |
| 1170 | // Flowing through a blood vessel: a soft, moist wall laced with branching veins and |
| 1171 | // capillaries, side vessels opening off it, and biconcave cells tumbling past toward the |
| 1172 | // camera. Bass drives a heartbeat dilation wave that travels along the wall, the cell |
| 1173 | // flow surges with the music clock, and each attack spawns a cluster of cells ahead. |
| 1174 | float4 arteryCell(float2 q, float2 centre, float radius, float seed, float t) { |
| 1175 | // Returns colour weight (x), rim (y), coverage (z) of a tumbling biconcave disc. |
| 1176 | float tilt = t * (.4 + seed * .6) + seed * 9; |
| 1177 | float spin = t * (.3 + seed * .3) + seed * 17; |
| 1178 | float2 local = rot(q - centre, -spin); |
| 1179 | float squeeze = max(fabs(cos(tilt)), .18f); |
| 1180 | float e = length(float2(local.x, local.y / squeeze)) / radius; |
| 1181 | float cover = smoothstep(1.f, .9f, e); |
| 1182 | float dimple = smoothstep(.15f, .75f, e) * (.55 + .45 * squeeze); |
| 1183 | float rim = exp(-pow((e - .8) / .18, 2.f)); |
| 1184 | return float4(dimple, rim, cover, e); |
| 1185 | } |
| 1186 | float3 pulseArteries(Ctx c, constant NativeFrame &f) { |
| 1187 | const float lens = 1.0, bend = .6; |
| 1188 | float vessel = c.size; |
| 1189 | // The music clock adds to the flow, so energetic passages rush the camera along. |
| 1190 | float zc = c.travel * 1.3 + c.m * .8; |
| 1191 | float4 tube = whTube(c.uv, zc, bend, lens, vessel); |
| 1192 | float a = tube.x, d0 = tube.z, r = tube.w; |
| 1193 | // Heartbeat dilation: a travelling bulge, stronger with bass. |
| 1194 | float pulseClock = c.t * 1.6 + c.m * 2.5; |
| 1195 | float beatPhase = (zc + d0) * .55 - pulseClock; |
| 1196 | float beat = pow(.5 + .5 * sin(beatPhase), 3.f); |
| 1197 | float dilate = 1 + (.03 + c.b.x * .24) * beat; |
| 1198 | float d = d0 * dilate; |
| 1199 | float z = zc + d; |
| 1200 | beat = pow(.5 + .5 * sin(z * .55 - pulseClock), 3.f); |
| 1201 | float foot = c.px * d * d / lens; |
| 1202 | float sharp = exp(-foot * 6); |
| 1203 | // Moist wall with folds, veins and capillaries. |
| 1204 | float2 w = float2(a / TAU * 8, z * 1.3 / vessel); |
| 1205 | float folds = whFbmP(w + float2(0, c.t * .05), 8, 4); |
| 1206 | float2 toSite; |
| 1207 | float2 warp = float2(whFbmP(w * 1.5 + 7.3, 12, 2), whFbmP(w * 1.5 + 2.1, 12, 2)) - .5; |
| 1208 | // Veins: wandering ridged lines of a warped noise field. |
| 1209 | float veinField = whFbmP(float2(a / TAU * 6, z * .9 / vessel) + warp * .9, 6, 3); |
| 1210 | float vein = 1 - smoothstep(0.f, .025f + foot * .3, fabs(veinField - .5)); |
| 1211 | float veinPulse = c.b.y * pow(.5 + .5 * sin(z * 1.1 - c.t * 2.4 - c.m * 3), 3.f); |
| 1212 | float4 capCells = whVoronoiP(float2(a / TAU * 30, z * 4.5 / vessel) + warp * 1.2, 30, .9, toSite); |
| 1213 | float capillary = (1 - smoothstep(0.f, .06f, capCells.y - capCells.x)) * sharp; |
| 1214 | float3 tissue = mix(deep(.08 + folds * .15, f) * .55, paint(.18 + folds * .3, f) * .55, smoothstep(.3f, .75f, folds)); |
| 1215 | tissue *= .55 + .6 * folds; |
| 1216 | tissue = mix(tissue, deep(.02, f) * .25 + paint(.05, f) * .12 + paint(.35, f) * veinPulse * 1.6, vein * .75 * (.4 + .6 * sharp)); |
| 1217 | tissue = mix(tissue, paint(.12, f) * .3 + paint(.4, f) * c.b.w * .35, capillary * (.18 + c.b.w * .25)); |
| 1218 | float sheen = smoothstep(.55f, .8f, folds) * pow(max(cos(a - 1.9), 0.f), 3.f) * sharp; |
| 1219 | tissue += paint(.6, f) * sheen * (.12 + c.b.z * .7); |
| 1220 | // The heartbeat wave flushes the wall it passes: brighter and warmer with the bass. |
| 1221 | tissue = tissue * (1 + beat * c.b.x * 1.1) + paint(.35, f) * beat * (.06 + c.b.x * .5); |
| 1222 | // Low-mids swell slow patches of the wall in and out of shadow. |
| 1223 | tissue *= 1 + c.b.y * .55 * smoothstep(.45f, .75f, whNoiseP(float2(a / TAU * 4, z * .35 - c.t * .2), 4)); |
| 1224 | // Side vessels branching off the wall. |
| 1225 | float holeRow = floor(z / 3.2); |
| 1226 | for (int k = 0; k <= 1; ++k) { |
| 1227 | float id = holeRow + float(k); |
| 1228 | float holeZ = (id + .5) * 3.2, holeA = hash11(id * 4.7) * TAU - PI; |
| 1229 | float2 o = float2(whWrap(a - holeA) * vessel, (z - holeZ) * .8); |
| 1230 | float hr = length(o) / (.32 * vessel); |
| 1231 | float inside = smoothstep(1.f, .85f, hr); |
| 1232 | float lip = exp(-pow((hr - 1) / .12, 2.f)); |
| 1233 | tissue = mix(tissue, deep(.05, f) * .12 + paint(.1, f) * .2 * (1 - hr) * (1 - hr), inside); |
| 1234 | tissue += paint(.4, f) * lip * (.25 + c.b.z * .8); |
| 1235 | } |
| 1236 | float clear = whFog(d, c, .05, .1); |
| 1237 | float3 haze = deep(.1, f) * .25 + paint(.15, f) * .12; |
| 1238 | float3 color = mix(haze, tissue, clear); |
| 1239 | // Cells tumbling toward the camera, composited front to back. |
| 1240 | float flow = c.travel * .3 + c.t * .1 + c.m * .25; |
| 1241 | float3 cells = 0; |
| 1242 | float transmit = 1; |
| 1243 | const int layers = 9; |
| 1244 | for (int k = layers - 1; k >= 0; --k) { |
| 1245 | float2 slot = layerSlot(k, layers, flow); |
| 1246 | float depth = mix(11.f, .45f, slot.x); |
| 1247 | float fade = layerFade(slot.x) * whFog(depth, c, .05, .1); |
| 1248 | float2 centreOffset = whCentre(zc, depth, bend, lens); |
| 1249 | float2 q = (c.uv - centreOffset) * depth / lens; |
| 1250 | float grid = .48 * vessel; |
| 1251 | float2 cell = floor(q / grid); |
| 1252 | float seed = hash21(cell + slot.y * 13.1); |
| 1253 | float2 centre = (cell + .5 + (hash22(cell + slot.y * 7.7) - .5) * .3) * grid; |
| 1254 | if (seed < .2 || length(centre) > .8 * vessel) continue; |
| 1255 | float4 disc = arteryCell(q, centre, .15 * vessel, seed, c.t); |
| 1256 | float alpha = disc.z * fade; |
| 1257 | float cellBand = c.b[int(fract(seed * 6.1) * 3.99)]; |
| 1258 | float3 tint = paint(.04 + seed * .14 + cellBand * .12, f) * (.35 + .65 * disc.x) * (1 + cellBand * 1.1) + paint(.5, f) * disc.y * (.35 + c.b.z * 1.2); |
| 1259 | cells += transmit * alpha * tint; |
| 1260 | transmit *= 1 - alpha; |
| 1261 | } |
| 1262 | // Attack: a cluster of cells bursts out of a point ahead and spreads. |
| 1263 | if (c.hit > .001) { |
| 1264 | // The Coaster version bursts nearer, so the cells stay in view as the tube bends away. |
| 1265 | float depth = f.scene == 130 ? 2.6 : 1.2; |
| 1266 | float2 centreOffset = whCentre(zc, depth, bend, lens); |
| 1267 | float2 q = (c.uv - centreOffset) * depth / lens; |
| 1268 | float2 hub = .35 * vessel * float2(cos(c.t * .4), sin(c.t * .4)); |
| 1269 | for (int k = 0; k < 7; ++k) { |
| 1270 | float seed = hash11(float(k) * 3.3 + 1); |
| 1271 | float angle = float(k) / 7 * TAU + seed; |
| 1272 | float2 centre = hub + float2(cos(angle), sin(angle)) * (.08 + (1 - c.hit) * .45) * vessel; |
| 1273 | float4 disc = arteryCell(q, centre, .1 * vessel, seed, c.t); |
| 1274 | float alpha = disc.z * c.hit; |
| 1275 | cells += transmit * alpha * (paint(.08 + seed * .1, f) * (.45 + .6 * disc.x) + paint(.6, f) * disc.y * .5); |
| 1276 | transmit *= 1 - alpha; |
| 1277 | } |
| 1278 | } |
| 1279 | return cells + transmit * color + paint(.35, f) * .15 * exp(-r * 4); |
| 1280 | } |
| 1281 | |
| 1282 | // ---------------------------------------------------------------- 131 Zebra Warp |
| 1283 | // An op-art tunnel: bold stripes in log-polar coordinates spiral out of a drifting |
| 1284 | // vanishing point and bend in sinusoidal warps, alternating black with two vivid palette |
| 1285 | // colours for a strong motion illusion. Bass deepens the warp inside a slowly turning |
| 1286 | // sector, highs thread thin bright lines through the black stripes and each attack |
| 1287 | // inverts a band of stripes that rushes outward. |
| 1288 | float3 zebraWarp(Ctx c, constant NativeFrame &f) { |
| 1289 | float2 vanish = float2(sin(c.t * .19) * .3, cos(c.t * .15) * .2 - .05); |
| 1290 | float2 q = c.uv - vanish; |
| 1291 | float r = max(length(q), 1e-4f), angle = atan2(q.y, q.x); |
| 1292 | float density = 8.5 / c.size; |
| 1293 | float lr = log(r); |
| 1294 | float sector = pow(.5 + .5 * cos(whWrap(angle - c.t * .35)), 3.f); |
| 1295 | float amp = .3 + .15 * sin(c.t * .3) + c.b.x * 1.2 * sector; |
| 1296 | float warp = amp * sin(angle * 3 + lr * 2.5 - c.t * .8 - c.m * .6) + .22 * sin(angle * 5 - lr * 1.5 + c.t * .5); |
| 1297 | // The music clock adds to the inward rush of the stripes. |
| 1298 | float s = lr * density - c.travel * 1.7 - c.m * 1.5 + angle / TAU * 4 + warp; |
| 1299 | float w = (density + 3 * amp + 2) / r * c.px; // stripe units per pixel |
| 1300 | float mask = smoothstep(-PI * w, PI * w, sin(PI * s)); |
| 1301 | // Attack: a band of inverted stripes rushes outward as the envelope decays. |
| 1302 | float bandR = .1 + (1 - c.hit) * 3.5; |
| 1303 | float invert = smoothstep(0.f, .6f, c.hit) * .85 * smoothstep(.24f, .18f, fabs(lr - log(bandR))); |
| 1304 | mask = mix(mask, 1 - mask, invert); |
| 1305 | float pick = floor((s + .5) * .5); |
| 1306 | pick -= 2 * floor(pick * .5); |
| 1307 | float3 colorA = paint(.25 + .03 * sin(c.t * .11), f), colorB = paint(.75 + .03 * sin(c.t * .13 + 1), f); |
| 1308 | // Low-mids and high-mids each brighten one stripe colour. |
| 1309 | float3 stripeColor = pick < .5 ? colorA * (1 + c.b.y * .5) : colorB * (1 + c.b.z * .5); |
| 1310 | float3 dark = deep(.4, f) * .03; |
| 1311 | float3 color = mix(dark, stripeColor, mask); |
| 1312 | // Highs: thin bright threads through the black stripes. |
| 1313 | float strand = fabs(fract(s * .5 + .25) - .5) * 2; |
| 1314 | color += mix(colorA, colorB, .5) * exp(-pow(strand / (.03 + w * .7), 2.f)) * (1 - mask) * c.b.w * 2.2 * smoothstep(.35f, .1f, w); |
| 1315 | // Stripes finer than a pixel settle to their average; the throat darkens with depth. |
| 1316 | float3 average = (colorA + colorB) * .25 + dark * .5; |
| 1317 | color = mix(color, average, smoothstep(.25f, .7f, w)); |
| 1318 | color *= .35 + .65 * smoothstep(0.f, .8f, r); |
| 1319 | return color * .62 + paint(.85, f) * .12 * exp(-r * 8); |
| 1320 | } |
| 1321 | |
| 1322 | // ---------------------------------------------------------------- 132 Pixel Tunnel |
| 1323 | // A quantized light tunnel. A square tunnel is sampled at the centre of chunky screen |
| 1324 | // pixels. Its dark walls carry crisp emissive pixel strips whose light runs like |
| 1325 | // pixel-sorted streaks (each run ramps from a dim tail to a bright head) flowing toward |
| 1326 | // the camera, and their glow spreads over the walls as dithered gradients quantized to a |
| 1327 | // few levels. Thin pixel rings mark the depth and the far end resolves into a stepped, |
| 1328 | // glowing core. Each band lights its own family of strips, bass sends a chase along the |
| 1329 | // pixel rows and each attack flashes a ring of pixels just ahead. |
| 1330 | float pixelBayer(float2 cell) { |
| 1331 | int x = int(cell.x - 4 * floor(cell.x / 4)), y = int(cell.y - 4 * floor(cell.y / 4)); |
| 1332 | const int m[16] = {0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5}; |
| 1333 | return (float(m[y * 4 + x]) + .5) / 16; |
| 1334 | } |
| 1335 | // Light carried by strip column `colId` at depth z (0 when the column is dark). |
| 1336 | float pixelStrip(float colId, float z, Ctx c) { |
| 1337 | float seed = hash11(colId * 1.37 + 3); |
| 1338 | if (seed < .4) return 0; |
| 1339 | float speed = 3 + seed * 3; |
| 1340 | float runLength = 2 + 2.5 * hash11(colId * 2.1); |
| 1341 | float s = (z + (c.t + c.m * .8) * speed) / runLength + hash11(colId * 4.7); |
| 1342 | float along = fract(s); |
| 1343 | float on = step(.3f, hash11(floor(s) + colId * 13.1)); |
| 1344 | float ramp = floor(along * along * 6) / 6; // the run steps up toward its head |
| 1345 | float head = step(.9f, along); |
| 1346 | float band = c.b[int(fract(seed * 7.1) * 3.99)]; |
| 1347 | return on * (ramp * .8 + head * 1.2) * (.7 + band * 1.8); |
| 1348 | } |
| 1349 | float3 pixelTunnel(Ctx c, constant NativeFrame &f) { |
| 1350 | // Chunky pixels stay square on screen whatever the camera rotation or zoom. |
| 1351 | float2 res = max(f.resolution, float2(1)); |
| 1352 | float shortSide = min(res.x, res.y); |
| 1353 | float block = max(2.f, floor(shortSide / 90 * c.size + .5)); |
| 1354 | float2 cellId = floor(c.screen * res / block); |
| 1355 | float2 uv = ((cellId + .5) * block - res * .5) / (shortSide * .5); |
| 1356 | uv.y = -uv.y; |
| 1357 | float zoom = clamp(f.style.w, .3f, 2.f); |
| 1358 | uv = rot(uv, f.camera.x) / zoom; |
| 1359 | const float lens = 1.1, columns = 12, rowH = .5; |
| 1360 | // The music clock adds to the forward motion, so energetic passages speed it up. |
| 1361 | float zc = c.travel * 2.4 + c.m * 1.5; |
| 1362 | uv -= float2(sin(c.t * .31) * .08, cos(c.t * .23) * .05); |
| 1363 | uv = rot(uv, c.t * .04); |
| 1364 | // The Coaster version rides the course at each chunky pixel's centre, so blocks stay square. |
| 1365 | if (f.scene != 132) { |
| 1366 | Ctx cell = c; |
| 1367 | cell.uv = uv; |
| 1368 | uv = coasterRide(cell, 132, true).uv; |
| 1369 | } |
| 1370 | float m = max(fabs(uv.x), fabs(uv.y)); |
| 1371 | float d = min(lens / max(m, 1e-3f), 60.f); |
| 1372 | float z = zc + d; |
| 1373 | bool side = fabs(uv.x) > fabs(uv.y); |
| 1374 | float face = side ? (uv.x > 0 ? 0.f : 2.f) : (uv.y > 0 ? 1.f : 3.f); |
| 1375 | float across = (side ? uv.y : uv.x) / m; // -1..1 along the face |
| 1376 | float slot = (across + 1) * .5 * columns; |
| 1377 | float col = floor(slot), within = slot - col; |
| 1378 | float dither = pixelBayer(cellId); |
| 1379 | float clear = whFog(d, c, .045, .09); |
| 1380 | // How many screen pixels one strip column spans: thin far strips merge into glow. |
| 1381 | float chunk = block * c.px; // one chunky pixel in uv units |
| 1382 | float colPixels = 2 / columns * m / chunk; |
| 1383 | float resolve = smoothstep(1.5f, 3.f, colPixels); |
| 1384 | // The strip in this column (a crisp core) and dithered glow from it and its neighbours. |
| 1385 | float core = 0, glowAmount = 0, hueSeed = 0; |
| 1386 | for (int k = -1; k <= 1; ++k) { |
| 1387 | float cc = col + float(k); |
| 1388 | if (cc < 0 || cc >= columns) continue; |
| 1389 | float colId = face * columns + cc; |
| 1390 | // Strips sweeping right past the lens fade so no huge block flips in one frame. |
| 1391 | float level = pixelStrip(colId, z, c) * mix(.3f, 1.f, smoothstep(.45f, 1.3f, d)); |
| 1392 | float dist = fabs(slot - (cc + .5)); |
| 1393 | if (k == 0) { core = level * step(fabs(within - .5), .22f) * resolve; hueSeed = hash11(colId * 5.3); } |
| 1394 | glowAmount += level * exp(-dist * 2.2) * .45; |
| 1395 | } |
| 1396 | // Thin rings every few metres and a bass chase along the pixel rows. |
| 1397 | float row = floor(z / rowH); |
| 1398 | float ringDist = fabs(z - round(z / 4) * 4); |
| 1399 | float ring = step(ringDist, max(.05f, chunk * d * d / lens * .6)) * .8 * smoothstep(.7f, 1.8f, d); |
| 1400 | float chase = pow(.5 + .5 * sin(row * .6 - c.t * 5 - c.m * 3), 8.f) * c.b.x * 1.2; |
| 1401 | float gap = (row + .5) * rowH - zc; |
| 1402 | float flash = c.hit * 1.6 * smoothstep(1.4f, 2.2f, gap) * (1 - smoothstep(3.2f, 4.2f, gap)); |
| 1403 | // Quantize everything to a few dithered levels of palette colour. |
| 1404 | const float steps = 5; |
| 1405 | float glowLevel = floor(min((glowAmount + chase * .5 + flash * .6) * clear, 1.2f) * steps + dither) / steps; |
| 1406 | float coreLevel = floor(min((core + ring + chase * .6 + flash) * clear, 1.5f) * steps + dither) / steps; |
| 1407 | float hue = floor((z * .03 + face * .25 + c.t * .02) * 5 + dither) / 5; |
| 1408 | // Walls: a dithered gradient that brightens toward the glowing core. |
| 1409 | float ambient = floor((.32 + .55 * exp(-m * 2)) * 4 + dither) / 4; |
| 1410 | float3 wall = mix(deep(.3 + face * .1, f), paint(hue + .5, f), .45) * ambient * .3; |
| 1411 | float3 color = wall + paint(hue + hueSeed * .25, f) * glowLevel * .35 + paint(hue + hueSeed * .25 + .08, f) * coreLevel * .9; |
| 1412 | // Stepped glowing core at the far end. |
| 1413 | float coreGlow = floor(exp(-m * 4.5) * 6 + dither) / 6; |
| 1414 | color += paint(.85 + .1 * sin(c.t * .2), f) * coreGlow * .55; |
| 1415 | return color; |
| 1416 | } |
| 1417 | |
| 1418 | // ---------------------------------------------------------------- 133 Geode Passage |
| 1419 | // Flying through the hollow of a giant geode: walls bristling with crystal points that |
| 1420 | // radiate inward. Each voronoi cell is raised into a pyramid whose flat facets slope down |
| 1421 | // toward its neighbours, so every crystal shows crisp, individually lit faces and a |
| 1422 | // glowing tip; dark crevices separate the crystals, and patches of banded agate show |
| 1423 | // where the shell breaks through. Bass makes the crystals nearest the camera glow from |
| 1424 | // inside, highs sparkle on single facets and each attack lights a cluster of crystals. |
| 1425 | // Nearest and second-nearest site offsets of a voronoi field that repeats every |
| 1426 | // `period` cells in x; id receives the nearest cell. |
| 1427 | float4 geodeCells(float2 p, float period, thread float2 &id) { |
| 1428 | float2 cell = floor(p), fr = fract(p), near1 = 0, near2 = 0; |
| 1429 | float first = 64, second = 64; |
| 1430 | id = 0; |
| 1431 | for (int y = -1; y <= 1; ++y) for (int x = -1; x <= 1; ++x) { |
| 1432 | float2 g = float2(x, y), cid = cell + g; |
| 1433 | cid.x -= period * floor(cid.x / period); |
| 1434 | float2 delta = g + .5 + .8 * (hash22(cid) - .5) - fr; |
| 1435 | float dd = dot(delta, delta); |
| 1436 | if (dd < first) { second = first; near2 = near1; first = dd; near1 = delta; id = cid; } |
| 1437 | else if (dd < second) { second = dd; near2 = delta; } |
| 1438 | } |
| 1439 | return float4(near1, near2); |
| 1440 | } |
| 1441 | float3 geodePassage(Ctx c, constant NativeFrame &f) { |
| 1442 | const float lens = 1.05, columns = 22; |
| 1443 | // The music clock adds to the forward motion, so energetic passages speed it up. |
| 1444 | float zc = c.travel * 1.2 + c.m * .8; |
| 1445 | float4 tube = whTube(c.uv, zc, .42, lens, 1); |
| 1446 | float a = tube.x, d0 = tube.z, r = tube.w; |
| 1447 | // The geode turns slowly around the flight path; `spin` addresses its surface. |
| 1448 | float spin = a - c.t * .06 - c.m * .05; |
| 1449 | float zScale = 3.4 / c.size; |
| 1450 | float2 id; |
| 1451 | float4 sites = geodeCells(float2(spin / TAU * columns, (zc + d0) * zScale), columns, id); |
| 1452 | float edge = (dot(sites.zw, sites.zw) - dot(sites.xy, sites.xy)) / (2 * max(length(sites.zw - sites.xy), 1e-4f)); |
| 1453 | float zone = smoothstep(.36f, .48f, whFbmP(float2(spin / TAU * 5, (zc + d0) * .45), 5, 3)); |
| 1454 | float height = clamp(edge * 2.4, 0.f, 1.f) * zone; |
| 1455 | // Crystal tips stand in from the wall: one damped refinement adds parallax. |
| 1456 | float seed = hash21(id); |
| 1457 | float d = d0 * (1 - (.16 + .2 * seed) * height * exp(-d0 * .4)); |
| 1458 | float z = zc + d; |
| 1459 | sites = geodeCells(float2(spin / TAU * columns, z * zScale), columns, id); |
| 1460 | seed = hash21(id); |
| 1461 | edge = (dot(sites.zw, sites.zw) - dot(sites.xy, sites.xy)) / (2 * max(length(sites.zw - sites.xy), 1e-4f)); |
| 1462 | float shell = whFbmP(float2(spin / TAU * 5, z * .45), 5, 3); |
| 1463 | zone = smoothstep(.36f, .48f, shell); |
| 1464 | height = clamp(edge * 2.4, 0.f, 1.f) * zone; |
| 1465 | float foot = c.px * d * d / lens; |
| 1466 | float sharp = exp(-foot * 5); |
| 1467 | // The facet faces the neighbour that shares this edge: its normal leans that way. |
| 1468 | float2 slopeDir = normalize(sites.zw - sites.xy + 1e-5); |
| 1469 | float3 inward = -float3(cos(a), sin(a), 0); |
| 1470 | float3 tangent = float3(-sin(a), cos(a), 0), along = float3(0, 0, 1); |
| 1471 | float lean = .8 + .7 * seed; |
| 1472 | float3 n = normalize(inward + (tangent * slopeDir.x + along * slopeDir.y) * lean); |
| 1473 | float facetSeed = hash21(floor((sites.zw - sites.xy) * 7.3) + id); |
| 1474 | float3 view = normalize(float3(cos(a), sin(a), d)); |
| 1475 | float3 key = normalize(float3(.35, .6, -.7)); |
| 1476 | float diffuse = max(dot(n, key), 0.f), front = max(dot(n, -view), 0.f); |
| 1477 | float3 refl = reflect(view, n); |
| 1478 | float spec = pow(max(dot(refl, key), 0.f), 40.f) + pow(max(dot(refl, -view), 0.f), 60.f) * .5; |
| 1479 | float3 tint = paint(.45 + seed * .45, f); |
| 1480 | // Internal glow: a hot tip, a slow pulse; bass lights the nearest crystals from inside. |
| 1481 | float inner = pow(height, 3.f) * (.4 + .25 * sin(c.t * .7 + seed * 20) + c.b.z * .8); |
| 1482 | inner += (.3 + .7 * height) * c.b.x * 1.5 * exp(-d * .45) * zone; |
| 1483 | float clusterRow = floor(z / 4); |
| 1484 | float burst = 0; |
| 1485 | for (int k = -1; k <= 1; ++k) { |
| 1486 | float row = clusterRow + float(k); |
| 1487 | float cz = (row + .5) * 4, ca = hash11(row * 5.3) * TAU - PI; |
| 1488 | float window = smoothstep(.8f, 1.8f, cz - zc) * (1 - smoothstep(4.5f, 6.f, cz - zc)); |
| 1489 | float2 o = float2(whWrap(spin - ca), (z - cz) * .7); |
| 1490 | burst += window * max(1 - length(o) / 1.1, 0.f); |
| 1491 | } |
| 1492 | inner += c.hit * smoothstep(0.f, .3f, burst) * (.3 + .7 * height) * 2.4 * zone; |
| 1493 | float sparkle = pow(.5 + .5 * sin(c.t * (4 + facetSeed * 6) + facetSeed * 60), 20.f) * c.b.w * 2.5 * step(.55f, facetSeed); |
| 1494 | float facetShade = .05 + .8 * pow(diffuse, 1.5f) + .3 * front * front * (.3 + .7 * facetSeed); |
| 1495 | float3 crystal = tint * facetShade + paint(.93, f) * spec * .6 * sharp + paint(.78 + seed * .17, f) * inner * .6; |
| 1496 | crystal += paint(.97, f) * sparkle * smoothstep(.2f, .6f, height) * sharp; |
| 1497 | // Dark crevices where neighbouring crystals meet. |
| 1498 | float crevice = 1 - smoothstep(0.f, .05f + foot * 1.5, edge); |
| 1499 | crystal = mix(crystal, deep(.4, f) * .04, crevice * .85 * sharp); |
| 1500 | // Banded agate where the shell breaks through the crystal fields. |
| 1501 | float2 aw = float2(spin / TAU * 6, z * .9); |
| 1502 | float bands = whFbmP(aw, 6, 4) * 30 + shell * 12; |
| 1503 | float stripe = smoothstep(.35f, .65f, .5 + .5 * sin(bands * TAU)); |
| 1504 | float bandTone = fract(floor(bands) * .37); |
| 1505 | float3 light = bandTone < .55 ? paint(.95, f) * .45 : paint(.25 + bandTone * .5, f) * .55; |
| 1506 | float3 agate = mix(deep(.15 + shell * .3, f) * .18, light * (1 + c.b.y * .8), stripe * mix(1.f, .5f, 1 - sharp)); |
| 1507 | agate = mix(paint(.3, f) * .22, agate, sharp); |
| 1508 | float3 color = mix(agate, crystal, smoothstep(.15f, .4f, zone)); |
| 1509 | float clear = whFog(d, c, .045, .1); |
| 1510 | float3 haze = deep(.3, f) * .14 + paint(.7, f) * .07; |
| 1511 | return (mix(haze, color, clear) + paint(.85, f) * .25 * exp(-r * 5)) * .88; |
| 1512 | } |
| 1513 | |
| 1514 | #define WORMHOLE_EFFECTS(X) X(stormEye) X(sonarPipe) X(cubeHelix) X(phylloTube) X(teslaTube) X(foldTunnel) X(vectorTube) X(orbitalCorridor) X(mirrorballTunnel) X(chromaPipe) X(rainbowSlide) X(pulseArteries) X(zebraWarp) X(pixelTunnel) X(geodePassage) |
| 1515 | WORMHOLE_EFFECTS(NATIVE_EFFECT) |
| 1516 | |
| 1517 | // Coaster versions: the same designs riding the roller-coaster course. |
| 1518 | NATIVE_COASTER(stormEye, 117, false) |
| 1519 | NATIVE_COASTER(sonarPipe, 118, false) |
| 1520 | NATIVE_COASTER(phylloTube, 120, false) |
| 1521 | NATIVE_COASTER(teslaTube, 121, false) |
| 1522 | NATIVE_COASTER(foldTunnel, 122, false) |
| 1523 | NATIVE_COASTER(vectorTube, 123, false) |
| 1524 | NATIVE_COASTER(mirrorballTunnel, 125, false) |
| 1525 | NATIVE_COASTER(chromaPipe, 127, false) |
| 1526 | NATIVE_COASTER(rainbowSlide, 129, false) |
| 1527 | NATIVE_COASTER(pulseArteries, 130, false) |
| 1528 | NATIVE_COASTER(pixelTunnel, 132, true) |
| 1529 | NATIVE_COASTER(geodePassage, 133, false) |