PulseCanvas / app · pulsecanvas.ai / Sources / PulseCanvas / Resources / NativeExpansionKinetic.metal
| 1 | // Original PulseCanvas designs 320–329. Dancing visuals as physical-material choreography: |
| 2 | // kinetic installations and physical phenomena that move with the music. Every design is |
| 3 | // a pure function of its uniforms. Procedural time (which already integrates the music |
| 4 | // clock) drives the main motion; each band drives its own group of elements and every |
| 5 | // attack starts a local event (a ring, a strike, a splash, a pluck) that runs outward |
| 6 | // while the attack envelope decays. |
| 7 | |
| 8 | // ---------------------------------------------------------------- shared helpers |
| 9 | // Attack envelope normalised by Chaos: 1 at an attack onset, decaying to 0. |
| 10 | float kin_attack(Ctx c, constant NativeFrame &f) { return saturate(c.hit / max(f.camera.y, .05f)); } |
| 11 | // Progress of the latest attack's event: 0 at the onset, running toward 1 as it decays. |
| 12 | float kin_age(float attack) { return 1 - pow(attack, .35f); } |
| 13 | // Strength of the attack's event: fades with the envelope and scales with Chaos. |
| 14 | float kin_strength(float attack, constant NativeFrame &f) { return sqrt(attack) * f.camera.y; } |
| 15 | float kin_sq(float x) { return x * x; } |
| 16 | float kin_wrap(float a) { return a - TAU * floor(a / TAU + .5); } |
| 17 | |
| 18 | // ---------------------------------------------------------------- 320 Pin Art |
| 19 | // A pin-screen relief seen at an angle: a dense lattice of polished pins whose heads are |
| 20 | // pushed out by unseen forms gliding behind the screen, so a relief of pin heads and |
| 21 | // exposed shafts rises and falls. Bass presses the broad forms further out, the low mids |
| 22 | // roll a long swell across the screen, the high mids ring fine ripples, highs glint pin |
| 23 | // heads and every attack presses a sharp ring through that spreads from a drifting point. |
| 24 | constant float kin_pinSlant = .36; |
| 25 | |
| 26 | float kin_pinRelief(float2 q, float2 ext, Ctx c, float age, float strength) { |
| 27 | float t = c.t * .13 + c.travel * .05, span = min(ext.x, ext.y); |
| 28 | float h = 0; |
| 29 | for (int k = 0; k < 3; ++k) { |
| 30 | float fk = float(k); |
| 31 | float2 centre = float2(sin(t * (1.1 + fk * .23) + fk * 2.1), sin(t * (.83 + fk * .17) + fk * 4.3)) * ext * .6; |
| 32 | float radius = span * (.42 + .1 * sin(t * .7 + fk * 1.9)); |
| 33 | float2 d = q - centre; |
| 34 | h += (1.8 + 2.6 * c.b.x) * exp(-dot(d, d) / (radius * radius)); |
| 35 | } |
| 36 | h += (.2 + 1.7 * c.b.y) * kin_sq(.5 + .5 * sin(dot(q, float2(.2, .13)) - c.t * .8)); |
| 37 | float2 o = float2(sin(t * 1.7), cos(t * 1.3)) * ext * .4; |
| 38 | float r = length(q - o); |
| 39 | h += c.b.z * 1.6 * (.5 + .5 * sin(r * 1.3 - c.t * 3)) * exp(-r / span * 1.2); |
| 40 | float2 a = float2(sin(t * 2.3 + 1), cos(t * 1.9)) * ext * .35; |
| 41 | float ring = abs(length(q - a) - (1 + age * span * .9)) - .9; |
| 42 | h += strength * 5 * (1 - smoothstep(-.3f, .3f, ring)); |
| 43 | return h; |
| 44 | } |
| 45 | |
| 46 | float3 pinArt(Ctx c, constant NativeFrame &f) { |
| 47 | float lean = 1 + .18 * c.uv.y / c.extent.y; |
| 48 | float cell = .088 * c.size; |
| 49 | float2 q = c.uv * lean / cell, ext = c.extent / cell; |
| 50 | float px = c.px * lean / cell; |
| 51 | float attack = kin_attack(c, f), age = kin_age(attack), strength = kin_strength(attack, f); |
| 52 | float column = floor(q.x - kin_pinSlant * q.y + .5), row = floor(q.y + .5); |
| 53 | float2 hole = q - float2(column + kin_pinSlant * row, row); |
| 54 | float bounce = kin_pinRelief(q, ext, c, age, strength); |
| 55 | // the dark perforated plate, warmed by light thrown back from the raised pins |
| 56 | float3 col = deep(.25, f) * .1 + paint(.3, f) * .035 * bounce; |
| 57 | col *= .4 + .6 * smoothstep(.1f, .16f, length(hole)); |
| 58 | int top = int(floor(q.y + .45)); |
| 59 | const float3 light = normalize(float3(-.5, .45, .75)); |
| 60 | const float3 halfway = normalize(light + float3(0, 0, 1)); |
| 61 | float behind = 0; |
| 62 | for (int n = 0; n < 6; ++n) { |
| 63 | float j = float(top - n); |
| 64 | float2 base = float2(column + kin_pinSlant * j, j); |
| 65 | float e = clamp(.25 + kin_pinRelief(base, ext, c, age, strength), 0.f, 5.f); |
| 66 | // a pin standing proud of the pin behind it faces the light |
| 67 | float facing = n == 0 ? .5f : saturate(.5f + .45f * (e - behind)); |
| 68 | behind = e; |
| 69 | float2 tip = base + e * float2(kin_pinSlant, 1); |
| 70 | float id = hash21(float2(column, j)); |
| 71 | float ds = sdSegment(q, base, tip), across = saturate(ds / .065); |
| 72 | float shaft = 1 - smoothstep(.065 - px, .065 + px, ds); |
| 73 | float along = saturate(dot(q - base, float2(kin_pinSlant, 1)) / max(e * 1.0648f, .01f)); |
| 74 | float3 shaftColor = paint(.2 + .06 * e, f) * (.12 + .1 * e * along) * (1.3 - across * across) + paint(.9, f) * .1 * e * along * kin_sq(1 - across); |
| 75 | col = mix(col, shaftColor, shaft); |
| 76 | float radius = .34 + .02 * e; |
| 77 | float2 dv = (q - tip) / radius; |
| 78 | float rr = length(dv); |
| 79 | float head = 1 - smoothstep(1 - px / radius, 1 + px / radius, rr); |
| 80 | float3 normal = float3(dv, sqrt(max(0.f, 1 - rr * rr))); |
| 81 | float diffuse = saturate(dot(normal, light)); |
| 82 | float spec = pow(saturate(dot(normal, halfway)), 36.f); |
| 83 | float glint = c.b.w * 5 * pow(.5 + .5 * sin(c.t * 2.1 + id * 70), 30.f); |
| 84 | float3 headColor = paint(.06 + .18 * e + .04 * id, f) * (.2 + .85 * diffuse) * (.22 + .3 * e) * (.55 + .9 * facing); |
| 85 | headColor += paint(.97, f) * spec * (.25 + .18 * e + glint) + paint(.95, f) * glint * .15; |
| 86 | col = mix(col, headColor, head); |
| 87 | } |
| 88 | return col; |
| 89 | } |
| 90 | NATIVE_EFFECT(pinArt) |
| 91 | |
| 92 | // ---------------------------------------------------------------- 321 Kinetic Rain |
| 93 | // A kinetic installation: hundreds of glowing drops hang on fine threads in a deep grid, |
| 94 | // seen from slightly above, and their heights trace one morphing surface coloured by |
| 95 | // height. Each band shapes its own wave in the surface (bass a broad swell, low mids a |
| 96 | // diagonal roll, high mids a tight cross ripple, highs a sparkle on the drops) and each |
| 97 | // attack sends a raised, flaring ring wave across the grid. |
| 98 | float kin_rainSurface(float2 g, Ctx c, float age, float strength) { |
| 99 | float t = c.t * .4 + c.travel * .15; |
| 100 | float y = .5 * sin(g.x * .38 + t * .9) * cos(g.y * .33 - t * .6) + .3 * sin((g.x + g.y) * .24 - t * .7); |
| 101 | y += c.b.x * 1.1 * sin(length(g - float2(0, 8)) * .42 - c.t * 1.2); |
| 102 | y += c.b.y * .75 * sin(g.x * .62 - g.y * .3 + c.t * 1.05); |
| 103 | y += c.b.z * .4 * sin(g.y * 1.15 + g.x * .3 - c.t * 2.2); |
| 104 | float r = length(g - float2(sin(c.t * .13) * 3, 6.5)); |
| 105 | y += strength * 1.6 * exp(-kin_sq(r - age * 13) * .4); |
| 106 | return y; |
| 107 | } |
| 108 | |
| 109 | float3 kineticRain(Ctx c, constant NativeFrame &f) { |
| 110 | float attack = kin_attack(c, f), age = kin_age(attack), strength = kin_strength(attack, f); |
| 111 | float focal = 1.45 * max(1.f, c.extent.y * .82) * c.size; |
| 112 | const float pitch = .3, spacing = .72; |
| 113 | float cs = cos(pitch), sn = sin(pitch); |
| 114 | float2 uv = c.uv; |
| 115 | float3 ray = float3(uv.x, uv.y * cs - focal * sn, uv.y * sn + focal * cs); |
| 116 | float3 col = paint(.95, f) * .03 + paint(.75, f) * .05 * exp(-kin_sq(uv.y - .25) * 2); |
| 117 | for (int k = 0; k < 16; ++k) { |
| 118 | float z = 1.1 + float(k) * .8; |
| 119 | float x = (floor(z / ray.z * uv.x / spacing) + .5) * spacing; |
| 120 | float2 g = float2(x, z); |
| 121 | float surface = kin_rainSurface(g, c, age, strength); |
| 122 | float y = -2 + surface; |
| 123 | float yc = y * cs + z * sn, zc = -y * sn + z * cs; |
| 124 | float2 drop = float2(x, yc) * focal / zc; |
| 125 | float ty = y + 7, tzc = max(-ty * sn + z * cs, .3f); |
| 126 | float2 anchor = float2(x, ty * cs + z * sn) * focal / tzc; |
| 127 | float rs = .085 * focal / zc; |
| 128 | float d = length(uv - drop); |
| 129 | float fade = exp(-float(k) * (.03 + .05 * c.fog)); |
| 130 | float3 tint = paint(.08 + surface * .5 + .5 + float(k) * .01, f); |
| 131 | float core = smoothstep(rs + c.px, rs * .4, d); |
| 132 | float halo = exp(-d * d / (rs * rs * 2.8)); |
| 133 | float spec = exp(-length_squared(uv - drop - rs * float2(-.3, .35)) / kin_sq(rs * .3)); |
| 134 | float sparkle = c.b.w * 3 * pow(.5 + .5 * sin(c.t * 2.7 + hash21(g) * 80), 24.f); |
| 135 | float thickness = .006 * focal / zc, width = max(thickness, c.px * .8); |
| 136 | float strand = (1 - smoothstep(width * .5, width * 1.5, sdSegment(uv, drop, anchor))) * thickness / width; |
| 137 | float lit = exp(-max(uv.y - drop.y, 0.f) * 1.6); |
| 138 | col += fade * (tint * (core * 1.3 + halo * .6 + strand * (.1 + .5 * lit)) + paint(.98, f) * (spec * .7 + sparkle * core)); |
| 139 | } |
| 140 | return col; |
| 141 | } |
| 142 | NATIVE_EFFECT(kineticRain) |
| 143 | |
| 144 | // ---------------------------------------------------------------- 322 Plasma Globe |
| 145 | // A large glass plasma globe seen close up: luminous filaments reach from the central |
| 146 | // electrode to the glass, wander slowly, fan into branches near the glass and burn bright |
| 147 | // where they touch it, inside a violet gas glow. Each band strengthens, thickens and |
| 148 | // stirs its own filaments and every attack fires a burst of fresh filaments outward. |
| 149 | float3 plasmaGlobe(Ctx c, constant NativeFrame &f) { |
| 150 | float attack = kin_attack(c, f), age = kin_age(attack), strength = kin_strength(attack, f); |
| 151 | float2 ext = c.extent; |
| 152 | float radius = .95 * (min(ext.x, ext.y) + .3 * (max(ext.x, ext.y) - min(ext.x, ext.y))) * c.size; |
| 153 | float2 p = c.uv; |
| 154 | float r = length(p), a = atan2(p.y, p.x), rn = r / radius; |
| 155 | float t = c.t * .3 + c.travel * .1; |
| 156 | float inside = 1 - smoothstep(radius - c.px * 2, radius + c.px * 2, r); |
| 157 | float3 col = deep(.35, f) * (.18 + .25 * rn * rn) * inside + paint(.25, f) * .1 * exp(-max(r - radius, 0.f) * 1.6) * (1 - inside); |
| 158 | col += paint(.3, f) * .1 * inside * fbm2(p * 2.5 + float2(t, -t * .7), 3); |
| 159 | for (int k = 0; k < 9; ++k) { |
| 160 | float fk = float(k), band = c.b[k & 3]; |
| 161 | float tilt = .55 + .45 * sin(t * .4 + fk * 2.3); |
| 162 | float reach = radius * (.62 + .36 * tilt) * (.9 + .12 * band); |
| 163 | float s = r / reach; |
| 164 | float heading = fk * TAU / 9 + .7 * sin(t * (.5 + .07 * fk) + fk * 1.7) + t * .25; |
| 165 | float wander = (.3 + .5 * band) * s * sin(rn * 3.1 - c.t * .9 + fk * 3.1) + .06 * s * sin(r * 14 - c.t * 4 + fk * 5); |
| 166 | float fork = smoothstep(.4f, 1.f, s); |
| 167 | float ending = 1 - smoothstep(.97f, 1.03f, s); |
| 168 | float contact = 1 + 3 * exp(-kin_sq((s - 1) * 14)); |
| 169 | for (int j = -1; j <= 1; ++j) { |
| 170 | float fj = float(j); |
| 171 | float branch = heading + wander + fj * fork * (.2 + .06 * sin(t * 2 + fk + fj)) + fork * fork * .08 * sin(r * 24 - c.t * 6 + fk * 3 + fj * 2); |
| 172 | float d = abs(kin_wrap(a - branch)) * r; |
| 173 | float weight = j == 0 ? 1.f : fork; |
| 174 | float width = radius * (.004 + .006 * band) * (1.4 - .7 * s) * (j == 0 ? 1.f : .7f); |
| 175 | float core = exp(-d * d / (width * width)), halo = glow(d, width * 6); |
| 176 | col += (paint(.92, f) * core + paint(.42 + .12 * fj + .1 * band, f) * halo * .35) * weight * ending * contact * (.45 + 1.4 * band); |
| 177 | } |
| 178 | } |
| 179 | for (int k = 0; k < 6; ++k) { |
| 180 | float fk = float(k); |
| 181 | float heading = fk * TAU / 6 + t * 1.3 + .4 * sin(fk * 4.1); |
| 182 | float reach = radius * (.3 + .7 * sqrt(age)); |
| 183 | float s = r / reach; |
| 184 | float branch = heading + .25 * s * sin(rn * 5 - c.t * 3 + fk * 2); |
| 185 | float d = abs(kin_wrap(a - branch)) * r, width = radius * .009 * (1.3 - .6 * s); |
| 186 | col += (paint(.97, f) * exp(-d * d / (width * width)) + paint(.6, f) * glow(d, width * 5) * .4) * (1 - smoothstep(.95f, 1.05f, s)) * strength * 3; |
| 187 | } |
| 188 | float electrode = radius * .09; |
| 189 | col += paint(.88, f) * (fill(r - electrode, c.px * 2) * (.7 + .3 * noise2(p * 40 / radius + c.t)) + glow(r, electrode * 1.4) * (.6 + 1.5 * strength)); |
| 190 | col += paint(.8, f) * glow(r - radius, radius * .006) * .5 + paint(.95, f) * .35 * exp(-kin_sq((r - radius * .9) * 30 / radius)) * exp(-kin_sq(kin_wrap(a - 2.2) * 3)); |
| 191 | return col; |
| 192 | } |
| 193 | NATIVE_EFFECT(plasmaGlobe) |
| 194 | |
| 195 | // ---------------------------------------------------------------- 323 Jacob's Ladder |
| 196 | // Rows of Jacob's ladders at three depths: electric arcs bridge pairs of diverging rails, |
| 197 | // climb as they stretch and bow upward, flicker and break at the top while the next arc |
| 198 | // strikes at the base. Bass thickens the arcs, each band powers its own ladders, highs |
| 199 | // make the arcs crackle and every attack strikes a fresh arc at the base with sparks. |
| 200 | float3 kin_ladderLayer(float2 uv, float scale, float period, float lift, float layer, Ctx c, constant NativeFrame &f, float age, float strength) { |
| 201 | float2 p = uv / scale; |
| 202 | p.y -= lift; |
| 203 | p.x += (layer == 1 ? period * .5 : layer * .13) + c.travel * (.03 + .02 * layer); |
| 204 | float cell = floor(p.x / period + .5); |
| 205 | float lx = p.x - cell * period, y = p.y; |
| 206 | float seed = hash21(float2(cell, layer * 7.1)); |
| 207 | float band = c.b[int(abs(cell) + layer) & 3]; |
| 208 | float px = c.px / scale; |
| 209 | const float gap = .045, spread = .17, height = 2.1; |
| 210 | float3 col = 0.f; |
| 211 | float heat = 0; |
| 212 | for (int j = 0; j < 2; ++j) { |
| 213 | float fj = float(j); |
| 214 | float phase = fract(c.t * (.12 + .04 * seed) + fj * .5 + seed); |
| 215 | float life = smoothstep(0.f, .05f, phase) * (1 - smoothstep(.84f, .98f, phase)); |
| 216 | float ya = .08 + phase * (height - .45); |
| 217 | float halfSpan = gap + spread * ya, xs = lx / halfSpan; |
| 218 | float bow = (.1 + 1.5 * phase * phase) * halfSpan; |
| 219 | float sway = .22 * sin(c.t * 3.1 + fj * 2 + seed * 9) * phase * halfSpan; |
| 220 | float crackle = (.008 + .022 * c.b.w) * (sin(xs * 7 + c.t * 17 + fj * 5) + .5 * sin(xs * 19 - c.t * 29 + seed * 30)); |
| 221 | float curve = ya + (bow + sway * xs + crackle * (.4 + phase)) * (1 - xs * xs); |
| 222 | float d = abs(y - curve) / (1 + abs(2 * bow * xs / halfSpan) * .7); |
| 223 | float spanMask = 1 - smoothstep(.98f, 1.04f, abs(xs)); |
| 224 | float width = (.026 + .05 * c.b.x) * (1 - .35 * phase); |
| 225 | float flicker = .8 + .2 * sin(c.t * 41 + fj * 9 + seed * 40); |
| 226 | float energy = life * flicker * (.5 + 1.6 * band) * (1.15 - .4 * phase); |
| 227 | col += (paint(.97, f) * exp(-d * d / (width * width * .3)) * 1.5 + paint(.7, f) * exp(-d * d / (width * width * 2.5)) * .7 + paint(.55, f) * glow(d, width * 4) * .45) * spanMask * energy; |
| 228 | col += paint(.4, f) * glow(d, .35) * .08 * smoothstep(1.8f, 1.f, abs(xs)) * energy; |
| 229 | heat += exp(-kin_sq(y - ya) * 50) * energy; |
| 230 | // the arc breaks into sparks at the top |
| 231 | float breakup = smoothstep(.8f, .92f, phase) * life; |
| 232 | float2 sparkAt = float2(lx, y) - float2(sin(seed * 20 + fj) * halfSpan * .6, curve * 0 + ya + bow + .1 * (phase - .8) * 6); |
| 233 | col += paint(.9, f) * glow(length(sparkAt), .02) * breakup * band; |
| 234 | } |
| 235 | // A fresh arc strikes at the base on each attack and throws sparks upward. |
| 236 | { |
| 237 | float ya = .05 + age * .45, halfSpan = gap + spread * ya, xs = lx / halfSpan; |
| 238 | float curve = ya + (.12 + .06 * sin(xs * 11 + c.t * 29)) * halfSpan * (1 - xs * xs); |
| 239 | float d = abs(y - curve), width = .025 + .03 * strength; |
| 240 | col += (paint(.99, f) * exp(-d * d / (width * width)) * 1.4 + paint(.65, f) * glow(d, width * 4) * .6) * (1 - smoothstep(.98f, 1.04f, abs(xs))) * strength * 4; |
| 241 | heat += exp(-kin_sq(y - ya) * 50) * strength * 3; |
| 242 | for (int k = 0; k < 5; ++k) { |
| 243 | float3 h = hash33(float3(cell, layer, float(k))); |
| 244 | float2 spark = float2((h.x - .5) * .9 * age, .05 + age * (.5 + h.y * 1.1) - age * age * .6); |
| 245 | col += paint(.92, f) * glow(length(float2(lx, y) - spark), .014) * strength * 1.6; |
| 246 | } |
| 247 | } |
| 248 | float yc = clamp(y, 0.f, height); |
| 249 | float railD = abs(abs(lx) - (gap + spread * yc)) * .986 + max(-y, 0.f) + max(y - height, 0.f); |
| 250 | float rail = 1 - smoothstep(.016 - px, .016 + px, railD); |
| 251 | float sheen = 1 - kin_sq(saturate(railD / .016)); |
| 252 | col = mix(col, paint(.3, f) * (.25 + .35 * sheen) + paint(.95, f) * min(heat, 2.f) * .7 * sheen, rail); |
| 253 | col += paint(.5, f) * glow(railD, .025) * (.05 + .25 * min(heat, 2.f)); |
| 254 | col += paint(.95, f) * glow(length(float2(abs(lx) - gap - spread * height, y - height)), .03) * .25; |
| 255 | float post = sdBox2(float2(abs(lx) - gap, y + .12), float2(.03, .12)); |
| 256 | col = mix(col, paint(.2, f) * .3, fill(post, px)); |
| 257 | return col; |
| 258 | } |
| 259 | |
| 260 | float3 jacobsLadder(Ctx c, constant NativeFrame &f) { |
| 261 | float attack = kin_attack(c, f), age = kin_age(attack), strength = kin_strength(attack, f); |
| 262 | float2 uv = c.uv / c.size; |
| 263 | float ey = c.extent.y / c.size; |
| 264 | float3 col = deep(.25, f) * .16 + paint(.35, f) * .08 * exp(-kin_sq(uv.y / ey + .3) * 1.5); |
| 265 | col += kin_ladderLayer(uv, .3 * ey, 1.9, -.9, 0, c, f, age, strength) * .35; |
| 266 | col += kin_ladderLayer(uv, .55 * ey, 2.6, -1.25, 1, c, f, age, strength) * .65; |
| 267 | col += kin_ladderLayer(uv, ey, 5, -1.08, 2, c, f, age, strength); |
| 268 | return col; |
| 269 | } |
| 270 | NATIVE_EFFECT(jacobsLadder) |
| 271 | |
| 272 | // ---------------------------------------------------------------- 324 Hanging Mobile |
| 273 | // A large balanced hanging mobile in front of a lit wall: nested wire arms turn on their |
| 274 | // pivots and carry glowing flat shapes that spin on their own wires, while each translucent |
| 275 | // shape throws a soft coloured shadow on the wall behind. Each arm swings with its own |
| 276 | // band, shapes brighten with their arm's band and every attack sets one arm spinning. |
| 277 | constant float kin_mobileFocal = 3.2, kin_mobileWall = 1.4; |
| 278 | constant float3 kin_mobileLight = float3(-1.6, 2.6, -9); |
| 279 | |
| 280 | float2 kin_mobileProject(float3 p) { return p.xy * kin_mobileFocal / (kin_mobileFocal + p.z); } |
| 281 | float2 kin_mobileShadow(float3 p) { |
| 282 | float3 s = p + (p - kin_mobileLight) * (kin_mobileWall - p.z) / (p.z - kin_mobileLight.z); |
| 283 | return kin_mobileProject(s); |
| 284 | } |
| 285 | float kin_mobileOutline(float2 q, int kind) { |
| 286 | if (kind == 0) return length(q) - 1; |
| 287 | if (kind == 1) return max(length(q - float2(.6, 0)), length(q + float2(.6, 0))) - 1.1; |
| 288 | if (kind == 2) return max(length(q) - 1, .85 - length(q - float2(.5, .3))); |
| 289 | float2 r = abs(q); return max(r.x * .866 + q.y * .5, -q.y) - .55; |
| 290 | } |
| 291 | float3 kin_mobileArm(float3 pivot, float angle, float tilt, float left, float right, thread float3 &leftEnd) { |
| 292 | float2 dir = float2(cos(angle), sin(angle)); |
| 293 | leftEnd = pivot + float3(-dir.x * left, tilt * left, -dir.y * left); |
| 294 | return pivot + float3(dir.x * right, -tilt * right, dir.y * right); |
| 295 | } |
| 296 | |
| 297 | |
| 298 | // ---------------------------------------------------------------- 325 Prism Carousel |
| 299 | // Glass prisms ride a slowly turning carousel and spin on their own axes, each splitting a |
| 300 | // light beam into a broad spectral fan that sweeps across the dark wall above and glints |
| 301 | // in the glossy floor below. Each prism follows its own band (its fan widens and |
| 302 | // brightens), highs sparkle in the glass and every attack flicks the front prisms so |
| 303 | // their fans sweep across the wall. |
| 304 | float3 kin_prismFans(float2 p, float yC, float rx, float ry, float flick, Ctx c, constant NativeFrame &f) { |
| 305 | float3 col = 0.f; |
| 306 | float texture = .82 + .18 * noise2(p * 9); |
| 307 | for (int k = 0; k < 6; ++k) { |
| 308 | float fk = float(k), band = c.b[k & 3]; |
| 309 | float around = fk * TAU / 6 + c.t * .09 + c.travel * .06; |
| 310 | float near = .5 - .5 * sin(around); |
| 311 | float2 origin = float2(rx * cos(around), yC + ry * sin(around)); |
| 312 | float spin = c.t * (.2 + .045 * fk) + fk * 1.7 + band * .9 + flick * near * near; |
| 313 | float heading = PI * .5 + 1.15 * sin(spin); |
| 314 | float spread = .2 + .08 * sin(spin * 1.3 + fk) + .22 * band; |
| 315 | float2 d = p - origin; |
| 316 | float dist = length(d); |
| 317 | float s = kin_wrap(atan2(d.y, d.x) - heading) / spread; |
| 318 | float reach = .5 + .35 * near + .4 * band; |
| 319 | float fan = smoothstep(1.f, .7f, abs(s)) * smoothstep(.12f, .45f, dist) * exp(-kin_sq(max(dist - reach, 0.f)) * 1.2); |
| 320 | float edge = exp(-kin_sq((abs(s) - .85) * 9)) * .5; |
| 321 | col += (paint(.5 + .5 * s, f) * (1 + edge) + paint(.97, f) * edge * .3) * fan * (.35 + 1.2 * band) * (.6 + .4 * near) * texture / (.6 + dist * .9); |
| 322 | } |
| 323 | return col; |
| 324 | } |
| 325 | |
| 326 | float3 prismCarouselScene(Ctx c, constant NativeFrame &f) { |
| 327 | float attack = kin_attack(c, f), age = kin_age(attack), strength = kin_strength(attack, f); |
| 328 | float2 p = c.uv / c.size, ext = c.extent / c.size; |
| 329 | float yC = -ext.y * .5, rx = min(ext.x * .66, 1.25f), ry = .2; |
| 330 | float flick = 2.6 * strength * sin(age * PI) + .5 * strength; |
| 331 | float3 col = paint(.95, f) * .03 + deep(.9, f) * .06 * (1 - smoothstep(-1.f, 1.f, p.y / ext.y)); |
| 332 | float floorY = yC - ry - .06; |
| 333 | if (p.y > floorY) { |
| 334 | col += kin_prismFans(p, yC, rx, ry, flick, c, f); |
| 335 | } else { |
| 336 | float2 m = float2(p.x + .015 * sin(p.y * 50 + c.t), 2 * floorY - p.y); |
| 337 | col += kin_prismFans(m, yC, rx, ry, flick, c, f) * .3 * exp((p.y - floorY) * 1.5); |
| 338 | col *= .8 + .2 * sin(p.y * 90 / ext.y); |
| 339 | } |
| 340 | // the carousel: a glowing rim, spokes and the turning prisms |
| 341 | float2 e = (p - float2(0, yC)) / float2(rx, ry); |
| 342 | float rim = abs(length(e) - 1) * ry; |
| 343 | col += paint(.85, f) * glow(rim, .005) * .5 + paint(.3, f) * glow(rim, .04) * .12; |
| 344 | float hub = length(e); |
| 345 | float spokes = abs(sin((atan2(e.y, e.x) - c.t * .09) * 3)) * hub * ry; |
| 346 | col += paint(.7, f) * glow(spokes, .003) * .25 * step(hub, 1.f); |
| 347 | for (int k = 0; k < 6; ++k) { |
| 348 | float fk = float(k), band = c.b[k & 3]; |
| 349 | float around = fk * TAU / 6 + c.t * .09 + c.travel * .06; |
| 350 | float near = .5 - .5 * sin(around); |
| 351 | float2 origin = float2(rx * cos(around), yC + ry * sin(around)); |
| 352 | float spin = c.t * (.2 + .045 * fk) + fk * 1.7 + band * .9 + flick * near * near; |
| 353 | float scale = .085 * (.7 + .45 * near); |
| 354 | float2 q = p - origin - float2(0, scale * .55); |
| 355 | float2 face = float2(q.x / max(abs(cos(spin)), .25f), q.y) / scale; |
| 356 | float tri = max(abs(face.x) * .866 + face.y * .5, -face.y) - .5; |
| 357 | float body = fill(tri * scale, c.px * 1.5); |
| 358 | float glint = c.b.w * 2.5 * pow(.5 + .5 * sin(c.t * 3 + fk * 11), 12.f); |
| 359 | float3 glass = paint(.5 + .35 * face.x, f) * (.35 + .6 * band) + paint(.97, f) * (glint + .5 * smoothstep(.15f, -.2f, face.x * sin(spin) + face.y * .4)); |
| 360 | col = mix(col, glass, body * .85); |
| 361 | col += paint(.95, f) * glow(tri * scale, .006) * (.4 + .7 * band + strength * 3 * near * near); |
| 362 | } |
| 363 | return col; |
| 364 | } |
| 365 | // The reviewed look, with a faint palette floor so tall frames stay covered when zoomed out. |
| 366 | float3 prismCarousel(Ctx c, constant NativeFrame &f) { return max(prismCarouselScene(c, f), paint(.9, f) * .06); } |
| 367 | NATIVE_EFFECT(prismCarousel) |
| 368 | |
| 369 | // ---------------------------------------------------------------- 326 Cone Splash |
| 370 | // A low close-up across a vibrating membrane covered in pools of coloured paint. Paint |
| 371 | // leaps off it in crowns with lobed rims, flung droplets and a central jet that rises as |
| 372 | // each crown collapses, while ripples run through the wet paint. Each paint colour rides |
| 373 | // its own band (its splashes leap higher and its pools pulse), bass flexes the membrane |
| 374 | // and every attack throws a large crown up from the front of the membrane. |
| 375 | constant float kin_splashEye = .55; |
| 376 | |
| 377 | float3 kin_splashCrown(float2 uv, float horizon, float focal, float2 site, float age, float scale, float hue, float seed, Ctx c, constant NativeFrame &f) { |
| 378 | float3 col = 0.f; |
| 379 | float rc = scale * (.1 + .5 * sqrt(age)); |
| 380 | float crown = scale * .9 * sin(PI * min(age * 1.6 + .12, 1.f)) * (1 - .35 * age); |
| 381 | float across = (uv.x * site.y / focal - site.x) / rc; |
| 382 | if (abs(across) < 1.02) { |
| 383 | float sx = sqrt(max(0.f, 1 - across * across)); |
| 384 | for (int side = 0; side < 2; ++side) { |
| 385 | float facing = side == 0 ? 1.f : -1.f; |
| 386 | float z = site.y + facing * rc * sx; |
| 387 | float theta = atan2(facing * sx, across); |
| 388 | float rim = crown * (.5 + .5 * pow(.5f + .5f * cos(9 * theta + seed * 20), 3.f)); |
| 389 | float vb = horizon - kin_splashEye * focal / z, vt = horizon + (rim - kin_splashEye) * focal / z; |
| 390 | float sheet = smoothstep(vb - c.px, vb + c.px, uv.y) * (1 - smoothstep(vt - c.px * 2, vt + c.px, uv.y)); |
| 391 | float height = saturate((uv.y - vb) / max(vt - vb, 1e-4f)); |
| 392 | float3 tint = paint(hue, f) * (.35 + .55 * (.5 + .5 * across) + .4 * height) * (side == 0 ? .55f : 1.f); |
| 393 | col = mix(col, tint, sheet * (side == 0 ? .7f : .9f)); |
| 394 | col += paint(hue + .1, f) * glow(uv.y - vt, .004 * focal / z) * .6 * step(vb, uv.y); |
| 395 | } |
| 396 | } |
| 397 | float flight = max(age - .3, 0.f); |
| 398 | float rd = rc + flight * scale * .9; |
| 399 | float lift = crown * .9 + flight * scale * 2.4 - flight * flight * scale * 4; |
| 400 | float across2 = (uv.x * site.y / focal - site.x) / rd; |
| 401 | if (flight > 0 && abs(across2) < 1.1 && lift > -.1) { |
| 402 | for (int side = 0; side < 2; ++side) { |
| 403 | float facing = side == 0 ? 1.f : -1.f; |
| 404 | float theta = atan2(facing * sqrt(max(0.f, 1 - across2 * across2)), across2); |
| 405 | float lobe = round(theta * 9 / TAU + seed * 20 / TAU) - seed * 20 / TAU; |
| 406 | float a = lobe * TAU / 9; |
| 407 | float3 drop = float3(site.x + rd * cos(a), lift, site.y + rd * sin(a)); |
| 408 | float2 s = float2(drop.x, drop.y - kin_splashEye) * focal / drop.z + float2(0, horizon); |
| 409 | float r = scale * .045 * focal / drop.z; |
| 410 | float d = length(uv - s); |
| 411 | col += paint(hue, f) * (smoothstep(r + c.px, r * .5, d) * .9 + glow(d, r * 1.5) * .25) + paint(.95, f) * exp(-length_squared(uv - s - r * float2(-.3, .3)) / kin_sq(r * .3)) * .5; |
| 412 | } |
| 413 | } |
| 414 | float jet = max(age - .45, 0.f) / .55; |
| 415 | if (jet > 0) { |
| 416 | float hj = scale * 1.7 * sin(PI * jet); |
| 417 | float2 b = float2(site.x, -kin_splashEye) * focal / site.y + float2(0, horizon); |
| 418 | float2 tp = float2(site.x, hj - kin_splashEye) * focal / site.y + float2(0, horizon); |
| 419 | float width = scale * .05 * focal / site.y; |
| 420 | float d = sdSegment(uv, b, tp); |
| 421 | col += paint(hue + .05, f) * (smoothstep(width + c.px, width * .3, d) * .9 + glow(d, width) * .2); |
| 422 | float dt = length(uv - tp - float2(0, width * 1.6)); |
| 423 | col += paint(hue, f) * smoothstep(width * 1.6 + c.px, width * .6, dt) + paint(.95, f) * glow(dt, width * .5) * .3; |
| 424 | } |
| 425 | return col; |
| 426 | } |
| 427 | |
| 428 | float3 coneSplashScene(Ctx c, constant NativeFrame &f) { |
| 429 | float attack = kin_attack(c, f), age = kin_age(attack), strength = kin_strength(attack, f); |
| 430 | float2 uv = c.uv; |
| 431 | float focal = 1.5 * c.size * max(1.f, c.extent.y * .8); |
| 432 | float horizon = c.extent.y * .22; |
| 433 | // backdrop: dark studio with soft coloured light pools above the membrane's rim |
| 434 | float3 col = paint(.95, f) * .025; |
| 435 | for (int k = 0; k < 4; ++k) { |
| 436 | float2 o = float2(sin(c.t * .05 + float(k) * 1.9) * c.extent.x * .8, horizon + .35 + .35 * sin(float(k) * 2.3 + c.t * .04)); |
| 437 | col += paint(float(k) * .25 + .05, f) * .06 * exp(-length_squared(uv - o) * 2.2); |
| 438 | } |
| 439 | float2 sites[6]; float ages[6], scales[6], hues[6], seeds[6]; |
| 440 | for (int k = 0; k < 5; ++k) { |
| 441 | float clock = c.t * .1 + float(k) / 5; |
| 442 | float id = floor(clock); |
| 443 | float3 h = hash33(float3(id, float(k), 3.7)); |
| 444 | int paintIndex = int(h.z * 3.99); |
| 445 | sites[k] = float2((h.x * 2 - 1) * .9 * c.extent.x, 1.7 + h.y * 2.6); |
| 446 | ages[k] = fract(clock); |
| 447 | scales[k] = (.8 + .35 * h.y) * (.65 + 1.2 * c.b[paintIndex]); |
| 448 | hues[k] = float(paintIndex) * .25 + .05; |
| 449 | seeds[k] = h.x + h.y; |
| 450 | } |
| 451 | sites[5] = float2(sin(c.t * .05) * .6 * c.extent.x, 1.8); |
| 452 | ages[5] = age; scales[5] = strength * 2.4; hues[5] = .8; seeds[5] = .3; |
| 453 | if (uv.y < horizon) { |
| 454 | float z = kin_splashEye * focal / (horizon - uv.y); |
| 455 | float2 g = float2(uv.x * z / focal, z); |
| 456 | float2 m = g * .5 + float2(0, c.travel * .08); |
| 457 | m += .7 * float2(fbm2(m * .7 + float2(c.t * .02, 0), 2), fbm2(m * .7 + 5.2, 2)); |
| 458 | float marble = noise2(m * 1.4) * 4; |
| 459 | int paintIndex = min(int(marble), 3); |
| 460 | float seam = smoothstep(0.f, .12f, .5f - abs(fract(marble) - .5f)); |
| 461 | float band = c.b[paintIndex]; |
| 462 | float ripple = 0; |
| 463 | for (int k = 0; k < 6; ++k) { |
| 464 | float r = length(g - sites[k]); |
| 465 | float front = scales[k] * (.2 + 2.2 * ages[k]); |
| 466 | ripple += sin((r - front) * 16) * exp(-kin_sq(r - front) * 5) * (1 - ages[k]) * min(scales[k], 1.2f); |
| 467 | } |
| 468 | ripple += c.b.x * .7 * sin(length(g - float2(0, 4)) * 5 - c.t * 3) + band * .5 * sin(g.x * 3 + g.y * 2 - c.t * 2); |
| 469 | float fresnel = smoothstep(1.f, 7.f, z); |
| 470 | float sheen = pow(saturate(.55 + .45 * sin(g.x * 1.3 + ripple * 1.8 + c.t * .2)), 5.f) * (.25 + .75 * fresnel); |
| 471 | float fade = exp(-z * (.05 + .08 * c.fog)); |
| 472 | float3 tint = paint(float(paintIndex) * .25 + .05, f); |
| 473 | float3 surface = (tint * seam * (.07 + .2 * band + .05 * ripple) + tint * sheen * seam * (.6 + .6 * band) + paint(.97, f) * pow(sheen, 4.f) * .35) * fade; |
| 474 | col = mix(col, surface, smoothstep(0.f, .015f, horizon - uv.y)); |
| 475 | } |
| 476 | for (int k = 0; k < 6; ++k) { |
| 477 | if (scales[k] < .01) continue; |
| 478 | col += kin_splashCrown(uv, horizon, focal, sites[k], ages[k], scales[k], hues[k], seeds[k], c, f) * (k == 5 ? 1.4f : 1.f); |
| 479 | } |
| 480 | return col; |
| 481 | } |
| 482 | // The reviewed look, with a faint palette floor so tall frames stay covered when zoomed out. |
| 483 | float3 coneSplash(Ctx c, constant NativeFrame &f) { return max(coneSplashScene(c, f), paint(.9, f) * .06); } |
| 484 | NATIVE_EFFECT(coneSplash) |
| 485 | |
| 486 | // ---------------------------------------------------------------- 327 Wind Tunnel |
| 487 | // A side view into a wind tunnel: dyed smoke streamlines flow past a cylinder, an airfoil |
| 488 | // and a small post, bending around them and rolling up into alternating vortex streets in |
| 489 | // their wakes. Bass raises the flow speed (the streamlines tighten and stream faster), the |
| 490 | // low and high mids strengthen the shedding behind the two cylinders, highs shimmer in the |
| 491 | // wakes and every attack sheds one strong vortex behind the cylinder. |
| 492 | float kin_windVortex(float2 p, float2 centre, float strength, float core) { |
| 493 | float2 d = p - centre; |
| 494 | return strength * .5 * log(dot(d, d) + core * core); |
| 495 | } |
| 496 | |
| 497 | float3 windTunnel(Ctx c, constant NativeFrame &f) { |
| 498 | float attack = kin_attack(c, f), age = kin_age(attack), strength = kin_strength(attack, f); |
| 499 | float2 p = c.uv / c.size, ext = c.extent / c.size; |
| 500 | float flow = 1 + .35 * c.b.x; |
| 501 | const int count = 3; |
| 502 | float2 centres[count] = {float2(-ext.x * .55, ext.y * .28), float2(ext.x * .3, ext.y * .5), float2(-ext.x * .05, -ext.y * .4)}; |
| 503 | float radii[count] = {.24, .13, .12}; |
| 504 | float shed[count] = {.5 + 1.2 * c.b.y, .4 + 1.2 * c.b.z, .25 + .6 * c.b.z}; |
| 505 | // smoke wobble in the wakes |
| 506 | float2 q = p; |
| 507 | for (int o = 0; o < count; ++o) { |
| 508 | float behind = smoothstep(0.f, .4f, p.x - centres[o].x) * exp(-kin_sq((p.y - centres[o].y) / (radii[o] * 3))); |
| 509 | q += behind * (.025 + .05 * c.b.w) * float2(noise2(p * 6 - float2(c.t * 2, 0)) - .5, noise2(p * 6 + 7.3 - float2(c.t * 2, 0)) - .5); |
| 510 | } |
| 511 | float psi = q.y * flow, along = q.x; |
| 512 | for (int o = 0; o < count; ++o) { |
| 513 | float2 d = q - centres[o]; |
| 514 | float r2 = max(dot(d, d), 1e-4f), R2 = radii[o] * radii[o]; |
| 515 | if (o == 2) { d = rot(d, .18); d.x *= .32; r2 = max(dot(d, d), 1e-4f); } |
| 516 | psi -= flow * R2 * d.y / r2; |
| 517 | along += R2 * d.x / r2; |
| 518 | float clock = c.t * .32 + float(o) * .37; |
| 519 | for (int j = 0; j < 4; ++j) { |
| 520 | float n = floor(clock) - float(j); |
| 521 | float ageV = fract(clock) + float(j); |
| 522 | float sign = n - 2 * floor(n * .5) < .5 ? 1.f : -1.f; |
| 523 | float2 pos = centres[o] + float2(radii[o] * (1.3 + ageV * 2.4), sign * radii[o] * .5); |
| 524 | float fade = smoothstep(0.f, .7f, ageV) * (1 - smoothstep(2.6f, 4.f, ageV)); |
| 525 | psi += kin_windVortex(q, pos, sign * shed[o] * fade * radii[o], radii[o] * .45); |
| 526 | } |
| 527 | } |
| 528 | psi += kin_windVortex(q, centres[2] + float2(-.03, .02), .12 + .25 * c.b.z, .05); |
| 529 | float2 kickAt = centres[0] + float2(radii[0] * (1.3 + age * 4), radii[0] * .4); |
| 530 | psi += kin_windVortex(q, kickAt, strength * 1.4 * radii[0], radii[0] * .4); |
| 531 | float spacing = .075; |
| 532 | float lines = psi / spacing, index = floor(lines + .5); |
| 533 | float aa = max(fwidth(lines), 1e-4f); |
| 534 | float offset = abs(lines - index); |
| 535 | float core = 1 - smoothstep(.06f, .06f + aa * 1.5f, offset); |
| 536 | float halo = exp(-offset * offset * 18); |
| 537 | float dash = .55 + .45 * sin(along * 7 - c.t * 2.2 + index * 1.7); |
| 538 | float sheet = .5 + .5 * cos(TAU * lines); |
| 539 | float hue = fract(index * .137) * .7 + .15; |
| 540 | float3 col = deep(.3, f) * .1 + paint(hue, f) * (.06 + .1 * sheet) + paint(hue, f) * (core * (.5 + .5 * dash) + halo * .35 * dash) * (.8 + .4 * c.b.x); |
| 541 | col += paint(.95, f) * glow(length(p - kickAt), .06) * strength * 1.2; |
| 542 | col += paint(.9, f) * c.b.w * .6 * pow(noise2(p * 30 + float2(-c.t * 3, 0)), 8.f) * core; |
| 543 | // obstacles: dark solids with bright rims and a stagnation glint |
| 544 | for (int o = 0; o < count; ++o) { |
| 545 | float2 d = p - centres[o]; |
| 546 | float sd; |
| 547 | if (o == 2) { |
| 548 | float2 l = rot(d, .18); |
| 549 | float x = saturate(l.x / .72 + .5); |
| 550 | float thick = .55 * (.2969 * sqrt(x) - .126 * x - .3516 * x * x + .2843 * x * x * x - .1015 * x * x * x * x); |
| 551 | sd = max(abs(l.y) - thick * .72, abs(l.x) - .36); |
| 552 | } else sd = length(d) - radii[o]; |
| 553 | float solid = fill(sd, c.px); |
| 554 | col = mix(col, deep(.2, f) * .15, solid); |
| 555 | col += paint(.85, f) * glow(sd, .006) * .5 + paint(.95, f) * glow(length(d + float2(radii[o], 0)), .02) * .3 * (1 - solid); |
| 556 | } |
| 557 | return col; |
| 558 | } |
| 559 | NATIVE_EFFECT(windTunnel) |
| 560 | |
| 561 | // ---------------------------------------------------------------- 328 Tensegrity Pulse |
| 562 | // A slowly turning tensegrity sculpture: six glowing struts float apart, held only by a |
| 563 | // web of taut cables, with guy cables running out to the room. Each band tightens its own |
| 564 | // cable group (the cables glow and ring in fast standing waves), bass makes the struts |
| 565 | // burn brighter and every attack plucks a cable hard while a ripple runs through the |
| 566 | // whole structure. |
| 567 | constant float3 kin_tensVertex[12] = { |
| 568 | float3(0, 1, 1.618034), float3(0, 1, -1.618034), float3(0, -1, 1.618034), float3(0, -1, -1.618034), |
| 569 | float3(1.618034, 0, 1), float3(-1.618034, 0, 1), float3(1.618034, 0, -1), float3(-1.618034, 0, -1), |
| 570 | float3(1, 1.618034, 0), float3(1, -1.618034, 0), float3(-1, 1.618034, 0), float3(-1, -1.618034, 0)}; |
| 571 | constant int kin_tensCable[48] = {0, 4, 0, 5, 0, 8, 0, 10, 1, 6, 1, 7, 1, 8, 1, 10, 2, 4, 2, 5, 2, 9, 2, 11, |
| 572 | 3, 6, 3, 7, 3, 9, 3, 11, 4, 8, 4, 9, 5, 10, 5, 11, 6, 8, 6, 9, 7, 10, 7, 11}; |
| 573 | |
| 574 | float3 tensegrityPulse(Ctx c, constant NativeFrame &f) { |
| 575 | float attack = kin_attack(c, f), age = kin_age(attack), strength = kin_strength(attack, f); |
| 576 | float2 uv = c.uv; |
| 577 | float unit = min(c.extent.x, c.extent.y) * c.size; |
| 578 | float yaw = c.t * .1 + c.travel * .06, pitch = .45 + .2 * sin(c.t * .05); |
| 579 | float cy = cos(yaw), sy = sin(yaw), cp = cos(pitch), sp = sin(pitch); |
| 580 | float2 screen[12]; float depth[12]; |
| 581 | for (int i = 0; i < 12; ++i) { |
| 582 | float3 v = kin_tensVertex[i]; |
| 583 | v *= 1 + strength * .12 * sin(age * 9 - float(i) * 1.3); |
| 584 | v = float3(v.x * cy + v.z * sy, v.y, -v.x * sy + v.z * cy); |
| 585 | v = float3(v.x, v.y * cp - v.z * sp, v.y * sp + v.z * cp); |
| 586 | float s = 6 / (6 + v.z); |
| 587 | screen[i] = v.xy * s * unit * .46; |
| 588 | depth[i] = s; |
| 589 | } |
| 590 | float3 col = deep(.3, f) * .12 + paint(.25, f) * .08 * exp(-dot(uv, uv) / (unit * unit) * .6); |
| 591 | int plucked = int(floor(c.t * .37)) % 24; |
| 592 | float lineWidth = max(.0035 * unit, c.px * .7); |
| 593 | for (int m = 0; m < 24; ++m) { |
| 594 | float2 a = screen[kin_tensCable[2 * m]], b = screen[kin_tensCable[2 * m + 1]]; |
| 595 | float band = c.b[m & 3]; |
| 596 | float2 ab = b - a; |
| 597 | float len = length(ab); |
| 598 | float2 dir = ab / len; |
| 599 | float2 rel = uv - a; |
| 600 | float along = saturate(dot(rel, dir) / len); |
| 601 | float side = dir.x * rel.y - dir.y * rel.x; |
| 602 | float pluck = m == plucked ? strength * 2.5 : 0.f; |
| 603 | float amp = len * (.004 + .035 * band + .05 * pluck) * sin(PI * along * (1 + float(m % 3))) * cos(c.t * (7 + float(m % 5)) + float(m)); |
| 604 | float d = length(float2(max(abs(dot(rel, dir) - len * .5) - len * .5, 0.f), side - amp)); |
| 605 | float shade = .6 + .4 * (depth[kin_tensCable[2 * m]] + depth[kin_tensCable[2 * m + 1]] - 1.6); |
| 606 | col += paint(.55 + .35 * band + .1 * float(m & 3) * .5, f) * ((1 - smoothstep(lineWidth * .5, lineWidth * 1.5, d)) * (.5 + 1.1 * band + pluck) + glow(d, lineWidth * 4) * (.12 + .5 * band + pluck)) * shade; |
| 607 | } |
| 608 | // guy cables out to the room |
| 609 | for (int g = 0; g < 6; ++g) { |
| 610 | int v = g == 0 ? 8 : g == 1 ? 10 : g == 2 ? 9 : g == 3 ? 11 : g == 4 ? 4 : 7; |
| 611 | float2 anchor = float2(g == 4 ? 1.1 : g == 5 ? -1.1 : (g % 2 == 0 ? .6 : -.6), g < 2 ? 1.1 : g < 4 ? -1.1 : .1) * c.extent * 1.05; |
| 612 | float d = sdSegment(uv, screen[v], anchor); |
| 613 | float band = c.b[g & 3]; |
| 614 | col += paint(.3 + .15 * float(g & 3), f) * ((1 - smoothstep(lineWidth * .4, lineWidth * 1.2, d)) * (.25 + .6 * band) + glow(d, lineWidth * 5) * (.05 + .2 * band)); |
| 615 | } |
| 616 | for (int s = 0; s < 6; ++s) { |
| 617 | int i0 = 2 * s, i1 = 2 * s + 1; |
| 618 | float2 a = screen[i0], b = screen[i1]; |
| 619 | float persp = (depth[i0] + depth[i1]) * .5; |
| 620 | float radius = .03 * unit * persp; |
| 621 | float d = sdSegment(uv, a, b); |
| 622 | float across = saturate(d / radius); |
| 623 | float body = 1 - smoothstep(radius - c.px, radius + c.px, d); |
| 624 | float3 strut = paint(.82 + .08 * float(s & 1), f) * (.6 + .9 * c.b.x) * (1.2 - across * across) * (.5 + .6 * persp); |
| 625 | col = mix(col, strut, body); |
| 626 | col += paint(.7, f) * glow(d - radius, radius * .9) * (.2 + .5 * c.b.x); |
| 627 | col += paint(.95, f) * (glow(length(uv - a), radius * .8) + glow(length(uv - b), radius * .8)) * .35; |
| 628 | } |
| 629 | return col; |
| 630 | } |
| 631 | NATIVE_EFFECT(tensegrityPulse) |
| 632 | |
| 633 | // ---------------------------------------------------------------- 329 Shadow Modulator |
| 634 | // A kinetic light sculpture in an empty room: perforated metal screens, tinted glass |
| 635 | // panels and rods orbit and spin around a bare lamp, and the room's walls and floor are |
| 636 | // swept by their moving projections: magnified grids of light spots, coloured panes and |
| 637 | // rod shadows. Each band turns its own screen and tints its own light, and every attack |
| 638 | // swings an extra perforated screen through the beam. |
| 639 | float kin_modulatorPattern(float2 l, int kind, float t) { |
| 640 | if (kind == 0) { float4 h = hexCell(l * 14); return smoothstep(.3f, .24f, length(h.xy)); } |
| 641 | if (kind == 1) return smoothstep(.15f, .3f, abs(fract(length(l) * 9 - t * .2) - .5)); |
| 642 | if (kind == 2) { float2 g = abs(fract(l * 6) - .5); return smoothstep(.32f, .28f, max(g.x, g.y)); } |
| 643 | return smoothstep(.2f, .3f, abs(fract(atan2(l.y, l.x) * 1.91 + length(l) * 4) - .5)); |
| 644 | } |
| 645 | |
| 646 | float3 shadowModulator(Ctx c, constant NativeFrame &f) { |
| 647 | float attack = kin_attack(c, f), age = kin_age(attack), strength = kin_strength(attack, f); |
| 648 | float focal = 1.25 * c.size; |
| 649 | float3 dir = float3(c.uv, focal); |
| 650 | // room: back wall, floor, ceiling and side walls |
| 651 | float tb = 4.2 / dir.z; |
| 652 | float tf = dir.y < 0 ? -1.25 / dir.y : 1e5; |
| 653 | float tc = dir.y > 0 ? 2.6 / dir.y : 1e5; |
| 654 | float ts = 3.8 / max(abs(dir.x), 1e-4f); |
| 655 | float tw = min(min(tb, ts), min(tf, tc)); |
| 656 | float3 hit = dir * tw; |
| 657 | float3 normal = tw == tb ? float3(0, 0, -1) : tw == tf ? float3(0, 1, 0) : tw == tc ? float3(0, -1, 0) : float3(-sign(dir.x), 0, 0); |
| 658 | float3 lamp = float3(0, .35, 2.2); |
| 659 | float t = c.t * .2 + c.travel * .07; |
| 660 | float3 toLamp = lamp - hit; |
| 661 | float dist2 = dot(toLamp, toLamp); |
| 662 | float lambert = saturate(dot(normal, toLamp) * rsqrt(dist2)); |
| 663 | float3 transmit = float3(1); |
| 664 | float3 seen = float3(0); float seenAlpha = 0; |
| 665 | for (int k = 0; k < 5; ++k) { |
| 666 | float fk = float(k); |
| 667 | float band = k < 4 ? c.b[k] : 0.f; |
| 668 | float orbit = k < 4 ? fk * TAU / 4 + t * (.6 + .15 * fk) : -1.9 + .6 * sin(t * .7) + 2.6 * strength * (1 + sin(age * PI)); |
| 669 | float reach = k < 4 ? .38 + .07 * fk : .3; |
| 670 | float3 centre = lamp + float3(reach * cos(orbit), .3 * sin(fk * 1.7 + t * .5), reach * sin(orbit)); |
| 671 | float spin = orbit + t * (1.1 + .3 * fk) * (k & 1 ? -1.f : 1.f) + band * 1.4; |
| 672 | float lean = .35 * sin(t * .8 + fk * 2.1); |
| 673 | float3 n = normalize(float3(cos(spin) * cos(lean), sin(lean), sin(spin) * cos(lean))); |
| 674 | float3 e1 = normalize(cross(n, float3(0, 1, 0))), e2 = cross(e1, n); |
| 675 | float size = k < 4 ? .2 + .03 * fk : .17; |
| 676 | int kind = k < 4 ? k : 0; |
| 677 | float3 tint = k == 1 || k == 3 ? paint(.15 + .3 * fk, f) * (.8 + .8 * band) : float3(1); |
| 678 | // shadow on the room |
| 679 | float3 ray = hit - lamp; |
| 680 | float denom = dot(ray, n); |
| 681 | float s = dot(centre - lamp, n) / (abs(denom) > 1e-4 ? denom : 1e-4); |
| 682 | if (s > 0 && s < 1) { |
| 683 | float3 at = lamp + ray * s - centre; |
| 684 | float2 l = float2(dot(at, e1), dot(at, e2)) / size; |
| 685 | float blur = .03 + .05 * (1 - s); |
| 686 | float inside = smoothstep(1 + blur, 1 - blur, length(l)); |
| 687 | float open = kin_modulatorPattern(l, kind, c.t); |
| 688 | float3 pass = k == 1 || k == 3 ? mix(tint, float3(1.4), open) : float3(open * 1.2); |
| 689 | transmit *= mix(float3(1), pass, inside); |
| 690 | } |
| 691 | // the sculpture itself as seen by the camera |
| 692 | float sv = dot(centre, n) / dot(dir, n); |
| 693 | if (sv > 0 && sv < tw) { |
| 694 | float3 at = dir * sv - centre; |
| 695 | float2 l = float2(dot(at, e1), dot(at, e2)) / size; |
| 696 | float inside = smoothstep(1.02f, .98f, length(l)); |
| 697 | float open = kin_modulatorPattern(l, kind, c.t); |
| 698 | float lit = abs(dot(n, normalize(lamp - dir * sv))); |
| 699 | float3 face = (k == 1 || k == 3 ? tint * .5 : paint(.3, f) * .25) * (.4 + lit) + paint(.85, f) * .3 * pow(lit, 8.f); |
| 700 | float cover = inside * (1 - open * .85) * (1 - seenAlpha); |
| 701 | seen += face * cover + paint(.9, f) * glow(abs(length(l) - 1) * size, .004) * .3; |
| 702 | seenAlpha += cover; |
| 703 | } |
| 704 | } |
| 705 | // rods sweeping around the lamp |
| 706 | float shadowRods = 1; |
| 707 | for (int k = 0; k < 3; ++k) { |
| 708 | float fk = float(k); |
| 709 | float around = fk * TAU / 3 - t * (.8 + .2 * c.b[(k + 1) & 3]); |
| 710 | float3 a = lamp + float3(.6 * cos(around), -.55, .6 * sin(around)); |
| 711 | float3 b = a + float3(.25 * sin(t + fk), 1.2, .25 * cos(t * .7 + fk)); |
| 712 | float3 u = hit - lamp, v = b - a, w0 = lamp - a; |
| 713 | float uu = dot(u, u), uv = dot(u, v), vv = dot(v, v), uw = dot(u, w0), vw = dot(v, w0); |
| 714 | float den = max(uu * vv - uv * uv, 1e-5f); |
| 715 | float sc = saturate((uv * vw - vv * uw) / den), tcl = saturate((uu * vw - uv * uw) / den); |
| 716 | float d = length(w0 + u * sc - v * tcl); |
| 717 | float r = .018 * (1 + 5 * (1 - sc)); |
| 718 | shadowRods *= mix(1.f, smoothstep(r * .5, r * 1.5, d), step(.05f, sc)); |
| 719 | } |
| 720 | float3 lampColor = paint(.7, f); |
| 721 | float3 col = lampColor * (1.6 * lambert / (.4 + dist2 * .35)) * transmit * shadowRods + deep(.4, f) * .05; |
| 722 | col = mix(col, seen, saturate(seenAlpha)); |
| 723 | float2 lampScreen = lamp.xy * focal / lamp.z; |
| 724 | col += paint(.9, f) * glow(length(c.uv - lampScreen), .03) * .8; |
| 725 | return col; |
| 726 | } |
| 727 | NATIVE_EFFECT(shadowModulator) |