Branchwell

PulseCanvas / app · pulsecanvas.ai / Sources / PulseCanvas / Resources / NativeExpansionFlight.metal

Raw 36.3 KB on 23ffa4e102ea595ec83f2b18683b75332fc815c3
1// Original PulseCanvas designs 330–339. Flights that are not roads: canopies, strata,
2// pillar forests, parallax silhouettes, river deltas, auroras, waterfalls, orbits, comets
3// and cloud seas. Every scene is analytic (plane, sphere and layer intersections); no
4// preset formulas, textures or third-party shader sources are used.
5
6// ---------------------------------------------------------------- 330 Canopy Flight
7// Rows of hanging crystals are evaluated analytically at their own depth. The floor is a
8// mirror: the same rows are reused with world height reflected, so the reflection is exact.
9
10constant float CANOPY_CEIL = 1.f;
11constant float CANOPY_FLOOR = -.85f;
12constant float CANOPY_ROW = 1.15f;
13constant float CANOPY_COL = .95f;
14
15float canopy_rhombus(float2 q, float2 r) {
16 q = abs(q);
17 return (q.x * r.y + q.y * r.x - r.x * r.y) / length(r);
18}
19
20struct CanopyPendant { float2 anchor; float wire; float2 size; float sway; float energy; float3 tone; };
21
22CanopyPendant canopy_make(float rowId, float cell, float stagger, Ctx c, constant NativeFrame &f) {
23 CanopyPendant k;
24 float3 h = hash33(float3(rowId, cell, 3.1));
25 k.anchor = float2((cell + stagger + (h.x - .5f) * .3f) * CANOPY_COL, CANOPY_CEIL);
26 k.wire = .05f + .38f * h.y;
27 k.size = float2(.06f + .05f * h.z, .13f + .14f * hash21(float2(cell, rowId + .5f)));
28 k.sway = (.07f + .34f * c.b.x) * sin(c.t * 1.05f + h.x * 6.28f + rowId * .4f) + .025f * sin(c.t * 2.3f + h.y * 9);
29 float band = c.b[int(h.z * 3.99f)];
30 float ripple = c.hit * pow(.5f + .5f * sin(rowId * .75f + cell * .45f - c.t * 2.4f), 6.f) * 3.2f;
31 k.energy = .5f + 1.9f * band + ripple;
32 k.tone = paint(h.x * .5f + rowId * .06f + cell * .11f, f);
33 return k;
34}
35
36float3 canopy_pendant(float2 w, CanopyPendant k, float pw, Ctx c, constant NativeFrame &f) {
37 float2 q = rot(w - k.anchor, -k.sway);
38 float2 local = q - float2(0, -k.wire - k.size.y);
39 float body = canopy_rhombus(local, k.size);
40 float facet = local.x > 0 ? .45f : 1.f;
41 float ridge = glow(local.x, pw * 1.5f + .004f) * .8f + glow(local.y, pw * 1.5f + .004f) * .5f;
42 float core = exp(-dot(local / k.size, local / k.size) * 2.5f);
43 float inside = fill(body, pw);
44 float3 col = k.tone * inside * (facet * (.3f + .35f * (1 - abs(local.y) / k.size.y)) + ridge + core * .6f) * k.energy;
45 col += k.tone * glow(body, .01f + pw) * .9f * k.energy;
46 col += k.tone * glow(body, .09f) * .07f * k.energy;
47 float wireD = sdSegment(q, float2(0), float2(0, -k.wire));
48 col += k.tone * glow(wireD, pw + .003f) * .3f;
49 float tip = length(q - float2(0, -k.wire - 2 * k.size.y));
50 col += paint(.92f, f) * glow(tip, .008f + pw) * (.35f + 3 * c.b.w);
51 return col;
52}
53
54// A crystal seen in the dark mirror: a soft vertical smear of its light.
55float3 canopy_reflection(float2 w, CanopyPendant k) {
56 float2 center = k.anchor + rot(float2(0, -k.wire - k.size.y), k.sway);
57 float2 d = w - center;
58 float spread = k.size.x * (1.4f + .5f * abs(d.y));
59 float streak = exp(-d.x * d.x / (spread * spread)) * exp(-abs(d.y) * 1.1f) * smoothstep(-2.6f, -1.6f, w.y);
60 return k.tone * streak * k.energy * .4f;
61}
62
63float3 canopy_ceiling(float2 w, float dz, Ctx c, constant NativeFrame &f) {
64 float3 col = deep(.3f, f) * .025f;
65 float row0 = floor(w.y / CANOPY_ROW);
66 for (int r = 0; r < 2; ++r) {
67 float rowId = row0 + float(r);
68 float stagger = hash11(rowId + .37f);
69 float cellF = w.x / CANOPY_COL - stagger;
70 float cell = floor(cellF + .5f);
71 float other = cell + (cellF > cell ? 1 : -1);
72 for (int m = 0; m < 2; ++m) {
73 CanopyPendant k = canopy_make(rowId, m == 0 ? cell : other, stagger, c, f);
74 float2 d = w - float2(k.anchor.x, rowId * CANOPY_ROW);
75 float r2 = dot(d, d);
76 col += k.tone * (exp(-r2 * 30) * .25f + glow(sqrt(r2), .02f) * .2f) * k.energy;
77 }
78 }
79 return col * exp(-dz * (.05f + .1f * c.fog));
80}
81
82float3 canopyFlightScene(Ctx c, constant NativeFrame &f) {
83 const float lens = 1.3f;
84 const int rows = 12;
85 float2 p = rot(c.uv, .06f * sin(c.travel * .05f + .8f)) / c.size;
86 float camZ = c.travel * 2.4f;
87 float camX = 1.1f * sin(c.travel * .06f) + .2f * sin(c.t * .04f);
88 float ay = max(abs(p.y), .015f);
89 float3 col;
90 if (p.y > 0) {
91 float dz = CANOPY_CEIL * lens / ay;
92 col = canopy_ceiling(float2(p.x * dz / lens + camX, dz + camZ), dz, c, f);
93 } else {
94 float dzFloor = -CANOPY_FLOOR * lens / ay;
95 float2 fw = float2(p.x * dzFloor / lens + camX, dzFloor + camZ);
96 float wobble = .025f * sin(fw.y * 3.1f + sin(fw.x * 2.3f) + c.t * .9f);
97 float dz = (CANOPY_CEIL - 2 * CANOPY_FLOOR) * lens / ay;
98 col = canopy_ceiling(float2(p.x * dz / lens + camX + wobble * dz, dz + camZ), dz, c, f) * .35f;
99 col += deep(.65f, f) * .05f * (.6f + .4f * noise2(fw * 2));
100 }
101 col += paint(.55f, f) * exp(-ay * 7.f) * .12f + paint(.8f, f) * glow(ay, .015f) * .08f;
102 float base = floor(camZ / CANOPY_ROW);
103 for (int j = rows; j >= 1; --j) {
104 float rowId = base + float(j);
105 float dz = rowId * CANOPY_ROW - camZ;
106 float fade = smoothstep(float(rows) * CANOPY_ROW, float(rows - 4) * CANOPY_ROW, dz) * smoothstep(.25f, .9f, dz)
107 * exp(-dz * (.07f + .1f * c.fog));
108 float scale = dz / lens;
109 float2 w = float2(p.x * scale + camX, p.y * scale);
110 bool mirrored = w.y < CANOPY_FLOOR;
111 if (mirrored) {
112 w.y = 2 * CANOPY_FLOOR - w.y;
113 w.x += .05f * sin(w.y * 3 + rowId + c.t * 1.3f) * (1 - w.y);
114 }
115 if (mirrored ? w.y > 3.5f : (w.y < -.05f || w.y > CANOPY_CEIL + .1f)) continue;
116 float stagger = hash11(rowId + .37f);
117 float cellF = w.x / CANOPY_COL - stagger;
118 float cell = floor(cellF + .5f);
119 float other = cell + (cellF > cell ? 1 : -1);
120 CanopyPendant a = canopy_make(rowId, cell, stagger, c, f);
121 CanopyPendant b = canopy_make(rowId, other, stagger, c, f);
122 float3 light;
123 if (mirrored) light = canopy_reflection(w, a) + canopy_reflection(w, b);
124 else {
125 float pw = c.px * scale * 1.2f;
126 light = canopy_pendant(w, a, pw, c, f) + canopy_pendant(w, b, pw, c, f);
127 }
128 col += light * fade;
129 }
130 return col;
131}
132// The reviewed look, with a faint palette floor so tall frames stay covered when zoomed out.
133float3 canopyFlight(Ctx c, constant NativeFrame &f) { return max(canopyFlightScene(c, f), paint(.9, f) * .06); }
134NATIVE_EFFECT(canopyFlight)
135
136// ---------------------------------------------------------------- 331 Strata Glide
137// A thin gap between two vast planes. Each plane carries its own flowing strata: broad
138// warm layers below, finer cross-cut layers above. Seams between layers glow.
139
140float3 strata_plane(float2 w, float dz, bool upper, Ctx c, constant NativeFrame &f) {
141 float s;
142 if (upper) {
143 s = (w.y - w.x) * .26f + 1.6f * fbm2(float2(w.x * .16f + c.t * .03f, w.y * .1f), 3) + c.t * .05f;
144 s += c.b.z * .5f * sin(w.x * .55f - w.y * .3f + c.t * .5f);
145 s *= 5.f;
146 } else {
147 s = (w.x + w.y) * .24f + 1.8f * fbm2(float2(w.x * .12f, w.y * .08f - c.t * .04f), 3) - c.t * .06f;
148 s += c.b.y * .6f * sin(w.x * .5f + w.y * .3f + c.t * .45f);
149 s *= 3.6f;
150 }
151 s += .3f * sin(s * 1.3f);
152 float idx = floor(s), fr = fract(s);
153 float aa = fwidth(s);
154 float detail = 1 - smoothstep(.15f, .6f, aa);
155 float seamD = min(fr, 1 - fr);
156 float seam = (1 - smoothstep(0.f, .03f + aa * 1.5f, seamD)) * detail;
157 float wide = exp(-seamD * 10);
158 float phase = idx * .23f + (upper ? .5f : 0.f);
159 float grain = .75f + .25f * sin(fr * 23 + idx);
160 float layer = mix(.11f, (.04f + .2f * fr * fr) * grain, detail);
161 float3 col = paint(phase, f) * layer * (upper ? .6f + 1.6f * c.b.z : .7f + 1.5f * c.b.y);
162 float hitSeam = (idx - 3 * floor(idx / 3)) == 0 ? 1.f : .2f;
163 float run = pow(.5f + .5f * cos(dz * .5f - c.t * 4.f + idx * .3f), 4.f);
164 col += paint(.88f + idx * .05f, f) * (seam * .9f + wide * .22f * detail) * (1 + c.hit * hitSeam * run * 5);
165 float glint = pow(noise2(w * float2(3.f, 1.5f) + c.t * .3f), 10.f);
166 col += paint(.95f, f) * glint * wide * c.b.w * 14 * detail * smoothstep(1.f, 2.5f, dz);
167 return col;
168}
169
170float3 strataGlide(Ctx c, constant NativeFrame &f) {
171 const float lens = 1.25f;
172 float2 p = c.uv;
173 float camZ = c.travel * 2.6f;
174 float camX = .8f * sin(c.travel * .05f);
175 float gap = .42f * (1 + .5f * c.b.x) * c.size;
176 bool upper = p.y > 0;
177 float ay = max(abs(p.y), .004f);
178 float dz = gap * lens / ay;
179 float2 w = float2(p.x * dz / lens + camX, dz + camZ);
180 float3 col = strata_plane(w, dz, upper, c, f);
181 float3 haze = mix(paint(.62f, f), paint(.8f, f), .5f + .5f * sin(p.x * .7f + c.t * .1f)) * .16f;
182 col = mix(haze, col, exp(-dz * (.03f + .06f * c.fog)));
183 col += paint(.85f, f) * (exp(-ay * 16) * .3f + glow(ay, .008f) * .35f);
184 return col;
185}
186NATIVE_EFFECT(strataGlide)
187
188// ---------------------------------------------------------------- 332 Pillar Forest
189// The camera weaves along a clear path through an endless grid of luminous columns. A 2D
190// grid walk finds the columns front to back; height along each column comes from the ray.
191
192float pillar_path(float z) { return 1.3f * sin(z * .23f) + .55f * sin(z * .51f + 1.3f); }
193float pillar_slope(float z) { return 1.3f * .23f * cos(z * .23f) + .55f * .51f * cos(z * .51f + 1.3f); }
194
195float3 pillarForest(Ctx c, constant NativeFrame &f) {
196 const float lens = 1.15f;
197 float camZ = c.travel * 1.4f;
198 float slope = pillar_slope(camZ);
199 float2 p = rot(c.uv, -slope * .12f) / c.size;
200 float yaw = atan(slope) * .75f;
201 float camY = .3f * sin(c.t * .11f);
202 float2 ro = float2(pillar_path(camZ), camZ);
203 float pitch = .3f + .12f * sin(c.t * .07f);
204 float up = p.y * cos(pitch) + lens * sin(pitch);
205 float2 flat = rot(float2(p.x, lens * cos(pitch) - p.y * sin(pitch)), -yaw);
206 float flatLength = max(length(flat), 1e-3f);
207 float2 rd = flat / flatLength;
208 rd = float2(abs(rd.x) < 1e-4f ? 1e-4f : rd.x, abs(rd.y) < 1e-4f ? 1e-4f : rd.y);
209 float rise = up / flatLength;
210 float elevation = atan2(up, flatLength);
211 float fogK = .26f + .3f * c.fog;
212 float3 fogColor = deep(.55f, f) * .05f + paint(.5f, f) * exp(-elevation * elevation * 9) * .12f + paint(.72f, f) * smoothstep(.4f, 1.4f, elevation) * .2f;
213 float3 col = 0;
214 float trans = 1;
215 float2 cell = floor(ro);
216 float2 stepDir = float2(rd.x > 0 ? 1 : -1, rd.y > 0 ? 1 : -1);
217 float2 tDelta = abs(1 / rd);
218 float2 tMax = (cell + max(stepDir, 0.f) - ro) / rd;
219 for (int i = 0; i < 16; ++i) {
220 float3 h = hash33(float3(cell, 3.7));
221 float2 center = cell + .5f + (h.xy - .5f) * .2f;
222 bool present = h.z > .62f && abs(center.x - pillar_path(center.y)) > .8f;
223 if (present) {
224 float r = .06f + .14f * fract(h.x * 7.31f);
225 float2 o = ro - center;
226 float s0 = -dot(o, rd);
227 float side = o.x * rd.y - o.y * rd.x;
228 float dPerp = abs(side);
229 if (s0 > 0) {
230 float aa = c.px * s0 / lens * 1.3f + .002f;
231 float cover = smoothstep(r + aa, r - aa, dPerp);
232 float u = clamp(side / r, -1.f, 1.f);
233 float sHit = s0 - sqrt(max(r * r - dPerp * dPerp, 0.f));
234 float y = camY + sHit * rise;
235 float ndv = sqrt(max(1 - u * u, 0.f));
236 float band = c.b[int(fract(h.z * 13.7f) * 3.99f)];
237 float energy = .6f + 2.f * band;
238 float rings = pow(.5f + .5f * cos((y * .55f - c.t * .5f + h.x * 5) * TAU), 18.f);
239 float surge = pow(.5f + .5f * cos((y * .2f - c.t * 1.3f + h.y * 3) * TAU), 24.f);
240 float3 tone = paint(.3f + h.x * .5f + y * .03f, f);
241 float segment = .75f + .25f * sin(y * 1.7f + h.y * 9 + c.t * .3f);
242 float3 pc = tone * (.22f + .3f * ndv) * energy * segment;
243 pc += paint(.95f, f) * pow(ndv, 6.f) * .3f * energy;
244 pc += paint(.92f + h.y * .08f, f) * (rings * (.5f + 2.5f * c.hit) + surge * c.hit * 4);
245 float fog = exp(-sHit * fogK);
246 col += trans * cover * mix(fogColor, pc, fog);
247 col += trans * (1 - cover) * tone * (glow(dPerp - r, .04f + .04f * band) * .4f + glow(dPerp - r, .25f) * .06f) * energy * fog;
248 trans *= 1 - cover;
249 }
250 }
251 if (trans < .02f) break;
252 if (tMax.x < tMax.y) { cell.x += stepDir.x; tMax.x += tDelta.x; }
253 else { cell.y += stepDir.y; tMax.y += tDelta.y; }
254 }
255 return col + trans * fogColor;
256}
257NATIVE_EFFECT(pillarForest)
258
259// ---------------------------------------------------------------- 333 Parallax Express
260// A sideways window view: far hills, crystal spires, arch domes and near pylons slide
261// laterally at increasing speeds. Each layer has its own band; attacks flare the pylons.
262
263struct ExpressSpire { float height; float ridge; float id; };
264
265ExpressSpire express_spires(float x, float width, float seed, float lift) {
266 ExpressSpire s; s.height = -9; s.ridge = 9; s.id = 0;
267 float cell = floor(x / width);
268 for (int k = -1; k <= 1; ++k) {
269 float id = cell + float(k);
270 float3 h = hash33(float3(id, seed, 2.7));
271 float apex = (id + .2f + .6f * h.x) * width;
272 float tall = (.3f + .7f * h.y) * lift;
273 float y = tall - abs(x - apex) * (2.4f + 2.6f * h.z);
274 if (y > s.height) { s.height = y; s.ridge = x - apex; s.id = id; }
275 }
276 return s;
277}
278
279float express_hills(float x, float seed) {
280 return .55f * noise2(float2(x * .45f, seed)) + .3f * noise2(float2(x * 1.2f, seed + 4)) + .15f * noise2(float2(x * 3.1f, seed + 9));
281}
282
283float3 parallaxExpress(Ctx c, constant NativeFrame &f) {
284 float2 p = c.uv / c.size;
285 float span = c.extent.y / c.size;
286 float y = p.y / span;
287 float x = p.x;
288 float run = c.travel * 1.1f;
289 float px = c.px / span * 1.5f;
290 // Sky: deep gradient with slow glowing ribbons and faint stars.
291 float drift = noise2(float2(x * .35f - run * .04f, y * 2.5f));
292 float3 col = mix(paint(.3f, f) * .3f, deep(.75f, f) * .07f, smoothstep(-.1f, 1.f, y));
293 col += paint(.55f + y * .2f, f) * pow(.5f + .5f * sin(y * 9 + drift * 4 + c.t * .1f), 10.f) * .22f * smoothstep(0.f, .4f, y);
294 float2 star = float2(x * 18 - run * .4f, y * 18);
295 float2 sid = floor(star);
296 float sh = hash21(sid);
297 col += paint(.9f, f) * glow(length(fract(star) - .5f - (hash22(sid) - .5f) * .6f), .04f) * step(.88f, sh) * (.3f + 2 * c.b.w * sh) * smoothstep(.1f, .5f, y);
298 // Far ridge (bass).
299 float xa = x * .8f + run * .12f;
300 float ha = .05f + .4f * express_hills(xa, 1.3f) + .07f * c.b.x * sin(xa * 2.3f + c.t * .4f);
301 float da = y - ha;
302 col = mix(col, deep(.25f, f) * .12f + paint(.25f, f) * .18f * exp(da * 7), smoothstep(px, -px, da));
303 col += paint(.22f + xa * .03f, f) * glow(da, .01f) * (.45f + 2.f * c.b.x);
304 // Crystal spires (low-mid).
305 float xb = x + run * .38f;
306 ExpressSpire sp = express_spires(xb, .3f, 3, .8f + .4f * c.b.y);
307 float hb = -.4f + sp.height;
308 float db = y - hb;
309 float3 sh3 = hash33(float3(sp.id, 5, 1));
310 float3 spireTone = paint(.4f + sh3.x * .4f, f);
311 float facet = sp.ridge > 0 ? .35f : 1.f;
312 float3 spireFill = deep(.4f, f) * .06f + spireTone * (.03f + .16f * facet * exp(db * 4.f));
313 spireFill += spireTone * glow(sp.ridge, .005f) * .5f * smoothstep(.0f, -.4f, db) * (.4f + 1.6f * c.b.y);
314 col = mix(col, spireFill, smoothstep(px, -px, db));
315 col += spireTone * glow(db, .007f) * (.6f + 2.f * c.b.y);
316 // Neon arches (high-mid): outlines with a faint veil inside.
317 float xc = x + run * .85f;
318 float period = .9f;
319 float u = (fract(xc / period) - .5f) * period;
320 float aid = floor(xc / period);
321 float radius = .27f + .08f * hash11(aid);
322 float base = -.64f;
323 float dome = length(float2(u, y - base)) - radius;
324 float3 archTone = paint(.7f + hash11(aid + 3) * .25f, f);
325 float above = step(base, y);
326 col = mix(col, deep(.75f, f) * .05f, smoothstep(px, -px, y - base));
327 col = mix(col, col * .55f + archTone * .05f, smoothstep(px, -px, dome) * above);
328 col += archTone * glow(dome, .008f) * (.6f + 2.2f * c.b.z) * above;
329 col += archTone * glow(dome + .06f, .005f) * (.25f + 1.4f * c.b.z) * above;
330 col += archTone * glow(y - base, .008f) * .6f;
331 // Near light bars streaking past, with a low ground edge (attacks flare them).
332 float xd = x + run * 2.6f;
333 float pid = floor(xd / 1.4f);
334 float pu = (fract(xd / 1.4f) - .5f) * 1.4f;
335 float ground = -.84f + .025f * sin(xd * 2.1f);
336 float dg = y - ground;
337 float flash = 1 + 4 * c.hit;
338 float3 nearTone = paint(.15f + hash11(pid + 7) * .35f, f);
339 float bar = glow(pu, .03f + .02f * hash11(pid)) * smoothstep(.95f, .2f, y);
340 col += nearTone * bar * .35f * flash;
341 col = mix(col, deep(.15f, f) * .1f + nearTone * .14f * exp(dg * 5), smoothstep(px, -px, dg));
342 col += nearTone * glow(dg, .01f) * .8f * flash;
343 float streaks = pow(.5f + .5f * sin(y * 70 + hash11(floor(y * 11)) * 6), 20.f) * smoothstep(.0f, -.12f, dg);
344 col += paint(.6f + hash11(floor(y * 11)) * .35f, f) * streaks * (.3f + 1.2f * c.b.w) * (.6f + .4f * sin(xd * 3 + y * 40)) * flash;
345 return col;
346}
347NATIVE_EFFECT(parallaxExpress)
348
349// ---------------------------------------------------------------- 334 Delta Flyover
350// Looking straight down on a delta of light. Meandering trunks run downstream; each
351// spawns distributaries that peel off, diverge and taper out; fine capillaries glow
352// around them. Every channel has a world-space id, so the scroll never pops.
353
354constant float DELTA_TRUNK = 2.3f;
355constant float DELTA_CELL = 1.5f;
356
357float delta_trunk(float i, float y) {
358 float h = hash11(i + .71f);
359 return (i + .5f) * DELTA_TRUNK + DELTA_TRUNK * (.26f * sin(y * .21f + h * 6.3f) + .12f * sin(y * .53f + h * 17));
360}
361
362float3 deltaFlyover(Ctx c, constant NativeFrame &f) {
363 float zoom = exp2(.35f * sin(c.t * .031f));
364 float2 p = rot(c.uv / c.size, .25f * sin(c.t * .023f)) * 2.2f * zoom;
365 float2 w = p + float2(1.5f * sin(c.travel * .03f), c.travel * 1.4f);
366 float px = c.px / c.size * 2.2f * zoom;
367 float terrain = fbm2(w * float2(.8f, .45f), 3);
368 float3 col = deep(.3f + terrain * .3f, f) * (.025f + .07f * terrain);
369 float lagoon = fbm2(w * float2(.35f, .2f) + 11, 3);
370 col += paint(.35f + lagoon * .3f, f) * smoothstep(.5f, .68f, lagoon) * .07f;
371 col += paint(.55f, f) * glow(lagoon - .5f, .012f) * .06f;
372 float surge = c.hit * 4;
373 float trunkLight = 0, branchLight = 0, twigLight = 0, wet = 0;
374 float i0 = floor(w.x / DELTA_TRUNK), j0 = floor(w.y / DELTA_CELL);
375 for (int k = -1; k <= 1; ++k) {
376 float i = i0 + float(k);
377 float trunkX = delta_trunk(i, w.y);
378 float trunkD = abs(w.x - trunkX);
379 float pulse = pow(.5f + .5f * sin(w.y * 1.2f + c.t * 3 + i * 2.1f), 10.f);
380 float flow = .7f + .3f * sin(w.y * 6 + c.t * 2.4f + i);
381 trunkLight += (smoothstep(.085f + px, .085f - px, trunkD) * flow * .9f + glow(trunkD, .2f) * .45f) * (1 + surge * pulse);
382 wet += exp(-trunkD * 1.5f);
383 for (int m = 0; m < 4; ++m) {
384 float j = j0 + float(m);
385 float3 h = hash33(float3(i, j, 4.4));
386 if (h.x < .3f) continue;
387 float start = (j + .3f + .4f * h.y) * DELTA_CELL;
388 float len = DELTA_CELL * (1.6f + 1.4f * h.z);
389 float t = (start - w.y) / len;
390 if (t < 0 || t > 1) continue;
391 float side = h.x > .65f ? 1.f : -1.f;
392 float spread = DELTA_TRUNK * (.25f + .3f * h.y) * pow(smoothstep(0.f, 1.f, t), .7f);
393 float branchX = trunkX + side * spread + .08f * sin(w.y * 2.3f + h.z * 9) * t;
394 float d = abs(w.x - branchX);
395 float taper = (1 - t) * smoothstep(0.f, .08f, t);
396 float width = .02f + .035f * (1 - t);
397 float bpulse = pow(.5f + .5f * sin(w.y * 1.6f + c.t * 3.4f + j * 3.3f + i), 10.f);
398 branchLight += (smoothstep(width + px, width - px, d) + glow(d, width * 3) * .45f) * taper * (1 + surge * bpulse);
399 wet += exp(-d * 2.5f) * taper;
400 // Twigs peel off the branch in short sub-cells.
401 float sub = DELTA_CELL * .4f;
402 float k0 = floor(w.y / sub);
403 for (int q = 0; q < 3; ++q) {
404 float kk = k0 + float(q);
405 float3 g = hash33(float3(i * 7 + j, kk, 9.1));
406 float tStart = (kk + .5f) * sub;
407 float tLen = sub * (1.2f + g.z);
408 float u = (tStart - w.y) / tLen;
409 float parentT = (start - tStart) / len;
410 if (g.x < .35f || u < 0 || u > 1 || parentT < .03f || parentT > .9f) continue;
411 float tSide = g.y > .5f ? 1.f : -1.f;
412 float twigX = branchX + tSide * (.18f + .2f * g.z) * pow(u, .7f);
413 float td = abs(w.x - twigX);
414 float tTaper = (1 - u) * smoothstep(0.f, .1f, u) * smoothstep(.03f, .15f, parentT) * smoothstep(.9f, .6f, parentT);
415 twigLight += (smoothstep(.012f + px, .006f, td) + glow(td, .03f) * .35f) * tTaper;
416 }
417 }
418 }
419 col += paint(.92f, f) * trunkLight * (.45f + 1.8f * c.b.x);
420 col += paint(.66f, f) * branchLight * (.45f + 1.9f * c.b.y);
421 col += paint(.45f, f) * twigLight * (.35f + 2.f * c.b.z);
422 col += deep(.6f, f) * min(wet, 1.5f) * .05f;
423 float2 sparkleCell = floor(w * 7);
424 float3 sh = hash33(float3(sparkleCell, 2.9));
425 float sparkle = glow(length(w * 7 - sparkleCell - .2f - sh.xy * .6f), .07f) * step(.75f, sh.z) * (.5f + .5f * sin(c.t * 4 + sh.x * 30));
426 col += paint(.97f, f) * sparkle * min(trunkLight + branchLight, 1.f) * (.2f + 4 * c.b.w);
427 return col;
428}
429NATIVE_EFFECT(deltaFlyover)
430
431// ---------------------------------------------------------------- 335 Aurora Overpass
432// Curtains hang across the sky at stable depths; each folds along its length, and folds
433// seen edge-on glow brighter. The dark plain mirrors the same curtains.
434
435float3 auroraOverpass(Ctx c, constant NativeFrame &f) {
436 const float lens = 1.2f, camH = .6f, gapZ = 1.9f;
437 const int sheets = 11;
438 float2 p = c.uv / c.size;
439 float vy = p.y + .42f;
440 bool ground = vy < 0;
441 float camZ = c.travel * 2.1f;
442 float camX = 1.2f * sin(c.travel * .045f);
443 float3 col;
444 if (ground) {
445 float dg = camH * lens / max(-vy, .01f);
446 float2 g = float2(p.x * dg / lens + camX, dg + camZ);
447 col = deep(.6f, f) * .06f + paint(.5f, f) * .05f * noise2(g * float2(1.5f, .6f));
448 col += paint(.6f, f) * exp(vy * 9) * .2f;
449 } else {
450 col = mix(paint(.55f, f) * .2f, deep(.75f, f) * .12f, saturate(vy * .7f));
451 float2 star = p * 24;
452 float2 sid = floor(star);
453 col += paint(.9f, f) * glow(length(fract(star) - .5f), .05f) * step(.9f, hash21(sid)) * .5f;
454 }
455 float base = floor(camZ / gapZ);
456 for (int j = sheets; j >= 1; --j) {
457 float id = base + float(j);
458 float dz0 = id * gapZ - camZ;
459 float3 h = hash33(float3(id, 5.3, 1.9));
460 float k1 = .5f + .35f * h.x, ph = h.y * TAU;
461 float amp = .8f + 1.2f * c.b.x;
462 float x0 = p.x * dz0 / lens + camX;
463 float arg = x0 * k1 + ph + c.t * .3f;
464 float arg2 = x0 * k1 * 2.4f - c.t * .45f + ph * 2;
465 float dz = dz0 + amp * (sin(arg) + .45f * sin(arg2));
466 if (dz < .25f) continue;
467 float x = p.x * dz / lens + camX;
468 float y = vy * dz / lens;
469 float gain = 1;
470 if (ground) { y = -2 * camH - y; x += .05f * sin(y * 5 + c.t); gain = .3f; }
471 float lower = .65f + .55f * h.z + .3f * sin(x * .23f + id * 1.7f + c.t * .1f);
472 float v = y - lower;
473 float pw = c.px * dz / lens * 2;
474 float edge = smoothstep(-.04f - pw, .04f + pw, v) * exp(-max(v, 0.f) * (1.1f + .6f * h.x));
475 float slope = amp * k1 * (cos(arg) + 1.08f * cos(arg2));
476 float fold = min(sqrt(1 + slope * slope) - 1, 2.5f);
477 float rays = (.45f + .55f * noise2(float2(x * 3.2f + id * 11, c.t * .18f + id))) * (.7f + .3f * noise2(float2(x * 9, id * 3 + c.t * .3f)));
478 float band = c.b[int(h.z * 3.99f)];
479 float lift = c.hit * pow(.5f + .5f * sin(x * .45f - c.t * .9f + id * 2.3f), 6.f) * (.5f + fold) * 2.5f;
480 float fade = smoothstep(float(sheets) * gapZ, float(sheets - 3) * gapZ, dz0) * smoothstep(.25f, 1.2f, dz) * exp(-dz * (.02f + .06f * c.fog));
481 float3 tone = paint(.75f - min(max(v, 0.f) * .2f, .45f) + h.x * .2f + id * .05f, f);
482 float rim = glow(v, .035f + pw) * smoothstep(-.4f, 0.f, v) * .6f;
483 col += tone * (edge * rays * (.25f + .9f * fold) + rim) * (.4f + 1.8f * band + lift) * fade * gain;
484 }
485 return col;
486}
487NATIVE_EFFECT(auroraOverpass)
488
489// ---------------------------------------------------------------- 336 Cascade Climb
490// Climbing the face of a vast waterfall. The camera looks up the wall; ledges with wavy
491// lips pass below, threads of falling light run down each sheet and mist rises off lips.
492
493float cascade_lip(float n, float x) { return n * 2.6f + .3f * sin(x * .7f + n * 1.9f) + .14f * sin(x * 1.9f + n); }
494
495float3 cascadeClimb(Ctx c, constant NativeFrame &f) {
496 const float lens = 1.25f, pitch = .45f, wallD = 2.f;
497 float2 p = c.uv / c.size;
498 float camY = c.travel * 1.5f;
499 float camX = .5f * sin(c.travel * .06f);
500 float cp = cos(pitch), sp = sin(pitch);
501 float ry = p.y * cp + lens * sp, rz = lens * cp - p.y * sp;
502 float s = wallD / max(rz, .03f);
503 float x = camX + p.x * s, y = camY + ry * s;
504 float n = floor(y / 2.6f);
505 float lipBelow = cascade_lip(n, x);
506 if (lipBelow > y) { n -= 1; lipBelow = cascade_lip(n, x); }
507 float lipAbove = cascade_lip(n + 1, x);
508 float above = y - lipBelow;
509 // Sheets of falling light, each fed by one band.
510 float sheetCoord = x * .85f + .35f * sin(y * .15f + x * .3f);
511 float sheetId = floor(sheetCoord);
512 float sheetEdge = fract(sheetCoord);
513 float band = c.b[int(sheetId - 4 * floor(sheetId / 4))];
514 float threadX = x * 7;
515 float threadId = floor(threadX);
516 float th = hash21(float2(threadId, 4.2f));
517 float phase = y * (.45f + .3f * th) + c.t * (.5f + .45f * th) + th * 13;
518 float fall = pow(.5f + .5f * sin(phase * TAU), 3.f);
519 float profile = pow(1 - abs(fract(threadX) - .5f) * 2, 3.f);
520 float aa = fwidth(threadX);
521 float detail = 1 - smoothstep(.25f, .7f, aa);
522 float threads = mix(.18f, profile * (.3f + .9f * fall), detail);
523 float sheetMask = smoothstep(0.f, .1f, sheetEdge) * smoothstep(1.f, .9f, sheetEdge);
524 float recess = 1 - .55f * smoothstep(.45f, 0.f, lipAbove - y);
525 float3 water = paint(.35f + sheetId * .11f + y * .008f, f) * (.16f + .2f * noise2(float2(x * 2, y * .5f + c.t * .4f)) + threads * (.35f + 1.6f * band));
526 float3 col = mix(deep(.4f, f) * .12f, water, .25f + .75f * sheetMask) * recess;
527 // Lips glow where water curls over.
528 float lipGlow = glow(above, .035f + aa * .02f) + glow(lipAbove - y, .035f + aa * .02f);
529 col += paint(.88f + sheetId * .03f, f) * lipGlow * .9f * (.7f + .6f * band);
530 // Mist rising off the lower lip; attacks burst it.
531 float burstSel = smoothstep(.2f, .9f, .5f + .5f * sin(n * 2.1f + c.t * .35f));
532 float burst = c.hit * burstSel;
533 float mist = fbm2(float2(x * 1.1f, (y - c.t * .35f) * 1.4f), 3);
534 float rise = exp(-max(above, 0.f) * (2.4f - 1.5f * burst));
535 col += paint(.6f + mist * .2f, f) * mist * rise * (.55f + 3.2f * burst);
536 float spray = pow(noise2(float2(x * 22, y * 22 - c.t * 5)), 12.f);
537 col += paint(.95f, f) * spray * rise * (.6f + 9 * c.b.w) * detail;
538 // Far reaches of the falls dissolve into bright mist.
539 float far = 1 - exp(-s * .045f);
540 col = mix(col, paint(.55f, f) * .45f + paint(.85f, f) * .1f, saturate(far * (.8f + .4f * c.fog)));
541 // Near spray drifting past the lens.
542 float near = pow(.5f + .5f * sin(p.x * 2.7f + 1.3f * sin(p.x * 1.4f + 2)), 8.f) * pow(.5f + .5f * sin(p.y * 1.6f + c.travel * 3 + c.t * .8f), 4.f);
543 col += paint(.7f, f) * near * .18f;
544 return col;
545}
546NATIVE_EFFECT(cascadeClimb)
547
548// ---------------------------------------------------------------- 337 Night Orbit
549// A low orbit over the dark side of a planet. A ray-sphere hit gives surface coordinates;
550// two voronoi networks, nodes and dust glow on the surface, with a bright limb above.
551
552float3 orbit_space(float3 rd, float spin, Ctx c, constant NativeFrame &f) {
553 float3 rs = float3(rd.x, rd.y * cos(spin) - rd.z * sin(spin), rd.y * sin(spin) + rd.z * cos(spin));
554 float3 col = deep(.7f, f) * .08f + paint(.65f, f) * .1f * noise3(rs * 2.5f) * noise3(rs * 5 + 3);
555 float3 cell = floor(rs * 70);
556 float3 hs = hash33(cell);
557 float3 site = (cell + .25f + hs * .5f) / 70;
558 float star = glow(length(rs - site) * 70, .06f) * step(.8f, hs.x);
559 col += paint(.85f + hs.y * .15f, f) * star * (.4f + .8f * hs.z);
560 return col;
561}
562
563float3 nightOrbit(Ctx c, constant NativeFrame &f) {
564 const float R = 5.f, H = .5f, lens = 1.25f, pitch = .17f;
565 float2 p = rot(c.uv, .07f * sin(c.t * .05f)) / c.size;
566 float cp = cos(pitch), sp = sin(pitch);
567 float3 rd = normalize(float3(p.x, p.y * cp - lens * sp, lens * cp + p.y * sp));
568 float3 ro = float3(0, R + H, 0);
569 float orbit = c.travel * .9f;
570 float b = dot(ro, rd), disc = b * b - (dot(ro, ro) - R * R);
571 float closest = sqrt(max(dot(ro, ro) - b * b, 0.f)) - R;
572 float3 col;
573 if (disc > 0 && -b - sqrt(disc) > 0) {
574 float s = -b - sqrt(disc);
575 float3 P = ro + rd * s, n = P / R;
576 float facing = max(dot(n, -rd), .05f);
577 float2 q = float2(atan2(P.z, P.y) * R + orbit, asin(clamp(n.x, -1.f, 1.f)) * R) * .9f;
578 float foot = c.px * s / lens / facing * .9f;
579 float detail = 1 - smoothstep(.04f, .22f, foot);
580 float land = smoothstep(.36f, .6f, fbm2(q * .17f + 2, 3));
581 float4 v1 = voronoi(q * .7f, .9f, 0);
582 float4 v2 = voronoi(q * 2.1f + 7, .9f, 0);
583 float art = glow(v1.y - v1.x, .04f + foot * .7f) * (.5f + .5f * hash21(v1.zw));
584 float web = glow(v2.y - v2.x, .05f + foot * 2) * detail;
585 float node = glow(v1.x, .05f + foot) * step(.35f, hash21(v1.zw + 3));
586 float dust = pow(noise2(q * 6), 6.f) * detail;
587 float2 rel = q - float2(orbit * .9f + 2.6f, 0);
588 float dist = length(rel * float2(1, 1.3f));
589 float ring = c.hit * pow(.5f + .5f * sin(dist * 2.2f - c.t * 3.2f), 10.f) * exp(-dist * .2f);
590 float lift = 1 + 3 * ring;
591 col = deep(.45f + land * .2f, f) * (.05f + .07f * land);
592 col += paint(.1f + hash21(v1.zw) * .3f, f) * art * (.4f + .6f * land) * (.5f + 1.8f * c.b.x) * lift;
593 col += paint(.45f + hash21(v2.zw) * .25f, f) * web * (.15f + .6f * land) * (.4f + 1.8f * c.b.y) * lift;
594 col += paint(.9f, f) * node * land * (.5f + 2.5f * c.b.z) * lift;
595 col += paint(.75f, f) * dust * land * (.4f + 5 * c.b.w);
596 col += paint(.5f, f) * ring * .5f;
597 float haze = pow(1 - facing, 4.f);
598 col = mix(col, paint(.3f, f) * .5f, haze * (.7f + .3f * c.fog));
599 } else {
600 col = orbit_space(rd, orbit / R, c, f);
601 }
602 float alt = max(closest, 0.f);
603 float limbSide = .6f + .4f * sin(atan2(rd.x, rd.y + .3f) * 1.3f + c.t * .03f);
604 col += paint(.25f + alt * 2, f) * (exp(-alt * 22) * .9f + exp(-alt * 5) * .3f) * limbSide;
605 col += paint(.95f, f) * glow(closest, .006f) * .5f * limbSide;
606 return col;
607}
608NATIVE_EFFECT(nightOrbit)
609
610// ---------------------------------------------------------------- 338 Comet Chase
611// Chasing a comet head that hangs ahead and to one side. The ion and dust tails stream
612// out of it toward the camera; debris layers fly past on stable depth slots.
613
614float3 cometChase(Ctx c, constant NativeFrame &f) {
615 float2 p = c.uv / c.size;
616 float2 ext = c.extent / c.size;
617 float2 head = float2(.36f * ext.x, .3f * ext.y) + .05f * float2(sin(c.t * .31f), cos(c.t * .23f));
618 float2 d = p - head;
619 float r = max(length(d), 1e-3f);
620 float a = atan2(d.y, d.x);
621 float lr = log(r);
622 float axis = -2.6f + .08f * sin(c.t * .17f);
623 float rel = a - axis;
624 rel = atan2(sin(rel), cos(rel));
625 // Background: nebula haze and fixed stars.
626 float3 col = deep(.55f, f) * .18f + paint(.6f, f) * .07f * noise2(p * 1.3f + 4);
627 float2 star = p * 30;
628 float2 sid = floor(star);
629 col += paint(.85f, f) * glow(length(fract(star) - .5f - (hash22(sid) - .5f) * .6f), .05f) * step(.88f, hash21(sid)) * .45f;
630 // Dust tail: broad, curved, striated.
631 float curved = rel + .35f * lr;
632 float dustWidth = .55f + .3f * c.b.x;
633 float dust = exp(-curved * curved / (dustWidth * dustWidth));
634 float striae = .55f + .45f * sin(curved * 26 + sin(lr * 3 - c.travel * 2) * 1.5f);
635 float stream = .6f + .4f * pow(.5f + .5f * sin(lr * 7 - c.travel * 5 + curved * 3), 3.f);
636 float reach = smoothstep(.02f, .2f, r);
637 col += paint(.2f + curved * .25f + r * .1f, f) * dust * striae * stream * reach * (.45f + 1.6f * c.b.x);
638 // Ion tail: narrow, straight filaments.
639 float ion = rel + .55f;
640 float ionCore = exp(-ion * ion * 40);
641 float fil = pow(.5f + .5f * cos(ion * 110 + noise2(float2(lr * 3 - c.travel * 3, ion * 20)) * 6), 6.f);
642 float kink = .5f + .5f * sin(lr * 11 - c.travel * 7 + ion * 30);
643 col += paint(.62f + ion * .3f, f) * ionCore * (.25f + fil * (.6f + kink)) * reach * (.4f + 1.8f * c.b.y);
644 // Coma, nucleus and jets.
645 col += paint(.8f, f) * (glow(r, .13f) * .9f + glow(r, .45f) * .3f);
646 col += paint(.97f, f) * glow(r, .012f) * 1.2f;
647 float jets = pow(.5f + .5f * cos(a * 5 + c.t * .5f), 10.f) * exp(-r * 7);
648 col += paint(.9f, f) * jets * (.3f + 2.2f * c.b.z);
649 // Debris on forward-moving depth slots.
650 for (int k = 0; k < 5; ++k) {
651 float2 slot = layerSlot(k, 5, c.travel * .25f);
652 float scale = layerScale(slot.x, 3.2f);
653 float2 q = d * scale * 3 + float2(slot.y * 3.7f, slot.y * 1.9f);
654 float2 cell = floor(q);
655 float3 h = hash33(float3(cell, slot.y));
656 float2 site = cell + .2f + h.xy * .6f;
657 float glint = glow(length(q - site), .04f + .02f * h.z) * step(.72f, h.z);
658 float twinkle = .5f + .5f * sin(c.t * 3 + h.x * 20);
659 col += paint(.85f + h.y * .15f, f) * glint * (.4f + twinkle * (.3f + 2.5f * c.b.w)) * layerFade(slot.x) * 1.4f;
660 }
661 // Attack: a ring of fragments shed from the head.
662 float sector = floor(a / (TAU / 18));
663 float sh = hash11(sector + 3.3f);
664 float fa = (sector + .5f) * (TAU / 18);
665 float fr = .08f + (1.1f - c.hit) * (.5f + .5f * sh);
666 float2 frag = head + float2(cos(fa), sin(fa)) * fr;
667 col += paint(.92f, f) * glow(length(p - frag), .025f) * c.hit * 2.5f;
668 col += paint(.85f, f) * glow(r - fr, .03f) * c.hit * .6f * (.5f + .5f * sin(a * 9 + sh));
669 return col;
670}
671NATIVE_EFFECT(cometChase)
672
673// ---------------------------------------------------------------- 339 Cloud Sea
674// Skimming a sea of cloud tops. Voronoi puffs with billowing detail glow from inside;
675// light from below leaks through the crevices between them.
676
677float3 cloudSea(Ctx c, constant NativeFrame &f) {
678 const float lens = 1.2f, camH = .45f;
679 float2 p = c.uv / c.size;
680 float horizon = .38f;
681 float vy = horizon - p.y;
682 float camZ = c.travel * 2.2f;
683 float camX = .9f * sin(c.travel * .05f);
684 float3 col;
685 if (vy > 0) {
686 float dz = camH * lens / max(vy, .006f);
687 float2 w = float2(p.x * dz / lens + camX, dz + camZ);
688 float2 cw = w * float2(.75f, .55f);
689 float billow = fbm2(cw * 2.1f + float2(c.t * .05f, 0), 3);
690 float4 v = voronoi(cw + (billow - .5f) * .6f, .9f, c.t * .3f);
691 float puff = saturate(1 - v.x / .75f);
692 float crevice = 1 - smoothstep(0.f, .14f, v.y - v.x);
693 float3 h = hash33(float3(v.zw, 2.2));
694 float band = c.b[int(h.z * 3.99f)];
695 float flashSel = smoothstep(.55f, .95f, .5f + .5f * sin(h.x * TAU + c.t * .7f));
696 float flash = c.hit * flashSel * 4;
697 float3 tone = paint(h.x * .6f + .1f, f);
698 float top = puff * (.5f + .5f * billow);
699 col = deep(.45f + h.y * .2f, f) * .1f + paint(.6f + billow * .2f, f) * top * .3f;
700 col += tone * pow(puff, 1.6f) * (.25f + 1.5f * band + flash) * (.6f + .5f * billow);
701 col += paint(.88f, f) * crevice * (.35f + .6f * c.b.x) * (.6f + .4f * billow);
702 float fog = exp(-dz * (.035f + .07f * c.fog));
703 col = mix(paint(.55f, f) * .55f, col, fog);
704 } else {
705 float up = -vy;
706 col = mix(paint(.55f, f) * .55f, deep(.8f, f) * .14f + paint(.75f, f) * .08f, saturate(up * 1.3f));
707 float streak = pow(.5f + .5f * sin(up * 14 + noise2(float2(p.x * .8f - c.travel * .1f, up * 3)) * 3), 8.f);
708 col += paint(.7f + up * .2f, f) * streak * .2f * exp(-up * 1.5f);
709 }
710 col += paint(.85f, f) * exp(-abs(vy) * 16) * .25f;
711 return col;
712}
713NATIVE_EFFECT(cloudSea)