PulseCanvas / app · pulsecanvas.ai / Sources / PulseCanvas / Resources / NativeRave.metal
| 1 | // PulseCanvas native designs. Original procedural code; see NativeCommon.metal. |
| 2 | |
| 3 | // Shared helpers for this file. |
| 4 | // Smooth per-element weight that drifts with the music clock (selects who reacts to an |
| 5 | // attack without ever switching abruptly). |
| 6 | float raveWeight(float m, float id, float sharpness) { |
| 7 | return pow(.5f + .5f * cos(m * .9f + id * 2.39f), sharpness); |
| 8 | } |
| 9 | // The attack envelope rides on a steady swell; this keeps only the punchy part. |
| 10 | float raveKick(float hit) { return smoothstep(.12f, .7f, hit); } |
| 11 | // Distance from p to the ellipse center + a cos(phi) + b sin(phi) (the projection of a |
| 12 | // tilted circle). An affine angle estimate is refined with damped Newton steps; phi |
| 13 | // returns the angle of the closest point. |
| 14 | float raveEllipse(float2 p, float2 center, float2 a, float2 b, thread float &phi) { |
| 15 | float det = a.x * b.y - a.y * b.x; |
| 16 | det = abs(det) < 1e-5 ? 1e-5 : det; |
| 17 | float2 d = p - center; |
| 18 | float2 w = float2(d.x * b.y - d.y * b.x, -d.x * a.y + d.y * a.x) / det; |
| 19 | phi = atan2(w.y, w.x); |
| 20 | for (int i = 0; i < 3; ++i) { |
| 21 | float cs = cos(phi), sn = sin(phi); |
| 22 | float2 s = a * cs + b * sn, ds = b * cs - a * sn; |
| 23 | float2 e = s - d; |
| 24 | float g = dot(e, ds), gg = dot(ds, ds) - dot(e, s); |
| 25 | phi -= clamp(g / max(abs(gg), 1e-5f), -.4f, .4f); |
| 26 | } |
| 27 | return length(d - a * cos(phi) - b * sin(phi)); |
| 28 | } |
| 29 | // Orthonormal basis (e1, e2) of the plane with normal n. |
| 30 | void raveBasis(float3 n, thread float3 &e1, thread float3 &e2) { |
| 31 | float3 helper = abs(n.y) < .9 ? float3(0, 1, 0) : float3(1, 0, 0); |
| 32 | e1 = normalize(cross(helper, n)); |
| 33 | e2 = cross(n, e1); |
| 34 | } |
| 35 | |
| 36 | // ---------------------------------------------------------------- Smoke Rings |
| 37 | // Vortex rings of luminous smoke drift through coloured beams in a dark room. Rings are |
| 38 | // launched on a staggered schedule from different directions, swell, wobble and slowly |
| 39 | // dissipate; their smoke rolls around the core. Zoom speed carries the camera through the |
| 40 | // dust in the beams. Bass thickens and brightens the rings, attacks launch a fast extra |
| 41 | // ring and highs glitter in the smoke. |
| 42 | constant float smokeFocal = 1.4; |
| 43 | float3 smokeRing(float2 uv, float3 start, float3 end, float age, float alpha, float id, float hue, float beam, float band, Ctx c, constant NativeFrame &f) { |
| 44 | if (alpha <= .002) return 0; |
| 45 | float travel = 1 - pow(1 - age, 1.7f); |
| 46 | float3 center = mix(start, end, travel); |
| 47 | float3 heading = normalize(end - start); |
| 48 | float3 axis = normalize(float3(heading.xy * .7 + float2(.25 * sin(c.t * .9 + id), .2 * cos(c.t * .7 + id * 1.3)), -1)); |
| 49 | float3 e1, e2; |
| 50 | raveBasis(axis, e1, e2); |
| 51 | float radius = (.55 + .35 * hash11(id * 3.7)) * (1 + 1.1 * age) * c.size; |
| 52 | float s = smokeFocal / max(center.z, .3f); |
| 53 | float2 c2 = center.xy * s; |
| 54 | float wobble = 1 + .05 * sin(c.t * 2.1 + id); |
| 55 | float2 a2 = e1.xy * radius * s * wobble, b2 = e2.xy * radius * s / wobble; |
| 56 | float thick = radius * (.2 + .12 * age) * (1 + c.b.x * .7 + band * .5) * s; |
| 57 | if (length(uv - c2) > (radius * s) * 1.3 + thick * 4) return 0; |
| 58 | float phi; |
| 59 | float d = raveEllipse(uv, c2, a2, b2, phi); |
| 60 | if (d > thick * 4) return 0; |
| 61 | float2 onRing = c2 + a2 * cos(phi) + b2 * sin(phi); |
| 62 | float inner = length(uv - c2) < length(onRing - c2) ? -1.f : 1.f; |
| 63 | float across = inner * d / thick; |
| 64 | float roll = fbm3(float3(cos(phi) * 1.7, sin(phi) * 1.7, across * .8 - c.t * 1.3 - c.m * 1.4 + id * 7.1), 3); |
| 65 | float core = exp(-across * across * 1.5); |
| 66 | float density = core * (.35 + 1.2 * roll * roll * 1.6) + exp(-abs(across) * 1.4) * .05; |
| 67 | float3 tint = paint(hue + band * .3, f); |
| 68 | float facing = .75 + .35 * dot(normalize(uv - c2 + 1e-4), float2(.35, .9)); |
| 69 | float depthFade = exp(-max(center.z - 2.f, 0.f) * (.06 + c.fog * .08)); |
| 70 | float3 color = tint * density * (.45 + .7 * beam) * facing + paint(.95, f) * pow(core * roll, 3.f) * .4; |
| 71 | float glitter = step(.982f, hash21(floor(uv * 230) + floor(c.t * 12))) * core * c.b.w * 3; |
| 72 | color += paint(.97, f) * glitter; |
| 73 | return color * alpha * depthFade * (1 + c.b.x * .4 + band * 1.6); |
| 74 | } |
| 75 | float3 smokeRings(Ctx c, constant NativeFrame &f) { |
| 76 | float2 drift = float2(sin(c.travel * .13) * .45, sin(c.travel * .09 + 1) * .2); |
| 77 | float2 uv = c.uv + drift; |
| 78 | // dark room, sweeping coloured beams and haze |
| 79 | float haze = fbm2(uv * 1.2 + float2(c.t * .05, c.t * .02), 4); |
| 80 | float3 color = deep(.55, f) * .06 + paint(.2, f) * .03; |
| 81 | float beamSum = 0; |
| 82 | float3 beamLight = 0; |
| 83 | for (int b = 0; b < 3; ++b) { |
| 84 | float fb = float(b); |
| 85 | float2 origin = float2((fb - 1) * c.extent.x * .8, c.extent.y + .3); |
| 86 | float2 d = uv - origin; |
| 87 | float ang = atan2(d.x, -d.y) - (.35 * sin(c.t * (.13 + fb * .04) + c.m * .25 + fb * 2.1) - (fb - 1) * .25); |
| 88 | float cone = exp(-ang * ang * 30) * smoothstep(5.f, .4f, length(d)); |
| 89 | beamSum += cone; |
| 90 | beamLight += paint(.15 + fb * .33, f) * cone * (1 + c.b[b + 1] * 1.6); |
| 91 | } |
| 92 | color += beamLight * (.1 + .16 * haze); |
| 93 | color += paint(.6, f) * .05 * haze; |
| 94 | // dust motes drifting toward the camera |
| 95 | for (int k = 0; k < 3; ++k) { |
| 96 | float2 slot = layerSlot(k, 3, c.travel * .12); |
| 97 | float phase = slot.x, id = slot.y; |
| 98 | float scale = layerScale(phase, 2) * 6; |
| 99 | float2 p = uv * scale + float2(id * 5.3, id * 2.9 + c.t * .1); |
| 100 | float2 cell = floor(p), local = fract(p) - .5; |
| 101 | float2 o = (hash22(cell + id) - .5) * .7; |
| 102 | float mote = exp(-length(local - o) * scale * 9 / (1 + phase * 3)); |
| 103 | color += paint(.9, f) * mote * layerFade(phase) * beamSum * .9 * (1 + c.b.w * 4) * step(.75f, hash21(cell + id * 3)); |
| 104 | } |
| 105 | // the rings: six staggered launches plus an attack ring |
| 106 | const int count = 8; |
| 107 | for (int k = 0; k < count; ++k) { |
| 108 | float clock = c.t * .07 + c.m * .05 + float(k) / float(count); |
| 109 | float age = fract(clock); |
| 110 | float id = floor(clock) * 7 + float(k) * 13; |
| 111 | float3 h = hash33(float3(id, 1.7, 3.1)); |
| 112 | float side = h.x < .5 ? -1.f : 1.f; |
| 113 | float z0 = 7 + h.y * 3, z1 = 2.1 + h.x * 1.8; |
| 114 | float2 from = float2(side * c.extent.x * (.5 + .4 * h.z), (h.z - .5) * 1.4 * c.extent.y); |
| 115 | float2 to = float2(-side * c.extent.x * (.1 + .75 * h.y), (h.x - .5) * 1.7 * c.extent.y); |
| 116 | float3 start = float3(from * z0 / smokeFocal, z0); |
| 117 | float3 end = float3(to * z1 / smokeFocal, z1); |
| 118 | float alpha = smoothstep(0.f, .1f, age) * (1 - smoothstep(.55f, 1.f, age)); |
| 119 | color += smokeRing(uv, start, end, age, alpha, id, h.z * 1.8, beamSum, c.b[k % 4], c, f); |
| 120 | } |
| 121 | float kick = raveKick(c.hit); |
| 122 | float3 launch = float3(sin(c.m * .7) * 3, -2 + .5 * cos(c.m * .5), 8); |
| 123 | float3 target = float3(-sin(c.m * .7) * .9, .5, 2.6); |
| 124 | color += smokeRing(uv, launch, target, (1 - kick) * .7, kick, 97, .95, beamSum, c.b.x, c, f) * 1.3; |
| 125 | return color; |
| 126 | } |
| 127 | |
| 128 | // ---------------------------------------------------------------- Wand Orbs |
| 129 | // Long-exposure light painting: wireframe globes are traced arc by arc by spinning LED |
| 130 | // wands, each meridian a dashed, slightly jittery stroke with a colour gradient along it, |
| 131 | // then the globe hangs, glows and dissolves while the next one is painted. Orbs stand at |
| 132 | // two depths over a dark mirror floor and Zoom speed dollies past them. Bands tint the |
| 133 | // wand gradients, attacks flash a bright equator arc and highs sparkle along the arcs. |
| 134 | constant float orbFocal = 1.3; |
| 135 | float3 wandOrb(float2 uv, float2 center, float radius, float scale, float cell, float layer, Ctx c, constant NativeFrame &f) { |
| 136 | float rs = radius * scale; |
| 137 | if (length(uv - center) > rs * 1.35 + .15) return 0; |
| 138 | float seed = hash11(cell * 1.31 + layer * 7.7); |
| 139 | float clock = c.t * .1 + c.m * .07 + seed * 5; |
| 140 | float band = c.b[int(fmod(abs(cell + layer * 2), 4.f))]; |
| 141 | float age = fract(clock); |
| 142 | float cycle = floor(clock); |
| 143 | float hueBase = hash11(cycle + cell * 3.1) * 1.6 + (c.b.y - c.b.z) * .35 + c.b.x * .2; |
| 144 | float build = smoothstep(0.f, .55f, age); |
| 145 | float dissolve = smoothstep(.78f, 1.f, age); |
| 146 | float fadeIn = smoothstep(0.f, .03f, age); |
| 147 | float yaw = c.t * .25 + c.m * .35 + seed * 6; |
| 148 | float roll = .3 * sin(seed * 9 + c.t * .1); |
| 149 | float2 axisX = rot(float2(1, 0), roll), axisY = rot(float2(0, 1), roll); |
| 150 | float pixel = c.px * 1.2; |
| 151 | float width = .006 * c.size * scale * (1 + c.b.x * .8 + band * .6); |
| 152 | const int arcs = 9; |
| 153 | float3 color = 0; |
| 154 | float swell = 1 + .1 * dissolve; |
| 155 | for (int k = 0; k < arcs; ++k) { |
| 156 | float fk = float(k); |
| 157 | float progress = clamp(build * float(arcs) - fk, 0.f, 1.f); |
| 158 | if (progress <= 0) break; |
| 159 | float theta = fk * PI / float(arcs) + yaw; |
| 160 | float2 a = axisX * rs * cos(theta) * swell, b = axisY * rs * swell; |
| 161 | float phi; |
| 162 | float d = raveEllipse(uv, center, a, b, phi); |
| 163 | if (d > .12) continue; |
| 164 | float q = fract((phi + PI * .5) / TAU); |
| 165 | float drawn = smoothstep(progress + .004f, progress - .004f, q); |
| 166 | float jitter = 1 + .25 * sin(q * 47 + fk * 3.1 + cycle); |
| 167 | float dash = .55 + .45 * smoothstep(.12f, .3f, fract(q * 40 + fk * .37)); |
| 168 | float front = .55 + .45 * cos(phi) * sin(theta) + .45; |
| 169 | float headGlow = progress < 1 ? exp(-abs(q - progress) * 60) * 2.5 : 0.f; |
| 170 | float3 tint = paint(hueBase + q * .7 + fk * .03, f); |
| 171 | float stroke = (line(d, width * jitter, pixel) * 1.3 + exp(-d / (.018 * scale * (1 + band * 1.5))) * .28) * (1 + band * 2.4); |
| 172 | float sparkle = pow(hash11(floor(q * 140) + fk * 17 + cycle), 18.f) * c.b.w * 3; |
| 173 | color += tint * stroke * drawn * dash * front * (1 + headGlow) + paint(.97, f) * sparkle * drawn * exp(-d / .01); |
| 174 | } |
| 175 | // attack: a bright equator arc |
| 176 | float flash = raveKick(c.hit) * raveWeight(c.m, cell + layer * 3, 2); |
| 177 | if (flash > .01) { |
| 178 | float phi; |
| 179 | float d = raveEllipse(uv, center, axisX * rs * 1.08, axisY * rs * .28, phi); |
| 180 | color += paint(.95, f) * (line(d, width * 1.6, pixel) * 1.5 + exp(-d / .03) * .5) * flash; |
| 181 | } |
| 182 | return color * fadeIn * (1 - dissolve); |
| 183 | } |
| 184 | float3 wandOrbs(Ctx c, constant NativeFrame &f) { |
| 185 | float tall = clamp((c.extent.y / c.extent.x - 1) / .78f, 0.f, 1.f); |
| 186 | float2 uv = (c.uv - float2(0, .3 * tall)) / (1 + .3 * tall); |
| 187 | float camX = c.travel * .35 + sin(c.t * .05) * .4; |
| 188 | float camY = .15; |
| 189 | float horizon = -.05; |
| 190 | float3 color = deep(.7, f) * .1 + paint(.2, f) * .05 * (1 + fbm2(uv * 1.5 + c.t * .03, 3)) + paint(.6, f) * .045; |
| 191 | color += paint(.85, f) * .05 * exp(-abs(uv.x + .4 * sin(c.t * .07)) * 1.5) * smoothstep(horizon, horizon + 2.f, uv.y); |
| 192 | color += paint(.6, f) * .06 * exp(-abs(uv.y - horizon) * 3); |
| 193 | if (uv.y < horizon) { |
| 194 | float depth = 1 / max(horizon - uv.y, .02f); |
| 195 | float sheen = exp(-abs(fract((uv.x * depth + camX) * .5) - .5) * 30) * .03 * exp(-(horizon - uv.y) * 2); |
| 196 | color = deep(.6, f) * .07 + paint(.6, f) * .04 + paint(.5, f) * sheen + paint(.6, f) * .05 * exp(-(horizon - uv.y) * 6); |
| 197 | } |
| 198 | for (int layer = 2; layer >= 0; --layer) { |
| 199 | float fl = float(layer); |
| 200 | float z = 2.3 + fl * 1.7 + fl * fl * .3; |
| 201 | float s = orbFocal / z; |
| 202 | float spacing = 2.5 - fl * .4; |
| 203 | float xw = uv.x / s + camX * (1 - fl * .3); |
| 204 | float cell = round(xw / spacing); |
| 205 | float seed = hash11(cell * 1.7 + fl * 5.1); |
| 206 | float radius = (.6 + .2 * seed) * c.size; |
| 207 | float floorY = -1.1 - camY; |
| 208 | float centerY = floorY + radius + .25 + fl * (.7 + .5 * seed) + .1 * sin(c.t * .4 + cell); |
| 209 | float2 center = float2((cell * spacing + (seed - .5) * .5 - camX * (1 - fl * .3)) * s, centerY * s); |
| 210 | float contact = floorY * s; |
| 211 | float depthFade = exp(-fl * (.3 + c.fog * .4)); |
| 212 | if (uv.y >= contact) { |
| 213 | color += wandOrb(uv, center, radius, s, cell, fl, c, f) * depthFade; |
| 214 | } else { |
| 215 | float2 mirrored = float2(uv.x + .004 * sin(uv.y * 90 + c.t), 2 * contact - uv.y); |
| 216 | color += wandOrb(mirrored, center, radius, s, cell, fl, c, f) * depthFade * .35 * exp(-(contact - uv.y) * 2.5); |
| 217 | } |
| 218 | } |
| 219 | return color; |
| 220 | } |
| 221 | |
| 222 | // ---------------------------------------------------------------- Faraday Dish |
| 223 | // Macro view straight down into a shallow dish of liquid vibrated from below: Faraday |
| 224 | // standing waves form square, hexagonal and quasicrystal lattices of crests that morph |
| 225 | // into each other, mirroring coloured studio lights, with light focused onto the dish |
| 226 | // floor under every crest and droplets bouncing on the surface. Zoom speed drifts and |
| 227 | // zooms across the dish. Bass raises the waves, the band balance shifts the lattice scale, |
| 228 | // attacks spray droplets and highs glitter on the crests. |
| 229 | |
| 230 | |
| 231 | // ---------------------------------------------------------------- String Resonance |
| 232 | // A giant light harp: long glowing strings cross the frame at slight angles and depths, |
| 233 | // held by bright bridge pins, and every span rings in standing-wave modes, drawn as a |
| 234 | // long-exposure envelope (bright at the turning points) around the moving string. Spans |
| 235 | // are plucked on a staggered schedule; Zoom speed slides the camera along the strings. |
| 236 | // Each band keeps its own string group ringing, attacks pluck a cluster hard and highs |
| 237 | // shimmer along the strings. |
| 238 | float3 stringResonance(Ctx c, constant NativeFrame &f) { |
| 239 | float2 uv = c.uv; |
| 240 | float haze = fbm2(uv * 1.1 + float2(c.t * .03, -c.t * .015), 4); |
| 241 | float3 color = deep(.25, f) * (.05 + .05 * haze) + paint(.1, f) * .025; |
| 242 | float3 glowSum = 0; |
| 243 | const int strings = 12; |
| 244 | float kick = raveKick(c.hit); |
| 245 | for (int i = 0; i < strings; ++i) { |
| 246 | float fi = float(i); |
| 247 | float3 h = hash33(float3(fi, 4.1, 9.3)); |
| 248 | float z = 1 + h.z * 1.6; |
| 249 | float scale = 1 / z; |
| 250 | float angle = (h.x - .5) * .32; |
| 251 | float y0 = ((fi + .5) / float(strings) * 2 - 1) * c.extent.y * .95 + (h.y - .5) * .12; |
| 252 | float2 local = rot(uv - float2(0, y0), -angle); |
| 253 | float maxAmp = .2 * scale + .05; |
| 254 | if (abs(local.y) > maxAmp + .25) continue; |
| 255 | float spanLength = 2.4 + h.x; |
| 256 | float xs = local.x * z + c.travel * .45 + h.y * 9; |
| 257 | float span = floor(xs / spanLength); |
| 258 | float s = xs / spanLength - span; |
| 259 | float3 hs = hash33(float3(span, fi, 2.7)); |
| 260 | float rate = .18 + hs.x * .2; |
| 261 | float clock = c.t * rate + c.m * rate * .9 + hs.y; |
| 262 | float age = fract(clock) / rate; |
| 263 | float pluck = smoothstep(0.f, .03f, age) * exp(-age * (.55 + hs.z * .4)); |
| 264 | int group = i % 4; |
| 265 | float drive = c.b[group] * .9 + kick * raveWeight(c.m, fi * .6, 3) * 1.4; |
| 266 | float strength = (pluck * .8 + drive) * scale; |
| 267 | float pluckAt = .15 + .3 * hs.z; |
| 268 | float a1 = .1 * strength * sin(PI * pluckAt); |
| 269 | float a2 = .05 * strength * sin(2 * PI * pluckAt); |
| 270 | float a3 = .03 * strength * sin(3 * PI * pluckAt); |
| 271 | float w = 9 + hs.x * 4; |
| 272 | float m1 = sin(PI * s), m2 = sin(2 * PI * s), m3 = sin(3 * PI * s); |
| 273 | float envelope = abs(a1 * m1) + abs(a2 * m2) + abs(a3 * m3); |
| 274 | float tv = c.t + c.m * .4; |
| 275 | float y = a1 * m1 * cos(w * tv) + a2 * m2 * cos(2 * w * tv + 1) + a3 * m3 * cos(3 * w * tv + 2); |
| 276 | float pixel = c.px * 1.2; |
| 277 | float width = .004 * c.size * scale + pixel * .4; |
| 278 | float ly = local.y; |
| 279 | // long-exposure envelope: dwell is longest at the turning points |
| 280 | float inside = smoothstep(envelope + pixel * 2, envelope - pixel, abs(ly)); |
| 281 | float dwell = envelope / sqrt(max(envelope * envelope - ly * ly, envelope * envelope * .02f) + 1e-6f); |
| 282 | float band = inside * clamp(dwell * .12f, 0.f, .9f) * smoothstep(0.f, .004f, envelope); |
| 283 | float3 tint = paint(.08 + fi / float(strings) * .85 + hs.z * .05, f); |
| 284 | float core = line(ly - y, width, pixel); |
| 285 | float bloom = exp(-abs(ly - y) / (.025 * scale + .01)) * .3 + exp(-max(abs(ly) - envelope, 0.f) / (.08 * scale)) * .08; |
| 286 | float shimmer = pow(hash21(float2(floor(xs * 60), floor(c.t * 14) + fi)), 24.f) * c.b.w * 3 * exp(-abs(ly - y) / .01); |
| 287 | float depthFade = exp(-(z - 1) * (.35 + c.fog * .4)); |
| 288 | float lit = .45 + 2.6 * strength; |
| 289 | color += (tint * (core * 1.1 + band * .55 + bloom * .8) * lit + paint(.97, f) * shimmer) * depthFade; |
| 290 | glowSum += tint * exp(-abs(ly) / .3) * .02 * lit * depthFade; |
| 291 | // bridge pins at the ends of every span |
| 292 | float pinX = (round(xs / spanLength) * spanLength - c.travel * .45 - h.y * 9) / z; |
| 293 | float pin = length(float2(local.x - pinX, ly) / float2(1, 2.5)); |
| 294 | color += paint(.9, f) * (exp(-pin / (.012 * scale)) * .9 + exp(-pin / (.06 * scale)) * .15) * depthFade; |
| 295 | } |
| 296 | return color + glowSum * (.6 + haze); |
| 297 | } |
| 298 | |
| 299 | // ---------------------------------------------------------------- Light Bars |
| 300 | // Kinetic light installation: four depth rows of hanging LED bars on fine wires rise, |
| 301 | // fall and tilt in travelling waves, each bar glowing along its length with a chasing |
| 302 | // gradient inside a lit haze. Zoom speed pans the camera along the rows (parallax). Each |
| 303 | // band lifts and tilts its own bar group, attacks flare a moving cluster of bars. |
| 304 | float3 lightBars(Ctx c, constant NativeFrame &f) { |
| 305 | float tall = clamp((c.extent.y / c.extent.x - 1) / .78f, 0.f, 1.f); |
| 306 | float camX = c.travel * .3 + sin(c.t * .05) * .5; |
| 307 | float camY = sin(c.t * .09) * .1; |
| 308 | float floorY = -.78 - .45 * tall; |
| 309 | float2 uv = c.uv; |
| 310 | bool mirror = uv.y < floorY; |
| 311 | float depthBelow = max(floorY - uv.y, 0.f); |
| 312 | if (mirror) uv = float2(uv.x + sin(depthBelow * 40 / (depthBelow + .1) + c.t) * .004, 2 * floorY - uv.y); |
| 313 | float haze = fbm2(uv * 1.3 + float2(c.t * .04, -c.t * .02), 3); |
| 314 | float3 color = deep(.35 + uv.y * .08, f) * (.1 + .08 * haze) + paint(.15, f) * .04; |
| 315 | float3 hazeLight = 0; |
| 316 | const int layers = 3; |
| 317 | const float eye = -.12; |
| 318 | for (int layer = layers - 1; layer >= 0; --layer) { |
| 319 | float fl = float(layer); |
| 320 | float z = 1 + fl * .75 + fl * fl * .25; |
| 321 | float2 p = float2(uv.x * z + camX * (1 + fl * .2), (uv.y - eye) * z + eye + camY); |
| 322 | float spacing = .26; |
| 323 | float id0 = round(p.x / spacing); |
| 324 | float pixel = c.px * z; |
| 325 | float depthFade = exp(-fl * (.25 + c.fog * .45)); |
| 326 | float width = .02 * c.size; |
| 327 | for (int k = -1; k <= 1; ++k) { |
| 328 | float id = id0 + float(k); |
| 329 | float x = id * spacing; |
| 330 | int group = int(fmod(abs(id + fl), 4.f)); |
| 331 | float band = c.b[group]; |
| 332 | float lift = .4 * sin(x * .85 - c.t * 1.15 - c.m * .9 + fl * 1.1) + .12 * sin(x * .3 + c.t * .5 + fl) + band * .45 * (group % 2 == 0 ? 1.f : -1.f); |
| 333 | float tilt = .13 * sin(x * .6 - c.t * .8 + fl * 1.3) + band * .2 * sin(float(group) * 1.7 + c.t * .8); |
| 334 | float length2 = .3 + .18 * tall; |
| 335 | float tier = (fmod(abs(id), 2.f) < .5 ? .42f : -.42f) * (1 + .7 * tall); |
| 336 | float2 center = float2(x, eye + .05 + tier + lift * .75); |
| 337 | float2 local = rot(p - center, -tilt); |
| 338 | float d = length(max(abs(local) - float2(0, length2), 0.f)) - width; |
| 339 | float along = local.y / length2; |
| 340 | float flare = c.hit * raveWeight(c.m, id * .7 + fl * 1.9, 4); |
| 341 | float chase = .5 + .5 * sin(along * 6 - c.t * 4 - c.m * 3 + id * 1.3); |
| 342 | float3 led = paint(.25 + along * .22 + fl * .13 + sin(id * .4 + c.t * .2) * .2, f); |
| 343 | float core = fill(d, pixel * 1.5); |
| 344 | float brightness = (.45 + .55 * chase + band * .6) * (1 + flare * 3.5); |
| 345 | color += led * (core * .9 + exp(-max(d, 0.f) / (.025 * c.size)) * .22) * brightness * depthFade; |
| 346 | hazeLight += led * exp(-max(d, 0.f) / .35) * .035 * brightness * depthFade; |
| 347 | float2 top = center + rot(float2(0, length2), tilt); |
| 348 | float wire = sdSegment(p, top, float2(top.x, top.y + 8)); |
| 349 | color += paint(.6, f) * exp(-wire / (pixel * 1.1)) * .1 * depthFade; |
| 350 | } |
| 351 | } |
| 352 | color += hazeLight * (.4 + 1.2 * haze); |
| 353 | if (mirror) color = color * .55 * exp(-depthBelow * 1.1) + deep(.4, f) * .06 + paint(.7, f) * .15 * exp(-depthBelow / .01); |
| 354 | return color; |
| 355 | } |
| 356 | |
| 357 | // ---------------------------------------------------------------- Sequin Curtain |
| 358 | // A wall of thousands of two-sided flip sequins in offset rows. Travelling flip waves |
| 359 | // (sweeps, spirals and rings that crossfade) turn each disc over, edge-on discs darken |
| 360 | // and catch sharp glints as the fronts pass, and a slow cloth ripple rolls through the |
| 361 | // whole curtain. Zoom speed pans and slightly zooms along it. Each band drives its own |
| 362 | // wave front, attacks flip a ring outward from a point and highs add glints. |
| 363 | float sequinFlip(float2 p, Ctx c) { |
| 364 | float tc = c.t * .05; |
| 365 | float3 w = pow(.5f + .5f * cos(tc * TAU + float3(0, 2.094, 4.189)), float3(2.f)) + float3(c.b.x, c.b.y, c.b.z) * 1.2; |
| 366 | float2 ctr = float2(sin(c.t * .11) * 1.2, cos(c.t * .09) * .6); |
| 367 | float2 d = p - ctr; |
| 368 | float sweep = sin(dot(p, normalize(float2(1, .35))) * 1.5 - c.t * 1.2); |
| 369 | float spiral = sin(atan2(d.y, d.x) * 2 + length(d) * 2.6 - c.t * 1.4); |
| 370 | float rings = sin(length(p - float2(-ctr.x, ctr.y * .5)) * 3.4 - c.t * 1.7 - c.m * .6); |
| 371 | float s = (w.x * sweep + w.y * spiral + w.z * rings) / (w.x + w.y + w.z); |
| 372 | s += c.b.w * .35 * sin(p.x * 5 + p.y * 3 - c.t * 3); |
| 373 | float flip = smoothstep(-.4f, .4f, s); |
| 374 | float kick = raveKick(c.hit); |
| 375 | float2 origin = float2(sin(c.m * .7) * 1.1, cos(c.m * .5) * .5); |
| 376 | float front = (1 - kick) * 2.4; |
| 377 | float ring = exp(-pow((length(p - origin) - front) / .22, 2.f)) * kick; |
| 378 | return mix(flip, 1 - flip, ring); |
| 379 | } |
| 380 | float3 sequinCurtain(Ctx c, constant NativeFrame &f) { |
| 381 | float zoom = 1 + .08 * sin(c.travel * .1); |
| 382 | float2 p = c.uv * zoom + float2(c.travel * .18, .1 * sin(c.travel * .07)); |
| 383 | float pitch = .075 * c.size; |
| 384 | float fold = sin(p.x * 2.1 + 1.4 * sin(p.y * 1.2 + c.t * .35) + c.t * .5); |
| 385 | p += float2(0, .015 * fold); |
| 386 | float4 cell = hexCell(p / pitch); |
| 387 | float2 q = cell.xy; |
| 388 | float2 centerP = cell.zw * float2(1, 1.7320508) * pitch; |
| 389 | float flip = sequinFlip(centerP, c); |
| 390 | float theta = flip * PI; |
| 391 | float ct = cos(theta), st = sin(theta); |
| 392 | float squash = max(abs(ct), .06f); |
| 393 | float2 sq = float2(q.x, q.y / squash); |
| 394 | float r = length(sq); |
| 395 | float pixel = c.px / pitch * 1.4; |
| 396 | float disc = fill(r - .47, pixel / squash); |
| 397 | float3 fabric = deep(.3, f) * .05 + paint(.7, f) * .02 * (1 + fold); |
| 398 | // cupped disc tilted about its horizontal axis |
| 399 | float3 n = normalize(float3(sq * .35 * float2(1, sign(ct)), 1)); |
| 400 | n = normalize(float3(n.x, n.y * ct + n.z * st, -n.y * st + n.z * ct)); |
| 401 | if (ct < 0) n = float3(n.x, -n.y, -n.z); |
| 402 | n.z = abs(n.z); |
| 403 | float2 jitter = hash22(cell.zw * 1.7) - .5; |
| 404 | n = normalize(n + float3(jitter * .22, 0)); |
| 405 | float3 key = normalize(float3(-.35 + .2 * sin(c.t * .13), .55, .75)); |
| 406 | float3 rim = normalize(float3(.6, -.3, .55)); |
| 407 | float3 refl = float3(2 * n.z * n.x, 2 * n.z * n.y, 2 * n.z * n.z - 1); |
| 408 | float spec = pow(max(dot(refl, key), 0.f), 40.f); |
| 409 | float spec2 = pow(max(dot(refl, rim), 0.f), 40.f); |
| 410 | float diffuse = max(dot(n, key), 0.f); |
| 411 | float hueA = .08 + .12 * sin(centerP.x * .4 + centerP.y * .3), hueB = .62 + .1 * sin(centerP.y * .5 - c.t * .1); |
| 412 | float3 side = ct > 0 ? paint(hueA, f) : paint(hueB, f); |
| 413 | float edgeOn = 1 - smoothstep(.05f, .45f, abs(ct)); |
| 414 | float glitter = 1 + c.b.w * 3 * step(.6f, hash21(cell.zw + floor(c.t * 4))); |
| 415 | float3 sequin = side * (.08 + .42 * diffuse) * (.8 + .25 * fold) * (1 - .6 * edgeOn) + side * side * .12; |
| 416 | sequin += (paint(.97, f) * spec * 2.4 + side * spec * 1.2) * glitter + paint(hueB + .3, f) * spec2 * .7; |
| 417 | sequin *= .9 + .2 * fill(r - .36, pixel) - .1; |
| 418 | float shadow = 1 - .5 * exp(-pow(length(q - float2(.06, -.08)) - .45, 2.f) * 40) * (1 - disc); |
| 419 | return mix(fabric * shadow, sequin, disc); |
| 420 | } |
| 421 | |
| 422 | // ---------------------------------------------------------------- Torsion Wave |
| 423 | // Wave-machine sculptures: hundreds of thin polished rods mounted crosswise on long spines |
| 424 | // that recede diagonally into the dark. Torsion waves and their reflections travel along |
| 425 | // each spine, twisting the rods, whose glowing tips leave short light trails. Three |
| 426 | // machines sit at different depths and Zoom speed moves the camera along the spines. |
| 427 | // Bass deepens the twist, bands add their own wave groups, attacks launch a pulse from |
| 428 | // the near end and highs sparkle the tips. |
| 429 | constant float torsionFocal = 1.3; |
| 430 | |
| 431 | |
| 432 | // ---------------------------------------------------------------- Spin Paint |
| 433 | // Spin art in motion: each pour lands on a spinning disc and flings outward as a fan of |
| 434 | // thin glossy streaks curving along logarithmic spirals, thinning toward the rim and |
| 435 | // ending in droplets, while a ring of colour smears around the landing radius. Pours |
| 436 | // layer up and fade so the canvas never saturates; overlapping discs spin at their own |
| 437 | // speeds and Zoom speed zooms seamlessly into the canvas. Bands pick the colour that |
| 438 | // pours, attacks fling an extra burst of streaks and highs add fine speckles. |
| 439 | |
| 440 | |
| 441 | // ---------------------------------------------------------------- Stadium Wave |
| 442 | // A vast perspective field of glowing balls (a crowd of lights) rises and falls in |
| 443 | // travelling waves: a stadium wave sweeping sideways, a diagonal swell and a circular |
| 444 | // ripple interfere, and colour follows height. Zoom speed flies the camera over the |
| 445 | // field. Bass raises the waves, each attack launches a ring wave from a drifting point. |
| 446 | float stadiumHeight(float2 g, float camZ, Ctx c) { |
| 447 | float sweep = pow(.5f + .5f * cos(g.x * .13 - c.t * 1.1 - c.m * .9 + g.y * .02), 12.f) * 1.4; |
| 448 | float swell = pow(.5f + .5f * cos(g.x * .06 + g.y * .11 - c.t * .7), 6.f); |
| 449 | float2 center = float2(sin(c.t * .13) * 6, camZ + 16); |
| 450 | float ripple = .5 + .5 * sin(length(g - center) * .55 - c.t * 2.2 - c.m * 1.6); |
| 451 | float h = (sweep * .9 + swell * .4 + ripple * .2) * (1 + c.b.x * 1.2); |
| 452 | float kick = raveKick(c.hit); |
| 453 | float2 origin = float2(sin(c.m * .7) * 7, camZ + 12 + 4 * cos(c.m * .5)); |
| 454 | float ring = (1 - kick) * 22 + 1; |
| 455 | h += kick * 1.1 * exp(-pow(length(g - origin) - ring, 2.f) * .35); |
| 456 | return h; |
| 457 | } |
| 458 | float3 stadiumWave(Ctx c, constant NativeFrame &f) { |
| 459 | const float focal = 1.25, camH = 4.6, maxLift = 2.2; |
| 460 | float horizon = c.extent.y * .62 + .3; |
| 461 | float camZ = c.travel * 1.6; |
| 462 | float camX = sin(c.t * .05) * 3; |
| 463 | float2 uv = c.uv; |
| 464 | float hz = horizon - uv.y; |
| 465 | // night sky with stadium floodlight glow |
| 466 | float3 color = deep(.7, f) * .08 + paint(.65, f) * .16 * exp(-abs(uv.y - horizon) * 4); |
| 467 | for (int k = 0; k < 4; ++k) { |
| 468 | float lx = (float(k) - 1.5) * c.extent.x * .6; |
| 469 | color += paint(.9, f) * .3 * exp(-length((uv - float2(lx, horizon + .1)) * float2(1, 2.5)) * 9); |
| 470 | } |
| 471 | if (hz <= 0) return color; |
| 472 | float zGround = camH * focal / hz; |
| 473 | float zNear = (camH - maxLift) * focal / hz; |
| 474 | float zCut = camH * focal / (horizon + c.extent.y + .3) * .8; |
| 475 | float3 ground = deep(.6, f) * .05 + paint(.6, f) * .03 * exp(-zGround * .03); |
| 476 | const float lattice = .62; |
| 477 | float radius = .17 * c.size; |
| 478 | float transmit = 1; |
| 479 | float3 accum = 0; |
| 480 | float j0 = ceil((max(zNear, zCut * .7f) + camZ - radius) / lattice), j1 = (zGround + camZ + radius) / lattice; |
| 481 | float pix = c.px * 1.2; |
| 482 | for (int k = 0; k < 30; ++k) { |
| 483 | float row = j0 + float(k); |
| 484 | if (row > j1) break; |
| 485 | float zr = row * lattice - camZ; |
| 486 | float nearFade = smoothstep(zCut * .7f, zCut, zr); |
| 487 | if (nearFade <= 0) continue; |
| 488 | float colX = round((uv.x * zr / focal + camX) / lattice) * lattice; |
| 489 | float2 g = float2(colX, row * lattice); |
| 490 | float h = stadiumHeight(g, camZ, c); |
| 491 | float y = .3 + h; |
| 492 | float s = focal / zr; |
| 493 | float2 center = float2((colX - camX) * s, horizon - (camH - y) * s); |
| 494 | float footY = horizon - camH * s; |
| 495 | float rs = radius * s; |
| 496 | float2 q = (uv - center) / rs; |
| 497 | float d = length(q); |
| 498 | float fade = exp(-zr * (.02 + c.fog * .035)) * nearFade; |
| 499 | float3 tint = paint(.06 + h * .36, f); |
| 500 | float stem = abs(uv.x - center.x) / rs; |
| 501 | float onStem = step(footY, uv.y) * step(uv.y, center.y); |
| 502 | accum += transmit * tint * exp(-stem * 8) * onStem * .16 * fade * min(rs / pix, 1.f); |
| 503 | float2 foot = (uv - float2(center.x, footY)) / (rs * float2(1.6, .5)); |
| 504 | accum += transmit * tint * exp(-dot(foot, foot) * 1.5) * .2 * (.3 + h) * fade; |
| 505 | accum += transmit * tint * exp(-max(d - 1, 0.f) * 3.5) * .08 * (.3 + h) * fade * min(rs / pix, 1.f); |
| 506 | float cover = (1 - smoothstep(1 - pix / rs, 1 + pix / rs, d)) * nearFade; |
| 507 | if (cover > 0) { |
| 508 | float2 qn = q / max(d, 1.f); |
| 509 | float nz = sqrt(max(1 - dot(qn, qn), 0.f)); |
| 510 | float3 ball = tint * (.25 + .5 * nz) * (.55 + .55 * h) + paint(.97, f) * pow(max(dot(float3(qn, nz), normalize(float3(-.4, .6, .7))), 0.f), 22.f) * .4; |
| 511 | ball = mix(color * .4 + paint(.6, f) * .05, ball, fade); |
| 512 | accum += transmit * cover * ball; |
| 513 | transmit *= 1 - cover; |
| 514 | if (transmit < .03) break; |
| 515 | } |
| 516 | } |
| 517 | float fieldFog = 1 - exp(-zGround * (.02 + c.fog * .03)); |
| 518 | ground = mix(ground, paint(.6, f) * .1, fieldFog); |
| 519 | return accum + transmit * ground; |
| 520 | } |
| 521 | |
| 522 | // ---------------------------------------------------------------- Liquid Floor |
| 523 | // A glossy black liquid dance floor seen at an angle, mirroring the club ceiling (LED |
| 524 | // strips, fixtures and roaming light pools). Unseen dancers' steps send rings across the |
| 525 | // surface in choreographed phrases (walks, turns and side steps) that interfere and bend |
| 526 | // the reflections. Zoom speed glides the camera across the floor. Bass strengthens the |
| 527 | // ripples, attacks add a hard stomp ring and highs sparkle in the reflections. |
| 528 | float2 liquidStepPos(float i, float n) { |
| 529 | float t = n / 1.6; |
| 530 | float2 center = float2(1.2 * sin(t * .23 + i * 2.1), 1.5 + i * 1.1 + .5 * cos(t * .17 + i)); |
| 531 | float2 heading = normalize(float2(1.1 * .23 * cos(t * .23 + i * 2.1), -.5 * .17 * sin(t * .17 + i)) + 1e-4); |
| 532 | float2 side = float2(-heading.y, heading.x); |
| 533 | float foot = fmod(n, 2.f) < .5 ? -1.f : 1.f; |
| 534 | float phrase = floor(hash11(floor(n / 8) + i * 7.3) * 3); |
| 535 | if (phrase < .5) return center + side * foot * .12; |
| 536 | if (phrase < 1.5) return center + .26 * float2(cos(n * .9), sin(n * .9)); |
| 537 | return center + side * foot * .28 + heading * .05 * sin(n); |
| 538 | } |
| 539 | float3 liquidCeiling(float3 origin, float3 dir, float camZ, Ctx c, constant NativeFrame &f) { |
| 540 | // LED wall far ahead: vertical colour bars that chase |
| 541 | float wallX = origin.x + dir.x / max(dir.z, .05f) * 12; |
| 542 | float bars = .5 + .5 * sin(wallX * 2.2 - c.t * 1.5); |
| 543 | float3 wall = paint(.1 + .8 * fract(floor(wallX * .7) * .37), f) * (.25 + .9 * pow(bars, 3.f)) * smoothstep(.0f, .12f, dir.y + .02f) * smoothstep(.45f, .05f, dir.y); |
| 544 | if (dir.y <= .02) return paint(.55, f) * .12 + wall * .6; |
| 545 | float t = (3.2 - origin.y) / dir.y; |
| 546 | float2 q = origin.xz + dir.xz * t; |
| 547 | float fade = exp(-t * .045); |
| 548 | float3 color = paint(.3 + .25 * sin(q.x * .3 + q.y * .2 + c.t * .1), f) * .12; |
| 549 | // rows of chasing LED strips across the room and dimmer strips along it |
| 550 | float stripD = abs(fract(q.y / 1.1) - .5) * 1.1; |
| 551 | float stripId = floor(q.y / 1.1); |
| 552 | float chase = .5 + .5 * sin(q.x * 2.2 - c.t * 3 - c.m * 2.5 + stripId * 1.7); |
| 553 | float stripBand = c.b[int(fmod(abs(stripId), 4.f))]; |
| 554 | color += paint(.1 + fract(stripId * .37) * .85, f) * (fill(stripD - .06, .015) * 1.5 + exp(-stripD / .15) * .4) * (.45 + .8 * chase) * (1 + stripBand * 2.2); |
| 555 | float laneD = abs(fract(q.x / 2.2) - .5) * 2.2; |
| 556 | float laneId = floor(q.x / 2.2); |
| 557 | color += paint(.55 + fract(laneId * .29) * .4, f) * (fill(laneD - .04, .015) * .8 + exp(-laneD / .12) * .2) * (.6 + .4 * sin(q.y * 1.5 + c.t * 2 + c.m * 1.5 + laneId)) * (1 + c.b[int(fmod(abs(laneId) + 2, 4.f))] * 1.8); |
| 558 | // fixtures |
| 559 | float2 cell = floor(q / 1.1), local = fract(q / 1.1) - .5; |
| 560 | float lamp = length(local); |
| 561 | float fixture = (fill(lamp - .07, .015) * 2 + exp(-lamp / .12) * .5) * step(.4f, hash21(cell)); |
| 562 | color += paint(.75 + .25 * hash21(cell + 2), f) * fixture * (.7 + .3 * sin(c.t * 2.3 + cell.x * 1.3 + cell.y)) * (1 + c.b[int(hash21(cell + 5) * 3.99)] * 2.4); |
| 563 | // sweeping beams and roaming pools of light |
| 564 | for (int k = 0; k < 3; ++k) { |
| 565 | float fk = float(k); |
| 566 | float2 pivot = float2((fk - 1) * 3, camZ + 6 + fk * 1.5); |
| 567 | float beamAngle = c.t * (.21 + fk * .05) + c.m * .3 + fk * 2.1; |
| 568 | float2 dirB = float2(cos(beamAngle), sin(beamAngle)); |
| 569 | float beamD = abs(dot(q - pivot, float2(-dirB.y, dirB.x))); |
| 570 | color += paint(.2 + fk * .3, f) * exp(-beamD / .3) * .45 * (1 + c.b[k + 1] * 2.2); |
| 571 | float2 pool = float2(sin(c.t * (.2 + fk * .07) + fk * 2) * 2.5, camZ + 5 + fk * 2.5 + 1.5 * cos(c.t * .15 + fk)); |
| 572 | color += paint(.25 + fk * .3, f) * .4 * exp(-length(q - pool) * 1.2); |
| 573 | } |
| 574 | return color * fade + paint(.5, f) * .12 * (1 - fade) + wall; |
| 575 | } |
| 576 | float3 liquidFloor(Ctx c, constant NativeFrame &f) { |
| 577 | const float focal = 1.3, height = 1.25; |
| 578 | float tall = clamp((c.extent.y / c.extent.x - 1) / .78f, 0.f, 1.f); |
| 579 | float horizon = c.extent.y * .78 + .1 - .2 * tall; |
| 580 | float2 uv = c.uv; |
| 581 | float camZ = c.travel * .8; |
| 582 | float camX = sin(c.travel * .05) * 1.5; |
| 583 | float3 color = paint(.5, f) * .12 * exp(-abs(uv.y - horizon) * 2) + deep(.6, f) * .04; |
| 584 | if (uv.y >= horizon) return color; |
| 585 | float z = height * focal / (horizon - uv.y); |
| 586 | float2 g = float2(uv.x * z / focal, z); |
| 587 | float3 eye = float3(camX, height, camZ); |
| 588 | float3 hit = float3(g.x + camX, 0, g.y + camZ); |
| 589 | float3 view = normalize(hit - eye); |
| 590 | // ripple field from the dancers' recent steps |
| 591 | float2 grad = 0; |
| 592 | float scale = 1 / c.size; |
| 593 | for (int i = 0; i < 3; ++i) { |
| 594 | float fi = float(i); |
| 595 | float clock = c.t * 1.6 + c.m * 1.0 + fi * .37; |
| 596 | float now = floor(clock); |
| 597 | for (int k = 0; k < 3; ++k) { |
| 598 | float n = now - float(k); |
| 599 | float tau = (clock - n) / 1.6; |
| 600 | float2 source = liquidStepPos(fi, n); |
| 601 | float2 d = g - source; |
| 602 | float dist = length(d) * scale; |
| 603 | float radius = tau * .6; |
| 604 | float amp = (.5 + c.b.x * 1.3) * exp(-tau * 1.1) / (1 + radius * 2.5) * smoothstep(0.f, .05f, tau); |
| 605 | float x = dist - radius; |
| 606 | float env = exp(-x * x / .03); |
| 607 | float slope = amp * (28 * cos(x * 28) - 2 * x / .03 * sin(x * 28)) * env; |
| 608 | grad += slope * d / max(length(d), 1e-3f); |
| 609 | } |
| 610 | } |
| 611 | float kick = raveKick(c.hit); |
| 612 | if (kick > .01) { |
| 613 | float2 d = g - float2(sin(c.m * .6) * .8, 2.6); |
| 614 | float x = length(d) * scale - (1 - kick) * 1.4; |
| 615 | float env = exp(-x * x / .05); |
| 616 | grad += kick * 1.6 * (24 * cos(x * 24) - 2 * x / .05 * sin(x * 24)) * env * d / max(length(d), 1e-3f); |
| 617 | } |
| 618 | float3 n = normalize(float3(-grad.x * .02, 1, -grad.y * .02)); |
| 619 | float3 r = reflect(view, n); |
| 620 | float fresnel = .05 + .95 * pow(1 - max(dot(-view, n), 0.f), 4.f); |
| 621 | float3 env = liquidCeiling(hit, r, camZ, c, f); |
| 622 | float3 surface = deep(.6, f) * .05 + env * (.34 + .5 * fresnel); |
| 623 | // light pools gliding over the surface |
| 624 | for (int k = 0; k < 2; ++k) { |
| 625 | float fk = float(k); |
| 626 | float2 pool = float2(sin(c.t * (.17 + fk * .06) + fk * 3) * 1.5, 2.5 + fk * 1.5 + cos(c.t * .13 + fk) * 1.2); |
| 627 | surface += paint(.2 + fk * .5, f) * .08 * exp(-length(g - pool) * 1.6); |
| 628 | } |
| 629 | float glint = step(.97f, hash21(floor(uv * 180) + floor(c.t * 12))) * c.b.w * smoothstep(.3f, 1.2f, dot(env, float3(.33))); |
| 630 | surface += paint(.97, f) * glint * 2; |
| 631 | float haze = 1 - exp(-z * (.03 + c.fog * .03)); |
| 632 | return mix(surface, color + paint(.5, f) * .06, haze); |
| 633 | } |
| 634 | |
| 635 | // ---------------------------------------------------------------- Confetti Storm |
| 636 | // Party confetti: layers of paper flakes and curly streamers flutter down through a |
| 637 | // bright stage glow, every flake spinning and tumbling so it flashes as it catches the |
| 638 | // light; Zoom speed carries the camera through the layers. Confetti cannons in the |
| 639 | // bottom corners fire on their own; bass launches extra bursts and attacks fire both. |
| 640 | |
| 641 | |
| 642 | // ---------------------------------------------------------------- Bokeh Club |
| 643 | // A nightclub seen through a fast lens wide open: layers of club lights and LED strips |
| 644 | // dissolve into large hexagonal bokeh with onion-ring texture and colour fringes at the |
| 645 | // rims, drifting and swirling in haze while the focus slowly racks through the layers. |
| 646 | // Zoom speed drifts the lens forward through them. Each band brightens its own group of |
| 647 | // lights, attacks flare a cluster and highs add tiny sharp sparkles. |
| 648 | |
| 649 | |
| 650 | // ---------------------------------------------------------------- Persistence Fans |
| 651 | // Holographic LED fans float in a dark room at different depths and angles; their |
| 652 | // spinning blades paint luminous shapes by persistence of vision (mandalas, a band-driven |
| 653 | // waveform ring, outward rings and starbursts that morph into each other), with faint |
| 654 | // blade sweeps, LED scanlines and flicker bands. Zoom speed dollies between the fans. |
| 655 | // The waveform ring follows the bands, attacks pop a starburst and highs sparkle LEDs. |
| 656 | |
| 657 | |
| 658 | // ---------------------------------------------------------------- Domino Run |
| 659 | // Glossy coloured dominoes stand in a long meandering line on a dark mirror floor; a |
| 660 | // toppling wave runs along it, each domino tipping onto the next with a glint, and every |
| 661 | // so often the chain forks into a side line that topples in step. The camera follows the |
| 662 | // falling front (Zoom speed sets how fast). The music clock pushes the wave, bands light |
| 663 | // the falling dominoes, attacks race a bright wave down the side line and highs glint. |
| 664 | constant float dominoSpacing = .3, dominoFork = 15; |
| 665 | float dominoPath(float z) { return 1.2 * sin(z * .19) + .5 * sin(z * .43 + 1.3); } |
| 666 | float dominoSlope(float z) { return 1.2 * .19 * cos(z * .19) + .5 * .43 * cos(z * .43 + 1.3); } |
| 667 | float dominoBranch(float z, thread float &side, thread float &along) { |
| 668 | float k = floor((z - 6) / dominoFork); |
| 669 | along = z - (k * dominoFork + 6); |
| 670 | side = hash11(k * 3.7) < .5 ? -1.f : 1.f; |
| 671 | if (along < .6 || along > 11) return 1e3; |
| 672 | return dominoPath(z) + side * (1 - cos(min(along, 7.f) / 7 * PI)) * .72; |
| 673 | } |
| 674 | float dominoBox(float3 p, float x, float zi, float slope, float fallFront, float size) { |
| 675 | float3 base = float3(x, 0, zi); |
| 676 | float2 tangent = normalize(float2(slope, 1)); |
| 677 | float2 normal = float2(tangent.y, -tangent.x); |
| 678 | float3 d = p - base; |
| 679 | float3 q = float3(dot(d.xz, normal), d.y, dot(d.xz, tangent)); |
| 680 | float thick = .035 * size, tall = .24 * size, wide = .11 * size; |
| 681 | float angle = clamp((fallFront - zi) / .45f, 0.f, 1.f) * 1.32; |
| 682 | float qy = q.y, qz = q.z - thick; |
| 683 | float ly = qy * cos(angle) + qz * sin(angle); |
| 684 | float lz = -qy * sin(angle) + qz * cos(angle); |
| 685 | return sdBox(float3(q.x, ly - tall, lz + thick), float3(wide, tall, thick)) - .006 * size; |
| 686 | } |
| 687 | constant float dominoLineGap = 3.4; |
| 688 | float dominoMap(float3 p, float front, float size, thread float &which, thread float &index) { |
| 689 | float lane = round((p.x - dominoPath(p.z)) / dominoLineGap); |
| 690 | float shift = lane * 7.3; |
| 691 | float offset = lane * dominoLineGap; |
| 692 | float lineFront = front - abs(lane) * 1.7; |
| 693 | float3 lp = float3(p.x - offset, p.y, p.z); |
| 694 | float i0 = round(lp.z / dominoSpacing); |
| 695 | float best = 1e3; |
| 696 | for (int k = 0; k < 2; ++k) { |
| 697 | float i = i0 - float(k); |
| 698 | float zi = i * dominoSpacing; |
| 699 | float d = dominoBox(lp, dominoPath(zi), zi, dominoSlope(zi), lineFront, size); |
| 700 | if (d < best) { best = d; which = lane * 2; index = i; } |
| 701 | float side, along; |
| 702 | float bx = dominoBranch(zi + shift, side, along); |
| 703 | bx += dominoPath(zi) - dominoPath(zi + shift); |
| 704 | if (bx < 100) { |
| 705 | float slope = dominoSlope(zi) + side * sin(min(along, 7.f) / 7 * PI) * PI / 7 * .72 * step(along, 7.f); |
| 706 | float db = dominoBox(lp, bx, zi, slope, lineFront, size); |
| 707 | if (db < best) { best = db; which = lane * 2 + 1; index = i; } |
| 708 | } |
| 709 | } |
| 710 | return best; |
| 711 | } |
| 712 | float3 dominoRun(Ctx c, constant NativeFrame &f) { |
| 713 | float size = c.size; |
| 714 | float front = c.t * 1.9 + c.travel * 1.5 + c.m * 1.1; |
| 715 | float camZ = front - 3.2; |
| 716 | float tall = clamp((c.extent.y / c.extent.x - 1) / .78f, 0.f, 1.f); |
| 717 | float3 eye = float3(dominoPath(camZ) * .6 + .9, 1.7 + 1.1 * tall, camZ); |
| 718 | float3 target = float3(dominoPath(camZ + 5) * .8, 0, camZ + 5.5); |
| 719 | float3 rd = cameraRay(c.uv, target - eye, float3(0, 1, 0), 1.5); |
| 720 | float3 sky = deep(.7, f) * .08 + paint(.6, f) * .14 * exp(-abs(rd.y + .04) * 7); |
| 721 | if (rd.y >= -.005) return sky; |
| 722 | float tFloor = eye.y / -rd.y; |
| 723 | float tStart = (eye.y - .62 * size) / -rd.y; |
| 724 | float t = max(tStart, 0.f); |
| 725 | float which = 0, index = 0; |
| 726 | bool hit = false; |
| 727 | for (int s = 0; s < 44; ++s) { |
| 728 | float3 p = eye + rd * t; |
| 729 | float d = dominoMap(p, front, size, which, index); |
| 730 | if (d < .002) { hit = true; break; } |
| 731 | t += max(d * .9, .004f); |
| 732 | if (t > tFloor) break; |
| 733 | } |
| 734 | float3 light = normalize(float3(-.5, .8, .35)); |
| 735 | float fog = exp(-max(min(t, tFloor) - 2, 0.f) * (.06 + c.fog * .06)); |
| 736 | if (hit) { |
| 737 | float3 p = eye + rd * t; |
| 738 | const float2 e = float2(.003, -.003); |
| 739 | float dummyA, dummyB; |
| 740 | float3 n = normalize(e.xyy * dominoMap(p + e.xyy, front, size, dummyA, dummyB) + e.yyx * dominoMap(p + e.yyx, front, size, dummyA, dummyB) |
| 741 | + e.yxy * dominoMap(p + e.yxy, front, size, dummyA, dummyB) + e.xxx * dominoMap(p + e.xxx, front, size, dummyA, dummyB)); |
| 742 | float lane = round(which * .5 - .25); |
| 743 | float zi = index * dominoSpacing; |
| 744 | float falling = clamp((front - abs(lane) * 1.7 - zi) / .45f, 0.f, 1.f); |
| 745 | float moving = falling * (1 - falling) * 4; |
| 746 | float band = c.b[int(fmod(abs(index), 4.f))]; |
| 747 | float hue = fract(index * .061 + which * .37) * 1.8; |
| 748 | float3 tint = paint(hue, f); |
| 749 | float diffuse = max(dot(n, light), 0.f); |
| 750 | float spec = pow(max(dot(reflect(rd, n), light), 0.f), 40.f); |
| 751 | float rim = pow(1 - max(dot(-rd, n), 0.f), 3.f); |
| 752 | float side, along; |
| 753 | dominoBranch(index * dominoSpacing + lane * 7.3, side, along); |
| 754 | float kick = raveKick(c.hit); |
| 755 | float race = fmod(abs(which), 2.f) > .5 ? kick * exp(-pow(along - (1 - kick) * 11, 2.f) * .8) : 0.f; |
| 756 | float glint = 1 + c.b.w * 3 * step(.8f, hash11(index * 1.7 + floor(c.t * 8))); |
| 757 | float3 color = tint * (.12 + .7 * diffuse) * (1 + band * (1.2 + 1.6 * moving) + falling * .15) + paint(.97, f) * spec * 1.3 * glint + tint * rim * .35 * (1 + band * 2); |
| 758 | color += paint(.95, f) * race * 1.5 + tint * moving * .35; |
| 759 | return mix(sky, color, fog); |
| 760 | } |
| 761 | // mirror floor: soft reflections and contact shadows from the nearest dominoes |
| 762 | float3 p = eye + rd * tFloor; |
| 763 | float3 color = deep(.6, f) * .07 + paint(.6, f) * .03; |
| 764 | float near = dominoMap(p + float3(0, .12 * size, 0), front, size, which, index); |
| 765 | float zi = index * dominoSpacing; |
| 766 | float3 tint = paint(fract(index * .061 + which * .37) * 1.8, f); |
| 767 | float floorBand = c.b[int(fmod(abs(index), 4.f))]; |
| 768 | color += tint * (exp(-max(near, 0.f) * 9) * .45 + exp(-max(near, 0.f) * 2.5) * .06) * (1 + floorBand * 2.5); |
| 769 | color *= .55 + .45 * smoothstep(0.f, .12f, dominoMap(p + light * .08, front, size, which, index)); |
| 770 | float2 g = p.xz; |
| 771 | color += paint(.5, f) * .04 * exp(-abs(fract(g.x * .5) - .5) * 40) * exp(-tFloor * .1); |
| 772 | float reflection = pow(1 - abs(rd.y), 5.f); |
| 773 | color += sky * reflection * 1.5; |
| 774 | return mix(sky, color, fog); |
| 775 | } |
| 776 | |
| 777 | // ---------------------------------------------------------------- Aerial Silks |
| 778 | // Circus aerial silks under a big top: long doubled fabric drops hang from the rigging, |
| 779 | // swinging like pendulums with ripples running down them and twisting into spiral wraps, |
| 780 | // inside soft spotlight cones and haze under strings of lights. Zoom speed pans along the |
| 781 | // ring. Bass swings the silks wider, attacks unroll a drop so its wrap slides down and |
| 782 | // spins loose. |
| 783 | |
| 784 | |
| 785 | // ---------------------------------------------------------------- Hula Hoops |
| 786 | // Columns of glowing LED hoops gyrate in the dark at two depths, each hoop a tilted |
| 787 | // ellipse of chasing LEDs that leaves a long light-painted trail, with face-on hoops |
| 788 | // spinning above and everything mirrored in a glossy floor. Zoom speed pans along the |
| 789 | // line. Bass lights extra hoops low in each column, attacks toss a hoop upward and highs |
| 790 | // sparkle the LEDs. |
| 791 | |
| 792 | |
| 793 | #define RAVE_EFFECTS(X) X(smokeRings) X(wandOrbs) X(stringResonance) X(lightBars) X(sequinCurtain) X(stadiumWave) X(liquidFloor) X(dominoRun) |
| 794 | RAVE_EFFECTS(NATIVE_EFFECT) |