PulseCanvas / app · pulsecanvas.ai / Sources / PulseCanvas / Resources / NativeExpansionDrive.metal
| 1 | // Newly authored PulseCanvas driving studies. No preset formulas, third-party |
| 2 | // textures, shader translations or external implementations are used. |
| 3 | |
| 4 | struct DriveWall { float angle; float radius; float depth; float distance; float aa; }; |
| 5 | DriveWall driveWall(float2 p, Ctx c, float pitch) { |
| 6 | DriveWall w; |
| 7 | p /= c.size; |
| 8 | w.radius = max(length(p), .035f); |
| 9 | w.angle = atan2(p.y, p.x); |
| 10 | w.distance = 1 / w.radius; |
| 11 | w.depth = pitch * w.distance + c.travel; |
| 12 | w.aa = min(.3f, c.px * (1 + w.distance * w.distance)); |
| 13 | return w; |
| 14 | } |
| 15 | float driveStripe(float phase, float thickness, float aa) { |
| 16 | return 1 - smoothstep(thickness, thickness + max(.02f, aa), abs(sin(phase))); |
| 17 | } |
| 18 | |
| 19 | // A continuous curved motorway below a billowing sky. Four staggered lane |
| 20 | // markings, luminous shoulders and road ripples have independent audio inputs. |
| 21 | |
| 22 | |
| 23 | // Three braided track ribbons wind around an illuminated tube. The gaps reveal |
| 24 | // a second, counter-rotating wall of oblique seams, rather than a flat ring stack. |
| 25 | float3 iridescentRaceway(Ctx c, constant NativeFrame &f) { |
| 26 | float2 p = rot(c.uv, .12 * sin(c.t * .3)); |
| 27 | DriveWall w = driveWall(p, c, 2.4); |
| 28 | float helix = w.angle * 3 + w.depth * .8 - c.t * .35; |
| 29 | float ribbon = pow(.5 + .5 * cos(helix + c.b.y * sin(w.depth) * 2), 3.f); |
| 30 | float seam = driveStripe(w.angle * 12 - w.depth * 1.1 + c.t * .4, .06, w.aa); |
| 31 | float curb = driveStripe(helix, .1 + c.b.w * .09, w.aa); |
| 32 | float grain = .65 + .35 * sin(w.depth * 4 + sin(w.angle * 7)); |
| 33 | float3 color = paint((.5 + .3 * sin(w.angle)) + w.depth * .022, f) * (ribbon * (.65 + grain) + seam * .3); |
| 34 | color += paint(w.depth * .05 + .6, f) * curb * (1 + c.hit * .6); |
| 35 | return color * smoothstep(.025f, .18f, w.radius) + paint(.5, f) * .08; |
| 36 | } |
| 37 | |
| 38 | // Four beveled planes converge into a bending diamond gallery. Wall reflections |
| 39 | // move in opposite directions and diagonal braces open with the low-mid band. |
| 40 | float3 cobaltCatapult(Ctx c, constant NativeFrame &f) { |
| 41 | float2 p = rot(c.uv / c.size + float2(sin(c.t * .19), cos(c.t * .16)) * .09, PI * .25); |
| 42 | float radius = max(max(abs(p.x), abs(p.y)), .045f); |
| 43 | float depth = 2.6 / radius + c.travel * 1.8; |
| 44 | float face = abs(p.x) > abs(p.y) ? p.y / radius : p.x / radius; |
| 45 | float seam = driveStripe(depth * 1.7 + face * 2.5, .075, c.px / radius); |
| 46 | float diagonal = driveStripe(face * 8 + sin(depth * .3) * 2, .08 + c.b.y * .18, c.px / radius); |
| 47 | float bevel = pow(min(abs(p.x), abs(p.y)) / radius, 16.f); |
| 48 | float3 color = paint(face * .13 + depth * .02, f) * (.25 + .22 * sin(depth + face * 5)); |
| 49 | color += paint(.75 + depth * .03, f) * (seam * 1.3 + diagonal * .7 + bevel * .8); |
| 50 | return color * smoothstep(.02f, .12f, radius) + deep(.7, f) * .12; |
| 51 | } |
| 52 | |
| 53 | // A rocket corridor of long comet plumes. Each plume curves through its own |
| 54 | // arc; faded stable depth slots prevent spawning flashes during forward travel. |
| 55 | float3 tangerineRocket(Ctx c, constant NativeFrame &f) { |
| 56 | float3 color = paint(.4, f) * .08; |
| 57 | for (int k = 0; k < 6; ++k) { |
| 58 | float2 slot = layerSlot(k, 6, c.travel * .12); |
| 59 | float scale = layerScale(slot.x, 2.6) / c.size; |
| 60 | float2 p = rot(c.uv * scale, slot.y * .21 + c.t * .15); |
| 61 | float a = atan2(p.y, p.x), r = length(p); |
| 62 | float plume = driveStripe(a * 9 + r * 1.7 + sin(r + c.t * .3) + slot.y, .08 + c.b.z * .1, c.px * scale / max(.15f, r)); |
| 63 | float tail = pow(.5 + .5 * cos(r * 2 - c.t * .8 + slot.y), 3.f); |
| 64 | float arc = glow(r - (1.2 + .15 * sin(a * 6 + c.t + slot.y) + c.b[int(slot.y - 4 * floor(slot.y / 4))] * .16), .035 * c.size); |
| 65 | color += paint(slot.y * .12 + (.5 + .3 * sin(a)), f) * (plume * tail * .8 + arc * 1.4) * layerFade(slot.x); |
| 66 | } |
| 67 | return color; |
| 68 | } |
| 69 | |
| 70 | // A pentagonal acceleration chamber with alternating inset facets. Surface |
| 71 | // pressure deforms each angular panel; forward zoom and twist stay procedural. |
| 72 | float3 prismaticOverdrive(Ctx c, constant NativeFrame &f) { |
| 73 | DriveWall w = driveWall(c.uv, c, 1.7); |
| 74 | float twist = w.angle + w.depth * .22 + c.t * .12; |
| 75 | float panel = cos(twist * 5); |
| 76 | float facet = .7 + .3 * panel; |
| 77 | float pressure = sin(twist * 10 + w.depth * .8) * c.b.x * .55; |
| 78 | float ribs = driveStripe(w.depth * 2.3 + facet * 2 + pressure, .13, w.aa); |
| 79 | float bolts = pow(.5 + .5 * cos(twist * 20), 10.f) * pow(.5 + .5 * cos(w.depth * 4.6), 10.f); |
| 80 | float3 color = paint((.5 + .3 * sin(twist)) + w.depth * .015, f) * (.18 + facet * .5 + ribs * 1.3); |
| 81 | color += paint(.75, f) * bolts * (1 + c.b.w); |
| 82 | return color * smoothstep(.025f, .12f, w.radius) + deep(.8, f) * .12; |
| 83 | } |
| 84 | |
| 85 | // Five long ruled sails twist around a dark core. The fabric has distinct |
| 86 | // crosswise folds; percussion shakes individual folds rather than the camera. |
| 87 | float3 scarletSlipstream(Ctx c, constant NativeFrame &f) { |
| 88 | DriveWall w = driveWall(c.uv, c, 2.2); |
| 89 | float3 color = deep(.2, f) * .2; |
| 90 | for (int k = 0; k < 5; ++k) { |
| 91 | float phase = w.angle - float(k) * TAU / 5 + w.depth * (.19 + float(k) * .025) + c.t * .16; |
| 92 | float fold = sin(w.depth * 3 + float(k) * 1.7) * (.15 + c.b[k % 4] * .4); |
| 93 | float sail = glow(sin(phase) + fold, .14 * c.size) * (.5 + .5 * cos(phase)); |
| 94 | float weave = .7 + .3 * sin(w.depth * 9 + phase * 7); |
| 95 | color += paint(float(k) * .17 + w.depth * .017, f) * sail * weave; |
| 96 | } |
| 97 | return color * smoothstep(.025f, .12f, w.radius) + paint(.3, f) * .07; |
| 98 | } |
| 99 | |
| 100 | // Suspended twin carriageways cross a reflective valley. Rail separation is |
| 101 | // fixed; their banks and luminous cross ties dance to different frequency bands. |
| 102 | float3 laserAutobahn(Ctx c, constant NativeFrame &f) { |
| 103 | float2 p = c.uv / c.size; |
| 104 | float horizon = .28; |
| 105 | float z = 1.8 / max(abs(p.y - horizon), .04f) + c.travel * 2; |
| 106 | float x = p.x / max(abs(p.y - horizon), .04f); |
| 107 | float roadCenter = sin(z * .14 + c.t * .19) * 1.2; |
| 108 | float banks = .5 + .5 * cos(z * .6 + c.b.x * sin(x) * 2); |
| 109 | float rails = glow(abs(x - roadCenter) - 2.4, .14 * c.size); |
| 110 | float ties = driveStripe(z * 3, .075 + c.b.z * .1, c.px * z) * exp(-abs(x - roadCenter) * .35); |
| 111 | float mountains = .5 + .5 * sin(p.x * 3 + sin(p.x * 2 + c.t * .1)); |
| 112 | float3 color = paint(.8 + mountains * .15, f) * (.1 + mountains * .2); |
| 113 | float3 road = paint(x * .035 + z * .012, f) * (.12 + banks * .2 + rails * 1.7 + ties * .8); |
| 114 | return mix(color, road, smoothstep(-.05f, .05f, horizon - p.y)); |
| 115 | } |
| 116 | |
| 117 | // A flowing canyon seen from within. Narrow liquid strata curl around wide |
| 118 | // concave walls, with separate bass swells and high-frequency surface ripples. |
| 119 | float3 rainbowRiptide(Ctx c, constant NativeFrame &f) { |
| 120 | float2 p = c.uv + float2(sin(c.t * .23), cos(c.t * .17)) * .13; |
| 121 | DriveWall w = driveWall(p, c, 1.9); |
| 122 | float stream = w.depth * .55 + sin(w.angle * 3 + w.depth * .18) * 2; |
| 123 | stream += c.b.x * sin(w.angle * 5 + w.depth) * .6; |
| 124 | float ripple = sin(stream * 6 + c.b.w * sin(w.angle * 24) * 2); |
| 125 | float liquid = .5 + .5 * sin(stream); |
| 126 | float sheen = pow(max(0.f, ripple), 14.f); |
| 127 | float bank = .3 + .7 * pow(.5 + .5 * cos(w.angle * 2), 2.f); |
| 128 | float3 color = paint(stream * .035 + (.5 + .3 * sin(w.angle)), f) * (bank * .65 + liquid * .45); |
| 129 | color += paint(.85, f) * sheen * (.8 + c.detail); |
| 130 | return color * smoothstep(.025f, .14f, w.radius) + paint(.2, f) * .08; |
| 131 | } |
| 132 | |
| 133 | // A winding road through luminous rectangular archways. Perspective slats |
| 134 | // bend continuously left/right; walls carry traveling, independently pulsing bars. |
| 135 | float3 electricSwitchback(Ctx c, constant NativeFrame &f) { |
| 136 | float2 p = c.uv / c.size; |
| 137 | float r = max(max(abs(p.x), abs(p.y * .8)), .04f); |
| 138 | float z = 2 / r + c.travel * 2.4; |
| 139 | float curve = sin(z * .13 + c.t * .3) * .35 + sin(z * .31) * .13; |
| 140 | float side = p.x / r - curve; |
| 141 | float arch = driveStripe(z * 1.8 + sin(side * 3) * c.b.y * .25, .1, c.px / r); |
| 142 | float vertical = driveStripe(side * 3.5, .08, c.px / r); |
| 143 | float bottom = smoothstep(.1f, -.25f, p.y); |
| 144 | float groove = .5 + .5 * sin(z * 5 + side * 2 + c.t * .5); |
| 145 | float3 color = paint(side * .2 + z * .02, f) * (.18 + arch * 1.4 + vertical * .35 + bottom * groove * .25); |
| 146 | return color * smoothstep(.02f, .12f, r) + deep(.65, f) * .15; |
| 147 | } |
| 148 | |
| 149 | // A drum-machine tunnel tiled with dancing oval lamps. Each lamp has a smooth |
| 150 | // spatial phase and band assignment; there is no hash-based frame flicker. |
| 151 | float3 discoTransit(Ctx c, constant NativeFrame &f) { |
| 152 | DriveWall w = driveWall(rot(c.uv, c.t * .07), c, 2.3); |
| 153 | float column = w.angle * 8 / PI; |
| 154 | float row = w.depth * .7; |
| 155 | float2 tile = float2(column, row); |
| 156 | float2 id = floor(tile), local = fract(tile) - .5; |
| 157 | float phase = sin(id.x * TAU / 16) * 2 + id.y * 1.3; |
| 158 | float band = c.b[int(id.x + id.y - 4 * floor((id.x + id.y) / 4))]; |
| 159 | float dance = sin(c.t * 1.6 + phase) * .09; |
| 160 | float2 shape = (local - float2(dance, sin(c.t + phase) * .07)) / float2(.32 + band * .1, .36); |
| 161 | float lamp = 1 - smoothstep(.85f, 1.f, dot(shape, shape)); |
| 162 | float center = glow(length(shape), .25); |
| 163 | float joints = driveStripe(column * PI, .08, w.aa) + driveStripe(row * PI, .08, w.aa); |
| 164 | float3 color = paint(phase * .08 + .3, f) * (lamp * (.5 + band) + center * .7 + joints * .2 + .1); |
| 165 | return color * smoothstep(.02f, .13f, w.radius) + paint(.5, f) * .06; |
| 166 | } |
| 167 | |
| 168 | |
| 169 | NATIVE_EFFECT(iridescentRaceway) |
| 170 | NATIVE_EFFECT(cobaltCatapult) |
| 171 | NATIVE_EFFECT(tangerineRocket) |
| 172 | NATIVE_EFFECT(prismaticOverdrive) |
| 173 | NATIVE_EFFECT(scarletSlipstream) |
| 174 | NATIVE_EFFECT(laserAutobahn) |
| 175 | NATIVE_EFFECT(rainbowRiptide) |
| 176 | NATIVE_EFFECT(electricSwitchback) |
| 177 | NATIVE_EFFECT(discoTransit) |