PulseCanvas / app · pulsecanvas.ai / Sources / PulseCanvas / Resources / NativeExpansionPortalII.metal
| 1 | // Final version of 314 Quilted Pipe (its v2 review clip was red-tagged). |
| 2 | // Original PulseCanvas designs 310–319: portal tunnels. Each is a perspective tube or portal |
| 3 | // stack whose walls carry one strong surface material (chainmail, feathers, tartan, |
| 4 | // herringbone, quilting, lace, zippers, cable knit, basketry, louvres). Cross-sections and |
| 5 | // cameras vary: a billowing bent bore, a pointed vault, a twisting rounded square, a |
| 6 | // rectangular hall, an off-axis pipe, a lace stack, a helical seam, a padded bent tube, |
| 7 | // an elliptic burrow seen from low down and an octagon. Original procedural code; every |
| 8 | // audio term is zero at zero Chaos. |
| 9 | |
| 10 | // ---------------------------------------------------------------- shared portal helpers |
| 11 | // Smooth wandering offset for a vanishing point. |
| 12 | float2 ptlDrift(float t, float2 amount) { |
| 13 | return float2(sin(t * .21 + .6) + .5 * sin(t * .34 + 2.3), cos(t * .17 + 1.1) + .5 * sin(t * .29 + .2)) / 1.5 * amount; |
| 14 | } |
| 15 | // Bent view: far depths converge on the drifting vanishing point while the near walls stay |
| 16 | // put. One-to-one for |vanish| < .9. |
| 17 | float2 ptlBend(float2 uv, float2 vanish) { return uv - vanish * exp(-dot(uv, uv) * 1.6); } |
| 18 | float ptlFog(float depth, Ctx c, float base) { return exp(-depth * (base + c.fog * .12)); } |
| 19 | float ptlAttack(Ctx c) { return smoothstep(.03f, .65f, c.hit); } |
| 20 | // Attack front: a band of depth that starts near the camera and runs away as the attack |
| 21 | // decays, so every hit sends a local event down the tunnel. |
| 22 | float ptlFront(Ctx c, float depth, float near, float far, float width) { |
| 23 | float x = (depth - near - (1 - ptlAttack(c)) * far) / width; |
| 24 | return c.hit * exp(-x * x); |
| 25 | } |
| 26 | float ptlWrap(float x, float period) { return x - period * floor(x / period); } |
| 27 | float ptlBand(Ctx c, float id) { return c.b[min(3, int(ptlWrap(id, 4.f)))]; } |
| 28 | // Travelling pulse used to spread a band's response down the tunnel as moving bands of |
| 29 | // light rather than a uniform brightness change. |
| 30 | float ptlSurge(float x) { float s = .5 + .5 * sin(x); return s * s * s; } |
| 31 | |
| 32 | // ---------------------------------------------------------------- 310 Chainmail Bore |
| 33 | // A bent bore lined with interlocking 4-in-1 chainmail. Two staggered ring families tilt |
| 34 | // opposite ways, so every crossing alternates over and under. Bass billows the mesh in |
| 35 | // rolling folds and lights their crests, low-mids roll light behind the mesh, high-mids |
| 36 | // tint the staggered ring family, highs spin bright glints around the rings and attacks run |
| 37 | // a bright ripple through whole linked rings. |
| 38 | struct PtlRing { float cover; float height; float across; float2 dir; float2 centre; float family; }; |
| 39 | |
| 40 | PtlRing ptlNoRing() { |
| 41 | PtlRing ring; |
| 42 | ring.cover = 0; ring.height = -9; ring.across = 0; ring.dir = float2(0, 1); ring.centre = 0; ring.family = 0; |
| 43 | return ring; |
| 44 | } |
| 45 | PtlRing ptlMailRing(float2 p, float2 centre, float family, float aa) { |
| 46 | const float radius = .4, wire = .088; |
| 47 | PtlRing ring; |
| 48 | float2 l = p - centre; |
| 49 | float dist = length(l); |
| 50 | ring.dir = l / max(dist, 1e-4f); |
| 51 | ring.across = clamp((dist - radius) / wire, -1.f, 1.f); |
| 52 | ring.cover = 1 - smoothstep(wire - aa, wire + aa, abs(dist - radius)); |
| 53 | // Opposite tilts for the two families make every crossing alternate over and under. |
| 54 | ring.height = (family > .5 ? -l.y : l.y) / radius; |
| 55 | ring.centre = centre; |
| 56 | ring.family = family; |
| 57 | return ring; |
| 58 | } |
| 59 | float3 ptlMailShade(PtlRing ring, Ctx c, constant NativeFrame &f, float unit, float travel, float crest) { |
| 60 | float seed = hash21(float2(ptlWrap(ring.centre.x, 20.f), ring.centre.y) + ring.family * 41); |
| 61 | float s = ring.across; |
| 62 | float3 n = normalize(float3(ring.dir * s, sqrt(max(0.f, 1 - s * s)) + .2)); |
| 63 | // Each ring has its own light that circles it: the glint spins around the wire. |
| 64 | float spin = seed * TAU + c.t * (.5 + seed) * (seed > .5 ? 1 : -1); |
| 65 | float3 light = normalize(float3(cos(spin), sin(spin), 1.1)); |
| 66 | float diffuse = max(0.f, dot(n, light)); |
| 67 | float spec = pow(max(0.f, dot(n, normalize(light + float3(0, 0, 1)))), 28.f); |
| 68 | float ripple = ptlFront(c, ring.centre.y * unit - travel, 1.1, 6, .3); |
| 69 | float twinkle = step(.5f, seed) * pow(.5 + .5 * sin(c.t * 4.3 + seed * 60), 6.f); |
| 70 | float3 base = paint(.04 + seed * .24 + ring.family * (.3 + c.b.z * .2), f); |
| 71 | float surge = ptlSurge(ring.centre.y * .7 - c.t * 2.2 + 2 * sin(ring.centre.x * TAU / 10)); |
| 72 | float3 color = base * (.04 + .5 * diffuse) * (1 + ring.family * c.b.z * 7 * surge + crest * 2.6); |
| 73 | color += paint(.95, f) * spec * (.5 + c.b.w * 6 * (.25 + twinkle)); |
| 74 | color += paint(.85 + seed * .1, f) * ripple * (1 + 2.5 * spec + diffuse); |
| 75 | return color; |
| 76 | } |
| 77 | |
| 78 | |
| 79 | // ---------------------------------------------------------------- 311 Feather Vault |
| 80 | // A pointed vault lined with long overlapping iridescent feathers whose tips flow toward the |
| 81 | // viewer. Farther rows lie on top, like scales, and the feathers lean so the rows spiral. |
| 82 | // Bass lifts waves of feathers (they reach out, catch light and throw shadows), low-mids |
| 83 | // light the shafts, high-mids the vane rims, highs shimmer the barbs and attacks ruffle a |
| 84 | // wave of feathers down the vault. |
| 85 | float ptlVaultRadius(float a) { |
| 86 | float s = sin(a), co = cos(a); |
| 87 | // Pointed arch above (two circular arcs meeting at the apex), a flatter oval below. |
| 88 | if (s > 0) return sqrt(1.55f * 1.55f - .3025f * s * s) - .55f * abs(co); |
| 89 | return rsqrt(co * co + s * s / .8f); |
| 90 | } |
| 91 | struct PtlFeather { float alpha; float shadow; float3 color; }; |
| 92 | |
| 93 | PtlFeather ptlFeather(float2 p, float row, float column, Ctx c, constant NativeFrame &f, float aa, float resolve, float rowDepth, float N) { |
| 94 | PtlFeather fe; |
| 95 | float seed = hash21(float2(ptlWrap(column, N), row)); |
| 96 | float sway = .5 + .5 * sin(row * .7 + column * 1.3 - c.t * 1.2); |
| 97 | float ruffle = ptlFront(c, rowDepth, 1.1, 6, .35); |
| 98 | float lift = c.b.x * (.2 + .8 * sway * sway) * 1.5 + ruffle * 1.4; |
| 99 | float y = p.y - row + lift * .2; |
| 100 | float t = (y + 1.6) / 2.1; // 0 at the tip, 1 at the base |
| 101 | // Feathers lean and their tips curl, so the rows read as a flowing helix. |
| 102 | float x = p.x - column + t * .95 - .12 * (1 - t) * (1 - t) - .04 * sin(c.t * .7 + seed * 6); |
| 103 | float halfWidth = .5 * pow(saturate(t * 2.2), .6f) * (1 + lift * .08); |
| 104 | float edge = abs(x) - halfWidth; |
| 105 | float body = smoothstep(-.01f, .03f, t) * (1 - smoothstep(.9f, 1.f, t)); |
| 106 | // Barbs sweep from the shaft back toward the base; some vanes split apart. |
| 107 | float barbCoord = y + abs(x) * 1.6; |
| 108 | float split = smoothstep(.04f, .015f, abs(fract(barbCoord * .8 + seed * 3) - .5)) * step(.08f, abs(x)) * step(.35f, seed); |
| 109 | fe.alpha = (1 - smoothstep(-aa, aa, edge)) * body * (1 - split * resolve * .9); |
| 110 | float st = (y + 1.8 + .2 * lift) / 2.1; |
| 111 | fe.shadow = (1 - smoothstep(-.1f, .12f, abs(x) - .55f * pow(saturate(st * 2.2), .6f))) * smoothstep(0.f, .1f, st) * (.45 + .55 * saturate(lift)); |
| 112 | float across = saturate(abs(x) / max(halfWidth, 1e-3f)); |
| 113 | float barbs = pow(.5 + .5 * cos(barbCoord * 14 * TAU), 2.f); |
| 114 | float shimmer = c.b.w * sin(barbCoord * 7 + c.t * 3 + seed * 9); |
| 115 | float3 film = filmColor(seed * .5 + across * .45 + t * .4 + shimmer * .3 + c.t * .02, f); |
| 116 | float tuck = mix(1.f, .12f, smoothstep(.22f, .55f, t)); |
| 117 | float surge = ptlSurge(row * .8 - c.t * 3 + 2 * sin(column * TAU / N * 3)); |
| 118 | float barbLight = mix(.55f, .3f + .8f * barbs * (1 + 6 * c.b.w * surge), resolve); |
| 119 | float3 color = film * (.09 + .34 * (1 - across * .6)) * barbLight * tuck; |
| 120 | color += film * lift * .45 * pow(1 - across * .7, 2.f) * tuck; |
| 121 | float shaft = line(x, .028 * (1.3 - t * .6), aa) * smoothstep(.02f, .08f, t); |
| 122 | color += paint(.9, f) * shaft * (.12 + 2.6 * c.b.y) * tuck; |
| 123 | float rim = smoothstep(-.1f, -.01f, edge); |
| 124 | color += paint(.72 + seed * .12, f) * rim * (.06 + 2.2 * c.b.z) * tuck; |
| 125 | color += paint(.92, f) * ruffle * (.4 + barbs) * tuck; |
| 126 | fe.color = color; |
| 127 | return fe; |
| 128 | } |
| 129 | |
| 130 | |
| 131 | // ---------------------------------------------------------------- 312 Tartan Tube |
| 132 | // A twisting rounded-square tube wrapped in tartan: a symmetric sett of crossing thread |
| 133 | // stripes woven as a 2/2 twill, so the diagonal weave shows in every check. Each of the four |
| 134 | // thread colours belongs to one band and brightens with it; attacks send a bright stripe |
| 135 | // along the weft, lighting only the weft floats so the twill flashes. |
| 136 | float ptlSett(float s) { |
| 137 | float x = abs(fract(s) - .5) * 2; |
| 138 | return x < .07 ? 3 : x < .36 ? 0 : x < .44 ? 2 : x < .64 ? 1 : x < .7 ? 3 : x < .84 ? 2 : 0; |
| 139 | } |
| 140 | float3 ptlThread(float slot, float phase, Ctx c, constant NativeFrame &f) { |
| 141 | float3 hue = slot < .5 ? paint(.97, f) : slot < 1.5 ? paint(.04, f) : slot < 2.5 ? paint(.74, f) : paint(.5, f); |
| 142 | float gain = slot < .5 ? .26 : slot < 2.5 ? .36 : .55; |
| 143 | return hue * (gain + 3 * c.b[min(3, int(slot))] * ptlSurge(phase + slot * 1.9)); |
| 144 | } |
| 145 | |
| 146 | |
| 147 | // ---------------------------------------------------------------- 313 Herringbone Hall |
| 148 | // A rectangular hall paved on every surface with 2:1 herringbone tiles and glowing grout; |
| 149 | // the pattern folds continuously around the corners. Bass tilts and lights tiles in chevron |
| 150 | // waves that roll down the hall, low-mids glow the vertical tiles, high-mids sheen the |
| 151 | // horizontal ones, highs light the grout and attacks flash a whole herringbone row. |
| 152 | struct PtlBrick { float2 local; float2 id; float2 centre; float vertical; float edge; }; |
| 153 | |
| 154 | // Herringbone of 2x1 bricks in brick units: a staircase of horizontal/vertical pairs |
| 155 | // repeating along (1,1) and (0,4). |
| 156 | PtlBrick ptlHerringbone(float2 p) { |
| 157 | PtlBrick b; |
| 158 | float m = floor(p.x), lx = p.x - m; |
| 159 | float yp = p.y - m + 3, n = floor(yp / 4), yl = yp - 4 * n; |
| 160 | if (yl < 2) { |
| 161 | b.local = float2(yl, lx); b.id = float2(m - 2, n); b.vertical = 1; |
| 162 | b.centre = float2(m + .5, m - 2 + 4 * n); |
| 163 | } else if (yl < 3) { |
| 164 | b.local = float2(lx + 1, yl - 2); b.id = float2(m - 1, n); b.vertical = 0; |
| 165 | b.centre = float2(m, m - .5 + 4 * n); |
| 166 | } else { |
| 167 | b.local = float2(lx, yl - 3); b.id = float2(m, n); b.vertical = 0; |
| 168 | b.centre = float2(m + 1, m + .5 + 4 * n); |
| 169 | } |
| 170 | b.edge = min(min(b.local.x, 2 - b.local.x), min(b.local.y, 1 - b.local.y)); |
| 171 | return b; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | // ---------------------------------------------------------------- 314 Quilted Pipe |
| 176 | // An off-axis view down a round pipe upholstered in puffy quilted diamonds: the camera rides |
| 177 | // close to one wall and slowly orbits the axis, so near diamonds loom large on one side. |
| 178 | // Bass inflates diamonds in rolling groups, low-mids brighten alternate diamonds, high-mids |
| 179 | // light the tufted buttons, highs glow the running stitches and attacks press a dimple |
| 180 | // wave through the quilt. |
| 181 | float3 quiltedPipe(Ctx c, constant NativeFrame &f) { |
| 182 | const float N = 11; |
| 183 | float orbit = c.t * .05; |
| 184 | float2 eye = float2(cos(orbit), sin(orbit)) * .5; |
| 185 | float3 forward = normalize(float3(-eye * .3, 1)); |
| 186 | float3 ray = cameraRay(c.uv / c.size, forward, float3(0, 1, 0), 1.15); |
| 187 | float2 dxy = ray.xy; |
| 188 | float bq = dot(eye, dxy), aq = max(dot(dxy, dxy), 1e-7f); |
| 189 | float tq = (-bq + sqrt(max(0.f, bq * bq - aq * (dot(eye, eye) - 1)))) / aq; |
| 190 | float2 hit = eye + dxy * tq; |
| 191 | float depth = min(tq * ray.z, 200.f); |
| 192 | float a = atan2(hit.y, hit.x); |
| 193 | float travel = c.travel * 1.2, zw = depth + travel; |
| 194 | float2 grid = float2(a, zw) * N / TAU; |
| 195 | float2 dia = float2(grid.x + grid.y, grid.x - grid.y); |
| 196 | float2 cell = floor(dia), l = fract(dia) - .5; |
| 197 | float fw = max(length(fwidth(hit)), fwidth(zw)) * N / TAU * 1.4; |
| 198 | float aa = clamp(fw, .01f, .5f); |
| 199 | float parity = ptlWrap(cell.x + cell.y, 2.f); |
| 200 | float seed = hash21(float2(cell.x - cell.y, ptlWrap(cell.x + cell.y, 2 * N))); |
| 201 | float cellDepth = (cell.x - cell.y) * .5 * TAU / N - travel; |
| 202 | float group = .5 + .5 * sin(cellDepth * .9 - c.t * 1.1 + parity * 2.2 + a); |
| 203 | float press = ptlFront(c, cellDepth, 1.1, 5, .35); |
| 204 | float inflate = .6 + .2 * sin(seed * 6 + c.t * .6) + 1.7 * c.b.x * group * group - 2.4 * press; |
| 205 | float2 cl = cos(PI * l), sl = sin(PI * l); |
| 206 | float2 grad = -PI * float2(sl.x * cl.y, cl.x * sl.y) * inflate; |
| 207 | float3 n = normalize(float3(-grad * .45, 1)); |
| 208 | float spin = c.t * .15; |
| 209 | float3 light = normalize(float3(cos(spin) * .8, sin(spin) * .8 + .3, .8)); |
| 210 | float diffuse = .55 * n.z * n.z + .45 * max(0.f, dot(n, light)); |
| 211 | float spec = pow(max(0.f, dot(n, normalize(light + float3(0, 0, 1)))), 22.f); |
| 212 | float edge = .5 - max(abs(l.x), abs(l.y)); |
| 213 | float crease = smoothstep(0.f, .2f, edge); |
| 214 | float3 satin = paint(.06 + parity * .36 + seed * .12, f) * (.02 + .42 * pow(diffuse, 3.f)) * (.25 + .75 * crease); |
| 215 | satin *= 1 + parity * 7 * c.b.y * ptlSurge(cellDepth * 1.3 - c.t * 2.2 + sin(a * 2)); |
| 216 | satin += paint(.88, f) * spec * (.25 + .4 * saturate(inflate)) * crease; |
| 217 | // Running stitches just inside every seam. |
| 218 | float seamAlong = abs(l.x) > abs(l.y) ? dia.y : dia.x; |
| 219 | float dash = smoothstep(.12f, .2f, abs(fract(seamAlong * 5) - .5)); |
| 220 | float stitch = line(edge - .075, .018, aa) * dash; |
| 221 | float3 stitchColor = paint(.95, f) * (.25 + 3 * c.b.w); |
| 222 | float3 color = mix(satin, stitchColor, stitch * smoothstep(.3f, .1f, fw)); |
| 223 | // Tufted buttons where the seams cross. |
| 224 | float button = length(.5 - abs(l)); |
| 225 | color = mix(color, paint(.75, f) * (.25 + 3 * c.b.z), fill(button - .075, aa)); |
| 226 | color += paint(.75, f) * glow(button, .06) * c.b.z * .6; |
| 227 | color += paint(.92, f) * press * (crease * .6 + glow(edge, .06) * 1.5); |
| 228 | float3 average = paint(.2, f) * .14; |
| 229 | color = mix(average, color, smoothstep(.4f, .12f, fw)); |
| 230 | float3 core = deep(.6, f) * .1 + paint(.85, f) * exp(-length(dxy) * 9) * 1.0; |
| 231 | return mix(core, color, ptlFog(depth, c, .045)); |
| 232 | } |
| 233 | NATIVE_EFFECT(quiltedPipe) |
| 234 | |
| 235 | // ---------------------------------------------------------------- 315 Lace Funnel |
| 236 | // A funnel of layered lace rings drifting toward the viewer against a hot core of light. |
| 237 | // The lace is laid out on conformal log-polar tiles, so every motif keeps its shape at |
| 238 | // every radius: rows of rimmed eyelets in cloth stitch, five-petal flowers over net and |
| 239 | // spotted net, with a picot inner edge and a scalloped border. Alternate layers turn against |
| 240 | // each other. Each layer's eyelets glow with its own band, highs light the cords and attacks |
| 241 | // bloom light through the openwork of one layer as it passes. |
| 242 | float4 ptlLace(float2 g, float yIn, float yOut, float aa) { |
| 243 | float y = g.y - yIn, row = floor(y); |
| 244 | float shift = ptlWrap(row, 2.f) * .5; |
| 245 | float2 l = float2(fract(g.x + shift) - .5, y - row - .5); |
| 246 | float type = ptlWrap(row, 3.f); |
| 247 | // A ring cord runs along every row boundary. |
| 248 | float cord = line(abs(l.y) - .5, .05, aa), cloth = 0, hole = 0, rim = 0; |
| 249 | if (type < .5) { |
| 250 | // Eyelet row: a band of cloth stitch pierced by rimmed eyelets. |
| 251 | float e = length(l * float2(1, 1.15)); |
| 252 | hole = fill(e - .16, aa); |
| 253 | rim = line(e - .2, .04, aa); |
| 254 | cloth = fill(abs(l.y) - .3, aa); |
| 255 | } else if (type < 1.5) { |
| 256 | // Scallop row: cloth arches, each pierced by an eyelet, open net between them. |
| 257 | float2 m = float2(l.x, l.y + .5); |
| 258 | float arch = length(m) - .46; |
| 259 | float eye = length(m - float2(0, .22)) - .08; |
| 260 | cloth = fill(arch, aa); |
| 261 | hole = fill(eye, aa); |
| 262 | rim = max(line(arch, .045, aa), line(eye - .035, .028, aa)); |
| 263 | } else { |
| 264 | // Bar row: open net crossed by slanted twisted bars joining the cords. |
| 265 | rim = line(abs(l.x - l.y * .6) - .02, .035, aa) * (.75 + .25 * sin(l.y * 40)); |
| 266 | } |
| 267 | cord = max(cord, rim); |
| 268 | float4 h = hexCell(g * 5); |
| 269 | float hexEdge = .5 - max(abs(h.x), max(abs(.5 * h.x + .866 * h.y), abs(.5 * h.x - .866 * h.y))); |
| 270 | float netThread = mix(.3f, line(hexEdge, .09, aa * 5), smoothstep(.12f, .05f, aa)); |
| 271 | float clothTex = mix(.6f, .5f + .5f * sin((l.x + l.y) * 50) * sin((l.x - l.y) * 50), smoothstep(.05f, .02f, aa)); |
| 272 | // Picot inner edge and scalloped outer border. |
| 273 | float sx = fract(g.x) - .5; |
| 274 | float border = yOut - .35 + .35 * sqrt(max(0.f, 1 - 4 * sx * sx)); |
| 275 | float inside = fill(g.y - border, aa) * fill(yIn - g.y, aa); |
| 276 | float edges = line(g.y - border, .08, aa) + line(g.y - yIn, .07, aa); |
| 277 | edges += line(length(float2(sx, g.y - yIn + .13)) - .1, .028, aa) * step(g.y, yIn); |
| 278 | float lace = max(cloth * .85, (1 - cloth) * netThread * .22); |
| 279 | float opacity = max(inside * max(lace, cord), edges) * (1 - hole * inside); |
| 280 | float glowLight = inside * (1 - hole) * (cloth * .5 * clothTex + (1 - cloth) * netThread * .12); |
| 281 | float holeGlow = inside * hole * (1 - smoothstep(0.f, .16f, length(l)) * .6); |
| 282 | return float4(saturate(opacity), glowLight, holeGlow, saturate(inside * cord + edges)); |
| 283 | } |
| 284 | |
| 285 | // Coaster versions: the same designs riding the roller-coaster course. |
| 286 | NATIVE_COASTER(quiltedPipe, 314, false) |