PulseCanvas / app · pulsecanvas.ai / Sources / PulseCanvas / Resources / NativeExpansionCosmosII.metal
| 1 | // Second versions of designs whose original and final review clips were both red-tagged. |
| 2 | // Original PulseCanvas designs 350–359. Cosmic phenomena drawn as vivid neon light, not |
| 3 | // photographic space art: beams, shells, streams, loops and lensed arcs built from analytic |
| 4 | // curves and a little noise. Every band drives its own structures; attacks make local events. |
| 5 | |
| 6 | // ---------------------------------------------------------------- shared helpers (cosm*) |
| 7 | // Ridged noise: thin bright creases, the raw material of filaments. |
| 8 | float cosmRidge(float2 p, int octaves) { |
| 9 | float sum = 0, amplitude = .5; |
| 10 | for (int i = 0; i < octaves; ++i) { |
| 11 | float n = 1 - abs(2 * noise2(p) - 1); |
| 12 | sum += amplitude * n * n; |
| 13 | p = float2(p.x * 1.6 - p.y * 1.2, p.x * 1.2 + p.y * 1.6) + 4.7; |
| 14 | amplitude *= .5; |
| 15 | } |
| 16 | return sum; |
| 17 | } |
| 18 | // Sparse twinkling specks, one jittered candidate per cell, with no seams at cell edges. |
| 19 | float cosmStars(float2 p, float density, float t) { |
| 20 | float2 id = floor(p), local = fract(p) - .5, h = hash22(id + 31.7); |
| 21 | float on = step(1 - density, hash21(id + 9.1)); |
| 22 | float2 offset = local - (h - .5) * .6; |
| 23 | float twinkle = .6 + .4 * sin(t * (1.1 + h.x * 2) + h.y * TAU); |
| 24 | return on * twinkle * exp(-dot(offset, offset) * 900); |
| 25 | } |
| 26 | // Distance in uv units to the nearest integer contour of a smooth field v. |
| 27 | float cosmContour(float v, float px) { |
| 28 | return abs(fract(v + .5) - .5) * px / max(fwidth(v), 1e-5f); |
| 29 | } |
| 30 | // Level of band i (0...3) for a data-dependent index, without dynamic vector indexing. |
| 31 | float cosmBand(float4 bands, float i) { |
| 32 | return dot(bands, saturate(1 - abs(float4(0, 1, 2, 3) - i))); |
| 33 | } |
| 34 | // Raised cosine in [0, 1], clamped so pow() never sees a rounding-negative base. |
| 35 | float cosmWave(float x) { return saturate(.5f + .5f * cos(x)); } |
| 36 | // A fixed oblique rotation, so value-noise lattice planes never line up with polar axes. |
| 37 | float3 cosmTilt(float3 p) { |
| 38 | return float3(.80f * p.x + .36f * p.y + .48f * p.z, -.48f * p.x + .80f * p.y + .36f * p.z, -.36f * p.x - .48f * p.y + .80f * p.z); |
| 39 | } |
| 40 | // Sharp crest of a ridge value (1 on the crest), widened where it would fall below a pixel. |
| 41 | float cosmCrest(float ridge, float sharpness) { |
| 42 | float k = min(sharpness, .8f / max(fwidth(ridge), 1e-4f)); |
| 43 | return exp(-k * (1 - ridge)) * sqrt(k / sharpness); |
| 44 | } |
| 45 | // Lay a two-body composition along the canvas's long axis. |
| 46 | float2 cosmLongAxis(float2 p, float2 extent) { |
| 47 | return extent.y > extent.x ? float2(p.y, -p.x) : p; |
| 48 | } |
| 49 | |
| 50 | |
| 51 | // ---------------------------------------------------------------- 351 Twin Suns |
| 52 | // A glowing star: saturated limb-darkened body with a soft edge, a neon rim, corona and rays. |
| 53 | float4 cosmSun(float2 d, float radius, float spin, float hue, float corona, constant NativeFrame &f) { |
| 54 | float r = length(d) / radius; |
| 55 | float mu = sqrt(max(0.f, 1 - r * r)); |
| 56 | float2 sp = rot(d / radius, spin); |
| 57 | float cells = noise2(sp * 5 + 3.3) * .6 + noise2(sp * 11 + 8.1) * .4; |
| 58 | float3 surface = paint(hue + .22 * mu + .1 * cells, f) * (.3 + .55 * mu * (.6 + .6 * cells)) |
| 59 | + paint(.92, f) * pow(mu, 8.f) * .45; |
| 60 | float disc = 1 - smoothstep(.9f, 1.02f, r); |
| 61 | float a = atan2(d.y, d.x) + spin * .3; |
| 62 | float outer = max(r - 1, 0.f); |
| 63 | float rays = pow(cosmWave(a * 14 + 2 * sin(a * 5 + spin * 2)), 8.f) * exp(-outer * (3.2 - corona * 1.6)); |
| 64 | float halo = glow(outer, .2 + corona * .35) * (.22 + corona * .8); |
| 65 | float rim = glow(r - .98, .035) * .9 + glow(r - .98, .012); |
| 66 | float3 col = surface * disc + paint(hue + .3, f) * rim * (.5 + .8 * corona) |
| 67 | + paint(hue + .1, f) * (halo + rays * (.2 + corona * 1.2)) * (1 - disc); |
| 68 | return float4(col, disc); |
| 69 | } |
| 70 | |
| 71 | float3 twinSunsII(Ctx c, constant NativeFrame &f) { |
| 72 | float2 p = cosmLongAxis(c.uv / c.size, c.extent); |
| 73 | float phase = c.t * .3; |
| 74 | // The heavy primary rides close to the canvas centre while the companion swings wide along |
| 75 | // the long axis, so the forward-zoom echo of the primary reads as its own corona. |
| 76 | float span = clamp(max(c.extent.x, c.extent.y) / c.size, 1.f, 1.8f); |
| 77 | float2 orbit = float2(cos(phase) * (.62 + .35 * span), sin(phase) * .55); |
| 78 | float2 s1 = -orbit * .2, s2 = orbit * .8; |
| 79 | const float r1 = .2, r2 = .075; |
| 80 | |
| 81 | // Circumbinary outflow: trailing arms of fine glowing threads that turn with the orbit. |
| 82 | float rho = length(p), th = atan2(p.y, p.x); |
| 83 | float spiral = 2 * (th - phase) + log(rho + .08) * 3.4; |
| 84 | float arms = pow(cosmWave(spiral), 3.f); |
| 85 | float tex = fbm2(p * 2.1 + float2(c.t * .02, -c.t * .013), 4); |
| 86 | float threads = pow(cosmWave(spiral * 5 + tex * 5), 14.f); |
| 87 | float reachArms = exp(-rho * .45); |
| 88 | float3 col = deep(.2 + .25 * tex, f) * (.025 + .09 * tex * tex); |
| 89 | col += paint(.12 + .3 * tex, f) * pow(cosmWave(spiral), 1.5f) * reachArms * (.05 + .16 * tex) * (.6 + 1.2 * c.b.y); |
| 90 | col += paint(.35 + .4 * arms, f) * threads * arms * reachArms * (.3 + 1.6 * c.b.y); |
| 91 | |
| 92 | // Tidal streams pulled from the companion onto the primary, one strand per band. |
| 93 | float2 dv = s1 - s2; float len = length(dv); |
| 94 | float2 ax = dv / len, nv = float2(-ax.y, ax.x), rel = p - s2; |
| 95 | float u = dot(rel, ax) / len, v = dot(rel, nv), uc = clamp(u, 0.f, 1.f); |
| 96 | float ends = smoothstep(-.05f, .12f, u) * smoothstep(1.02f, .85f, u); |
| 97 | for (int k = 0; k < 4; ++k) { |
| 98 | float fk = float(k), level = c.b[k]; |
| 99 | float bend = ((.1 + .07 * fk) * len + .05 * sin(TAU * uc * 1.5 + c.t * .8 + fk * 1.7)) * sin(PI * uc) * (k % 2 == 0 ? 1.f : -.7f); |
| 100 | float dist = abs(v - bend); |
| 101 | float flow = pow(cosmWave(u * 18 - c.t * 2.4 + fk * 1.9 - PI * .5), 4.f); |
| 102 | float strand = glow(dist, .006 + .008 * level) * (.3 + .7 * flow) + glow(dist, .035) * .12; |
| 103 | col += paint(.25 + .17 * fk + .12 * flow, f) * strand * ends * (.3 + 1.9 * level); |
| 104 | } |
| 105 | |
| 106 | // Attacks erupt a flare loop and an ejected blob from each star. |
| 107 | float burst = c.hit * (.6 + .4 * c.hit) * 1.8; |
| 108 | float3 flares = 0; |
| 109 | for (int k = 0; k < 2; ++k) { |
| 110 | float2 s = k == 0 ? s1 : s2; float radius = k == 0 ? r1 : r2; |
| 111 | float fa = phase * (k == 0 ? 1.7 : -1.3) + float(k) * 2.4 + .8; |
| 112 | float2 dir = float2(cos(fa), sin(fa)); |
| 113 | float2 site = s + dir * radius; |
| 114 | float loopArc = abs(length(p - site) - radius * (.3 + 1.4 * c.hit)); |
| 115 | float outside = smoothstep(radius, radius * 1.05, length(p - s)); |
| 116 | float blob = glow(length(p - s - dir * radius * (1.15 + 3 * (1 - c.hit))), .04 + .06 * (1 - c.hit)); |
| 117 | flares += paint(.7, f) * (glow(loopArc, .008) * outside * 1.5 + blob) * burst; |
| 118 | } |
| 119 | |
| 120 | // Stars, drawn back to front; they swap only at full separation, never while overlapping. |
| 121 | float4 a = cosmSun(p - s1, r1, c.t * .2, .3, c.b.x, f); |
| 122 | float4 b = cosmSun(p - s2, r2, -c.t * .3, .62, .35 + c.b.z, f); |
| 123 | bool firstFront = sin(phase) > 0; |
| 124 | float4 back = firstFront ? b : a, front = firstFront ? a : b; |
| 125 | col = col * (1 - back.w) + back.rgb; |
| 126 | col += flares; |
| 127 | col = col * (1 - front.w) + front.rgb; |
| 128 | col += paint(.8, f) * cosmStars(p * 9, .25, c.t) * .5; |
| 129 | return col; |
| 130 | } |
| 131 | NATIVE_EFFECT(twinSunsII) |
| 132 | |
| 133 | // ---------------------------------------------------------------- 352 Supernova Shell |
| 134 | float3 supernovaShellII(Ctx c, constant NativeFrame &f) { |
| 135 | float2 p = c.uv / c.size; |
| 136 | float r = length(p); |
| 137 | float2 dirv = p / max(r, 1e-4f); |
| 138 | const float R = .64; |
| 139 | float wob = noise2(dirv * 2.2 + 11.3) - .5; |
| 140 | float Ro = R * (1 + .14 * wob), Ri = Ro * .78; |
| 141 | float shell = (sqrt(max(Ro * Ro - r * r, 0.f)) - sqrt(max(Ri * Ri - r * r, 0.f))) / sqrt(Ro * Ro - Ri * Ri); |
| 142 | |
| 143 | // Rayleigh-Taylor fingers: ridges of a noise field stretched along the radius. They drift |
| 144 | // outward in log radius, so the forward-zoom echo lines up with the fingers themselves. |
| 145 | // The music clock drives the expansion, so energetic passages push the fingers out faster. |
| 146 | float lr = log(max(r, .03f)); |
| 147 | float3 fq = float3(dirv * 6.5, lr * 1.25 - c.t * .05 - c.m * .45); |
| 148 | float ridgeA = 1 - abs(2 * noise3(cosmTilt(fq)) - 1); |
| 149 | float ridgeB = 1 - abs(2 * noise3(cosmTilt(fq * float3(1.8, 1.8, 1.5) + 7.3).zxy) - 1); |
| 150 | float fingerA = cosmCrest(ridgeA, 16), fingerB = cosmCrest(ridgeB, 22); |
| 151 | float bead = smoothstep(.62f, .9f, noise3(cosmTilt(fq * float3(1, 1, 5) + 2.1).yzx)); |
| 152 | float band = smoothstep(Ri * .35f, Ri, r) * smoothstep(Ro * 1.06f, Ro * .97f, r); |
| 153 | float tip = smoothstep(Ri * .8f, Ro, r); |
| 154 | |
| 155 | // Hit: a fresh shock ring races out and lights the fingers it crosses. |
| 156 | float Rh = R * (.08 + 1.35 * (1 - c.hit)) * (1 + .1 * wob); |
| 157 | float shockBoost = 1 + 2.5 * c.hit * exp(-(r - Rh) * (r - Rh) / .008); |
| 158 | float newRing = (glow(r - Rh, .012) * 2.2 + glow(r - Rh, .06) * .4) * c.hit; |
| 159 | |
| 160 | float inner = smoothstep(Ri, Ri * .25f, r); |
| 161 | float wisp = fbm2(p * 3 + float2(c.t * .02, 1.3), 3); |
| 162 | float Rs = R * (1.15 + .1 * (noise2(dirv * 3.1 + 2.2) - .5)); |
| 163 | float forward = glow(r - Rs, .006) * .9 + glow(r - Rs, .045) * .2; |
| 164 | float outside = smoothstep(Rs * .98f, Rs * 1.1f, r); |
| 165 | |
| 166 | float haze = fbm2(p * .9 + float2(4.1, c.t * .01), 3); |
| 167 | float3 col = deep(.9 + haze * .2, f) * (.05 + .12 * haze * haze); |
| 168 | col += paint(.95 + .1 * haze, f) * smoothstep(.5f, .85f, haze) * .06 * outside; |
| 169 | col += paint(.92, f) * shell * shell * .1; |
| 170 | col += paint(mix(.8f, .6f, tip), f) * band * fingerA * (.38 + 2 * c.b.x) * shockBoost; |
| 171 | col += paint(.06 + .12 * tip, f) * band * fingerB * (.24 + 2 * c.b.y) * shockBoost; |
| 172 | col += paint(.5, f) * band * fingerA * bead * (.3 + 3 * c.b.w) * shockBoost; |
| 173 | col += paint(1 - .1 * wisp, f) * inner * pow(wisp, 3.f) * (.4 + 1.8 * c.b.z); |
| 174 | col += paint(.02, f) * forward; |
| 175 | col += paint(.65, f) * newRing + paint(.5, f) * (glow(r, .02) * 1.4 + glow(r, .07) * .25); |
| 176 | col += paint(.6, f) * cosmStars(p * 11, .2, c.t) * .4 * outside; |
| 177 | return col; |
| 178 | } |
| 179 | NATIVE_EFFECT(supernovaShellII) |
| 180 | |
| 181 | // ---------------------------------------------------------------- 353 Galaxy Collision |
| 182 | // Two-armed log spiral in its own (de-projected) plane: x = arm A, y = arm B (broad), |
| 183 | // z = arm A spine, w = arm B spine (thin glowing cores). Radius returned separately. |
| 184 | float4 cosmSpiral(float2 q, float spin, float wind, thread float &r) { |
| 185 | r = max(length(q), 1e-3f); |
| 186 | float c1 = cos(atan2(q.y, q.x) - wind * log(r) - spin); |
| 187 | float a = max(c1, 0.f), b = max(-c1, 0.f); |
| 188 | return float4(pow(a, 6.f), pow(b, 6.f), pow(a, 110.f), pow(b, 110.f)); |
| 189 | } |
| 190 | |
| 191 | float3 galaxyCollisionII(Ctx c, constant NativeFrame &f) { |
| 192 | float2 p = cosmLongAxis(c.uv / c.size, c.extent); |
| 193 | float orbit = c.t * .035; |
| 194 | // A close pair near the centre: the forward-zoom echo lands on their own discs and tails. |
| 195 | float2 c1 = rot(float2(-.36, .1), orbit), c2 = rot(float2(.4, -.1), orbit); |
| 196 | float2 q1 = rot(p - c1, .5 + orbit); q1.y /= .6; |
| 197 | float2 q2 = rot(p - c2, -.9 + orbit); q2.y /= .5; |
| 198 | float r1, r2; |
| 199 | float4 g1 = cosmSpiral(q1 * .8, c.t * .16, 2.3, r1), g2 = cosmSpiral(q2 * .9, -c.t * .13, -2.1, r2); |
| 200 | float clumps = .45 + .55 * noise2(p * 9 + float2(c.t * .05, 0)); |
| 201 | |
| 202 | float disc1 = exp(-r1 * 2.6), disc2 = exp(-r2 * 3); |
| 203 | // Tidal tails: the outer arms keep going on the side facing away from the partner. |
| 204 | float2 away1 = normalize(c1 - c2); |
| 205 | float tailMask1 = smoothstep(-.2f, .5f, dot(normalize(p - c1 + 1e-4), away1)) * smoothstep(.25f, .6f, r1); |
| 206 | float tailMask2 = smoothstep(-.2f, .5f, dot(normalize(p - c2 + 1e-4), -away1)) * smoothstep(.25f, .6f, r2); |
| 207 | float tail1 = (g1.x * .6 + g1.z) * exp(-r1 * .75) * tailMask1; |
| 208 | float tail2 = (g2.y * .6 + g2.w) * exp(-r2 * .8) * tailMask2; |
| 209 | |
| 210 | // A bridge of stars stretched between the pair. |
| 211 | float2 dv = c2 - c1; float len = length(dv); |
| 212 | float2 ax = dv / len, rel = p - c1; |
| 213 | float u = dot(rel, ax) / len, v = dot(rel, float2(-ax.y, ax.x)); |
| 214 | float bridgeDist = abs(v - .16 * len * sin(PI * clamp(u, 0.f, 1.f))); |
| 215 | float bridge = (glow(bridgeDist, .025) + glow(bridgeDist, .005)) * smoothstep(-.05f, .2f, u) * smoothstep(1.05f, .8f, u); |
| 216 | |
| 217 | float armA = (g1.x * .35 + g1.z * 2.1) * disc1, armB = (g1.y * .35 + g1.w * 2.1) * disc1; |
| 218 | float armC = ((g2.x + g2.y) * .35 + (g2.z + g2.w) * 2.1) * disc2; |
| 219 | float tails = tail1 + tail2 + bridge * .5; |
| 220 | |
| 221 | // Starburst knots sit on the arms; attacks blossom them with an expanding ring. |
| 222 | float2 kq = p * 7, kid = floor(kq), kl = (fract(kq) - .5 - (hash22(kid + 2.7) - .5) * .6) / 7; |
| 223 | float kd = length(kl); |
| 224 | float knotOn = step(.6, hash21(kid + 6.1)); |
| 225 | float host = min(1.f, (armA + armB + armC) * 2 + tails * 2); |
| 226 | float knot = knotOn * host * (glow(kd, .006 + .014 * c.hit) * (.6 + 5 * c.hit) |
| 227 | + glow(kd - (.02 + .08 * (1 - c.hit)), .005) * c.hit * 3 * smoothstep(.5f, .9f, host)); |
| 228 | |
| 229 | float3 col = paint(0, f) * .05 + paint(.2, f) * exp(-min(length(p - c1), length(p - c2)) * 1.3) * .08; |
| 230 | col += paint(.75, f) * armA * clumps * (.5 + 2.4 * c.b.x); |
| 231 | col += paint(.55, f) * armB * clumps * (.5 + 2.4 * c.b.y); |
| 232 | col += paint(.3, f) * armC * clumps * (.55 + 2.4 * c.b.z); |
| 233 | col += paint(.45 + .25 * clumps, f) * tails * clumps * (.45 + 2.2 * c.b.w); |
| 234 | col += paint(.3, f) * (disc1 + disc2) * .1; |
| 235 | col += paint(.8, f) * (exp(-r1 * r1 * 90) * 1.8 + exp(-r2 * r2 * 110) * 1.6); |
| 236 | col += paint(.78, f) * knot; |
| 237 | col += paint(.7, f) * cosmStars(p * 10, .25, c.t) * .5; |
| 238 | return col; |
| 239 | } |
| 240 | NATIVE_EFFECT(galaxyCollisionII) |
| 241 | |
| 242 | // ---------------------------------------------------------------- 354 Solar Prominence |
| 243 | float3 solarProminenceII(Ctx c, constant NativeFrame &f) { |
| 244 | float2 p = c.uv / c.size; |
| 245 | const float Rs = 2.2; |
| 246 | // The limb crosses just below the canvas centre, so the forward-zoom echo of the limb |
| 247 | // stays on the limb instead of drawing a second horizon. |
| 248 | float2 C = float2(0, -.1 - Rs); |
| 249 | float2 d = p - C; float rr = length(d); |
| 250 | float h = rr - Rs; // height above the limb |
| 251 | float s = atan2(d.x, d.y) * Rs; // arc length along the limb |
| 252 | float above = smoothstep(-.004f, .02f, h); |
| 253 | |
| 254 | // Granulated surface, foreshortened toward the limb. |
| 255 | float mu = sqrt(max(0.f, 1 - (rr / Rs) * (rr / Rs))); |
| 256 | float2 gq = float2(s, acos(clamp(rr / Rs, 0.f, 1.f)) * Rs) * 9; |
| 257 | float4 cell = voronoi(gq + float2(c.t * .05, 0), .9, c.t * .6); |
| 258 | float granule = exp(-cell.x * cell.x * 4.5) * smoothstep(0.f, .14f, cell.y - cell.x); |
| 259 | float gran = mix(.55f, granule, smoothstep(0.f, .3f, mu)); |
| 260 | float plage = smoothstep(.55f, .8f, noise2(gq * .09 + 3.3)) * c.b.x; |
| 261 | float sink = .3 + .7 * exp(max(-h, 0.f) * -2.2); // the deep disc settles darker than the limb |
| 262 | // Glowing granules in hot orange over crimson lanes: saturated at every brightness. |
| 263 | float3 surface = (mix(paint(.04, f) * .3, paint(.2 + .32 * gran, f) * (.55 + .5 * mu), gran) |
| 264 | + paint(.75, f) * plage * gran * 1.1) * sink; |
| 265 | float disc = 1 - above; |
| 266 | |
| 267 | float hp = max(h, 0.f); |
| 268 | float streamer = pow(noise2(float2(s * 1.4, hp * .3 - c.t * .04)), 2.f); |
| 269 | float corona = exp(-hp * 2.2) * (.3 + .9 * streamer) + exp(-hp * .45) * streamer * .3; |
| 270 | float spicule = pow(noise2(float2(s * 45, c.t * .7)), 4.f) * 5 * exp(-hp / (.03 + .06 * c.b.w)) * above; |
| 271 | float limb = glow(h, .012); |
| 272 | float tall = 1 + .45 * max(c.extent.y - c.extent.x, 0.f); // taller loops on portrait canvases |
| 273 | // A faint arcade of nested field arches high in the corona. |
| 274 | float sa = (floor(s / 1.1) + .5) * 1.1; |
| 275 | float2 ea = float2((s - sa) / .55, hp / ((.8 + .2 * sin(sa * 3.1 + c.t * .1)) * tall)); |
| 276 | float ela = length(ea); |
| 277 | float arcade = glow(cosmContour(ela * 5, c.px) / c.size, .0035) * smoothstep(.98f, .85f, ela) * smoothstep(.2f, .35f, ela); |
| 278 | |
| 279 | float3 col = surface * disc; |
| 280 | col += (paint(0, f) * (.05 + .07 * streamer) + paint(.25 + .35 * streamer, f) * corona * .6) * above; |
| 281 | col += paint(.45, f) * arcade * above * (.2 + 1.3 * c.b.y); |
| 282 | col += paint(.85, f) * limb * .9 + paint(.3, f) * spicule * (.4 + 1.5 * c.b.w); |
| 283 | |
| 284 | // Prominence loops: twisted triple-strand arches, each band lifting its own loops. |
| 285 | for (int k = 0; k < 6; ++k) { |
| 286 | float fk = float(k), level = c.b[k % 4]; |
| 287 | float sk = (fk - 2.5) * .95 + .25 * sin(c.t * .05 + fk * 1.3); |
| 288 | float w = .2 + .16 * hash11(fk + 3.1); |
| 289 | float H = (.26 + .3 * hash11(fk + 8.7)) * (.6 + 1.2 * level) * (1 + .08 * sin(c.t * .3 + fk)) * tall; |
| 290 | float tilt = .5 * (hash11(fk + 1.9) - .5); |
| 291 | float2 e = float2((s - sk - h * tilt) / w, h / H); |
| 292 | float el = length(e), along = atan2(e.y, e.x), scale = min(w, H); |
| 293 | float rope = 0; |
| 294 | for (int j = 0; j < 3; ++j) { |
| 295 | float off = .09 * sin(along * 5 + c.t * 1.1 + float(j) * 2.09 + fk); |
| 296 | rope += glow((el - 1 - off) * scale, .005 + .003 * level); |
| 297 | } |
| 298 | float flow = pow(cosmWave(along * 7 - c.t * 2.2 + fk * 2 - PI * .5), 4.f); |
| 299 | float halo = glow((el - 1) * scale, .035) * .3; |
| 300 | col += paint(.55 + .3 * flow + .05 * fk, f) * (rope * (.4 + .6 * flow) + halo) * above * (.3 + 1.5 * level); |
| 301 | } |
| 302 | |
| 303 | // Attacks launch an ejection: a bright-fronted bubble rising off the limb. |
| 304 | float site = 1.1 * sin(c.t * .045); |
| 305 | float lift = 1 - c.hit; |
| 306 | float2 eb = float2(s - site, h - (.06 + lift * 1.1)); |
| 307 | float rad = .08 + lift * .5; |
| 308 | float bubble = length(eb * float2(1, 1.15)) - rad; |
| 309 | float cme = glow(bubble, .02 + .03 * lift) * 1.4 + glow(length(eb + float2(0, rad * .5)), .04 + .06 * lift) * .9; |
| 310 | col += paint(.88, f) * cme * c.hit * (.5 + .5 * c.hit) * 2 * above; |
| 311 | return col * .85; |
| 312 | } |
| 313 | NATIVE_EFFECT(solarProminenceII) |
| 314 | |
| 315 | // ---------------------------------------------------------------- 355 Quasar Jet |
| 316 | float3 quasarJetII(Ctx c, constant NativeFrame &f) { |
| 317 | float2 p = c.uv / c.size; |
| 318 | float ang = atan2(c.extent.y, c.extent.x) * .85 + .17 * sin(c.t * .09); |
| 319 | float2 q = rot(p, -ang); |
| 320 | float ax = abs(q.x), side = q.x < 0 ? -1.f : 1.f; |
| 321 | const float L = 1.15; |
| 322 | float reach = smoothstep(L + .15f, L - .25f, ax); |
| 323 | float wj = .022 + .06 * ax; |
| 324 | float flick = noise2(float2(ax * 7 - c.t * 6, side * 3.7)); |
| 325 | float jetLevel = .6 + .4 * flick + c.b.w * 2.6 * flick * flick; |
| 326 | float jet = exp(-q.y * q.y / (wj * wj)) * reach / (1 + ax * .6) * jetLevel; |
| 327 | float spine = glow(q.y, .0035 + .002 * ax) * reach / (1 + ax) * jetLevel; |
| 328 | |
| 329 | float helix = 0; |
| 330 | for (int j = 0; j < 2; ++j) { |
| 331 | float ph = ax * 13 - c.t * 2.2 + float(j) * PI + side; |
| 332 | helix += glow(q.y - wj * .85 * sin(ph), .004 + .002 * ax) * (.55 + .45 * cos(ph)); |
| 333 | } |
| 334 | helix *= reach * (.3 + 1.8 * c.b.z); |
| 335 | |
| 336 | float knots = 0; |
| 337 | for (int k = 0; k < 4; ++k) { |
| 338 | float ph = fract(c.t * .075 + float(k) * .25 + (side > 0 ? 0.f : .125f)); |
| 339 | knots += glow(length(float2(ax - ph * L, q.y * 1.4)), .018 + .02 * ax) * sin(PI * ph); |
| 340 | } |
| 341 | float lx = .06 + (1 - c.hit) * L * .85; |
| 342 | float launch = (glow(length(float2(ax - lx, q.y * 1.3)), .03 + .035 * lx) * 3 + glow(length(float2(ax - lx, q.y)), .15) * .4) |
| 343 | * c.hit * reach; |
| 344 | |
| 345 | // Radio lobes where the jets stall, with hot spots and glowing rims. |
| 346 | float2 lc = q - float2(side * L, 0); |
| 347 | float lt = fbm2(q * 2.3 + float2(-side * c.t * .04, c.t * .03), 4); |
| 348 | float lobeShape = length(lc * float2(.8, 1.2)) - (.34 + .26 * lt); |
| 349 | float strands = cosmRidge(lc * 3.4 + float2(c.t * .05, side * 2.3) + lt, 3) / .875; |
| 350 | float lobe = (smoothstep(.1f, -.25f, lobeShape) * .85 + exp(-max(lobeShape, 0.f) * 4) * .15) * (.15 + .85 * pow(strands, 3.f)); |
| 351 | float lobeRim = glow(lobeShape, .012) * (.2 + .8 * lt); |
| 352 | float hotspot = glow(length(lc + float2(side * .12, 0)), .04); |
| 353 | |
| 354 | float sheathW = .12 + .22 * ax / L; |
| 355 | float sheath = exp(-q.y * q.y / (sheathW * sheathW)) * reach; |
| 356 | float backflow = noise2(float2(ax * 4 + c.t * .5, q.y * 9)); |
| 357 | float cocoon = sheath * (.3 + .7 * backflow) * (.2 + 1.3 * c.b.y); |
| 358 | |
| 359 | float rp = length(p); |
| 360 | float hostGlow = exp(-length(rot(p, .4) * float2(1, 1.6)) * 2.2); |
| 361 | float haze = fbm2(p * 1.1 + float2(c.t * .05, 3), 4); |
| 362 | |
| 363 | float3 col = paint(.02 + haze * .2, f) * (.05 + .14 * haze * haze); |
| 364 | col += paint(.3 + .5 * strands, f) * lobe * (.3 + 1.6 * c.b.x) + paint(.85, f) * (lobeRim * .3 + hotspot) * (.5 + 1.2 * c.b.x); |
| 365 | col += paint(.45, f) * cocoon; |
| 366 | col += paint(.6, f) * jet * .8 + paint(.95, f) * spine * 1.2; |
| 367 | col += paint(.8, f) * helix; |
| 368 | col += paint(.95, f) * (knots * 1.2 + launch); |
| 369 | col += paint(.5, f) * hostGlow * .22 + paint(.98, f) * (glow(rp, .022) * 3 + glow(rp, .1) * .25); |
| 370 | col += paint(.9, f) * cosmStars(p * 10, .22, c.t) * .5; |
| 371 | return col * .85; |
| 372 | } |
| 373 | NATIVE_EFFECT(quasarJetII) |
| 374 | |
| 375 | |
| 376 | // ---------------------------------------------------------------- 357 Magnetosphere |
| 377 | float3 magnetosphereII(Ctx c, constant NativeFrame &f) { |
| 378 | float2 p = cosmLongAxis(c.uv / c.size, c.extent); |
| 379 | // The planet sits at the canvas centre, where the forward-zoom echo of the dipole field |
| 380 | // lands on the field itself. |
| 381 | float2 q = rot(p, .25 * sin(c.t * .14)); |
| 382 | const float Rp = .12; |
| 383 | // Dayside compressed by the wind (harder on attacks), nightside stretched into a tail. |
| 384 | float press = 1.45 + .15 * sin(c.t * .3) + .4 * c.hit; |
| 385 | float xd = q.x * mix(press, 1 / (1 + 1.25 * max(q.x, 0.f)), smoothstep(-.1f, .1f, q.x)); |
| 386 | float flap = .2 * sin(q.x * 2.2 - c.t * .8) * smoothstep(0.f, 1.5f, q.x); // the tail flaps in the wind |
| 387 | float rd = length(float2(xd, q.y + flap)); |
| 388 | float shellL = rd * rd * rd / max(xd * xd, 1e-6f); |
| 389 | float lv = log2(shellL) * 2.4 - c.t * .22; // field shells drift steadily outward |
| 390 | float id = floor(lv + .5); |
| 391 | float level = cosmBand(c.b, id - 4 * floor(id / 4)); |
| 392 | float lat = atan2(q.y, abs(xd)); |
| 393 | float bounce = .55 + .45 * pow(cosmWave(lat * 8 - c.t * 3 + id * 1.7 - PI * .5), 3.f); |
| 394 | float xm = -.62 + .7 * q.y * q.y; // magnetopause |
| 395 | float inside = smoothstep(xm - .02, xm + .03, q.x) * smoothstep(Rp, Rp * 1.3, length(q)); |
| 396 | float fieldD = cosmContour(lv, c.px) / c.size; |
| 397 | float crowd = smoothstep(.45f, .15f, fwidth(lv)); // fade lines where they bunch at the poles |
| 398 | float field = (glow(fieldD, .0045 + .003 * level) * bounce * crowd + glow(fieldD, .025) * .15 * crowd + .08 * (1 - crowd)) |
| 399 | * inside * (.3 + 1.7 * level); |
| 400 | |
| 401 | // Solar wind streamlines bending around the bow shock. |
| 402 | const float xb0 = -.86; |
| 403 | float body = 2.6 * .08 * log(1 + exp((q.x - xb0) / .08)); |
| 404 | float y2 = q.y * q.y; |
| 405 | float eta = sign(q.y) * sqrt(max(y2 - body, 0.f)); |
| 406 | float outside = smoothstep(0.f, .02f, y2 - body); |
| 407 | float wv = eta * 9; |
| 408 | float windD = cosmContour(wv, c.px) / c.size; |
| 409 | float dash = pow(cosmWave(q.x * 12 - c.t * 4 + hash11(floor(wv + .5)) * TAU - PI * .5), 6.f); |
| 410 | float wind = (glow(windD, .003) * (.25 + dash * (.5 + 2.2 * c.b.w))) * outside * smoothstep(.45f, .15f, fwidth(wv)); |
| 411 | float sheathMask = (1 - outside) * (1 - inside) * smoothstep(Rp, Rp * 1.3, length(q)); |
| 412 | float sheath = fbm2(q * 4 + float2(-c.t * .3, 0), 3) * sheathMask; |
| 413 | float bowD = abs(q.x - xb0 - y2 / 2.6) / sqrt(1 + (2 * q.y / 2.6) * (2 * q.y / 2.6)); |
| 414 | float mpD = abs(q.x - xm) / sqrt(1 + (1.4 * q.y) * (1.4 * q.y)); |
| 415 | |
| 416 | // Attacks fire an interplanetary shock front across the scene. |
| 417 | float xf = -2.8 + (1 - c.hit) * 5.4; |
| 418 | float shockD = q.x - xf - .25 * y2; |
| 419 | float shock = (glow(shockD, .02) * 2 + glow(shockD, .12) * .35 * step(shockD, 0.f)) * c.hit; |
| 420 | |
| 421 | float2 pole = float2(0, Rp * .9); |
| 422 | float aurora = glow(abs(length((q - pole) * float2(1, 3.2)) - .045), .006) + glow(abs(length((q + pole) * float2(1, 3.2)) - .045), .006); |
| 423 | |
| 424 | float pr = length(q) / Rp; |
| 425 | float disc = fill(pr - 1, c.px / Rp); |
| 426 | float2 nrm = q / Rp; |
| 427 | float day = clamp(-nrm.x * .9 + .25, 0.f, 1.f) * sqrt(max(0.f, 1 - pr * pr)); |
| 428 | |
| 429 | float haze = fbm2(p * 1.4 + float2(-c.t * .12, 0), 3); |
| 430 | float3 col = paint(.02 + haze * .2, f) * (.05 + .12 * haze * haze); |
| 431 | col += paint(.35, f) * sheath * .55; |
| 432 | col += paint(.25 + .1 * id, f) * field * .9 + paint(.15, f) * wind; |
| 433 | col += paint(.8, f) * (glow(bowD, .006) * .9 + glow(bowD, .05) * .2) + paint(.6, f) * glow(mpD, .005) * inside * .4; |
| 434 | col += paint(.92, f) * shock + paint(.95, f) * aurora * (.3 + 2 * c.b.z); |
| 435 | float dayRim = glow((pr - 1) * Rp, .005) * clamp(.45 - nrm.x * .7, 0.f, 1.f); |
| 436 | col = mix(col, deep(.1 + .2 * day, f) * .25 + paint(.4 + .3 * day, f) * day * .75, disc); |
| 437 | col += paint(.75, f) * dayRim * 1.3 + paint(.5, f) * glow(max(pr - 1, 0.f) * Rp, .02) * .35; |
| 438 | col += paint(.9, f) * cosmStars(p * 9, .2, c.t) * .4; |
| 439 | return col; |
| 440 | } |
| 441 | NATIVE_EFFECT(magnetosphereII) |
| 442 | |
| 443 | // ---------------------------------------------------------------- 358 Nebular Filaments |
| 444 | struct CosmCells { float d1; float d3; float edge; float2 a; float2 b; }; |
| 445 | CosmCells cosmCells(float2 p, float phase) { |
| 446 | float2 cell = floor(p), fp = fract(p); |
| 447 | float d1 = 64, d2 = 64, d3 = 64; float2 a = 0, b = 0, sa = 0, sb = 0; |
| 448 | float cosine, sine = sincos(phase, cosine); // every site circles its cell at one rate |
| 449 | for (int y = -1; y <= 1; ++y) for (int x = -1; x <= 1; ++x) { |
| 450 | float2 g = float2(x, y), id = cell + g; |
| 451 | uint seed = canvasSeed(canvasPair(id)); // one mix, split into two channels |
| 452 | float2 o = float2(float(seed & 0xFFFFu), float(seed >> 16)) * (.6f / 65536.f) - .3f; |
| 453 | float2 site = g + .5 + float2(o.x * cosine - o.y * sine, o.x * sine + o.y * cosine); |
| 454 | float2 delta = site - fp; |
| 455 | float d = dot(delta, delta); |
| 456 | bool first = d < d1, second = d < d2; // branch-free insertion keeps SIMD lanes together |
| 457 | d3 = second ? d2 : min(d3, d); |
| 458 | d2 = first ? d1 : (second ? d : d2); |
| 459 | b = first ? a : (second ? id : b); |
| 460 | sb = first ? sa : (second ? site : sb); |
| 461 | d1 = first ? d : d1; a = first ? id : a; sa = first ? site : sa; |
| 462 | } |
| 463 | CosmCells k; |
| 464 | k.d1 = sqrt(d1); k.d3 = sqrt(d3); k.a = a; k.b = b; |
| 465 | k.edge = abs(dot(fp - .5 * (sa + sb), normalize(sb - sa + 1e-5))); |
| 466 | return k; |
| 467 | } |
| 468 | |
| 469 | float3 cosmicWebII(Ctx c, constant NativeFrame &f) { |
| 470 | float2 p = c.uv / c.size; |
| 471 | float r = length(p); |
| 472 | // A supercluster sits ahead: the web crowds toward it, brightens and feeds it great filaments. |
| 473 | float well = exp(-r * 1.5), pull = 1 + 1.3 * exp(-r * 1.3); |
| 474 | float haze = fbm2(c.uv * .8 + float2(c.t * .01, 0), 2); |
| 475 | float3 col = paint(.02 + haze * .2, f) * (.03 + .1 * haze * haze) + paint(.45, f) * well * .08; |
| 476 | float bend = atan2(p.y, p.x) + .35 * sin(r * 2.2 - c.t * .12); |
| 477 | float spoke = glow(r * abs(sin(3 * bend)) / 3, .004 + .012 * r) * smoothstep(.05f, .25f, r) * exp(-r * .45); |
| 478 | for (int k = 0; k < 4; ++k) { |
| 479 | float2 s = layerSlot(k, 4, c.travel * .07); |
| 480 | float sc = layerScale(s.x, 2) * pull; |
| 481 | float2 q = rot(p * sc, s.y * 1.1) + hash22(float2(s.y, 7.3)) * 40; |
| 482 | q += .32 * sin(q.yx * float2(.9, 1.1) + float2(s.y, s.y * 1.7 + 2)); // bend the filaments |
| 483 | CosmCells v = cosmCells(q, c.t * .25 + s.y); |
| 484 | float edge = v.edge / sc, node = (v.d3 - v.d1) / sc; |
| 485 | float pair = hash21(v.a + v.b); |
| 486 | float band = floor(pair * 3.999); |
| 487 | float level = cosmBand(c.b, band); |
| 488 | float strength = fract(pair * 7.3); // some filaments thick and bright, some faint |
| 489 | float fade = layerFade(s.x) * (.3 + .7 * s.x) * (1 - c.fog * .5 * (1 - s.x)) * (.42 + .5 * well); |
| 490 | float beads = .55 + .45 * sin(q.x * 6.3 + s.y) * sin(q.y * 5.7 - s.y); |
| 491 | float pulseAlong = .6 + .4 * sin(v.d1 * 9 - c.t * 2 + hash21(v.a) * TAU); |
| 492 | float wide = (.0015 + .004 * s.x) * (.6 + strength) * (1 + 1.5 * exp(-node * sc * 4)); // thicker near clusters |
| 493 | float fil = (glow(edge, wide * (1 + 1.2 * level)) * (.4 + 2.2 * level) * beads * pulseAlong |
| 494 | + glow(edge, .03 * (.4 + s.x)) * .08) * (.3 + 1.1 * strength); |
| 495 | float lightUp = step(.45, hash21(v.a + 3.3)); |
| 496 | float flare = 1 + 3.5 * c.hit * lightUp; |
| 497 | float hub = glow(node, .009 + .018 * s.x) * flare + glow(node, .07 * (.4 + s.x)) * .28 * flare; |
| 498 | col += (paint(.25 + s.y * .11 + band * .1, f) * fil + paint(.75, f) * hub) * fade; |
| 499 | } |
| 500 | col += paint(.6, f) * spoke * (.4 + 1.2 * c.b.x); |
| 501 | col += paint(.78, f) * (glow(r, .03) * 1.2 + glow(r, .15) * .15) * (1 + 1.5 * c.hit); |
| 502 | return col * .8; |
| 503 | } |
| 504 | NATIVE_EFFECT(cosmicWebII) |
| 505 | |
| 506 | // ---------------------------------------------------------------- 359 Einstein Ring |
| 507 | float3 cosmGalaxySource(float2 d, float spin, float hue, constant NativeFrame &f) { |
| 508 | float r = length(d); |
| 509 | float phi = atan2(d.y, d.x) - 2.6 * log(r + .02); |
| 510 | float arms = pow(cosmWave(2 * phi - spin), 5.f); |
| 511 | float body = exp(-r * 6) * (.15 + .85 * arms) * 1.4 + exp(-r * r * 300) * 1.8; |
| 512 | return paint(hue + .3 * exp(-r * 6), f) * body; |
| 513 | } |
| 514 | |
| 515 | float3 einsteinRingII(Ctx c, constant NativeFrame &f) { |
| 516 | float2 th = c.uv / c.size; |
| 517 | float r = max(length(th), 1e-3f); |
| 518 | // Point lens plus a slowly turning external shear; mass breathes with the bass. |
| 519 | float thetaE = .56 * (1 + .3 * c.b.x); |
| 520 | float2 beta = th - thetaE * thetaE * th / (r * r); |
| 521 | float sa = c.t * .03; |
| 522 | float2 sh = float2(cos(2 * sa), sin(2 * sa)) * .1; |
| 523 | beta -= float2(sh.x * th.x + sh.y * th.y, sh.y * th.x - sh.x * th.y); |
| 524 | float centre = smoothstep(.06f, .22f, r); |
| 525 | |
| 526 | float bg = fbm2(beta * 1.6 + float2(3, c.t * .01), 4); |
| 527 | float3 col = deep(.9 + bg * .2, f) * (.04 + .1 * bg * bg) * centre; |
| 528 | col += paint(.1 + bg * .8, f) * pow(smoothstep(.45f, .9f, bg), 2.f) * .12 * centre; |
| 529 | // A field of faint background galaxies, sheared into tangential arclets around the lens. |
| 530 | float2 gq = beta * 3.2 + float2(7.1, 2.3); |
| 531 | float2 gid = floor(gq); |
| 532 | float3 gh = hash33(float3(gid, 4.7)); |
| 533 | float2 home = (gid + .5 - float2(7.1, 2.3)) / 3.2; // each galaxy lies along its circle |
| 534 | float2 go = rot(fract(gq) - .5 - (gh.xy - .5) * .45, -atan2(home.y, home.x) + (gh.z - .5) * .5) * float2(2.4, 1); |
| 535 | float arclet = exp(-dot(go, go) * 55) * step(.3f, gh.x) * smoothstep(thetaE * .75f, thetaE * 1.05f, r); |
| 536 | col += paint(gh.z > .5 ? .02 + .2 * gh.y : .74 + .22 * gh.y, f) * arclet * (.35 + 1.2 * c.b.w) * centre; |
| 537 | // A compact source almost exactly behind the lens: its image is a crisp near-complete ring |
| 538 | // on the Einstein radius, which swells and contracts with the lens mass. |
| 539 | float2 b0 = .05 * float2(cos(c.t * .11), sin(c.t * .13)); |
| 540 | float d0 = length(beta - b0); |
| 541 | col += paint(.02 + 2 * d0, f) * (exp(-d0 * d0 * 1400) * 2.2 + exp(-d0 * 12) * .35) * (.5 + 1.4 * c.b.x) * centre; |
| 542 | for (int j = 0; j < 5; ++j) { |
| 543 | float fj = float(j); |
| 544 | float2 home = float2(cos(fj * 2.4 + 1), sin(fj * 2.4 + 1)) * (.1 + .36 * fract(fj * .618 + .2)); |
| 545 | float2 sp = rot(home, c.t * (.04 + .015 * fj) * (j % 2 == 0 ? 1 : -1)); |
| 546 | float2 d = rot(beta - sp, fj * 1.3 + c.t * .1); |
| 547 | d.y /= .6; |
| 548 | float level = c.b[j % 4]; |
| 549 | float hue = j % 2 == 0 ? .02 + fj * .04 : .72 + fj * .05; // cool and hot sources alternate |
| 550 | col += cosmGalaxySource(d * (1.5 + fj * .15), c.t * .3 + fj, hue, f) * (.6 + 2.8 * level) * centre; |
| 551 | } |
| 552 | // Attacks slide a bright new source behind the lens: a ring forms, then breaks into arcs. |
| 553 | float2 sh2 = rot(float2(-.08 + (1 - c.hit) * .9, .04), c.t * .07); |
| 554 | float flash = length(beta - sh2); |
| 555 | col += paint(.75, f) * (glow(flash, .035) * 3 + glow(flash, .12) * .6) * c.hit * centre; |
| 556 | col += paint(.6, f) * cosmStars(beta * 9, .25, c.t) * .5 * centre; |
| 557 | col += paint(.9, f) * glow(r, .05) * .3; |
| 558 | return col; |
| 559 | } |
| 560 | NATIVE_EFFECT(einsteinRingII) |