Branchwell

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

Raw 21.2 KB on 87dd19288bbd69b69b6ac6e250fb5d18bfebb877
1// Liquid, molten and wave designs. Original PulseCanvas procedural code.
2// Every effect receives Ctx from NativeCommon.metal; audio terms are zero at zero Chaos.
3
4// ------------------------------------------------------------------ 31 Silk Cascade
5// Layered satin drapes hang at different depths and drift toward the viewer. Pleats run
6// down each drape; bass deepens them, attacks send a gust across the cloth, and highs
7// tighten the satin highlight.
8float silkHeight(float2 p, float id, Ctx c) {
9 float drift = c.t * .3 + c.m * .5 + id * 1.7;
10 float gust = c.b.x * .6 + c.hit * .5;
11 float sway = sin(p.y * .9 + drift) * (.9 + gust * .8) + sin(p.y * 2.3 - drift * 1.3 + id) * .25;
12 float pleats = sin(p.x * 5.5 + sway * 1.6 + id * 3.1);
13 pleats = sign(pleats) * pow(abs(pleats), .7f);
14 float secondary = sin(p.x * 13 + sway * 3 - p.y * .6) * .18;
15 float cascade = sin(p.y * 3.4 - drift * 2.2 + p.x * .8) * (.08 + gust * .14);
16 return pleats * .5 + secondary + cascade;
17}
18float3 silkCascade(Ctx c, constant NativeFrame &f) {
19 float3 color = deep(.15 + c.uv.y * .06, f) * .05;
20 const int count = 5;
21 for (int k = 0; k < count; ++k) {
22 float2 slot = layerSlot(k, count, c.travel * 0.1);
23 float phase = slot.x, id = slot.y, fade = layerFade(phase);
24 float scale = layerScale(phase, 2.2) * .7 / c.size;
25 float2 p = rot(c.uv, .12 * sin(id * 1.9)) * scale + float2(hash11(id) * 17, id * 5.3);
26 float coordinate = p.x * .23 + .12 * sin(p.y * .6 + c.t * .15 + id);
27 float gap = abs(fract(coordinate) - .5) * 2;
28 float width = .8 + .1 * sin(id * 2.3);
29 float edge = c.px * scale * 3;
30 float mask = (1 - smoothstep(width - edge, width + edge, gap)) * fade;
31 float shadow = (1 - smoothstep(width, width + .25, gap)) * fade;
32 float h = silkHeight(p, id, c), e = .006;
33 float2 slope = float2(silkHeight(p + float2(e, 0), id, c) - h, silkHeight(p + float2(0, e), id, c) - h) / e;
34 float3 n = normalize(float3(-slope * .16, 1));
35 float3 light = normalize(float3(-.65, .35, .65));
36 float diffuse = max(dot(n, light), 0.f);
37 float3 halfway = normalize(light + float3(0, 0, 1));
38 float sheen = pow(max(dot(n, halfway), 0.f), 40 + c.b.w * 80 + c.detail * 40);
39 float rim = pow(1 - n.z, 2.f);
40 float3 cloth = paint(.2 + hash11(id + 3) * .45 + h * .08, f);
41 float3 shaded = cloth * (.04 + diffuse * diffuse * .9 + rim * .2) + paint(.92, f) * sheen * (1.1 + c.detail);
42 shaded *= .75 + .25 * smoothstep(width, width * .6, gap);
43 float depthTone = mix(.3, 1., phase) * (1 - c.fog * .4 * (1 - phase));
44 color *= 1 - shadow * .7;
45 color = mix(color, shaded * depthTone, mask);
46 }
47 return color;
48}
49
50// ------------------------------------------------------------------ 33 Ribbon Foundry
51// Broad forged ribbons twist through depth. Each shows a chrome face and a hot face; the
52// twist reveals one, then the glowing edge, then the other. Music speeds individual
53// twists, bass curls the ribbons and highs heat their edges.
54float3 ribbonFoundry(Ctx c, constant NativeFrame &f) {
55 float3 color = deep(.08 + c.screen.y * .1, f) * .05;
56 color += paint(.9, f) * pow(noise2(c.uv * 3 + c.t * .1), 6.f) * .05;
57 const int count = 9;
58 for (int k = 0; k < count; ++k) {
59 float2 slot = layerSlot(k, count, c.travel * 0.09);
60 float phase = slot.x, id = slot.y, fade = layerFade(phase);
61 float scale = layerScale(phase, 2.6) * .6;
62 float angle = (hash11(id * 7.1) - .5) * 1.2;
63 float2 p = rot(c.uv, angle) * scale + float2(id * 2.3, (hash11(id) - .5) * 1.4);
64 float band = hash11(id * 3.3);
65 float curl = .38 + c.b.x * .3 * (band < .5 ? 1. : .6);
66 float center = curl * sin(p.x * 1.1 + c.t * .4 + id) + .18 * sin(p.x * 2.6 - c.t * .3 + id * 2);
67 center += c.hit * .12 * sin(p.x * 5 - c.m * 6 + id);
68 float twist = p.x * (1.4 + band) + c.t * (.6 + band * .5) + c.m * (.8 + band) + id;
69 float facing = cos(twist);
70 float halfWidth = .2 * c.size * max(abs(facing), .045);
71 float across = (p.y - center) / halfWidth;
72 float pixel = c.px * scale / halfWidth;
73 float body = (1 - smoothstep(1 - pixel, 1 + pixel, abs(across))) * fade;
74 float bevel = sqrt(max(0.f, 1 - across * across));
75 float3 n = normalize(float3(0, sin(twist) + across * .45 * facing, abs(facing) * (.5 + .5 * bevel)));
76 float3 light = normalize(float3(.3, .6, .75));
77 float specular = pow(max(dot(reflect(-light, n), float3(0, 0, 1)), 0.f), 24.f);
78 float3 chrome = paint(.3 + band * .4 + n.y * .2, f) * (.15 + .5 * max(dot(n, light), 0.f)) + paint(.95, f) * specular * 1.4;
79 float3 molten = paint(.75 + n.y * .15, f) * (.65 + .35 * bevel) * 1.4;
80 float3 face = facing > 0 ? chrome : molten;
81 float edge = pow(abs(across), 8.f) * (1 - abs(facing)) * (1.2 + c.b.w * 2);
82 face += paint(.9, f) * edge;
83 float depthTone = mix(.3, 1., phase);
84 color = mix(color * (1 - .4 * fade * exp(-abs(across) * .5) * step(1.f, abs(across))), face * depthTone, body);
85 color += paint(.85, f) * exp(-max(abs(across) - 1, 0.f) * 6) * .04 * fade * (1 - body);
86 }
87 return color;
88}
89
90// ------------------------------------------------------------------ 40 Lava Estuary
91// An oblique flight over a molten delta: cooled crust plates drift on glowing rivers.
92// Bass opens the cracks where surges pass, attacks flare the seams, highs lift embers.
93
94
95// ------------------------------------------------------------------ 78 Ferrofluid Crown
96// One continuous liquid height field: smooth magnetic crowns and travelling capillary
97// waves. Analytic slopes keep reflections joined across the triangular lattice.
98
99
100// ------------------------------------------------------------------ 79 Windowpane Drizzle
101// Rain running down a window in front of soft city lights. Every drop is a lens that
102// shows a sharp, inverted view of the lights. Bands brighten individual lights; the
103// music clock speeds the running drops.
104float3 bokehLights(float2 p, float blur, Ctx c, constant NativeFrame &f) {
105 float3 color = deep(.12 + p.y * .05, f) * .22 + paint(.3, f) * .05 * (1 + p.y);
106 for (int layer = 0; layer < 3; ++layer) {
107 float fl = float(layer);
108 float2 q = p * (1.4 + fl * .9) + float2(fl * 7.3, c.t * .025 * (fl + 1));
109 float2 base = floor(q);
110 for (int y = -1; y <= 1; ++y) for (int x = -1; x <= 1; ++x) {
111 float2 cell = base + float2(x, y);
112 float seed = hash21(cell + fl * 31);
113 if (seed < .3) continue;
114 float2 center = cell + .5 + (hash22(cell + fl * 17) - .5) * .8;
115 float band = c.b[int(fract(seed * 7.3) * 3.99)];
116 float radius = (.32 + fract(seed * 13.1) * .3) * (1 + band * .3);
117 float d = length(q - center);
118 float soft = blur * (1.4 + fl);
119 float disc = 1 - smoothstep(radius - soft, radius + soft, d);
120 float ring = exp(-pow((d - radius) / (soft + .03), 2.f)) * .3;
121 float shimmer = .65 + .35 * sin(c.t * (.4 + seed) + seed * 40) + c.hit * step(.6, fract(seed * 3.7)) * 1.2;
122 color += paint(seed * 1.6 + fl * .25, f) * (disc * .35 + ring * .5) * shimmer * (1 + band * 1.6) / (1 + fl * .6);
123 }
124 }
125 return color;
126}
127float3 windowpaneDrizzle(Ctx c, constant NativeFrame &f) {
128 float2 view = c.uv * (1 - .08 * sin(c.travel * .2)) + float2(0, c.travel * .05);
129 float2 refraction = 0.f;
130 float drop = 0;
131 // Static beads.
132 float2 grid = c.uv * 9 / c.size;
133 float2 cell = floor(grid), local = fract(grid) - .5;
134 float2 seed = hash22(cell);
135 float2 bead = local - (seed - .5) * .6;
136 float beadRadius = .08 + seed.x * .14;
137 float beadMask = 1 - smoothstep(beadRadius * .85, beadRadius, length(bead));
138 beadMask *= step(.35, seed.y);
139 refraction += bead / beadRadius * beadMask;
140 drop = max(drop, beadMask);
141 // Running drops with trails.
142 float columns = 5 / c.size;
143 float x = c.uv.x * columns;
144 float column = floor(x);
145 float lane = hash11(column * 3.7);
146 float speed = .25 + lane * .35;
147 float fall = c.t * speed + c.m * .4 * (lane + .3) + lane * 9;
148 float y = c.uv.y * columns * .6 + fall;
149 float segment = floor(y);
150 float local1 = fract(y);
151 float wiggle = sin(c.uv.y * 9 + lane * 20) * .08;
152 float2 runner = float2(fract(x) - .5 - wiggle - (hash11(segment + column) - .5) * .4, (local1 - .25) * 1.6);
153 float runnerRadius = .2 + hash11(column + segment * 1.7) * .1;
154 float runnerMask = (1 - smoothstep(runnerRadius * .8, runnerRadius, length(runner * float2(1, .7)))) * step(.3, hash11(segment * 2.1 + column));
155 float trail = (1 - smoothstep(.03f, .07f, abs(runner.x))) * smoothstep(.0f, .8f, local1 - .3) * .6 * step(.3, hash11(segment * 2.1 + column));
156 refraction += runner / runnerRadius * runnerMask * 1.4;
157 drop = max(drop, runnerMask);
158 float3 behind = bokehLights(view, .08, c, f);
159 float3 through = bokehLights(view * float2(-1, -1) * .6 + refraction * .3 + 2, .015, c, f);
160 float3 color = mix(behind * (1 - trail * .3), through * 1.3, drop);
161 float3 n = normalize(float3(refraction, 1));
162 color += paint(.95, f) * pow(max(dot(n, normalize(float3(-.5, .7, .6))), 0.f), 30.f) * drop * (1 + c.b.w);
163 color += paint(.9, f) * trail * .05;
164 return color;
165}
166
167// ------------------------------------------------------------------ 80 Ink Bloom
168// Palette inks billow downward through clear water over a pale ground. Bass makes the
169// plumes billow, attacks release fresh puffs, highs add fine filaments.
170float3 inkBloom(Ctx c, constant NativeFrame &f) {
171 float3 paper = mix(paint(.8, f), paint(1, f), .5) * 1.6;
172 float3 color = paper * (.9 + .1 * fbm2(c.uv * 3, 3));
173 for (int ink = 0; ink < 3; ++ink) {
174 float fi = float(ink);
175 float2 p = c.uv * (.9 + fi * .25) / c.size + float2(fi * 3.7, 0);
176 p.y += c.t * (.12 + fi * .03) + c.travel * .12;
177 float billow = .8 + c.b.x * .5 + c.e * .3;
178 float2 warp = float2(fbm2(p * 1.3 + float2(0, c.t * .1) + fi, 4), fbm2(p * 1.3 + float2(5.2, -c.t * .08) + fi, 4));
179 float2 q = p + (warp - .5) * 1.6 * billow;
180 q += curl2(q * 1.4 + c.m * .3) * (.08 + c.b.x * .08 + c.hit * .1);
181 float plume = fbm2(q * 1.6, 5);
182 float columns = .5 + .5 * sin(q.x * 2.3 + fi * 2);
183 float density = smoothstep(.45, .75, plume * (.75 + .45 * columns));
184 float filaments = pow(max(0.f, 1 - abs(fbm2(q * 6 + fi, 3) - .5) * 6), 3.f) * (.25 + c.detail * .4 + c.b.w * .8);
185 density = clamp(density + filaments * smoothstep(.3, .6, plume), 0.f, 1.f);
186 float3 inkColor = paint(.1 + fi * .32, f);
187 color = mix(color, color * inkColor * 1.1, density * .85);
188 }
189 return color;
190}
191
192// ------------------------------------------------------------------ 81 Oil Marble
193// Combed marbling with thin-film colors. Slow vortices fold the bands; the music clock
194// spins them, bass pulls the comb, attacks drop new rings of ink.
195float2 marbleWarp(float2 p, Ctx c) {
196 for (int i = 0; i < 4; ++i) {
197 float fi = float(i);
198 float2 center = float2(sin(c.t * .07 + fi * 2.3), cos(c.t * .06 + fi * 1.7)) * 1.6;
199 float2 d = p - center;
200 float r = length(d);
201 float spin = (.9 + c.b.y * .8) * exp(-r * r * .6) * sin(c.t * .11 + c.m * .4 + fi * 2.1);
202 p = center + rot(d, spin);
203 }
204 p.x += sin(p.y * 3.1 + c.t * .2) * (.12 + c.b.x * .18);
205 p.y += sin(p.x * 1.7 - c.t * .15) * .18;
206 return p;
207}
208float3 oilMarblePattern(float2 p, Ctx c, constant NativeFrame &f) {
209 float2 q = marbleWarp(p, c);
210 float drop = 0;
211 for (int i = 0; i < 3; ++i) {
212 float beat = floor(c.m * .5 + float(i) / 3);
213 float age = fract(c.m * .5 + float(i) / 3);
214 float2 center = (hash22(float2(beat, float(i))) - .5) * 3;
215 drop += sin(length(q - center) * 14 - age * 6) * exp(-length(q - center) * 1.5) * (1 - age) * smoothstep(0.f, .1f, age);
216 }
217 float bands = q.y * 2.2 + fbm2(q * 1.5, 4) * 1.4 + drop * (.35 + c.hit * .5);
218 float thickness = fract(bands);
219 float3 film = filmColor(bands * .35 + c.t * .01, f);
220 float vein = exp(-abs(thickness - .5) * 16) * .6;
221 return film * (.55 + .45 * smoothstep(.1f, .5f, thickness)) + paint(.95, f) * vein * (.5 + c.hit * .8);
222}
223float3 oilMarble(Ctx c, constant NativeFrame &f) {
224 float3 color = 0.f;
225 for (int octave = 0; octave < 2; ++octave) {
226 float2 z = octaveZoom(c.travel * .12, octave);
227 color += oilMarblePattern(c.uv * z.x * .9 / c.size + float2(0, float(octave) * 0), c, f) * z.y;
228 }
229 float2 n = curl2(c.uv * 3 + c.t * .05) * .1;
230 color += paint(.9, f) * pow(max(0.f, n.x + n.y), 2.f) * .3 * (1 + c.b.w);
231 return color;
232}
233
234// ------------------------------------------------------------------ 82 Chladni Sand
235// Sand piles into the nodal lines of a vibrating brass plate. The mode drifts slowly;
236// bass shakes grains off the lines and attacks scatter them, so loud passages blur the
237// figure and quiet ones let bold ridges form again.
238
239
240// ------------------------------------------------------------------ 83 Ripple Tank
241// An oblique view across a wide ripple tank. Drifting sources interfere; the curvature of
242// the surface focuses light into caustic lines on the floor. Each source follows its own
243// band; attacks drop a ring at a new point.
244float tankHeight(float2 p, Ctx c) {
245 float h = 0;
246 float2 cell = floor(p / 2.5);
247 for (int y = -1; y <= 1; ++y) for (int x = -1; x <= 1; ++x) {
248 float2 id = cell + float2(x, y);
249 float2 seed = hash22(id);
250 float2 source = (id + .5 + (seed - .5) * .5) * 2.5 + float2(sin(c.t * .2 + seed.x * 6), cos(c.t * .17 + seed.y * 6)) * .35;
251 float r = length(p - source);
252 float band = c.b[int(seed.x * 3.99)];
253 float amplitude = (.35 + band * .8 + c.hit * .5 * step(.5, seed.y)) / (1 + r * .6) * smoothstep(2.5f, 1.2f, r);
254 h += amplitude * sin(r * (8 + seed.y * 3) - c.t * 2.2 - c.m * 2 + seed.x * 6);
255 }
256 float drop = floor(c.m * .7), age = fract(c.m * .7);
257 float2 at = (hash22(float2(drop, 3)) - .5) * 6 + float2(0, c.travel * 1.2 + 6);
258 float r = length(p - at);
259 h += exp(-abs(r - age * 6) * 3) * sin(r * 9 - age * 20) * (1 - age) * smoothstep(0.f, .08f, age) * (.8 + c.hit * 1.6);
260 return h * .12;
261}
262float3 rippleTank(Ctx c, constant NativeFrame &f) {
263 // Seen from directly above, drifting across an endless tank.
264 float3 g = float3(c.uv, 0);
265 float2 p = rot(c.uv, .3) * 3.2 / c.size + float2(c.t * .05, c.travel * 1.2);
266 float e = .025;
267 float h = tankHeight(p, c);
268 float hx = tankHeight(p + float2(e, 0), c), hy = tankHeight(p + float2(0, e), c);
269 float hx2 = tankHeight(p - float2(e, 0), c), hy2 = tankHeight(p - float2(0, e), c);
270 float laplacian = (hx + hx2 + hy + hy2 - 4 * h) / (e * e);
271 float2 slope = float2(hx - hx2, hy - hy2) / (2 * e);
272 float2 floorUV = p + slope * .6;
273 float2 tile = abs(fract(floorUV * .5) - .5);
274 float grout = 1 - smoothstep(.0f, .04f, min(tile.x, tile.y));
275 float caustic = clamp(1 - laplacian * .35, 0.f, 5.f);
276 caustic = pow(caustic, 3.f) * .6;
277 float3 floorColor = deep(.3 + floorUV.x * .02, f) * (.25 - grout * .15);
278 float3 color = floorColor * (.4 + caustic * .9) + paint(.85 + h, f) * pow(max(caustic - 1, 0.f), 1.5f) * .5;
279 float3 n = normalize(float3(-slope * .5, 1));
280 color += paint(.95, f) * pow(max(dot(reflect(float3(0, 0, -1), n), normalize(float3(.3, .4, .85))), 0.f), 60.f) * .6;
281 float vignette = 1 - .35 * dot(g.xy, g.xy) / dot(c.extent, c.extent);
282 return color * vignette;
283}
284
285// ------------------------------------------------------------------ 84 Chrome Metaballs
286// A drifting field of liquid-chrome droplets that merge and part as the camera glides
287// through them. Each droplet swells with its own band; attacks ripple their skins.
288float metaField(float3 p, Ctx c) {
289 float3 cell = floor(p / 3), base = cell * 3;
290 float3 local = p - base - 1.5;
291 float3 octant = sign(local);
292 float d = 9;
293 for (int i = 0; i < 8; ++i) {
294 float3 o = float3(i & 1, (i >> 1) & 1, (i >> 2) & 1) * octant;
295 float3 id = cell + o;
296 float3 seed = hash33(id);
297 float band = c.b[int(seed.x * 3.99)];
298 float3 center = (id + .5) * 3 + sin(c.t * (.3 + seed * .4) + seed * TAU) * .9;
299 float radius = (.75 + seed.y * .45) * c.size * .9 * (1 + band * .35);
300 d = smin(d, length(p - center) - radius, .9);
301 }
302 d += c.hit * .03 * sin(p.x * 9 + c.m * 5) * sin(p.y * 9) * sin(p.z * 9 - c.m * 4);
303 float2 path = float2(sin(c.t * .11) * .8, cos(c.t * .09) * .6);
304 return max(d, .9 - length(p.xy - path));
305}
306float3 chromeMetaballs(Ctx c, constant NativeFrame &f) {
307 float3 ro = float3(sin(c.t * .11) * .8, cos(c.t * .09) * .6, c.travel * 1.6);
308 float3 rd = normalize(float3(c.uv, 1.4));
309 rd.xy = rot(rd.xy, c.t * .04);
310 float travel = 0, glow = 0;
311 bool hit = false;
312 for (int i = 0; i < 44; ++i) {
313 float d = metaField(ro + rd * travel, c);
314 glow += exp(-max(d, 0.f) * 4) * .012;
315 if (d < .002 * (1 + travel * .4)) { hit = true; break; }
316 travel += d;
317 if (travel > 26) break;
318 }
319 float3 background = deep(.2 + rd.y * .2, f) * .12 + paint(.6, f) * glow * .4;
320 if (!hit) return background;
321 float3 p = ro + rd * travel;
322 float2 e = float2(.004, 0);
323 float3 n = normalize(float3(metaField(p + e.xyy, c) - metaField(p - e.xyy, c), metaField(p + e.yxy, c) - metaField(p - e.yxy, c), metaField(p + e.yyx, c) - metaField(p - e.yyx, c)));
324 float3 r = reflect(rd, n);
325 float3 environment = mix(deep(.1, f) * .25, paint(.3 + r.y * .3, f) * .8, smoothstep(-.02f, .02f, r.y));
326 float2 box = abs(float2(atan2(r.x, r.z) - c.t * .05, r.y - .55));
327 box.x = abs(fract(box.x / 1.6 + .5) - .5) * 1.6;
328 environment += paint(.95, f) * (1 - smoothstep(.0f, .03f, max(box.x - .3, box.y - .12))) * 2.2;
329 environment += paint(.75, f) * exp(-abs(r.y) * 30) * .8;
330 environment += deep(.4, f) * .2 * step(r.y, 0.f) * smoothstep(.9f, 1.f, abs(sin(r.x / max(-r.y, .05f) * 3)));
331 float fresnel = .4 + .6 * pow(1 - max(dot(-rd, n), 0.f), 3.f);
332 float3 color = environment * fresnel;
333 float fog = exp(-travel * (.035 + c.fog * .05));
334 return mix(background, color, fog);
335}
336
337// ------------------------------------------------------------------ 85 Ocean Swell
338// Rolling open-ocean swells under a palette dusk. Bass lifts wave groups as they pass,
339// highs add chop and glitter, and the camera skims forward with Zoom speed.
340float swellHeight(float2 p, Ctx c, int octaves) {
341 float h = 0, amplitude = .55 * (1 + c.b.x * .5), frequency = .32;
342 float2 direction = normalize(float2(.3, 1));
343 for (int i = 0; i < octaves; ++i) {
344 float fi = float(i);
345 float2 d = rot(direction, fi * 1.37 - .6);
346 float phase = dot(p, d) * frequency + c.t * (.7 + fi * .21) + c.m * .25 * fi;
347 float wave = 1 - abs(sin(phase));
348 h += (wave * wave - .4) * amplitude;
349 amplitude *= .52 + c.b.w * .05; frequency *= 1.85;
350 }
351 return h;
352}
353float3 oceanSwell(Ctx c, constant NativeFrame &f) {
354 // The glide over the swell speeds up with the music clock.
355 float3 ro = float3(0, 1.6, c.travel * 2.5 + c.m * .8);
356 float3 rd = cameraRay(c.uv, float3(0, -.12, 1), float3(0, 1, 0), 1.5);
357 float3 sunDirection = normalize(float3(.25, .18, 1));
358 float3 sky = mix(paint(.85, f) * .9, deep(.25, f) * .35, smoothstep(-.05f, .5f, rd.y));
359 sky += paint(.98, f) * pow(max(dot(rd, sunDirection), 0.f), 400.f) * 4 + paint(.9, f) * pow(max(dot(rd, sunDirection), 0.f), 8.f) * .4;
360 float clouds = fbm2(rd.xz / max(rd.y, .05f) * .6 + c.t * .02, 4);
361 sky = mix(sky, paint(.6, f) * .6, smoothstep(.5f, .8f, clouds) * smoothstep(0.f, .2f, rd.y) * .6);
362 if (rd.y > 0) return sky;
363 float travel = (ro.y + .3) / -rd.y * .5, lastGap = 1;
364 for (int i = 0; i < 60; ++i) {
365 float3 p = ro + rd * travel;
366 float gap = p.y - swellHeight(p.xz, c, 4);
367 if (gap < .01) break;
368 travel += gap * .7;
369 lastGap = gap;
370 if (travel > 60) break;
371 }
372 float3 p = ro + rd * travel;
373 float e = .03;
374 float h = swellHeight(p.xz, c, 7);
375 float3 n = normalize(float3(h - swellHeight(p.xz + float2(e, 0), c, 7), e, h - swellHeight(p.xz + float2(0, e), c, 7)));
376 float3 r = reflect(rd, n);
377 r.y = abs(r.y);
378 float fresnel = .04 + .96 * pow(1 - max(dot(-rd, n), 0.f), 5.f);
379 float3 reflected = mix(paint(.85, f) * .9, deep(.25, f) * .35, smoothstep(-.05f, .5f, r.y)) + paint(.98, f) * pow(max(dot(r, sunDirection), 0.f), 120.f) * (3 + c.b.w * 4 + c.hit * 5);
380 // Crests glow from within on the low-mids, in bands that roll toward the viewer on the clock.
381 float roll = .5 + .5 * sin(p.z * .35 - c.m * 1.8 + p.x * .1);
382 float3 water = deep(.3, f) * .12 * (.6 + .4 * max(n.y, 0.f)) + paint(.45 + c.b.z * .15, f) * (.08 + c.b.y * .35 * roll) * smoothstep(-.2f, .6f, h);
383 float foam = smoothstep(.45f - c.hit * .12, .75f, h + .1 * fbm2(p.xz * 3, 3)) * (.6 + c.b.x * .5);
384 float3 color = mix(water, reflected, fresnel) + paint(.95, f) * foam * .5;
385 float distanceFog = 1 - exp(-travel * (.02 + c.fog * .03));
386 return mix(color, sky, distanceFog);
387}
388
389#define FLOW_EFFECTS(X) X(silkCascade) X(ribbonFoundry) X(windowpaneDrizzle) X(inkBloom) X(oilMarble) X(rippleTank) X(chromeMetaballs) X(oceanSwell)
390FLOW_EFFECTS(NATIVE_EFFECT)