Branchwell

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

Raw 35.4 KB on 32796b3b2cff314d20e7c78bdc17d74e2eace8c1
1// Second versions of designs whose original and final review clips were both red-tagged.
2// Original PulseCanvas designs 340–349. Full-frame materials in motion: liquids, films and crafts with vivid color, in the spirit of the kept Flow designs (Silk Cascade, Ink Bloom, Oil Marble, Chrome Metaballs) but with new materials.
3// Every design is Form scale: the material itself moves with procedural time and the music;
4// audio terms are zero at zero Chaos.
5
6// ---------------------------------------------------------------- shared helpers
7// A wandering point for attack events: a smooth path of the music clock, so each attack
8// lands somewhere new without anything jumping between frames.
9float2 mat_eventPoint(Ctx c, float seed, float reach) {
10 return float2(sin(c.m * 2.3 + seed * 4.1), sin(c.m * 1.7 + seed * 2.7 + 1.3)) * c.extent / c.size * reach;
11}
12// Picks a changing subset of elements for each attack; continuous in the music clock.
13float mat_pick(float seed, Ctx c) {
14 float s = .5 + .5 * sin(c.m * 3.7 + seed * TAU);
15 return s * s * s;
16}
17
18// ---------------------------------------------------------------- 340 Acrylic Cells
19// A poured acrylic skin: opaque streams of saturated paint and dark ground run across the
20// canvas, cells open in the cell-forming streams (a bright core, a coloured ring and a dark
21// wall) and fine lacing webs the light layers. Bass opens the cells, low-mids push the pour,
22// high-mids thicken the lacing, highs freckle micro-cells; attacks open a bloom of fresh cells.
23float3 acr_layer(float index, constant NativeFrame &f) {
24 float kind = hash11(index * 2.71 + 8.3);
25 // Each paint is one tube colour: a palette stop, never a muddy in-between.
26 float hue = floor(hash11(index * 1.37 + 2.9) * 4.99) * .25;
27 if (kind < .3) return deep(hue + .5, f) * .07;
28 return paint(hue, f) * (.6 + .3 * kind);
29}
30float3 acrylicCellsII(Ctx c, constant NativeFrame &f) {
31 float2 p = c.uv / c.size;
32 float t = c.t;
33 float2 base = p * .8 + float2(t * .03 + c.travel * .06, -t * .012);
34 float2 warp = float2(fbm2(base * .9 + float2(0, t * .02), 3), fbm2(base * .9 + float2(4.3, 1.7 - t * .018), 3));
35 float2 q = base + (warp - .5) * (1.45 + c.b.y * 1.5);
36 // Stacked pour layers of varying width run along the flow.
37 float s = q.y * 1.1 + q.x * .42 + .3 * sin(q.x * 1.2 + t * .04);
38 float layer = s * 2.7 + .3 * sin(s * 1.9 + 1.3);
39 float index = floor(layer), fr = fract(layer);
40 // Layer edges stay a constant few pixels wide however far the pour stretches them.
41 float aa = clamp(fwidth(layer) * 1.2, 1e-4f, .3f);
42 float3 color = mix(acr_layer(index, f), acr_layer(index + 1, f), smoothstep(1 - aa, 1.f, fr));
43 color *= .82 + .25 * sin(fr * PI);
44 // Cells: voronoi stretched along the flow, open only in the cell-forming streams.
45 float2 along = normalize(float2(1.1, -.42));
46 // Cells ride the pour but stay round, only a little stretched along it.
47 float2 cp = base + (warp - .5) * (.5 + c.b.y * .5);
48 float2 cq = float2(dot(cp, along) * 2.6, dot(cp, float2(-along.y, along.x)) * 3.4);
49 float4 v = voronoi(cq, .85, t * .12);
50 float2 seed = hash22(v.zw);
51 float region = smoothstep(.3f, .55f, noise2(cp * .9 + 11.3));
52 float2 event = mat_eventPoint(c, .3, .6);
53 float near = exp(-dot(p - event, p - event) * 2.4);
54 float pick = mat_pick(seed.x, c);
55 float radius = (.1 + .24 * seed.y) * region * (.65 + c.b.x * 1.3);
56 radius += (.14 + .14 * seed.y) * c.hit * (pick * .5 + near * 1.8);
57 radius = min(radius, .46f);
58 float present = smoothstep(0.f, .04f, radius);
59 float aac = c.px / c.size * 4 * 1.5;
60 float3 core = paint(floor(seed.x * 4.99) * .25, f) * 1.05;
61 float3 ring = paint(floor(seed.y * 4.99) * .25 + .5, f) * .8;
62 float3 wall = deep(seed.x, f) * .05;
63 float u = v.x;
64 float3 cell = mix(core, ring, smoothstep(radius * .5 - aac, radius * .5 + aac, u));
65 cell = mix(cell, wall, smoothstep(radius * .8 - aac, radius * .8 + aac, u));
66 float2 local = cq - v.zw - .5 - .425 * sin(t * .12 + seed * TAU);
67 float2 lit = local + float2(.32, -.32) * radius;
68 cell += paint(.5, f) * (1 - smoothstep(radius * .1 - aac, radius * .1 + aac, length(lit))) * .45;
69 float inside = (1 - smoothstep(radius - aac, radius + aac, u)) * present;
70 float rim = exp(-abs(u - radius) / .02) * present * (1 - inside);
71 color = mix(color, cell, inside);
72 color += paint(.5, f) * rim * (.25 + c.hit * (pick + near) * 1.4);
73 // Lacing and micro-cells on a finer web.
74 float4 web = voronoi(cq * 2.3 + 5.1, .85, t * .1);
75 float lace = 1 - smoothstep(.01f, .035f + c.b.z * .06f, web.y - web.x);
76 float laceRegion = smoothstep(.45f, .7f, noise2(q * 1.1 + 4.7)) * (1 - inside);
77 color = mix(color, paint(.5, f) * 1.1, lace * laceRegion * (.35 + c.b.z * 1.1));
78 float freckle = 1 - smoothstep(.04 + .12 * c.b.w, .07 + .12 * c.b.w, web.x);
79 color = mix(color, paint(hash21(web.zw), f) * .9, freckle * step(.6f, hash21(web.zw + 3.7)) * smoothstep(.02f, .1f, c.b.w) * (1 - inside) * region);
80 // Wet gloss: a slow window reflection across the pour.
81 float gloss = exp(-pow(dot(p, float2(.6, .8)) - 1.3 * sin(t * .045), 2.f) * 4);
82 color += paint(.5, f) * gloss * .07;
83 return color * .72;
84}
85NATIVE_EFFECT(acrylicCellsII)
86
87// ---------------------------------------------------------------- 341 Molten Glass
88// Thick canes of molten glass are pulled across a dark furnace. Each cane has an
89// incandescent core, a cooling glossy skin and twisted threads inside. Bass stretches the
90// canes and necks them thin, low-mids sway them, high-mids light the threads, highs glint
91// trapped seeds; attacks fold a kink into the canes and flare it white-hot.
92float3 moltenGlassII(Ctx c, constant NativeFrame &f) {
93 float2 p = c.uv / c.size;
94 float2 ext = c.extent / c.size;
95 float t = c.t;
96 float stretch = 1 + c.b.x * .9;
97 float3 color = deep(.03, f) * .04 + paint(.03, f) * .06 * fbm2(p * 1.4 + float2(t * .02, -t * .05), 3);
98 float2 event = mat_eventPoint(c, 1.7, .7);
99 const int count = 5;
100 for (int k = 0; k < count; ++k) {
101 float fk = float(k);
102 float seed = hash11(fk * 3.71 + .37);
103 float side = (k & 1) == 0 ? 1. : -1.;
104 float angle = side * (.12 + .3 * seed) + .1 * sin(t * .04 + fk * 1.3);
105 float2 center = float2(.25 * sin(fk * 2.1), (fk - 2) / 2 * ext.y * .78);
106 float2 q = rot(p - center, -angle);
107 float2 eq = rot(event - center, -angle);
108 float pick = mat_pick(seed, c);
109 float level = c.b[k % 4];
110 float x = q.x / stretch;
111 float amp = .08 + .06 * seed + c.b.y * .16;
112 float frequency = 1.1 + .9 * seed;
113 float phase = t * (.16 + .08 * seed) + seed * 9;
114 float yc = amp * sin(x * frequency + phase) + .05 * sin(x * 2.7 - phase * 1.3);
115 float slope = (amp * frequency * cos(x * frequency + phase) + .135 * cos(x * 2.7 - phase * 1.3)) / stretch;
116 float kink = exp(-pow((q.x - eq.x) / .4, 2.f)) * c.hit * (.45 + pick);
117 yc += kink * .35 * sin((q.x - eq.x) * 5);
118 float neckAt = sin(t * .05 + seed * 6) * ext.x * .6;
119 float neck = exp(-pow((q.x - neckAt) / (.55 * stretch), 2.f)) * (.15 + c.b.x * .5);
120 float width = (.13 + .07 * seed) * (1 - neck);
121 float u = (q.y - yc) / sqrt(1 + slope * slope) / width;
122 float aa = c.px / c.size / width * 1.5;
123 float body = 1 - smoothstep(1 - aa, 1 + aa, abs(u));
124 float uc = clamp(u, -1.f, 1.f);
125 float nz = sqrt(max(0.f, 1 - uc * uc));
126 float heat = (.6 + .3 * sin(x * .8 - t * .1 + seed * 7) + .35 * level) * (1 - neck * .6) + kink * 2.2;
127 // Glowing glass: emission peaks inside the cane, so there is no dark side.
128 float emission = heat * (.3 + .7 * nz * nz);
129 float twist = asin(uc) * 2 + x * (7 + 4 * seed) * side - t * (.35 + seed * .3);
130 float strand = smoothstep(.35f, .75f, sin(twist)) * nz;
131 float3 glass = paint(.12 + .72 * min(emission, 1.2f), f) * min(emission, 1.3f) * 1.05;
132 glass += paint(.88, f) * strand * (.08 + c.b.z * .9) * heat;
133 float3 n = float3(0, uc, nz);
134 float specular = pow(max(0.f, dot(n, normalize(float3(0, .58, .81)))), 220.f);
135 glass += paint(.95, f) * specular * 1.3;
136 glass += paint(.35, f) * pow(1 - nz, 8.f) * .35 * heat;
137 // Trapped seeds (tiny bubbles) glint with the highs.
138 float segment = floor(x * 2.5 + seed * 17);
139 float2 bubbleSeed = hash22(float2(segment, fk));
140 float2 bubble = float2((fract(x * 2.5 + seed * 17) - .2 - .6 * bubbleSeed.x) * .4 * stretch, (u - (bubbleSeed.y - .5) * 1.2) * width);
141 glass += paint(.95, f) * glow(length(bubble) - .01, .005) * (.04 + c.b.w * 2.4) * nz * sin(PI * fract(x * 2.5 + seed * 17));
142 // Translucent: canes behind still glow through, dimmed by the glass in front.
143 float outside = max(abs(u) - 1, 0.f) * width;
144 color += paint(.2 + .3 * min(heat, 1.f), f) * exp(-outside * 10) * .14 * heat * (1 - body);
145 color = color * (1 - .6 * body) + glass * body;
146 }
147 return color * .9;
148}
149NATIVE_EFFECT(moltenGlassII)
150
151// ---------------------------------------------------------------- 342 Liquid Crystal
152// A nematic film between crossed polarisers: interference colours set by the film's
153// retardation, dark brushes radiating from drifting defects. Each band twists the director
154// in its own region; attacks tear a defect pair out of the uniform field.
155float lc_pair(float2 p, float2 center, float2 offset) {
156 // +1/2 at center + offset and -1/2 at center - offset. Exactly zero when the offset is
157 // zero, so pairs can be born and annihilate continuously.
158 float2 a = p - center - offset, b = p - center + offset;
159 return .5 * atan2(a.y * b.x - a.x * b.y, a.x * b.x + a.y * b.y);
160}
161float3 liquidCrystalII(Ctx c, constant NativeFrame &f) {
162 float2 p = c.uv / c.size;
163 float2 ext = c.extent / c.size;
164 float t = c.t;
165 float theta = 1.3 * fbm2(p * .8 + float2(t * .02, -t * .015), 3) + .3 * sin(p.x * .8 + t * .06) + .25 * cos(p.y * 1.1 - t * .05);
166 theta += .22 * noise2(p * 4 + float2(t * .05, 0));
167 bool wide = ext.x >= ext.y;
168 int columns = wide ? 4 : 2, rows = wide ? 2 : 4;
169 for (int i = 0; i < 8; ++i) {
170 float fi = float(i);
171 int column = i % columns, row = i / columns;
172 float2 seed = hash22(float2(fi, 3.1));
173 float2 cell = float2((float(column) + .5) / float(columns), (float(row) + .5) / float(rows)) * 2 - 1;
174 float2 at = cell * ext * .85 + (seed - .5) * .5 + float2(sin(t * (.08 + seed.x * .05) + fi * 2.1), cos(t * (.07 + seed.y * .05) + fi * 1.3)) * .34;
175 float charge = ((column + row) & 1) == 0 ? .5 : -.5;
176 if (i == 1) charge = 1;
177 if (i == 6) charge = -1;
178 theta += charge * atan2(p.y - at.y, p.x - at.x);
179 }
180 for (int k = 0; k < 4; ++k) {
181 float angle = float(k) * 1.5708 + .7 + t * .03;
182 float2 at = float2(cos(angle), sin(angle)) * ext * .55;
183 theta += c.b[k] * .85 * exp(-dot(p - at, p - at) * 1.4);
184 }
185 float flare = 0;
186 for (int j = 0; j < 3; ++j) {
187 float fj = float(j);
188 float pick = mat_pick(fj * .31 + .1, c);
189 float2 at = mat_eventPoint(c, fj * 2.3, .6);
190 float separation = (c.hit * .35 + c.e * .08) * (.3 + pick);
191 float2 direction = float2(cos(fj * 2.1 + t * .1), sin(fj * 2.1 + t * .1));
192 theta += lc_pair(p, at, direction * separation);
193 flare += c.hit * (.3 + pick) * exp(-dot(p - at, p - at) * 4);
194 }
195 float polarizer = t * .065;
196 float brush = sin(2 * (theta - polarizer));
197 float intensity = brush * brush;
198 float retardation = 1 + 5.5 * fbm2(p * .6 + float2(t * .015, 3.7), 3) + .5 * length(p) + .12 * sin(t * .07);
199 float3 color = filmColor(retardation, f) * (.02 + .9 * pow(intensity, 1.3f));
200 color += paint(.9, f) * pow(intensity, 12.f) * .1;
201 color += paint(.85, f) * flare * intensity * .9;
202 return color * .88;
203}
204NATIVE_EFFECT(liquidCrystalII)
205
206// ---------------------------------------------------------------- 343 Incense Drift
207// Ribbons of incense smoke rise from below the frame, twist as thin lit sheets and curl
208// into loops on rising eddies before melting into a lit haze. Each plume follows its band,
209// bass thickens them all, low-mids spin the eddies; attacks curl a new loop.
210float3 incenseDriftII(Ctx c, constant NativeFrame &f) {
211 float2 p = c.uv / c.size;
212 float2 ext = c.extent / c.size;
213 float t = c.t;
214 float h = clamp(p.y / ext.y * .5 + .5, 0.f, 1.f);
215 float2 q = p + curl2(p * 1.1 + float2(0, -t * .12)) * (.015 + .09 * h * h);
216 for (int j = 0; j < 4; ++j) {
217 float fj = float(j);
218 float cycle = t * .022 + fj * .25;
219 float life = fract(cycle);
220 float2 seed = hash22(float2(floor(cycle), fj));
221 float2 at = float2((seed.x - .5) * 1.7 * ext.x, mix(-.4, 1.1, life) * ext.y);
222 float spin = (1.6 + c.b.y * 1.6) * sin(PI * life) * (seed.y < .5 ? -1. : 1.);
223 float2 d = q - at;
224 q = at + rot(d, spin * exp(-dot(d, d) * 5));
225 }
226 float2 event = mat_eventPoint(c, .7, .55);
227 float2 de = q - event;
228 q = event + rot(de, c.hit * 3.4 * exp(-dot(de, de) * 7));
229 float boost = 1 + c.hit * 2.5 * exp(-dot(p - event, p - event) * 6);
230 float haze = fbm2(q * 1.3 + float2(0, -t * .04), 4);
231 // A dark room: a little light pools low where the sticks burn, and the haze above
232 // holds a soft glow, so the lit ribbons stand out against depth rather than a flat wash.
233 float pool = exp(-pow(h + .1f, 2.f) * 4) * (.6 + .4 * sin(p.x * 1.3 + t * .03));
234 float3 color = deep(.08 + h * .1, f) * (.1 + .12 * pool) + paint(.25 + haze * .35, f) * haze * haze * (.05 + .32 * h);
235 for (int k = 0; k < 4; ++k) {
236 float fk = float(k);
237 float x0 = ((fk + .5) / 4 * 2 - 1) * ext.x * .82 + .12 * sin(t * .05 + fk * 2);
238 float sway = (.03 + .25 * h * h) * sin(q.y * 2.1 - t * .35 + fk * 1.9) + .1 * h * sin(q.y * 4.3 - t * .6 + fk);
239 float dx = q.x - x0 - sway;
240 float level = c.b[k];
241 float width = (.012 + .11 * h * h) * (1 + c.b.x * 1.4);
242 float twist = q.y * 5 - t * .8 + fk * 1.7;
243 float strands = 0;
244 for (int i = 0; i < 3; ++i) strands += glow(dx - width * sin(twist + float(i) * 2.094), .0035 + .012 * h);
245 float sheet = exp(-dx * dx / (width * width * 1.2 + 1e-4));
246 float fade = 1 - .7 * smoothstep(.6f, 1.f, h);
247 float3 tint = paint(.2 + fk * .17 + h * .35, f);
248 color += tint * (strands * .42 + sheet * .3) * fade * (.5 + level * 1.9) * boost;
249 color += paint(.95, f) * strands * strands * .05 * fade * (.5 + level) * boost;
250 }
251 return color;
252}
253NATIVE_EFFECT(incenseDriftII)
254
255
256// ---------------------------------------------------------------- 345 Heat Haze
257// A false-colour thermal view of a convection tank: rolls turn across the frame, hot plumes
258// rise where they meet and carry mushroom thermals upward through shimmering isotherms.
259// Bass heats every plume, each plume also follows its own band, highs add shimmer; attacks
260// release a hot bubble at the plume roots.
261float3 heatHazeII(Ctx c, constant NativeFrame &f) {
262 float2 p = c.uv / c.size;
263 float2 ext = c.extent / c.size;
264 float t = c.t;
265 float h = p.y / ext.y * .5 + .5;
266 float hc = clamp(h, 0.f, 1.f);
267 float2 shimmer = float2(fbm2(p * 2.4 + float2(0, -t * .3), 3), fbm2(p * 2.4 + float2(5.1, -t * .26), 3)) - .5;
268 float2 q = p + shimmer * (.07 + c.b.w * .28);
269 const float span = .6;
270 float xr = q.x / span + t * .01;
271 float T = .36 - .38 * hc;
272 // Counter-rotating convection rolls wrap warm streaks into spirals between the plumes.
273 float roll = floor(xr * .5);
274 float2 rl = float2((xr * .5 - roll - .5) * 2, (q.y / ext.y - .1 * sin(roll * 2.3)) * 1.4);
275 float rr = length(rl);
276 float turn = (int(roll) & 1) == 0 ? 1. : -1.;
277 float spiral = sin(atan2(rl.y, rl.x) + rr * 8 * turn - t * .7 * turn);
278 T += (.13 + c.b.y * .16) * spiral * smoothstep(1.05f, .25f, rr) * smoothstep(0.f, .2f, rr);
279 // Plumes rise where neighbouring rolls meet.
280 float plume = floor(xr * .5 + .5);
281 float dxr = (xr * .5 - plume) * 2 * span;
282 float seed = hash11(plume * 1.7 + .3);
283 float level = c.b[int(abs(plume)) % 4];
284 float sway = .07 * hc * sin(q.y * 2.3 - t * .4 + seed * 6) + .04 * hc * sin(q.y * 5 - t * .7 + seed * 3);
285 float dx = dxr - sway;
286 float wide = .035 + .07 * hc;
287 float strength = .32 + .2 * seed + c.b.x * .5 + level * .4;
288 T += strength * exp(-dx * dx / (wide * wide)) * (1.1 - .55 * hc);
289 // Mushroom thermals climb each plume.
290 for (int j = 0; j < 3; ++j) {
291 float life = fract(t * .045 + seed + float(j) / 3);
292 float y = mix(-1.25, 1.25, life) * ext.y;
293 float2 head = float2(dx, q.y - y);
294 float capWidth = .08 + .12 * life;
295 float cap = exp(-head.x * head.x / (capWidth * capWidth) - head.y * head.y / .01);
296 float curl = exp(-pow(abs(head.x) - capWidth, 2.f) / .003 - pow(head.y + .05, 2.f) / .006);
297 float stem = exp(-dx * dx / (wide * wide * .5)) * smoothstep(.0f, -.25f, head.y) * smoothstep(-.6f, -.2f, head.y);
298 T += (cap * .5 + curl * .38 + stem * .15) * strength * (1 - .3 * life);
299 }
300 float pick = mat_pick(seed, c);
301 float bubbleY = -ext.y * .72 + (1 - c.hit) * .45;
302 T += c.hit * (.6 + pick * 1.4) * exp(-(dx * dx + pow(q.y - bubbleY, 2.f)) / .025);
303 T += .05 * (fbm2(q * 3 + float2(0, -t * .2), 3) - .5);
304 float temp = clamp(T, 0.f, 1.5f);
305 // False colour: cool is dark red, warm a saturated orange, and only the hottest cores
306 // climb through gold to white, so mid temperatures never wash out to khaki.
307 float3 warm = paint(.02 + .44 * smoothstep(0.f, .85f, temp), f);
308 float3 color = mix(warm, paint(.98, f), smoothstep(1.f, 1.4f, temp)) * (.06 + 1.1 * smoothstep(.0f, .45f, temp) + .4 * max(temp - .8f, 0.f));
309 // Isotherms: thin, evenly wide contour lines however steep the temperature gradient.
310 float contour = T * 10;
311 float iso = fract(contour);
312 float isoWidth = clamp(fwidth(contour), 1e-3f, .45f);
313 // Where contours crowd together they fade out instead of greying the hot cores.
314 float isoLine = (1 - smoothstep(isoWidth * .6f, isoWidth * 1.6f, min(iso, 1 - iso))) * (1 - smoothstep(.12f, .3f, isoWidth));
315 color *= 1 - .3 * isoLine * smoothstep(.05f, .2f, temp) * (1 - smoothstep(.55f, .85f, temp));
316 color += paint(.9, f) * isoLine * .1 * temp * temp;
317 return color;
318}
319NATIVE_EFFECT(heatHazeII)
320
321// ---------------------------------------------------------------- 346 Gel Overlap
322// Translucent colour gels lie on a light table; where they overlap their colours multiply.
323// Each gel drifts and thickens with its band, the cut edges catch the light, and the music
324// clock slides a long strip over the stack; attacks shove it and flash its edges.
325float gel_sdf(float2 p, int k, float3 seed, float2 ext) {
326 if (k == 1 || k == 4 || k == 7) return length(p) - (.48 + .25 * seed.x);
327 if (k == 2) return sdBox2(p, float2(2.2 * max(ext.x, ext.y), .17 + .05 * seed.y)) - .02;
328 return sdBox2(p, float2(.55 + .35 * seed.y, .38 + .22 * seed.z)) - .06;
329}
330float3 gelOverlapII(Ctx c, constant NativeFrame &f) {
331 float2 p = c.uv / c.size;
332 float2 ext = c.extent / c.size;
333 float t = c.t;
334 float px = c.px / c.size * 1.5;
335 float glowField = .18 + 1.05 * exp(-dot(p / ext, p / ext) * 1.3);
336 float3 table = (paint(.5, f) + paint(.75, f) + paint(.95, f)) / 3;
337 float3 filter = float3(1);
338 float cover = 0, shade = 1;
339 float3 edges = 0;
340 for (int k = 0; k < 9; ++k) {
341 float fk = float(k);
342 float3 seed = hash33(float3(fk, 2.7, 9.1));
343 float level = k < 8 ? c.b[k % 4] : 0.;
344 float2 center;
345 float angle;
346 int shape = k;
347 if (k < 8) {
348 float2 home = (seed.xy - .5) * ext * 1.4;
349 float2 drift = float2(sin(t * (.04 + seed.z * .03) + fk * 1.7), cos(t * (.035 + seed.x * .03) + fk * 2.3)) * ext * .35;
350 float2 push = float2(cos(fk * 2.4), sin(fk * 2.4)) * level * .55;
351 center = home + drift + push;
352 angle = t * .03 * (seed.z - .5) + fk;
353 } else {
354 // The slider: a long strip glides back and forth on the music clock; attacks shove it.
355 center = float2(sin(c.m * .9 + 1.2) * ext.x * .75 + c.hit * .35, 0);
356 angle = 1.35;
357 shape = 2;
358 }
359 float2 local = rot(p - center, angle);
360 float d = gel_sdf(local, shape, seed, ext);
361 float shadow = 1 - smoothstep(-.02f, .09f, gel_sdf(rot(p - center - float2(.05, -.06), angle), shape, seed, ext));
362 float mask = fill(d, px);
363 float3 tint = paint(fk * .19 + .08 + .05 * sin(t * .02 + fk), f);
364 tint = pow(tint / max(max(tint.r, tint.g), max(tint.b, 1e-3f)), float3(2.6));
365 float density = .86 + level * .14;
366 filter *= mix(float3(1), tint, mask * density);
367 cover += mask;
368 shade *= 1 - .35 * shadow * (1 - mask);
369 float rim = line(d, .006, px) + glow(d, .01) * .3;
370 float sheen = mask * smoothstep(.2f, 1.f, sin(dot(local, float2(1.3, .8)) * 2 + t * .1 + fk)) * .1;
371 edges += (table * .35 + paint(.9, f) * .1) * (rim * (.16 + level * .9 + (k == 8 ? c.hit * 3 : 0.)) + sheen);
372 }
373 float covered = min(cover, 1.f);
374 float3 color = mix(table * .42, filter * (.8 + .25 * min(cover - 1, 1.f)), covered) * glowField * shade;
375 return (color + edges) * .82;
376}
377NATIVE_EFFECT(gelOverlapII)
378
379// ---------------------------------------------------------------- 347 Holo Foil
380// A sheet of crumpled holographic foil fills the frame: long straight folds, each dying out
381// somewhere in the sheet, split it into flat tilted facets whose diffraction rainbow slides
382// as the sheet flexes and the light moves. Bass deepens the folds, low-mids bend the sheet,
383// high-mids widen the rainbow, highs sparkle glitter flakes; attacks sweep a highlight.
384// Fold table: direction and grid jitter, then span, depth, mountain or valley and wobble phase.
385constant float4 holo_foldShape[24] = {
386 float4(0.4533, 0.8914, -0.0091, 0.1166),
387 float4(0.2087, 0.9780, -0.1367, -0.1458),
388 float4(0.9119, 0.4104, 0.0050, 0.0492),
389 float4(0.2996, 0.9541, 0.0715, 0.0295),
390 float4(0.8019, 0.5974, -0.0777, -0.1257),
391 float4(-0.6798, 0.7334, -0.0917, 0.0197),
392 float4(-0.0593, 0.9982, 0.0406, 0.0902),
393 float4(-0.8872, 0.4614, -0.0146, -0.0004),
394 float4(0.4170, 0.9089, 0.0212, 0.1031),
395 float4(-0.1742, 0.9847, 0.0669, -0.0178),
396 float4(-0.9864, 0.1642, 0.0219, 0.0611),
397 float4(0.8761, 0.4822, 0.0427, 0.0389),
398 float4(0.6464, 0.7630, 0.0395, -0.0383),
399 float4(0.5342, 0.8453, 0.1277, 0.0684),
400 float4(0.5890, 0.8081, -0.0807, 0.0293),
401 float4(0.0414, 0.9991, 0.0256, 0.1012),
402 float4(0.0004, 1.0000, 0.0486, -0.0559),
403 float4(-0.9361, 0.3517, 0.1184, -0.0745),
404 float4(-0.7139, 0.7002, 0.0971, 0.1212),
405 float4(0.7026, 0.7116, 0.0102, 0.0302),
406 float4(-0.6574, 0.7536, -0.1123, -0.0067),
407 float4(0.8592, 0.5117, 0.0133, -0.0957),
408 float4(0.7588, 0.6513, -0.0803, 0.1024),
409 float4(0.4562, 0.8899, 0.0113, 0.0796)};
410constant float4 holo_foldSize[24] = {
411 float4(1.0441, 0.5081, -1, 1.6482),
412 float4(1.4087, 0.5376, 1, 1.4102),
413 float4(1.2331, 0.4800, 1, 3.4016),
414 float4(0.8896, 0.4174, -1, 3.5601),
415 float4(1.2544, 0.5569, 1, 6.1110),
416 float4(0.4967, 0.3116, -1, 2.6663),
417 float4(0.4868, 0.5107, 1, 0.4695),
418 float4(1.5919, 0.3574, -1, 2.0644),
419 float4(1.5637, 0.5998, 1, 5.3051),
420 float4(1.3944, 0.4082, 1, 3.5323),
421 float4(0.5207, 0.3344, -1, 2.8307),
422 float4(0.7279, 0.5184, 1, 2.2901),
423 float4(0.4754, 0.3622, 1, 4.7969),
424 float4(1.3931, 0.3884, 1, 0.1466),
425 float4(0.7807, 0.3595, -1, 3.0191),
426 float4(0.5903, 0.4323, 1, 0.5335),
427 float4(1.1370, 0.3664, 1, 3.5982),
428 float4(0.8365, 0.5818, 1, 0.0843),
429 float4(1.2090, 0.3913, -1, 6.0840),
430 float4(1.4923, 0.4483, 1, 5.4160),
431 float4(1.3985, 0.3428, 1, 5.3823),
432 float4(1.2818, 0.2636, 1, 4.8497),
433 float4(0.9903, 0.3780, 1, 2.6605),
434 float4(1.3489, 0.4933, 1, 0.8857)};
435float3 holoFoilII(Ctx c, constant NativeFrame &f) {
436 float2 p = c.uv / c.size;
437 float2 ext = c.extent / c.size;
438 float t = c.t;
439 float px = c.px / c.size;
440 float2 sp = rot(p * 1.5, .08 * sin(t * .031)) + float2(c.travel * .05 + t * .004, -t * .002);
441 float reachAll = length(ext) * 1.5;
442 float flex = .6 + .25 * sin(t * .17) + c.b.x * .75;
443 float2 grad = 0;
444 float ridge = 0, valley = 0;
445 // Folds are spread over a jittered grid so every part of the canvas is crumpled.
446 bool wide = ext.x >= ext.y;
447 int columns = wide ? 6 : 4;
448 float2 drift = float2(c.travel * .05 + t * .004, -t * .002);
449 float soft = px * px * 4.5f, lineWidth = px * 2.4 + .003;
450 for (int k = 0; k < 24; ++k) {
451 float4 shape = holo_foldShape[k], size = holo_foldSize[k];
452 float2 cell = float2(float(k % columns) + .5, float(k / columns) + .5) / float2(float(columns), float(24 / columns));
453 float2 center = (cell * 2 - 1 + shape.zw) * ext * 1.5 + drift;
454 float2 n = normalize(shape.xy + float2(.03 * sin(t * .041 + size.w), 0));
455 float2 rel = sp - center;
456 // Each fold runs only part way across the sheet before it relaxes.
457 float a = dot(rel, float2(-n.y, n.x)) / size.x;
458 if (a * a > 6) continue;
459 float d = dot(rel, n);
460 float reach = exp(-a * a);
461 float side = d / sqrt(d * d + soft);
462 grad += size.y * flex * reach * side * size.z * n;
463 float creaseLine = exp(-abs(d) / lineWidth) * reach;
464 if (size.z > 0) ridge += creaseLine; else valley += creaseLine;
465 }
466 float bend = .1 + c.b.y * .45;
467 grad += bend * float2(cos(p.x * 1.3 + t * .11) * sin(p.y * .9 - t * .07), .7 * sin(p.x * 1.3 + t * .11) * cos(p.y * .9 - t * .07));
468 float3 n = normalize(float3(-grad * .9, 1));
469 float3 light = normalize(float3(cos(t * .09) * .6, sin(t * .07) * .5, 1));
470 float3 r = reflect(float3(0, 0, -1), n);
471 float facing = max(dot(r, light), 0.f);
472 // Diffraction: the rainbow order depends on the facet's tilt against the light.
473 float spread = 3.2 + c.b.z * 2.4;
474 float phase = dot(n.xy - light.xy * .4, float2(.85, .55)) * spread + dot(p, float2(.18, .12)) + t * .02;
475 float3 color = filmColor(phase, f) * (.13 + 1.05 * facing * facing);
476 color += paint(.9, f) * pow(facing, 24.f) * .45;
477 color += paint(.92, f) * min(ridge, 1.f) * (.2 + .35 * facing);
478 color *= 1 - .6 * min(valley, 1.f);
479 // Glitter flakes in the foil twinkle with the highs.
480 float2 gp = p * 22, gcell = floor(gp);
481 float2 gs = hash22(gcell);
482 float2 gl = fract(gp) - .5 - (gs.yx - .5) * .5;
483 float twinkle = pow(max(0.f, sin(t * (1.5 + gs.x * 2) + gs.y * TAU)), 16.f);
484 color += paint(.85 + .1 * gs.x, f) * (1 - smoothstep(.05f, .12f, length(gl))) * twinkle * (.03 + c.b.w * 2.2) * (.25 + facing);
485 // Attacks sweep a bright band across the foil, strongest on facets facing the light.
486 float sweepAngle = c.m * 1.3 + .6;
487 float2 axis = float2(cos(sweepAngle), sin(sweepAngle));
488 float sweep = exp(-pow(dot(p, axis) - ((1 - c.hit) * 2.2 - 1.1) * reachAll, 2.f) * 9) * c.hit;
489 color += filmColor(phase + .3, f) * sweep * (.6 + 1.4 * facing) * 1.4;
490 return color * .9;
491}
492NATIVE_EFFECT(holoFoilII)
493
494// ---------------------------------------------------------------- 348 Opal Fire
495// A black opal's play of colour: harlequin patches of spectral fire at two depths, each
496// with a rolling flash that slides through it as the stone tilts, plus pinfire sparks.
497// Each patch follows a band; attacks ignite a burst of fire that spreads through the patches.
498float3 opalFireII(Ctx c, constant NativeFrame &f) {
499 float2 p = c.uv / c.size;
500 float2 ext = c.extent / c.size;
501 float t = c.t;
502 float2 tilt = float2(sin(t * .11), cos(t * .087)) * .9;
503 float2 view = tilt + p * .4;
504 float2 event = mat_eventPoint(c, 2.9, .6);
505 float near = exp(-dot(p - event, p - event) * 3);
506 // Black potch with a deep coloured glow from fire further inside the stone.
507 float body = fbm2(p * 1.2 + float2(t * .01, 0), 3);
508 float3 color = deep(.05, f) * .04 + filmColor(body * 2.2 + dot(view, float2(.4, .3)), f) * .07 * body;
509 // Harlequin mosaic: patches, each a diffraction grating with its own angle.
510 float2 q = rot(p * 4.4 + float2(c.travel * .2, 0), .35) * float2(1, 1.3);
511 q += (float2(noise2(q * .45), noise2(q * .45 + 5.3)) - .5) * .5;
512 float4 v = voronoi(q, .85, t * .03);
513 float3 seed = hash33(float3(v.zw, 1.7));
514 float level = c.b[int(seed.z * 3.99)];
515 float2 grating = float2(cos(seed.x * TAU), sin(seed.x * TAU));
516 float facing = dot(view, grating) + (seed.y - .5) * 1.2;
517 float flash = pow(max(0.f, cos(facing * 2.2 + t * .02)), 4.f);
518 float ignite = c.hit * (near * 2.4 + mat_pick(seed.x, c) * .35);
519 // Each patch is a small diffraction grating: a spectrum runs across it and slides
520 // through it as the viewing angle changes. That sliding spectrum is the play of colour.
521 float2 local = q - v.zw - .5;
522 float across = dot(local, grating);
523 float spectrum = seed.y * 2 + across * .8 - facing * 1.1 + level * .35 + ignite * .25;
524 float band = .4 + .6 * pow(.5 + .5 * cos(across * 3 - facing * 5 + seed.z * 6), 2.f);
525 float grain = .7 + .3 * noise2(q * 9 + seed.xy * 40 + grating * t * .1);
526 float seam = .08 + .92 * smoothstep(0.f, c.px / c.size * 10, v.y - v.x);
527 float bright = (.04 + flash * (1.5 + level * 2.8) + ignite * 1.6) * band * grain * seam;
528 color += mix(paint(spectrum, f), filmColor(spectrum * 1.1, f), .7) * bright;
529 // Pinfire: tiny points of colour deeper in the stone.
530 float4 pin = voronoi(p * 15 + 3.3, .9, 0);
531 float2 ps = hash22(pin.zw);
532 float twinkle = pow(.5 + .5 * sin(dot(view, float2(cos(ps.x * TAU), sin(ps.x * TAU))) * 6 + ps.y * TAU), 10.f);
533 float dotMask = (1 - smoothstep(.03f, .09f, pin.x)) * step(.55f, ps.x);
534 color += filmColor(ps.y + .3, f) * dotMask * twinkle * (.35 + c.b.w * 2.6);
535 // Polished cabochon: a soft window reflection drifting over the stone.
536 float2 g = p - float2(-.45, .4) * ext - .25 * float2(sin(t * .05), cos(t * .04));
537 color += paint(.95, f) * exp(-dot(g * float2(1, 2.2), g * float2(1, 2.2)) * 2.5) * .12;
538 return color;
539}
540NATIVE_EFFECT(opalFireII)
541
542// ---------------------------------------------------------------- 349 Raku Crackle
543// Raku glaze straight from the kiln: smoky black glaze with pools of copper lustre whose
544// iridescence flows like oil, split by a crackle network whose seams still glow with
545// kiln heat. A broad gloss sweep rakes across the tiles; every tile is tilted a little,
546// so the copper flash breaks at each crack. Bands grow new crazing in their own regions,
547// bass heats the seams, low-mids shift the lustre colours, high-mids flash the copper,
548// highs glint metal flecks; attacks shatter a local patch with a radiating star fracture.
549float raku_edge(float4 v, float scale) { return (v.y - v.x) / scale; }
550float3 rakuCrackleII(Ctx c, constant NativeFrame &f) {
551 float2 p = c.uv / c.size;
552 float2 ext = c.extent / c.size;
553 float t = c.t;
554 float px = c.px / c.size;
555 float2 g = p + float2(c.travel * .04 + t * .004, t * .0015);
556 // Crack paths wander a little instead of running dead straight.
557 float2 gc = g + (float2(noise2(g * 1.3), noise2(g * 1.3 + 4.2)) - .5) * .3
558 + (float2(noise2(g * 6.1 + 2.3), noise2(g * 6.1 + 9.4)) - .5) * .05;
559 float4 big = voronoi(gc * 1.45, .9, 0);
560 float edgeBig = raku_edge(big, 1.45);
561 float4 fine = voronoi(gc * 4.4 + 3.1, .9, 0);
562 float edgeFine = raku_edge(fine, 4.4);
563 float2 tileSeed = hash22(big.zw);
564 // Crazed tiles lift slightly at their edges, so each one is a shallow dome with its own tilt.
565 float2 dome = (gc * 1.45 - big.zw - .5 - .45 * sin(tileSeed * TAU)) / 1.45;
566 float2 tilt = (tileSeed - .5) * .3 + (hash22(fine.zw) - .5) * .05 + dome * .9;
567 // Copper lustre pools on smoky black glaze.
568 float pool = fbm2(g * .85 + float2(2.3 - t * .006, t * .004), 3) + (tileSeed.x - .5) * .2;
569 float lustre = smoothstep(.4f, .54f, pool);
570 float thickness = fbm2(g * 1.5 + float2(t * .014, -t * .01), 3) * 2.4 + dot(tilt, float2(1.7, 1.2)) + c.b.y * .7;
571 // A broad gloss sweep: each tile's tilt shifts it, so the flash breaks at every crack.
572 float sweepAngle = .65 + .35 * sin(t * .019);
573 float2 sweepAxis = float2(cos(sweepAngle), sin(sweepAngle));
574 float sweepAt = sin(t * .047) * length(ext) * .75;
575 float s = dot(p + tilt * 1.8, sweepAxis) - sweepAt;
576 float sheen = exp(-s * s * 3.5);
577 // The reflected window: a crisp stripe that steps sideways at every crack.
578 float window = 1 - smoothstep(.12f, .16f, abs(s + .05 * sin(dot(p, sweepAxis.yx) * 2.3)));
579 float flash = .6 + sheen * (.6 + c.b.z * 1.8) + window * (.7 + c.b.z);
580 // Lustre bands run through the film; their hue follows their brightness like hot metal,
581 // dim bands red, bright ones gold, so the glaze never turns brown.
582 float band = flash * (.3 + .7 * smoothstep(-.35f, .75f, sin(thickness * 3.2)));
583 float3 film = mix(paint(.03 + .42 * min(band * band, 1.5f), f), filmColor(thickness, f), .15) * band;
584 float3 smoke = deep(.1 + .1 * tileSeed.y, f) * .05 + paint(0, f) * .05 * fbm2(g * 3 + 1.7, 2);
585 float3 color = mix(smoke + paint(.15, f) * .14 * sheen + paint(.42, f) * .3 * window, film, lustre);
586 color += paint(.8, f) * window * .1 * lustre;
587 // Metal flecks in the lustre glint with the highs.
588 float4 micro = voronoi(g * 13 + 7.7, .9, 0);
589 float fleck = (1 - smoothstep(.03f, .08f, micro.x)) * step(.72f, hash21(micro.zw));
590 color += paint(.9, f) * fleck * lustre * (.06 + .3 * sheen + c.b.w * 1.6);
591 // Bands grow new crazing in their own regions; the network also spreads slowly on its own.
592 float growth = 0;
593 for (int k = 0; k < 4; ++k) {
594 float angle = float(k) * 1.5708 + .4 + t * .02;
595 float2 at = float2(cos(angle), sin(angle)) * ext * .55;
596 growth += c.b[k] * exp(-dot(p - at, p - at) * 1.1);
597 }
598 float spread = .2 + .2 * sin(dot(g, float2(1.3, .9)) - t * .05) + growth * .9;
599 float front = noise2(gc * 2.3 + 6.1) * .85 + noise2(gc * 7.3 + 1.9) * .3;
600 float reveal = smoothstep(front - .06f, front + .06f, spread);
601 // Smoke stains the glaze along every crack; the seams themselves still glow.
602 float heat = .5 + .5 * noise2(gc * 2.2 + float2(0, t * .09)) + c.b.x * 1.2;
603 float3 seamColor = paint(.4 + .38 * min(heat, 1.f), f);
604 float3 haloColor = paint(.25 + .25 * min(heat, 1.f), f);
605 float wBig = max(.0045f, px * 1.1), wFine = max(.0025f, px * .8);
606 float crackBig = 1 - smoothstep(wBig * .4, wBig + px, edgeBig);
607 float crackFine = 1 - smoothstep(wFine * .4, wFine + px, edgeFine);
608 color *= 1 - .85 * exp(-edgeBig / .03) - .5 * exp(-edgeFine / .012) * (.3 + .7 * reveal);
609 color += seamColor * crackBig * (.45 + heat);
610 color += haloColor * exp(-edgeBig / (.01 + .018 * min(heat, 1.5f))) * .45 * heat;
611 color += seamColor * crackFine * reveal * (.1 + growth * 1.2 + .12 * heat);
612 // Attacks shatter a local patch: a star fracture and fine crazing radiate from the strike.
613 float2 strike = mat_eventPoint(c, 4.1, .55);
614 float2 d = p - strike;
615 float r = length(d);
616 float reach = .1 + (1 - c.hit) * .5;
617 float zone = c.hit * smoothstep(reach + .06f, reach - .12f, r);
618 float spokes = 9;
619 float a = atan2(d.y, d.x) + .15 * sin(r * 14 + strike.x * 5);
620 float spokeDistance = abs(fract(a / TAU * spokes + .5 * noise2(float2(r * 3, strike.y))) - .5) * TAU / spokes * r;
621 float star = 1 - smoothstep(wBig * .4, wBig + px, spokeDistance);
622 float crazing = 1 - smoothstep(.0015f, .0015f + px, raku_edge(micro, 13));
623 color *= 1 - .5 * zone;
624 color += paint(.9, f) * (star + crazing * .8) * zone * 1.6;
625 color += paint(.8, f) * exp(-pow((r - reach) / .045, 2.f)) * c.hit * .9;
626 return color;
627}
628NATIVE_EFFECT(rakuCrackleII)