# @author Claude # @model Claude Fable 5.2 # @description A small boat rides a storm toward a lighthouse and reaches it at first light. # @music 6/8 sea tune in D minor at 90 BPM: fog signal and bell buoy, low whistle over a lilting bass, then reed, brass and galloping drums under thunder, and the same tune in D major at dawn; the surf is one held noise voice automated from the timeline # @visual one continuous shot from the bow: heightfield-marched swell with Fresnel sky reflection and foam, a raymarched banded lighthouse on a skerry, an analytic rotating volumetric beam that whites out the lens on every second bar, thunder-triggered lightning, rain lit only where light crosses it, moon to sunrise; scale=2 dither=1 # @tags raymarch, ocean, storm, cinematic # @duration 64 # fyr.dmt - "fyr" is Norwegian for lighthouse. 90 BPM, 6/8, rpb=6: one beat = one # second, one bar = 12 rows = 2 s, eight 4-bar patterns = 64 s. # The two-sided beam turns once every 8 s, so it crosses the camera on rows 0 # and 24 of every pattern; the drum marks each pass. title FYR song bpm=90 speed=6 rpb=6 channels=8 loop=0 volume=0.45 scale=2 dither=1 order 0 1 2 3 4 5 6 7 pan 0.50 0.56 0.50 0.46 0.42 0.60 0.50 0.50 text ttl "FYR" text cap "A LIGHT KEPT FOR ONE BOAT" timeline { 0:00 stormv=0.08 covv=0.28 dawnv=0 lampv=1 titlev=0 2:00 stormv=0.22 covv=0.45 3:00 stormv=0.55 covv=0.80 4:00 stormv=1.00 covv=1.00 5:36 stormv=1.00 covv=1.00 6:00 stormv=0.42 covv=0.62 dawnv=0 7:00 stormv=0.14 covv=0.36 dawnv=0.55 7:20 titlev=0 7:24 lampv=1 7:30 lampv=0 7:34 titlev=1 7:47 stormv=0.06 covv=0.30 dawnv=1 lampv=0 titlev=1 } # ------------------------------------------------------------------ instruments inst drum { f = 46 + 130 * exp(-t * 16) $p = $p + f / sr body = sin($p * tau) * exp(-t * 3.4) skin = lp(noise(), 600) * exp(-t * 24) out(dist((body * 1.1 + skin * 0.6) * 1.3, 1.2) * 0.62) } inst brush { e = exp(-t * (16 + 26 * (1 - vel))) n = svf(noise(), 2100, 0.45) out((r2 * 0.8 + hp(noise(), 5200) * 0.35) * e * 2.6) } inst bass { e = env(0.02, 0.30, 0.70, 0.25) s = sin(ph * tau) * 0.9 + bsaw(ph, freq) * 0.28 s = svf(s, 170 + 520 * e, 0.25) out(dist(s * e, 1.2) * 0.50) } # p0 picks the third: S00 minor, SFF major inst pad nna=continue { e = env(0.55, 0.8, 0.85, 1.7) third = 2 ^ ((3 + step(0.5, p0)) / 12) a = usaw(freq, 0.15) + usaw(freq * third, 0.15) + usaw(freq * 1.4983, 0.15) s = svf(a, 420 + 1700 * evtl(stormv) + 280 * e, 0.14) out(s * e * 0.19) } inst whistle { e = env(0.06, 0.2, 0.86, 0.32) vib = 0.22 * sin(t * 5.4 * tau) * smooth(0.12, 0.5, t) tone = sin(ph * tau + vib) + sin(ph * tau * 2 + vib) * 0.14 + sin(ph * tau * 3) * 0.05 br = svf(noise(), freq * 2, 0.6) out((tone * 0.5 + r2 * 0.05 * (1 + 4 * exp(-t * 22))) * e * 0.34) } inst reed { e = env(0.035, 0.15, 0.82, 0.22) $q = fract($q + freq * 1.007 / sr) a = bsqr(ph, 0.5, freq) + bsqr($q, 0.42, freq) * 0.8 s = svf(a, 800 + 1900 * e + 2200 * p0, 0.22) out(s * e * (1 + 0.07 * sin(t * 5.2 * tau)) * 0.15) } inst horn nna=continue { e = env(0.22, 0.4, 0.8, 0.9) $q = fract($q + freq * 0.996 / sr) a = bsaw(ph, freq) + bsaw($q, freq) * 0.8 s = svf(a, 200 + 600 * e + 1500 * p0, 0.3) out(dist(s * e * 1.2, 1.5) * 0.30) } inst bell nna=continue { e = exp(-t * 1.5) m = sin(ph * tau * 3.51) * 1.5 * exp(-t * 3) out((sin(ph * tau + m) + sin(ph * tau * 2.76) * 0.3 * exp(-t * 4) + sin(ph * tau * 5.4) * 0.12 * exp(-t * 8)) * e * 0.22) } # held for the whole song; the timeline plays it. One wash per bar. inst sea { st = evtl(stormv) sw = 0.5 + 0.5 * sin((beat * 0.5 - 0.22) * tau) wash = svf(noise(), 240 + 380 * st + 900 * sw * sw, 0.45) ww = svf(noise(), 520 + 380 * sin(time * 0.37) + 900 * st, 0.78) wind = r2 rain = hp(noise(), 4200) * smooth(0.4, 0.9, st) out((wash * (0.30 + 0.70 * sw) * (0.9 + 0.9 * st) + wind * (0.10 + 0.40 * st) + rain * 0.30) * smooth(0, 3, time) * 0.42) } inst thunder nna=continue { crack = hp(noise(), 1500) * exp(-t * 8) * 0.5 roll = lp(lp(noise(), 120), 90) * exp(-t * 0.85) * (0.6 + 0.4 * sin(t * 13 + 3 * sin(t * 2.1))) * smooth(0, 0.12, t) out(dist(crack + roll * 9, 1.6) * 0.22) } inst cym { out((hp(noise(), 6500) + sin(tau * 5310 * t) * 0.2) * exp(-t * 2.4) * 0.20) } chan 0 { w = verb(x, 0.72, 0.6) out(x + w * 0.16) } chan 3 { w = verb(x, 0.85, 0.5) out(x * 0.75 + w * 0.45) } chan 4 { d = dly(x, 0.5, 0.30) w = verb(x, 0.84, 0.4) out(x * 0.85 + d * 0.22 + w * 0.42) } chan 5 { d = dly(x, 0.3333, 0.34) w = verb(x, 0.88, 0.45) out(x * 0.8 + d * 0.18 + w * 0.5) } chan 7 { w = verb(x, 0.93, 0.3) out(x * 0.8 + w * 0.7) } master { vl = verb(l + r * 0.2, 0.84, 0.35) vr = verb(r + l * 0.2, 0.84, 0.35) out(dist(l * 0.95 + vl * 0.15, 1.05), dist(r * 0.95 + vr * 0.15, 1.05)) } # ------------------------------------------------------------------ score # ch0 drum | ch1 brush/cym | ch2 bass | ch3 pad | ch4 whistle/reed | ch5 horn/bell | ch6 sea | ch7 thunder pattern 0 rows=48 { 00: C-2 1 24 | . | . | . | . | D-2 7 24 S20 | C-4 9 40 01: . 02: . 03: . 04: . 05: . 06: . 07: . 08: . 09: . 10: . 11: . 12: . 13: . 14: . 15: . 16: . | . | . | . | . | off 17: . 18: . 19: . 20: . | . | . | . | A-5 8 12 21: . 22: . 23: . 24: C-2 1 18 | . | . | D-3 4 10 S00 | . | A-1 7 20 25: . 26: . 27: . 28: . 29: . 30: . 31: . 32: . 33: . | . | . | . | A-5 8 0C 34: . 35: . 36: . 37: . 38: . 39: . 40: . | . | . | . | . | off 41: . 42: . 43: . 44: . 45: . | . | . | . | A-5 8 0E 46: . 47: . } pattern 1 rows=48 { 00: C-2 1 22 | . | D-2 3 24 | D-3 4 18 S00 | A-4 5 3A 01: . 02: . 03: . 04: . 05: . 06: . | . | A-2 3 1E | . | D-5 5 3A 07: . 08: . 09: . 10: . | . | . | . | E-5 5 3A 11: . 12: . | . | A#1 3 24 | A#2 4 18 SFF | F-5 5 3A 13: . 14: . | . | . | . | . | F-5 8 0C 15: . 16: . 17: . 18: . | . | F-2 3 1E | . | E-5 5 3A 19: . 20: . | . | . | . | D-5 5 3A 21: . 22: . | . | . | . | A#4 5 3A 23: . 24: C-2 1 18 | . | F-2 3 24 | F-3 4 18 SFF | C-5 5 3A 25: . 26: . 27: . 28: . | . | . | . | A-4 5 3A 29: . 30: . | . | C-2 3 1E | . | F-4 5 3A 31: . 32: . 33: . 34: . | . | . | . | A-4 5 3A 35: . 36: . | . | C-2 3 24 | C-3 4 18 SFF | G-4 5 3A 37: . 38: . | . | . | . | . | G-5 8 0C 39: . 40: . 41: . 42: . | . | G-2 3 1E | . | E-4 5 3A 43: . 44: . 45: . 46: . | . | . | . | G-4 5 3A 47: . } pattern 2 rows=48 { 00: C-2 1 24 | . | D-2 3 26 | D-3 4 1C S00 | A-4 5 3C | A-3 7 0B S30 01: . 02: . 03: . 04: . 05: . 06: . | C-5 2 0E | A-2 3 20 | . | D-5 5 3C 07: . 08: . 09: . 10: . | . | . | . | E-5 5 3C 11: . 12: C-2 1 16 | . | A#1 3 26 | A#2 4 1C SFF | F-5 5 3C | A#3 7 0B 13: . 14: . 15: . 16: . 17: . 18: . | C-5 2 0E | F-2 3 20 | . | G-5 5 3C 19: . 20: . | . | . | . | F-5 5 3C 21: . 22: . | . | . | . | D-5 5 3C 23: . 24: C-2 1 24 | . | G-1 3 26 | G-2 4 1C S00 | A#4 5 3C 25: . 26: . 27: . 28: . | . | . | . | D-5 5 3C 29: . 30: . | C-5 2 0E | D-2 3 20 | . | G-5 5 3C | G-3 7 0B 31: . 32: . 33: . 34: . 35: . 36: C-2 1 16 | . | A-1 3 26 | A-2 4 1C SFF | E-5 5 3C | A-3 7 0B 37: . 38: . 39: . 40: . 41: . 42: . | C-5 2 0E | E-2 3 20 | . | C#5 5 3C | C#4 7 0B 43: . 44: . 45: . 46: . | . | . | . | E-5 5 3C 47: . } pattern 3 rows=48 { 00: C-2 1 2C | . | D-2 3 2A | D-3 4 20 S00 | . | D-3 7 20 S60 01: . 02: . 03: . 04: . | C-5 2 12 | D-2 3 20 05: . 06: C-2 1 22 | . | D-2 3 26 07: . 08: . 09: . 10: C-2 1 16 | C-5 2 16 | D-2 3 20 11: . 12: C-2 1 2C | . | C-2 3 2A | C-3 4 20 SFF | . | E-3 7 20 13: . 14: . 15: . 16: . | C-5 2 12 | C-2 3 20 17: . 18: C-2 1 22 | . | C-2 3 26 19: . 20: . 21: . 22: C-2 1 16 | C-5 2 16 | C-2 3 20 23: . 24: C-2 1 2C | . | A#1 3 2A | A#2 4 20 SFF | D-5 6 2A S40 | F-3 7 20 25: . 26: . 27: . 28: . | C-5 2 12 | A#1 3 20 | . | F-5 6 2A 29: . 30: C-2 1 22 | . | A#1 3 26 | . | A#5 6 2A | . | . | A-2 10 1C 31: . 32: . 33: . 34: C-2 1 16 | C-5 2 16 | A#1 3 20 35: . 36: C-2 1 18 | . | A-1 3 2A | A-2 4 20 SFF | A-5 6 2A | A-3 7 20 37: . 38: C-2 1 1C 39: . 40: C-2 1 20 | . | A-1 3 20 41: . 42: C-2 1 24 | . | A-1 3 26 | . | ... . .. 443 43: C-2 1 28 44: C-2 1 2C 45: C-2 1 30 46: C-2 1 34 | . | A-1 3 20 47: C-2 1 38 } pattern 4 rows=48 { 00: C-2 1 38 | C-6 11 26 | D-2 3 30 | D-3 4 26 S00 | D-5 6 32 S90 | D-3 7 26 SA0 01: . 02: . | . | . | . | . | . | . | E-3 10 3C 03: . 04: . | C-5 2 16 | D-2 3 26 05: . 06: C-2 1 2C | . | D-2 3 2C | . | A-5 6 32 | F-3 7 26 07: . 08: . | C-5 2 0E 09: . 10: C-2 1 20 | C-5 2 1A | D-2 3 26 11: . 12: C-2 1 38 | . | C-2 3 30 | C-3 4 26 SFF | G-5 6 32 | E-3 7 26 13: . 14: . | C-5 2 0E 15: . 16: . | C-5 2 16 | C-2 3 26 17: . 18: C-2 1 2C | . | C-2 3 2C | . | E-5 6 32 | G-3 7 26 19: . 20: . | C-5 2 0E 21: . 22: C-2 1 20 | C-5 2 1A | C-2 3 26 | . | C-5 6 32 23: . 24: C-2 1 38 | . | A#1 3 30 | A#2 4 26 SFF | F-5 6 32 | D-3 7 26 25: . 26: . | C-5 2 0E 27: . 28: . | C-5 2 16 | A#1 3 26 29: . 30: C-2 1 2C | . | A#1 3 2C | . | D-5 6 32 | F-3 7 26 | . | G-2 10 2C 31: . 32: . | C-5 2 0E 33: . 34: C-2 1 20 | C-5 2 1A | A#1 3 26 | . | A#4 6 32 35: . 36: C-2 1 38 | . | A-1 3 30 | A-2 4 26 SFF | E-5 6 32 | E-3 7 26 37: . 38: . | C-5 2 0E 39: . 40: . | C-5 2 16 | A-1 3 26 41: . 42: C-2 1 2C | . | A-1 3 2C | . | C#5 6 32 | A-3 7 26 43: . 44: . | C-5 2 0E 45: . 46: C-2 1 20 | C-5 2 1A | A-1 3 26 | . | A-4 6 32 47: . } pattern 5 rows=48 { 00: C-2 1 38 | C-6 11 26 | D-2 3 30 | D-3 4 28 S00 | F-5 6 36 SC0 | D-3 7 2A SD0 01: . 02: . 03: . 04: . | C-5 2 16 | D-2 3 26 | . | A-5 6 36 05: . 06: C-2 1 2C | . | D-2 3 2C | . | D-6 6 36 | A-3 7 2A 07: . 08: . | C-5 2 0E 09: . 10: C-2 1 20 | C-5 2 1A | D-2 3 26 11: . 12: C-2 1 38 | . | C-2 3 30 | C-3 4 28 SFF | C-6 6 36 | G-3 7 2A | . | A-2 10 30 13: . 14: . | C-5 2 0E 15: . 16: . | C-5 2 16 | C-2 3 26 17: . 18: C-2 1 2C | . | C-2 3 2C | . | G-5 6 36 | E-3 7 2A 19: . 20: . | C-5 2 0E 21: . 22: C-2 1 20 | C-5 2 1A | C-2 3 26 | . | E-5 6 36 23: . 24: C-2 1 38 | . | A#1 3 30 | A#2 4 28 SFF | A#5 6 36 | F-3 7 2A 25: . 26: . | C-5 2 0E 27: . 28: . | C-5 2 16 | A#1 3 26 29: . 30: C-2 1 2C | . | A#1 3 2C | . | F-5 6 36 | A#3 7 2A 31: . 32: . | C-5 2 0E 33: . 34: C-2 1 20 | C-5 2 1A | A#1 3 26 | . | D-5 6 36 35: . 36: C-2 1 1C | . | A-1 3 30 | A-2 4 28 SFF | A-5 6 36 | A-3 7 2A | . | F-3 10 40 37: . 38: C-2 1 20 | C-5 2 0E 39: . 40: C-2 1 24 | C-5 2 16 | A-1 3 26 41: C-2 1 28 42: C-2 1 2C | . | A-1 3 2C | . | C#6 6 36 | E-3 7 2A 43: C-2 1 30 44: C-2 1 34 | C-5 2 0E | . | . | ... . .. 453 45: C-2 1 38 46: C-2 1 3C | C-5 2 1A | A-1 3 26 47: C-2 1 40 | . | off | off | off | off } pattern 6 rows=48 { 00: C-2 1 1C | . | D-2 3 1E | D-3 4 16 SFF | A-5 5 36 01: . 02: . | . | . | . | . | D-5 8 14 03: . 04: . 05: . 06: . | . | . | . | D-6 5 36 07: . 08: . 09: . 10: . | . | . | . | E-6 5 36 11: . 12: . | . | G-1 3 1E | G-2 4 16 SFF | F#6 5 36 13: . 14: . 15: . 16: . 17: . 18: . | . | . | . | E-6 5 36 19: . 20: . | . | . | . | D-6 5 36 | . | . | C-3 10 0C 21: . 22: . | . | . | . | B-5 5 36 23: . 24: C-2 1 12 | . | B-1 3 1E | B-2 4 16 S00 | D-6 5 36 25: . 26: . | . | . | . | . | F#5 8 12 27: . 28: . | . | . | . | B-5 5 36 29: . 30: . | . | . | . | F#5 5 36 31: . 32: . 33: . 34: . | . | . | . | B-5 5 36 35: . 36: . | . | A-1 3 1E | A-2 4 16 SFF | A-5 5 36 37: . 38: . 39: . 40: . 41: . 42: . | . | . | . | E-5 5 36 43: . 44: . 45: . 46: . | . | . | . | A-5 5 36 47: . } pattern 7 rows=48 { 00: C-2 1 1C | . | D-2 3 20 | D-3 4 1A SFF | A-5 5 36 01: . 02: . 03: . 04: . 05: . 06: . | . | . | . | D-6 5 36 07: . 08: . 09: . 10: . | . | . | . | E-6 5 36 11: . 12: . | . | G-1 3 20 | G-2 4 1A SFF | F#6 5 36 13: . 14: . 15: . 16: . 17: . 18: . | . | . | . | E-6 5 36 19: . 20: . 21: . 22: . 23: . 24: C-2 1 16 | . | D-2 3 22 | D-3 4 1A SFF | D-6 5 36 25: . 26: . | . | . | . | . | D-5 8 14 27: . 28: . 29: . 30: . | . | . | . | ... . .. 432 | A-5 8 14 31: . 32: . 33: . 34: . 35: . 36: . | . | . | . | . | D-6 8 14 37: . 38: . 39: . 40: . 41: . 42: . | . | . | . | . | F#6 8 14 43: . 44: . | . | off | off | off 45: . 46: . 47: . } # ------------------------------------------------------------------ visuals # World: metres, y up, +z toward the lighthouse. Everything in the pixel # program is relative to the camera, which sits on the boat at (0, camY, boatZ). uniform wS stK covK dawnK lampK titleK camY camRoll camPitch boatZ Lx Ly Lz Ld bdx bdz glare flashK boltK boltU fogD fogR fogG fogB ambR ambG ambB rainK sunX sunY sunZ # four swells running toward the camera; a*a sharpens the crests fn swell(px, pz) { wa = sin(px * 0.031 + pz * 0.150 + t * 1.22) wb = sin(pz * 0.262 - px * 0.085 + t * 1.64 + 1.3) wc = sin(px * 0.36 + pz * 0.42 + t * 2.3 + 4.0) wd = sin(pz * 0.83 - px * 0.52 + t * 3.1) return wS * (1.25 * (wa + 0.35 * wa * wa) + 0.62 * (wb + 0.3 * wb * wb) + 0.26 * wc + 0.11 * wd) } # sky for a direction, left in the accumulator: gradient, sun, moon, stars, cloud deck fn sky(ax, ay, az, oct) { yy = max(ay, 0) hz = (1 - yy) ^ 6 sd = max(ax * sunX + ay * sunY + az * sunZ, 0) sg = dawnK * (sd ^ 5 * 0.30 + sd ^ 48 * 0.55 + sd ^ 1500 * 2.5) cr = mix(mix(0.008, 0.028, hz), mix(0.06, 0.92, hz ^ 0.8), dawnK) + sg cg = mix(mix(0.014, 0.046, hz), mix(0.13, 0.50, hz), dawnK) + sg * 0.62 cb = mix(mix(0.036, 0.080, hz), mix(0.30, 0.34, hz), dawnK) + sg * 0.30 ci = 1.4 / (yy + 0.14) cc = fbm(ax * ci + t * 0.03 + 3, az * ci + t * 0.05 + boatZ * 0.004, oct) cl = smooth(0.78 - 0.55 * covK, 1.02 - 0.55 * covK, cc) * smooth(-0.01, 0.10, ay) * 0.96 open = (1 - cl) ^ 3 sq = 70 / (yy + 0.35) sh = hash(floor(ax * sq) * 12.9898 + floor(az * sq) * 78.233) sfx = fract(ax * sq) - 0.5 sfz = fract(az * sq) - 0.5 st = step(0.982, sh) * (1 - dawnK) * smooth(0.02, 0.2, ay) * (0.45 + 0.55 * sin(t * 3 + sh * 90)) * exp(-(sfx * sfx + sfz * sfz) * 30) * open md = max(ay * 0.292 + az * 0.885 - ax * 0.363, 0) mo = (smooth(0.99962, 0.99976, md) * 0.9 * open + md ^ 400 * 0.22 * (0.25 + 0.75 * open) + md ^ 30 * 0.05) * (1 - 0.9 * dawnK) cr += st + mo * 0.90 cg += st + mo * 0.95 cb += st * 1.1 + mo fl = flashK * (0.10 + 1.1 * exp(-abs(ax - boltU * 0.42) * 5)) * (0.2 + cc * cc * 2.2) ml = md ^ 6 * (1 - dawnK) kr = 0.014 + (0.05 + 0.05 * covK) * cc + ml * 0.06 + fl * 0.75 + dawnK * (0.20 + 0.75 * hz * (0.5 + sd ^ 3)) kg = 0.019 + (0.065 + 0.06 * covK) * cc + ml * 0.07 + fl * 0.80 + dawnK * (0.17 + 0.33 * hz) kb = 0.030 + (0.085 + 0.07 * covK) * cc + ml * 0.08 + fl + dawnK * (0.22 + 0.22 * hz) rgb(mix(cr, kr, cl), mix(cg, kg, cl), mix(cb, kb, cl)) } # lighthouse and skerry, q relative to the tower foot at sea level fn lh(qx, qy, qz) { rr = len(qx, qz) ek = sqrt(qx * qx / 676 + (qy + 1) * (qy + 1) / 72 + qz * qz / 400) drock = (ek - 1) * 8.5 + (fbm(qx * 0.18 + 7, qz * 0.18 + qy * 0.25, 3) - 0.5) * 5 dtow = max(rr - 4.3 + (qy - 6) * 0.055, abs(qy - 19) - 13) dgal = max(rr - 4.5, abs(qy - 32.3) - 0.35) dlan = max(rr - 2.3, abs(qy - 34.6) - 2.0) dcap = max(rr - (39.6 - qy) * 0.95, 36.6 - qy) * 0.7 return min(min(drock * 0.55, dtow), min(min(dgal, dlan), dcap)) } frame { stK = evtl(stormv) covK = evtl(covv) dawnK = evtl(dawnv) lampK = evtl(lampv) titleK = evtl(titlev) wS = 0.22 + 1.45 * stK boatZ = 170 * (0.55 * t / 64 + 0.45 * smooth(0, 64, t)) Lx = 15 Lz = 270 - boatZ camY = 2.7 + 0.85 * swell(0, boatZ) camPitch = (swell(0, boatZ + 4) - swell(0, boatZ - 4)) * 0.075 camRoll = (swell(4, boatZ) - swell(-4, boatZ)) * 0.09 + 0.01 * sin(t * 0.7) Ly = 34.6 - camY Ld = sqrt(Lx * Lx + Ly * Ly + Lz * Lz) th = atan2(-Lz, -Lx) + pi * t / 4 bdx = cos(th) bdz = sin(th) al = abs(bdx * Lx + bdz * Lz) / len(Lx, Lz) glare = exp(-(1 - al) * 110) * lampK tt = trig(7) flashK = exp(-tt * 4.5) * (0.6 + 0.4 * sin(tt * 75)) * vel(7) * step(0.25, vel(7)) * step(tt, 4) * 1.4 boltK = step(tt, 0.17) * step(0.25, vel(7)) * (0.5 + 0.5 * sin(tt * 110)) boltU = (note(7) - 48) * 0.13 fogD = 0.0012 + 0.0052 * stK fogR = mix(0.022 + 0.030 * stK, 0.60, dawnK) + flashK * 0.09 fogG = mix(0.034 + 0.036 * stK, 0.42, dawnK) + flashK * 0.10 fogB = mix(0.058 + 0.042 * stK, 0.37, dawnK) + flashK * 0.13 ambR = 0.045 + flashK * 0.55 + dawnK * 0.55 ambG = 0.060 + flashK * 0.60 + dawnK * 0.47 ambB = 0.090 + flashK * 0.72 + dawnK * 0.45 rainK = smooth(0.4, 0.85, stK) el = 0.11 * dawnK - 0.07 sunX = sin(-0.40) * cos(el) sunY = sin(el) sunZ = cos(-0.40) * cos(el) } pixel { rgb(0, 0, 0) if (abs(v) < 0.835) { dx = rot(u, v, camRoll) dy = r1 + 0.20 + camPitch dz = 2.2 il = 1 / sqrt(dx * dx + dy * dy + dz * dz) dx *= il dy *= il dz *= il depth = 4000 seaK = 0 cR = 0 cG = 0 cB = 0 # ---------- sea: relaxed heightfield march, then shade if (dy < 0.035) { sS = 0.5 hg = 1 mden = max(-dy, 0) + 0.03 + 0.12 * wS repeat i 20 { hg = camY + dy * sS - swell(dx * sS, boatZ + dz * sS) sS = max(sS + clamp(hg / mden, -1 - sS * 0.1, 5 + sS * 0.4), 0.5) } hg = camY + dy * sS - swell(dx * sS, boatZ + dz * sS) if (dy < -0.004 || hg < 0.3 + sS * 0.012) { seaK = 1 depth = sS wx = dx * sS wz = dz * sS gz = boatZ + wz eps = 0.2 + sS * 0.015 h0 = swell(wx, gz) nx = h0 - swell(wx + eps, gz) nz = h0 - swell(wx, gz + eps) ck = eps * (0.25 + 0.3 * stK) / (1 + sS * 0.03) hf = 5.5 / (1 + sS * sS * 0.002) c0 = fbm(wx * 0.8, gz * 0.8 + t * 0.9, 3) nx += ck * (sin(wx * 2.1 + gz * 1.3 + t * 3.1) + hf * (c0 - fbm(wx * 0.8 + 0.3, gz * 0.8 + t * 0.9, 3))) nz += ck * (sin(gz * 2.4 - wx * 1.1 + t * 2.7) + hf * (c0 - fbm(wx * 0.8, gz * 0.8 + 0.3 + t * 0.9, 3))) nl = 1 / sqrt(nx * nx + eps * eps + nz * nz) nx *= nl ny = eps * nl nz *= nl dn = dx * nx + dy * ny + dz * nz rx = dx - 2 * dn * nx ry = abs(dy - 2 * dn * ny) + 0.01 rz = dz - 2 * dn * nz sky(rx, ry, rz, 2) fre = 0.03 + 0.97 * (1 - clamp(-dn, 0, 1)) ^ 5 crest = clamp(h0 / (wS * 2.2) * 0.5 + 0.5, 0, 1) # the lamp on the water: beam footprint and a glitter path lvx = Lx - wx lvy = 34.6 - camY - dy * sS lvz = Lz - wz ld = sqrt(lvx * lvx + lvy * lvy + lvz * lvz) hd = len(lvx, lvz) + 0.001 bm = exp(-(1 - abs(lvx * bdx + lvz * bdz) / hd) * 420) * smooth(8, 30, hd) lit = lampK * bm * 500 / (ld * ld * 0.2 + 900) * exp(-fogD * ld) spc = max((rx * lvx + ry * lvy + rz * lvz) / ld, 0) sp = lampK * (spc ^ 60 * 0.5 + spc ^ 600 * 3) * (0.35 + 1.5 * bm + 2 * glare) * 90 / (ld + 90) * exp(-fogD * ld * 1.5) * (1 - 0.7 * stK) # foam on steep crests and where the swell meets the skerry fo = smooth(0.66, 1.0, crest + (fbm(wx * 0.16 + 11, gz * 0.16 + t * 0.30, 2) - 0.5) * 0.7) * smooth(0.20, 0.80, stK) fo = fo * mix(1, 0.45 + 0.9 * fbm(wx * 1.3, gz * 1.3 + t * 0.6, 2), 1 / (1 + sS * 0.04)) rk = len((wx - Lx) / 27, (wz - Lz) / 21) fo = max(fo, exp(-abs(rk - 1.0) * 7) * smooth(0.25, 0.7, fbm(wx * 0.4, gz * 0.4 - t * 0.9, 2) + 0.25 * stK)) fo = fo * 0.75 dk = stK * crest * crest cR = mix(mix(0.004 + 0.010 * crest + dawnK * 0.03 + dk * 0.012, cget(0), fre) + sp + lit * 0.03, (ambR + lit) * 0.85, fo) cG = mix(mix(0.016 + 0.040 * crest + dawnK * 0.07 + dk * 0.045, cget(1), fre) + sp * 0.9 + lit * 0.07, (ambG + lit * 0.9) * 0.85, fo) cB = mix(mix(0.028 + 0.045 * crest + dawnK * 0.09 + dk * 0.055, cget(2), fre) + sp * 0.65 + lit * 0.08, (ambB + lit * 0.65) * 0.85, fo) fk = exp(-fogD * sS) cR = mix(fogR, cR, fk) cG = mix(fogG, cG, fk) cB = mix(fogB, cB, fk) } } # ---------- sky, horizon haze, lightning bolt if (seaK < 0.5) { sky(dx, dy, dz, 4) hk = exp(-max(dy, 0) * (14 + 30 * stK)) * min(0.40 + 0.9 * stK, 1) bx = boltU + 0.10 * sin(v * 9 + 3) + 0.05 * sin(v * 23 + boltU * 40) + 0.02 * sin(v * 61) bolt = boltK * (exp(-abs(u - bx) * 120) + 0.25 * exp(-abs(u - bx) * 14)) * smooth(0.0, 0.08, dy) cR = mix(cget(0), fogR, hk) + bolt * 0.9 cG = mix(cget(1), fogG, hk) + bolt * 0.95 cB = mix(cget(2), fogB, hk) + bolt * 1.2 } # ---------- lighthouse: marched only inside its bounding column sc = (dx * Lx + dz * Lz) / (dx * dx + dz * dz) if (sc > 0 && len(dx * sc - Lx, dz * sc - Lz) < 30 && camY + dy * sc < 46) { sT = max(sc - 36, 0) dT = 1 repeat i 48 { dT = lh(dx * sT - Lx, camY + dy * sT, dz * sT - Lz) sT += max(dT, 0) } if (dT < 0.03 + sT * 0.0015 && sT < depth) { depth = sT qx = dx * sT - Lx qy = camY + dy * sT qz = dz * sT - Lz mx = lh(qx + 0.06, qy, qz) - dT my = lh(qx, qy + 0.06, qz) - dT mz = lh(qx, qy, qz + 0.06) - dT mk = 1 / sqrt(mx * mx + my * my + mz * mz + 0.0000001) mx *= mk my *= mk mz *= mk rr = len(qx, qz) rkn = 0.5 + fbm(qx * 0.5, qz * 0.5 + qy * 0.7, 3) alR = 0.070 * rkn alG = 0.070 * rkn alB = 0.080 * rkn emR = 0 emG = 0 emB = 0 if (qy > 5.5 && rr < 4.65 - (qy - 6) * 0.055) { band = step(fract((qy - 6) / 8.667), 0.5) streak = 0.78 + 0.22 * fbm(atan2(qx, qz) * 4, qy * 0.25, 2) alR = mix(0.72, 0.56, band) * streak alG = mix(0.71, 0.07, band) * streak alB = mix(0.67, 0.05, band) * streak win = step(abs(atan2(qx, -qz) + 0.15), 0.13) * (step(abs(qy - 13), 0.8) + step(abs(qy - 20.5), 0.8) + step(abs(qy - 27), 0.7)) alR *= 1 - win alG *= 1 - win alB *= 1 - win emR = win emG = win * 0.62 emB = win * 0.22 } if (qy > 31.9) { alR = 0.05 alG = 0.055 alB = 0.06 emR = 0 emG = 0 emB = 0 } if (qy > 32.7 && qy < 36.6 && rr < 2.6) { mull = step(0.10, abs(fract(atan2(qx, qz) * 8 / tau) - 0.5)) * lampK emR = mull * 1.5 emG = mull * 1.25 emB = mull * 0.7 } if (qy >= 36.6) { alR = 0.10 alG = 0.17 alB = 0.14 } hem = (0.55 + 0.45 * my) * (0.55 + 0.45 * max(-mx * 0.6 - mz * 0.8, 0)) mo = max(my * 0.292 + mz * 0.885 - mx * 0.363, 0) * (1 - dawnK) * (1 - covK * 0.8) lg = max(mx * boltU * 0.3 + my * 0.6 - mz * 0.74, 0) * flashK sn = max(mx * sunX + my * sunY + mz * sunZ, 0) * dawnK pd = sqrt(qx * qx + (34.6 - qy) * (34.6 - qy) + qz * qz) + 0.001 pl = max((my * (34.6 - qy) - mx * qx - mz * qz) / pd, 0) * lampK * 40 / (pd * pd + 12) cR = alR * (ambR * hem + mo * 0.10 + lg * 1.6 + sn * 1.2 + pl) + emR cG = alG * (ambG * hem + mo * 0.12 + lg * 1.7 + sn * 0.7 + pl * 0.8) + emG cB = alB * (ambB * hem + mo * 0.16 + lg * 2.0 + sn * 0.4 + pl * 0.45) + emB wl = (1 - smooth(0, 2.5 + 2.5 * stK, qy - swell(dx * sT, boatZ + dz * sT))) * (0.4 + 0.6 * fbm(qx * 0.6 + t * 0.5, qz * 0.6 + qy, 2)) * (0.3 + 0.7 * stK) * 0.8 cR = mix(cR, ambR * 0.9, wl) cG = mix(cG, ambG * 0.9, wl) cB = mix(cB, ambB * 0.9, wl) fk = exp(-fogD * sT) cR = mix(fogR, cR, fk) cG = mix(fogG, cG, fk) cB = mix(fogB, cB, fk) } } # ---------- the beam: closest approach of the view ray to a line through the lamp bb = dx * bdx + dz * bdz rw = -(dx * Lx + dy * Ly + dz * Lz) ee = -(bdx * Lx + bdz * Lz) den = max(1 - bb * bb, 0.0008) sb = clamp((bb * ee - rw) / den, 0, depth) tb = ee + bb * sb ox = dx * sb - Lx - bdx * tb oy = dy * sb - Ly oz = dz * sb - Lz - bdz * tb rad = 0.9 + 0.045 * abs(tb) core = exp(-(ox * ox + oy * oy + oz * oz) / (rad * rad)) glow = core * lampK * (0.25 + stK) * 2.2 / (rad * sqrt(den)) * exp(-abs(tb) * fogD * 0.7 - sb * fogD) # ---------- lamp halo, storm bloom and the lens streak when the beam finds us a2 = max(2 * (1 - (dx * Lx + dy * Ly + dz * Lz) / Ld), 0) vis = lampK * step(Ld - 6, depth) vy = dy - Ly / Ld hl = vis * (0.000035 / (a2 + 0.000012) * (1 + 14 * glare) + exp(-a2 * (900 - 500 * stK)) * 0.25 * (1 + 5 * glare) + glare * exp(-a2 * 18) * 0.9) hl += vis * exp(-vy * vy * 60000) * (0.02 + 0.6 * glare) / (1 + a2 * 300) lightR = glow + hl cR += lightR cG += lightR * 0.93 cB += lightR * 0.70 # ---------- rain, visible where there is light to catch rn = 0 repeat k 2 { rxx = (u + v * (0.16 + 0.22 * stK)) * (36 + 26 * k) hs = hash(floor(rxx) * 1.37 + k * 17.1) ryy = fract(v * (1.5 + k * 0.7) + t * (5.5 + 3 * hs + k * 2) + hs * 9) rn += smooth(0.90, 1.0, ryy) * (1 - abs(fract(rxx) - 0.5) * 2) ^ 3 * step(0.45, hs) } rn = rn * rainK * (0.05 + ambR * 0.25 + lightR * 0.7) cR += rn cG += rn * 1.02 cB += rn * 1.10 # ---------- the bow, a lantern on its stem pv = v + camPitch * 0.35 + 0.012 * sin(t * 1.3) hw = 1.25 * max(-0.56 - pv, 0) ^ 0.75 if (abs(u) < hw) { ed = hw - abs(u) rim = exp(-ed * 40) plank = 0.75 + 0.25 * step(0.12, abs(fract(u / hw * 3.5) - 0.5)) lan = exp(-len(u, pv + 0.60) * 9) * (0.9 + 0.1 * sin(t * 9)) wet = ambR * 0.25 + glare * 0.5 cR = (0.016 + lan * 0.30 + ambR * 0.05) * plank + rim * (0.03 + wet) cG = (0.013 + lan * 0.15 + ambG * 0.04) * plank + rim * (0.028 + wet) cB = (0.012 + lan * 0.05 + ambB * 0.035) * plank + rim * (0.03 + wet) } post1 = step(abs(u), 0.012) * step(abs(pv + 0.51), 0.06) cR = mix(cR, 0.02, post1) cG = mix(cG, 0.016, post1) cB = mix(cB, 0.014, post1) ll = len(u, pv + 0.44) lamp2 = exp(-ll * 70) * 1.2 + exp(-ll * 11) * 0.07 cR += lamp2 cG += lamp2 * 0.60 cB += lamp2 * 0.22 # ---------- title if (titleK > 0.001 && u < -0.1 && v > 0.0) { tx = (u + 1.32) / 0.20 ty = (0.56 - v) / 0.30 g1 = glyph(str(ttl, floor(tx)), fract(tx), ty) * step(0, tx) * step(tx, 3) * step(0, ty) * step(ty, 1) tx = (u + 1.31) / 0.044 ty = (0.17 - v) / 0.066 g2 = glyph(str(cap, floor(tx)), fract(tx), ty) * step(0, tx) * step(tx, 25) * step(0, ty) * step(ty, 1) gk = (g1 + g2 * 0.8 * smooth(0.5, 1, titleK)) * smooth(0, 0.6, titleK) cR = mix(cR, 1.00, gk) cG = mix(cG, 0.96, gk) cB = mix(cB, 0.88, gk) } rgb(1 - exp(-cR * 1.7), 1 - exp(-cG * 1.7), 1 - exp(-cB * 1.7)) } } post { a0 = tap(0, 0) g0 = r1 b0 = r2 sR = 0 sG = 0 sB = 0 repeat k 8 { an = k * 0.7854 + 0.3 rd = 3 + 4 * (k % 2) tr = tap(cos(an) * rd, sin(an) * rd) sR += tr * tr sG += r1 * r1 sB += r2 * r2 } ca = tap(u * 0.9, 0) rgb(mix(a0, ca, 0.5) + sR * 0.045, g0 + sG * 0.040, b0 + sB * 0.045) cmul(1 - 0.16 * (u * u * 0.4 + v * v)) gn = hash(x * w * 0.37 + y * h * 1.13 + frame * 7.7) - 0.5 cadd(gn * 0.028, gn * 0.028, gn * 0.032) cmul(smooth(0, 1.5, t) * (1 - smooth(62.5, 64, t))) cmul(step(abs(v), 0.835)) }