makepad/apps/vj/resources/effects/100_flash_crash.splash
Admin f44616b2a7 makepad-vj effects: the effect renderstack, with the shaders inside the documents
The VJ's EFFECT surface is a small renderer of its own. An effect is a
`.splash` DOCUMENT — engine choice, stages, fields, parameters and now the
SHADERS THEMSELVES live in the document rather than in Rust. That is the
shape this commit introduces (dev has never seen an intermediate one): a
document is the whole effect, and the Rust side is the engine families that
documents draw with.

The engine families: particles and emitters, GPU sim swarms and fluid, static
meshes (firefly synchrony, harmonograph loom, domino liturgy), tiles, flock,
clouds, city, pipes, stock charts, an SDF raymarcher with a subclassable
`scene_sdf`, and a mountain-jet endless range with a beat-pulsed fighter.

Three things make them a system rather than a demo reel:

  - SIM FIELDS — a float simulation-texture primitive, so an engine can carry
    GPU state across frames (wind, particles, fluid) instead of being a pure
    function of the clock.
  - CONTENT COUPLING — `content:` in a document and `input0` on every engine's
    tex0, so an effect can consume the program video: drapes, backdrops,
    mirrors, billboards, chrome, frescoes, canopy, glass, silk, wall, swarm,
    pen and mosaic families all take the picture playing behind them.
  - MUSIC BINDING — shaders read the beat, so the whole library moves with the
    track rather than on its own clock.

Roughly a hundred seeded preset documents ship with it, each with a lazily
rendered animated thumbnail (rendered 4x and box-downscaled, 16-tap SSAA);
the thumbnail pass went from four minutes to eleven seconds. CONTRACT.md is
the document contract and its verify recipe; IDEAS.md is the campaign tracker.
2026-08-23 01:35:44 +02:00

93 lines
3.4 KiB
Text

// FLASH CRASH — the red-terminal panic. Cascades arm at bar boundaries
// (`cascade` chance per bar) and slam the walk downward for most of a bar
// with doubled volatility; the shader's panic wash (`p2`) floods the
// terminal red on every pulse while a cascade is running, and down-candles
// burn blood-red through the bloom. Pattern taught: the crash is CPU state
// (a beat-clocked cascade machine), the panic is shader state (uniform
// `cascade` + the p2 binding) — the two lock to the same bar.
{
name: "Flash Crash"
engine: "stockcharts"
seed: 87
candles: 96
per_beat: 2
vol: 2.2
drift: -0.4
spike: 3.0
cascade: 0.65
bar: 4
ma: 10
grid_x: 4
grid_y: 8
scan: 18
width: 15
height: 8
beat_pulse: 0.8
p0: "0.2 + 0.3*pulse" // the whole board pumps
p1: "0.5 + 0.9*pulse" // crosshair panic
p2: "0.25 + 0.45*pulse" // red wash breathing on the beat
// PERFORMANCE DIALS — the chart engine's own p-levers; touching one
// holds its pulse binding above at a fixed level (PANIC full right =
// the board drowns in red).
dials: [
{name: "GAIN", bind: "p0", default: 0.5},
{name: "XHAIR", bind: "p1", default: 0.5},
{name: "PANIC", bind: "p2", default: 0.5}
]
color_bg: #x070102
color_a: #x9aa89a
color_b: #xff2333
color_c: #xffffff
cam_orbit: 0.0
cam_fov: 40
fog: 0.0
glow: 1.25
stages: [
{kind: "bloom", threshold: 0.35, strength: 1.6, levels: 3},
{kind: "feedback", amount: "0.30 + 0.25*pulse", zoom: 1.003, rotate: 0.0, dim: 0.93}
]
// THE LOOK LIVES HERE. This block is not a reference to the
// engine's shader — it IS the pixel math this effect runs.
// Rewrite it and the effect looks different; everything else
// (geometry, motion, the content coupling, the beat) keeps
// working, because the block SUBCLASSES the engine shader.
// Inputs: t = candle age 0..1, attr = (element class, age, up/down, move size).
// Signals: self.time_beat (time, beat, phase, pulse),
// self.sig (bar, bpm, energy, dt), self.user (p0..p3),
// self.col_a/b/c/bg, self.fog (density, glow, content, -).
shader: draw.DrawVjFxCharts {
fx_color: fn(t: float, attr: vec4, normal: vec3, wpos: vec3) -> vec4 {
let class = attr.x
if class < 0.5 {
// Candle body: col_a up / col_b down, big moves burn.
let base = self.col_b.mix(self.col_a, step(0.5, attr.z))
let burn = 0.75 + attr.w * 0.7 + self.time_beat.w * (1.0 - t) * 0.6
return vec4(base.xyz * burn, 1.0 - t * 0.55)
}
if class < 1.5 {
let base = self.col_b.mix(self.col_a, step(0.5, attr.z))
return vec4(base.xyz * 0.55, (1.0 - t * 0.55) * 0.8)
}
if class < 2.5 {
return vec4(self.col_a.xyz * 0.16, 0.5)
}
if class < 3.5 {
// Kept modest: the bloom stage amplifies this line, and an
// over-gained crosshair blows out into a white bar.
let g = 0.55 + self.user.y * 0.5 + self.time_beat.w * 0.25
return vec4(self.col_c.xyz * g, 0.8)
}
if class < 4.5 {
return vec4(self.col_c.xyz * 0.5 + self.col_a.xyz * 0.4, 0.85)
}
return vec4(self.col_a.xyz * 0.6, 0.9)
}
}
}