Log inGet started
Package

effect.assetType

Newest version

This package holds more than this page lists. See all of its files in its world.

README.md

effect

A set of visuals packaged as one thing: every impact a weapon makes, every stage of an explosion, the muzzle flash, impact and tracer of a gun. Each visual is an entry the effect plays by name. The graphs, the parts they are built from, and the shaders, materials, compute shaders and textures they use all live inside the effect.

The shape on disk

<name>.effect/
  effect.yaml   what it plays: entry name -> one graph, or a list of graphs played together
  graphs/       the graphs its entries play
  parts/        graphs those graphs use as nodes, each one whole piece of the look
  shaders/      shaders and shader modules its materials draw with
  materials/
  compute/      compute shaders its graphs run
  textures/
  README.md     what this effect shows, what each entry plays, what each input changes
  .metadata
  settings.yaml its values for the settings below

effect.yaml, graphs/, README.md and .metadata are required.

plays:
  flare: "~.graphs.flare"
  impact:
    - "~.graphs.impactFlash"
    - "~.graphs.impactDebris"
default: flare

Inside an effect ~.x names the effect's own x: ~.graphs.flare, ~.parts.crack, ~.shaders.lava, wherever the effect sits.

Post-processing it carries

post is the post-processing the effect brings with it: bloom on a fireball, a flash of exposure, a vignette. While an entry plays, it stands as a PostProcess region around the effect, and goes when the play stops or finishes:

post:
  radius: 30        # the region, a sphere around the effect unless `shape` says box or global
  falloff: 5        # the distance outside it over which the stack fades out
  effects:
    - { shader: "@builtin::shaders.post.bloom", priority: 10, values: { threshold: 1.2, intensity: 0.6 } }
    - { shader: "@builtin::shaders.post.vignette", priority: 20, values: { intensity: 0.4 } }

effects is the region's stack and the rest its fields, as the PostProcess component takes them (shape, radius, extents, falloff, priority, display, setsDisplay). The region applies while the camera is in it, so a picture of the effect on the preview stage shows it without; effects.capture of the effect placed (entity) shows it with.

Graphs and parts

A graph under graphs/ composes what one entry shows. A piece worth building and looking at on its own (the crack of a fissure, the spray, the smoke) is a graph under parts/, called as a node:

local crack = g["~/parts/crack"]({ length = length })

A part is a whole graph, so it previews and plays alone: the crack without the smoke in front of it. An operation several effects use (a streak look, a smoke puff) is a .procNode outside the effect, used the way a module is required.

Playing one

local beacons = asset.resolve("beacons", "effect")
local shown = beacons:play("flare", { root = mast, offset = { 0, 0.9, 0 }, inputs = { size = 0.4 } })
shown:set("size", 0.6)
shown:onFinished(function() print("done") end)

root is the entity it plays on and follows; inputs go to every graph of the entry that declares them; the handle answers set, pause, resume, seek, getTime, stop, isFinished and onFinished. A play finishes when every graph of its entry reaches the end of its timeline; a graph that states realTime alone has no end, so a play of it runs until stop(), and a simulation that runs once states its frames (g:timeline({ realTime = true, frames = 120 })). Plays of an entry no program holds are kept ready, built ahead of time: beacons:warm("flare", 6) keeps six ready for a burst. An Effect component, or a drop into the viewport, places an entry in a scene.

Entries played by a program

An entry whose graphs end on their own, take no plain input and carry no post is played by a program: its graphs are cooked once, when the entry is first asked for (entries() on the effect, warm, or the first play), and captured as one program over many copies. A play takes a slot of the program (effectRef:play is a write into a row of data, and the shot draws on the frame after it), so a burst of plays costs the frame no more than the program's one present: how many slots there are is the count warm or the pool setting states, 8 when neither does, and the program doubles ahead of the plays when a quarter of its slots or fewer are free. A play asked for with no slot free takes the oldest shot's, and that shot's handle reads finished.

entries().entries[name].program states where the program stands: state ("preparing", "ready" or "refused"), the reason an entry is refused, and, once ready, its copies, how many are live and free, the evictions and the doublings (grown). pool of such an entry is its slots, ready its free ones and playing its live ones. While the program is preparing, and for an entry it refused, a play is built as an entry plays without a program, one play at a time.

A play on a program takes numbers and vectors for its inputs and stands where offset and rotation put it. Its handle answers set (the copy begins its simulation again under the new value), pause (the copy stands at its age), resume, seek (the copy begins again at the step that puts it at that age), stop, getTime, isFinished, onFinished and playback; it carries no entity. A play that asks for a root, keep, an ending other than "graph", a speed other than 1, or an input that is neither a number nor a vector (and is not the default) is a play of its own: one made for the call that goes when it finishes.

entries() and entry(name) read what it plays; setEntry, removeEntry, renameEntry, setDefault and newGraph change it, keeping every line of effect.yaml they do not touch.

Settings

pool: how many plays of each entry there are, counting the ones playing (default 1). Each costs a whole play's memory, so a burst asks for more with warm where it is expected. An entry played while more of its plays are playing than it keeps builds the play, and keeps that many from then on, up to its most: the plays of a burst go back ready when they finish, and the next burst of the same size builds none. A play still being built for a call of an earlier frame counts as playing once its clock moves. A warm with a smaller count than the one before lets go of those too.

Of the plays of an entry that end on their own, at most its pool size play at once, and never fewer than 16 (entries() reports it as most, and those plays out now as playing). Such a play asked for while that many play takes over the oldest of them: it plays again from its start where the new play stands, and the handle of the play it was reads finished. A scene that plays one entry faster than its plays finish therefore holds a bounded number of them. A play that runs until stop() (ending = "loop", or an entry with a graph that has no end) and one that stays once finished (keep) play on where they were asked for, as many as the caller plays, until the caller stops them.

In search

Each asset inside an effect is found on its own and names the effect it belongs to. The effect itself is found by its preview, its README and its entries.