makepad/apps/vj/resources/effects/93_attractor_storm.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

78 lines
2.7 KiB
Text

// ATTRACTOR STORM — the second stateful-particle program: particles spawn
// on a SHELL and fall into an orbiting attractor with a strong tangential
// swirl — a storm eye that wanders. Every kick blasts the accretion disc
// outward (impulse) and the disc collapses back because velocity is REAL
// STATE integrated frame over frame. Speed paints color (speed_color).
{
name: "Attractor Storm"
engine: "simswarm"
seed: 9
count: 20164
size: 0.06
stretch: 0.06
speed_color: 0.16
spawn: "shell"
curl: 0.5
attract: 2.6
swirl: 1.9
gravity: 0.0
impulse: "(1.2 + pulse * 3.2) * (0.2 + 1.6*p0)"
drag: 0.55
max_speed: 11.0
life: 30.0
bound: 6.5
beat_pulse: 0.4
// PERFORMANCE DIALS — mid-knob = the stock look, exact.
p0: 0.5 p1: 0.5 p2: 0.5
dials: [
{name: "KICK", bind: "p0", default: 0.5},
{name: "TRAIL", bind: "p1", default: 0.5},
{name: "GLOW", bind: "p2", default: 0.5}
]
color_bg: #x0c0508
color_a: #x8f2a2a
color_b: #xffb35a
color_c: #xfff2e0
cam_orbit: 0.10
cam_height: 2.2
glow: 1.3
stages: [
{kind: "feedback", amount: "min(0.6 + (p1-0.5)*0.7, 0.97)", zoom: 1.008, rotate: 0.003, dim: 0.93},
{kind: "bloom", threshold: 0.45, strength: "1.4 * (0.25 + 1.5*p2)", levels: 3}
]
// 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 = age 0..1, attr = (id, speed, rnd, state age).
// 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.DrawVjFxSimSwarmDraw {
fx_color: fn(t: float, attr: vec4, normal: vec3, wpos: vec3) -> vec4 {
let sp = clamp(attr.y * self.flow.y, 0.0, 1.0)
let base = self.col_a.mix(self.col_b, sp)
let hot = base.xyz + self.col_c.xyz * pow(sp, 3.0) * 0.6
let fade = smoothstep(0.0, 0.06, t) * (1.0 - smoothstep(0.75, 1.0, t))
let boost = 0.8 + self.time_beat.w * 0.9
return vec4(hot * boost, fade)
}
fx_sprite: fn(uv: vec2, tint: vec4) -> vec4 {
let d = length(uv - vec2(0.5, 0.5)) * 2.0
let core = 1.0 - smoothstep(0.0, 0.45, d)
let halo = 1.0 - smoothstep(0.12, 1.0, d)
let a = clamp(core + halo * 0.55, 0.0, 1.0) * tint.w
return vec4(tint.x * a, tint.y * a, tint.z * a, 0.0)
}
}
}