PulseCanvas / app · pulsecanvas.ai / Sources / PulseCanvas / Resources / NativeExpansionFlightII.metal
| 1 | // Second versions of designs whose original and final review clips were both red-tagged. |
| 2 | // Original PulseCanvas designs 330–339. Flights that are not roads: canopies, strata, |
| 3 | // pillar forests, parallax silhouettes, river deltas, auroras, waterfalls, orbits, comets |
| 4 | // and cloud seas. Every scene is analytic (plane, sphere and layer intersections); no |
| 5 | // preset formulas, textures or third-party shader sources are used. |
| 6 | |
| 7 | // A point light inside a hashed grid cell. It fades to exactly zero before the cell |
| 8 | // border, so neighbouring cells never show seams. |
| 9 | float flight_spark(float d, float width, float reach) { return glow(d, width) * smoothstep(reach, reach * .4f, d); } |
| 10 | |
| 11 | // ---------------------------------------------------------------- 330 Canopy Flight |
| 12 | // Rows of hanging crystals are evaluated analytically at their own depth. The floor is a |
| 13 | // dark mirror: the same rows are reused with world height reflected, and each crystal |
| 14 | // shows there as a soft vertical smear of its light. Bass sways the pendants, each |
| 15 | // crystal follows one band, and attacks run a ripple of light along the rows. |
| 16 | |
| 17 | constant float CANOPY_CEIL = 1.f; |
| 18 | constant float CANOPY_FLOOR = -.85f; |
| 19 | constant float CANOPY_ROW = 1.15f; |
| 20 | constant float CANOPY_COL = .95f; |
| 21 | |
| 22 | float canopy_rhombus(float2 q, float2 r) { |
| 23 | q = abs(q); |
| 24 | return (q.x * r.y + q.y * r.x - r.x * r.y) / length(r); |
| 25 | } |
| 26 | |
| 27 | struct CanopyPendant { float2 anchor; float wire; float2 size; float sway; float energy; float3 tone; }; |
| 28 | |
| 29 | CanopyPendant canopy_make(float rowId, float cell, float stagger, Ctx c, constant NativeFrame &f) { |
| 30 | CanopyPendant k; |
| 31 | float3 h = hash33(float3(rowId, cell, 3.1)); |
| 32 | k.anchor = float2((cell + stagger + (h.x - .5f) * .3f) * CANOPY_COL, CANOPY_CEIL); |
| 33 | k.wire = .05f + .38f * h.y; |
| 34 | k.size = float2(.06f + .05f * h.z, .13f + .14f * hash21(float2(cell, rowId + .5f))); |
| 35 | 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); |
| 36 | float band = c.b[int(h.z * 3.99f)]; |
| 37 | float ripple = c.hit * pow(.5f + .5f * sin(rowId * .75f + cell * .45f - c.t * 2.4f), 6.f) * 3.2f; |
| 38 | k.energy = .5f + 1.9f * band + ripple; |
| 39 | k.tone = paint(h.x * .5f + rowId * .06f + cell * .11f, f); |
| 40 | return k; |
| 41 | } |
| 42 | |
| 43 | float3 canopy_pendant(float2 w, CanopyPendant k, float pw, Ctx c, constant NativeFrame &f) { |
| 44 | float2 q = rot(w - k.anchor, -k.sway); |
| 45 | float2 local = q - float2(0, -k.wire - k.size.y); |
| 46 | float body = canopy_rhombus(local, k.size); |
| 47 | float facet = local.x > 0 ? .45f : 1.f; |
| 48 | float ridge = glow(local.x, pw * 1.5f + .004f) * .8f + glow(local.y, pw * 1.5f + .004f) * .5f; |
| 49 | float core = exp(-dot(local / k.size, local / k.size) * 2.5f); |
| 50 | float inside = fill(body, pw); |
| 51 | float3 col = k.tone * inside * (facet * (.3f + .35f * (1 - abs(local.y) / k.size.y)) + ridge + core * .6f) * k.energy; |
| 52 | col += k.tone * glow(body, .01f + pw) * .9f * k.energy; |
| 53 | col += k.tone * glow(body, .09f) * .07f * k.energy; |
| 54 | float wireD = sdSegment(q, float2(0), float2(0, -k.wire)); |
| 55 | col += k.tone * glow(wireD, pw + .003f) * .3f; |
| 56 | float tip = length(q - float2(0, -k.wire - 2 * k.size.y)); |
| 57 | col += paint(.92f, f) * glow(tip, .008f + pw) * (.35f + 3 * c.b.w); |
| 58 | return col; |
| 59 | } |
| 60 | |
| 61 | // A crystal seen in the dark mirror: a soft vertical smear of its light. |
| 62 | float3 canopy_reflection(float2 w, CanopyPendant k) { |
| 63 | float2 center = k.anchor + rot(float2(0, -k.wire - k.size.y), k.sway); |
| 64 | float2 d = w - center; |
| 65 | float spread = k.size.x * (1.4f + .5f * abs(d.y)); |
| 66 | float streak = exp(-d.x * d.x / (spread * spread)) * exp(-abs(d.y) * 1.1f) * smoothstep(CANOPY_FLOOR, CANOPY_FLOOR + .6f, w.y) * smoothstep(3.4f, 2.4f, w.y); |
| 67 | return k.tone * streak * k.energy * .4f; |
| 68 | } |
| 69 | |
| 70 | float3 canopy_ceiling(float2 w, float dz, Ctx c, constant NativeFrame &f) { |
| 71 | float3 col = paint(.3f + .1f * sin(w.x * .4f + w.y * .2f), f) * .055f; |
| 72 | float row0 = floor(w.y / CANOPY_ROW); |
| 73 | for (int r = 0; r < 2; ++r) { |
| 74 | float rowId = row0 + float(r); |
| 75 | float stagger = hash11(rowId + .37f); |
| 76 | float cellF = w.x / CANOPY_COL - stagger; |
| 77 | float cell = floor(cellF + .5f); |
| 78 | float other = cell + (cellF > cell ? 1 : -1); |
| 79 | for (int m = 0; m < 2; ++m) { |
| 80 | CanopyPendant k = canopy_make(rowId, m == 0 ? cell : other, stagger, c, f); |
| 81 | float2 d = w - float2(k.anchor.x, rowId * CANOPY_ROW); |
| 82 | float r2 = dot(d, d); |
| 83 | col += k.tone * (exp(-r2 * 30) * .25f + glow(sqrt(r2), .02f) * .2f) * k.energy; |
| 84 | } |
| 85 | } |
| 86 | return col * exp(-dz * (.05f + .1f * c.fog)); |
| 87 | } |
| 88 | |
| 89 | |
| 90 | // ---------------------------------------------------------------- 331 Strata Glide |
| 91 | // A thin gap between two vast planes. Each plane carries its own flowing strata: broad |
| 92 | // warm layers below, finer cross-cut layers above. Seams between layers glow. |
| 93 | |
| 94 | float3 strata_plane(float2 w, float dz, bool upper, Ctx c, constant NativeFrame &f) { |
| 95 | float s; |
| 96 | if (upper) { |
| 97 | s = (w.y - w.x) * .26f + 1.6f * fbm2(float2(w.x * .16f + c.t * .03f, w.y * .1f), 3) + c.t * .035f; |
| 98 | s += c.b.z * .5f * sin(w.x * .55f - w.y * .3f + c.t * .5f); |
| 99 | s *= 5.f; |
| 100 | } else { |
| 101 | s = (w.x + w.y) * .24f + 1.8f * fbm2(float2(w.x * .12f, w.y * .08f - c.t * .04f), 3) - c.t * .042f; |
| 102 | s += c.b.y * .6f * sin(w.x * .5f + w.y * .3f + c.t * .45f); |
| 103 | s *= 3.6f; |
| 104 | } |
| 105 | s += .3f * sin(s * 1.3f); |
| 106 | float idx = floor(s), fr = fract(s); |
| 107 | float aa = fwidth(s); |
| 108 | float detail = 1 - smoothstep(.15f, .6f, aa); |
| 109 | float seamD = min(fr, 1 - fr); |
| 110 | float seam = (1 - smoothstep(0.f, .03f + aa * 1.5f, seamD)) * detail; |
| 111 | float wide = exp(-seamD * 10); |
| 112 | float phase = .12f + .6f * fract(idx * .23f + (upper ? .5f : 0.f)); |
| 113 | float grain = .75f + .25f * sin(fr * 23 + idx); |
| 114 | float layer = mix(.11f, (.04f + .2f * fr * fr) * grain, detail); |
| 115 | float3 col = paint(phase, f) * layer * (upper ? .6f + 1.6f * c.b.z : .7f + 1.5f * c.b.y); |
| 116 | float hitSeam = (idx - 3 * floor(idx / 3)) == 0 ? 1.f : .2f; |
| 117 | float run = pow(.5f + .5f * cos(dz * .5f - c.t * 4.f + idx * .3f), 4.f); |
| 118 | col += paint(.88f + idx * .05f, f) * (seam * .9f + wide * .22f * detail) * (1 + c.hit * hitSeam * run * 5); |
| 119 | float glint = pow(noise2(w * float2(3.f, 1.5f) + c.t * .3f), 10.f); |
| 120 | col += paint(.95f, f) * glint * wide * c.b.w * 14 * detail * smoothstep(1.f, 2.5f, dz); |
| 121 | return col; |
| 122 | } |
| 123 | |
| 124 | |
| 125 | // ---------------------------------------------------------------- 332 Pillar Forest |
| 126 | // The camera weaves along a clear path through an endless grid of luminous columns and |
| 127 | // looks slightly up, so the columns converge overhead. A 2D grid walk finds them front to |
| 128 | // back; height along each column comes from the ray. Each column follows one band and |
| 129 | // attacks send bright rings racing up the columns. |
| 130 | |
| 131 | float pillar_path(float z) { return 1.3f * sin(z * .23f) + .55f * sin(z * .51f + 1.3f); } |
| 132 | float pillar_slope(float z) { return 1.3f * .23f * cos(z * .23f) + .55f * .51f * cos(z * .51f + 1.3f); } |
| 133 | |
| 134 | |
| 135 | // ---------------------------------------------------------------- 333 Parallax Express |
| 136 | // A sideways window view: a far ridge, crystal spires, neon arches and near light bars |
| 137 | // slide laterally at increasing speeds. Each layer has its own band; attacks flare the |
| 138 | // near layer. |
| 139 | |
| 140 | struct ExpressSpire { float height; float ridge; float id; }; |
| 141 | |
| 142 | ExpressSpire express_spires(float x, float width, float seed, float lift) { |
| 143 | ExpressSpire s; s.height = -9; s.ridge = 9; s.id = 0; |
| 144 | float cell = floor(x / width); |
| 145 | for (int k = -1; k <= 1; ++k) { |
| 146 | float id = cell + float(k); |
| 147 | float3 h = hash33(float3(id, seed, 2.7)); |
| 148 | float apex = (id + .2f + .6f * h.x) * width; |
| 149 | float tall = (.3f + .7f * h.y) * lift; |
| 150 | float y = tall - abs(x - apex) * (2.4f + 2.6f * h.z); |
| 151 | if (y > s.height) { s.height = y; s.ridge = x - apex; s.id = id; } |
| 152 | } |
| 153 | return s; |
| 154 | } |
| 155 | |
| 156 | float express_hills(float x, float seed) { |
| 157 | return .55f * noise2(float2(x * .45f, seed)) + .3f * noise2(float2(x * 1.2f, seed + 4)) + .15f * noise2(float2(x * 3.1f, seed + 9)); |
| 158 | } |
| 159 | |
| 160 | |
| 161 | // ---------------------------------------------------------------- 334 Delta Flyover |
| 162 | // Looking straight down on a delta of light. Meandering trunks run downstream; each |
| 163 | // spawns distributaries that peel off, diverge and taper out, and twigs peel off those. |
| 164 | // Every channel has a world-space id, so the scroll never pops. Trunks, distributaries |
| 165 | // and twigs each follow one band; attacks send surges down the channels. |
| 166 | |
| 167 | constant float DELTA_TRUNK = 2.3f; |
| 168 | constant float DELTA_CELL = 1.5f; |
| 169 | |
| 170 | float delta_trunk(float i, float y) { |
| 171 | float h = hash11(i + .71f); |
| 172 | return (i + .5f) * DELTA_TRUNK + DELTA_TRUNK * (.26f * sin(y * .21f + h * 6.3f) + .12f * sin(y * .53f + h * 17)); |
| 173 | } |
| 174 | |
| 175 | |
| 176 | // ---------------------------------------------------------------- 335 Aurora Overpass |
| 177 | // Curtains hang across the sky at stable depths; each folds along its length, and folds |
| 178 | // seen edge-on glow brighter. The dark plain mirrors the same curtains. |
| 179 | |
| 180 | |
| 181 | // ---------------------------------------------------------------- 336 Cascade Climb |
| 182 | // Climbing the face of a vast waterfall. Tiers of falls drop between wavy ledges; each |
| 183 | // fall is a column of downward-streaming light fed by one band, and mist boils up at |
| 184 | // its foot. The camera rises with travel and looks slightly up the wall. |
| 185 | |
| 186 | constant float CASCADE_TIER = 2.4f; |
| 187 | constant float CASCADE_COLUMN = 1.15f; |
| 188 | |
| 189 | float cascade_lip(float n, float x) { return n * CASCADE_TIER + .28f * sin(x * .7f + n * 1.9f) + .12f * sin(x * 1.9f + n); } |
| 190 | |
| 191 | float3 cascadeClimbII(Ctx c, constant NativeFrame &f) { |
| 192 | const float lens = 1.25f, pitch = .24f, wallD = 2.f; |
| 193 | float2 p = c.uv / c.size; |
| 194 | float camY = c.travel * 1.5f; |
| 195 | float camX = .6f * sin(c.travel * .05f); |
| 196 | float cp = cos(pitch), sp = sin(pitch); |
| 197 | float ry = p.y * cp + lens * sp, rz = lens * cp - p.y * sp; |
| 198 | float s = wallD / max(rz, .03f); |
| 199 | float x = camX + p.x * s, y = camY + ry * s; |
| 200 | float n = floor(y / CASCADE_TIER); |
| 201 | float lipBelow = cascade_lip(n, x); |
| 202 | if (lipBelow > y) { n -= 1; lipBelow = cascade_lip(n, x); } |
| 203 | float lipAbove = cascade_lip(n + 1, x); |
| 204 | float above = y - lipBelow, below = lipAbove - y; |
| 205 | // Rock face. |
| 206 | float rock = fbm2(float2(x * 1.4f, y * 1.1f), 3); |
| 207 | float3 col = deep(.35f + rock * .3f, f) * (.03f + .06f * rock) + paint(.4f, f) * pow(rock, 4.f) * .1f; |
| 208 | // Falls: meandering columns that change from tier to tier. |
| 209 | float xw = x + .07f * sin(y * .5f + n * 2.3f); |
| 210 | float colId = floor(xw / CASCADE_COLUMN); |
| 211 | float3 h = hash33(float3(colId, n, 6.6)); |
| 212 | float band = c.b[int(fract(h.z * 7.13f) * 3.99f)]; |
| 213 | float local = abs(fract(xw / CASCADE_COLUMN) - .5f) * CASCADE_COLUMN; |
| 214 | float width = (h.x < .15f ? 0.f : .2f + .26f * h.y) + .08f * band; |
| 215 | float fall = smoothstep(width, width - .08f, local) * smoothstep(0.f, .08f, below + .05f); |
| 216 | float streakA = fbm2(float2(xw * 7.f, y * .32f + c.t * .9f + h.x * 9), 3); |
| 217 | float streakB = noise2(float2(xw * 17.f, y * .55f + c.t * 1.5f)); |
| 218 | float speedUp = smoothstep(0.f, 1.4f, below); |
| 219 | float water = pow(streakA, 1.6f) * 1.6f + streakB * .35f * speedUp; |
| 220 | float edgeLight = exp(-(width - local) * 9); |
| 221 | float3 waterTone = paint(.45f + h.x * .3f + streakA * .2f, f); |
| 222 | float foam = smoothstep(.55f, .8f, streakA + streakB * .3f) * speedUp; |
| 223 | col = mix(col, waterTone * (.04f + water * .34f + edgeLight * .16f) * (.5f + 1.7f * band) + paint(.9f, f) * foam * .28f, fall); |
| 224 | // Lips glow where water curls over the ledge. |
| 225 | float lipPx = c.px * wallD * lens / max(rz * rz, .01f); |
| 226 | float lipLine = glow(below, .03f + lipPx) * (.4f + .8f * fall) + glow(above, .03f + lipPx) * .4f; |
| 227 | col += paint(.9f, f) * lipLine * .8f; |
| 228 | // Mist boils up from the foot of each fall; attacks burst it. |
| 229 | float burst = c.hit * smoothstep(.15f, .85f, .5f + .5f * sin(n * 2.1f + colId * 1.3f + c.t * .35f)); |
| 230 | float mist = fbm2(float2(x * 1.2f, (y - c.t * .4f) * 1.3f), 3); |
| 231 | float footing = smoothstep(width + .5f, width - .2f, local) * (h.x < .2f ? .3f : 1.f); |
| 232 | float rise = exp(-max(above, 0.f) * (1.7f - 1.f * burst)) * smoothstep(-.05f, .05f, above); |
| 233 | col += paint(.66f + mist * .25f, f) * smoothstep(.2f, .7f, mist) * rise * (.5f + 1.3f * footing) * (.9f + 3.f * burst); |
| 234 | float churn = exp(-max(above, 0.f) * 5) * smoothstep(-.03f, .03f, above) * fall * (.5f + .5f * streakB); |
| 235 | col += paint(.9f, f) * churn * (.7f + 1.4f * band + 2 * burst); |
| 236 | col += paint(.85f, f) * exp(-max(below, 0.f) * 7) * fall * (.15f + .4f * streakA) * (.6f + band); |
| 237 | float spray = flight_spark(length(fract(float2(x * 9, y * 9 - c.t * 6)) - .5f), .05f, .45f) * step(.8f, hash21(floor(float2(x * 9, y * 9 - c.t * 6)))); |
| 238 | col += paint(.95f, f) * spray * rise * footing * (.3f + 5 * c.b.w); |
| 239 | // The far reaches dissolve into bright haze. |
| 240 | float far = 1 - exp(-s * .05f); |
| 241 | col = mix(col, paint(.5f, f) * .3f + paint(.8f, f) * .06f, saturate(far * (.75f + .4f * c.fog))); |
| 242 | return col; |
| 243 | } |
| 244 | NATIVE_EFFECT(cascadeClimbII) |
| 245 | |
| 246 | // ---------------------------------------------------------------- 337 Night Orbit |
| 247 | // A low orbit over the dark side of a planet. A ray-sphere hit gives surface coordinates; |
| 248 | // two voronoi networks, nodes and dust glow on the surface, with a bright limb above. |
| 249 | |
| 250 | float3 orbit_space(float3 rd, float spin, Ctx c, constant NativeFrame &f) { |
| 251 | float3 rs = float3(rd.x, rd.y * cos(spin) - rd.z * sin(spin), rd.y * sin(spin) + rd.z * cos(spin)); |
| 252 | float3 col = deep(.7f, f) * .08f + paint(.65f, f) * .1f * noise3(rs * 2.5f) * noise3(rs * 5 + 3); |
| 253 | float3 cell = floor(rs * 70); |
| 254 | float3 hs = hash33(cell); |
| 255 | float3 site = (cell + .25f + hs * .5f) / 70; |
| 256 | float star = flight_spark(length(rs - site) * 70, .06f, .25f) * step(.8f, hs.x); |
| 257 | col += paint(.85f + hs.y * .15f, f) * star * (.4f + .8f * hs.z); |
| 258 | return col; |
| 259 | } |
| 260 | |
| 261 | float3 nightOrbitII(Ctx c, constant NativeFrame &f) { |
| 262 | const float R = 5.f, H = .5f, lens = 1.25f, pitch = .6f; |
| 263 | float2 p = rot(c.uv, .07f * sin(c.t * .05f)) / c.size; |
| 264 | float cp = cos(pitch), sp = sin(pitch); |
| 265 | float3 rd = normalize(float3(p.x, p.y * cp - lens * sp, lens * cp + p.y * sp)); |
| 266 | float3 ro = float3(0, R + H, 0); |
| 267 | float orbit = c.travel * .9f; |
| 268 | float b = dot(ro, rd), disc = b * b - (dot(ro, ro) - R * R); |
| 269 | float closest = (b < 0 ? sqrt(max(dot(ro, ro) - b * b, 0.f)) : length(ro)) - R; |
| 270 | float3 col; |
| 271 | if (disc > 0 && -b - sqrt(disc) > 0) { |
| 272 | float s = -b - sqrt(disc); |
| 273 | float3 P = ro + rd * s, n = P / R; |
| 274 | float facing = max(dot(n, -rd), .05f); |
| 275 | float2 q = float2(atan2(P.z, P.y) * R + orbit, asin(clamp(n.x, -1.f, 1.f)) * R) * .9f; |
| 276 | float foot = c.px * s / lens / facing * .9f; |
| 277 | float detail = 1 - smoothstep(.02f, .1f, foot); |
| 278 | float land = smoothstep(.26f, .46f, fbm2(q * .15f + 2, 3)); |
| 279 | float4 v1 = voronoi(q * 1.7f, .9f, 0); |
| 280 | float4 v2 = voronoi(q * 5.f + 7, .9f, 0); |
| 281 | float art = glow(v1.y - v1.x, .02f + foot * 1.7f) * (.4f + .6f * hash21(v1.zw)); |
| 282 | float web = glow(v2.y - v2.x, .025f + foot * 5.f) * detail; |
| 283 | float node = glow(v1.x, .045f + foot * 1.7f) * step(.2f, hash21(v1.zw + 3)); |
| 284 | float2 dustCell = floor(q * 9); |
| 285 | float3 dh = hash33(float3(dustCell, 1.7)); |
| 286 | float dust = flight_spark(length(q * 9 - dustCell - .2f - dh.xy * .6f), .08f, .2f) * step(.55f, dh.z) * detail * (.5f + .5f * sin(c.t * 3 + dh.x * 40)); |
| 287 | float2 rel = q - float2(orbit * .9f + 2.6f, 0); |
| 288 | float dist = length(rel * float2(1, 1.3f)); |
| 289 | float ring = c.hit * pow(.5f + .5f * sin(dist * 2.2f - c.t * 3.2f), 10.f) * exp(-dist * .2f); |
| 290 | float lift = 1 + 3 * ring; |
| 291 | col = deep(.45f + land * .2f, f) * (.02f + .035f * land) + paint(.35f + .1f * art, f) * (1 - land) * (.03f + .03f * noise2(q * 2.5f)); |
| 292 | col += paint(.3f + hash21(v1.zw) * .25f, f) * (art * .8f + exp(-(v1.y - v1.x) * 7) * .12f) * (.25f + .75f * land) * (.45f + 1.9f * c.b.x) * lift; |
| 293 | col += paint(.55f + hash21(v2.zw) * .2f, f) * web * (.35f + .65f * land) * (.35f + 1.9f * c.b.y) * lift * .6f; |
| 294 | col += paint(.92f, f) * node * land * (.45f + 2.6f * c.b.z) * lift; |
| 295 | col += paint(.8f, f) * dust * land * (.3f + 4 * c.b.w); |
| 296 | col += paint(.5f, f) * ring * .35f; |
| 297 | float haze = pow(1 - facing, 6.f); |
| 298 | col = mix(col, paint(.3f, f) * .3f, haze * (.5f + .3f * c.fog)); |
| 299 | } else { |
| 300 | col = orbit_space(rd, orbit / R, c, f); |
| 301 | } |
| 302 | float limbSide = .6f + .4f * sin(rd.x * 2.2f + c.t * .03f); |
| 303 | float alt = abs(closest); |
| 304 | float sky = closest > 0 ? 1.f : .25f; |
| 305 | col += paint(.25f + alt * 2, f) * (exp(-alt * 22) * .8f + exp(-alt * 5) * .25f) * limbSide * sky; |
| 306 | col += paint(.95f, f) * glow(closest, .006f) * .5f * limbSide; |
| 307 | return col; |
| 308 | } |
| 309 | NATIVE_EFFECT(nightOrbitII) |
| 310 | |
| 311 | // ---------------------------------------------------------------- 338 Comet Chase |
| 312 | // Chasing a comet head that hangs ahead and to one side. The ion and dust tails stream |
| 313 | // out of it toward the camera; debris layers fly past on stable depth slots. |
| 314 | |
| 315 | |
| 316 | // ---------------------------------------------------------------- 339 Cloud Sea |
| 317 | // Skimming a sea of cloud tops. The deck is a billowing height field traced with a short |
| 318 | // march; tops catch sky light, while coloured lights on a world grid glow up through the |
| 319 | // thin valleys between billows. Each light has its own band. |
| 320 | |
| 321 | constant float CLOUD_LIGHT = 2.f; |
| 322 | |
| 323 | float cloud_height(float2 w, float drift) { |
| 324 | float2 q = w * 1.2f + float2(drift, 0); |
| 325 | float a = abs(2 * noise2(q) - 1), b = abs(2 * noise2(q * 2.4f + 5.2f) - 1), d = abs(2 * noise2(q * 5.3f + 1.7f) - 1); |
| 326 | return .26f * sqrt(a) + .1f * sqrt(b) + .035f * d; |
| 327 | } |
| 328 | |
| 329 | float3 cloud_light(float2 w, Ctx c, constant NativeFrame &f) { |
| 330 | float2 cell = floor(w / CLOUD_LIGHT); |
| 331 | float2 d = w - (cell + .5f) * CLOUD_LIGHT; |
| 332 | float3 h = hash33(float3(cell, 8.3)); |
| 333 | float falloff = 1 - smoothstep(0.f, CLOUD_LIGHT * .55f, length(d)); |
| 334 | float band = c.b[int(h.z * 3.99f)]; |
| 335 | float select = smoothstep(.55f, .95f, .5f + .5f * sin(h.x * TAU + c.t * .6f)); |
| 336 | float energy = .45f + 2.4f * band + c.hit * select * 6; |
| 337 | return paint(.15f + h.x * .7f, f) * falloff * falloff * energy; |
| 338 | } |
| 339 | |
| 340 | float3 cloudSeaII(Ctx c, constant NativeFrame &f) { |
| 341 | const float lens = 1.2f, camH = .75f, top = .42f; |
| 342 | float2 p = c.uv / c.size; |
| 343 | float horizon = .34f; |
| 344 | float vy = horizon - p.y; |
| 345 | float camZ = c.travel * 1.5f; |
| 346 | float camX = .9f * sin(c.travel * .05f); |
| 347 | float drift = c.t * .04f; |
| 348 | float3 haze = paint(.55f, f) * .28f + paint(.8f, f) * .05f; |
| 349 | float3 col; |
| 350 | if (vy > 0) { |
| 351 | float3 rd = float3(p.x, -vy, lens); |
| 352 | float t = (camH - top) / vy; |
| 353 | float3 pos = float3(camX, camH, camZ) + rd * t; |
| 354 | float gap = pos.y - cloud_height(pos.xz, drift); |
| 355 | float prevT = t, prevGap = gap; |
| 356 | for (int i = 0; i < 24 && gap > 0; ++i) { |
| 357 | prevT = t; prevGap = gap; |
| 358 | t += max(gap * .55f / vy, .015f + t * .012f); |
| 359 | pos = float3(camX, camH, camZ) + rd * t; |
| 360 | gap = pos.y - cloud_height(pos.xz, drift); |
| 361 | } |
| 362 | if (gap < 0) t = mix(prevT, t, prevGap / max(prevGap - gap, 1e-4f)); |
| 363 | pos = float3(camX, camH, camZ) + rd * t; |
| 364 | float2 w = pos.xz; |
| 365 | float e = .02f + t * .004f; |
| 366 | float hc = cloud_height(w, drift); |
| 367 | float3 n = normalize(float3(hc - cloud_height(w + float2(e, 0), drift), e, hc - cloud_height(w + float2(0, e), drift))); |
| 368 | float thin = 1 - saturate(hc / .3f); |
| 369 | float2 q = w * 1.2f + float2(drift, 0); |
| 370 | float creaseA = abs(2 * noise2(q) - 1), creaseB = abs(2 * noise2(q * 2.4f + 5.2f) - 1); |
| 371 | float crease = exp(-creaseA * 9) + .5f * exp(-creaseB * 12); |
| 372 | float3 inner = cloud_light(w, c, f); |
| 373 | float sky = saturate(n.y * .5f - n.z * .5f + .2f); |
| 374 | float rim = pow(1 - saturate(dot(n, -normalize(rd))), 3.f); |
| 375 | float3 lit = paint(.6f + hc * .8f, f) * sky * sky * .14f + inner * (.06f + thin * thin * .6f + crease * 1.8f) |
| 376 | + (paint(.88f, f) * .12f + inner * .35f) * rim * (.5f + 1.2f * c.b.x); |
| 377 | float depth = t * lens; |
| 378 | col = mix(haze, lit, exp(-depth * (.035f + .07f * c.fog))); |
| 379 | } else { |
| 380 | float up = -vy; |
| 381 | col = mix(haze, deep(.8f, f) * .1f + paint(.75f, f) * .05f, saturate(up * 1.4f)); |
| 382 | float streak = pow(.5f + .5f * sin(up * 14 + noise2(float2(p.x * .8f - c.travel * .1f, up * 3)) * 3), 8.f); |
| 383 | col += paint(.7f + up * .2f, f) * streak * .15f * exp(-up * 1.5f); |
| 384 | } |
| 385 | col += paint(.85f, f) * exp(-abs(vy) * 18) * .2f; |
| 386 | return col; |
| 387 | } |
| 388 | NATIVE_EFFECT(cloudSeaII) |