Builtin Library
- ..
- README.md4.9 KB
- about.yaml532 B
- behavior.luau15.1 KB
- inspector.luau3.5 KB
- template
- type.yaml1.6 KB
README.md
Post effect (asset type)
A post effect is a post-process shader on the screen, as an asset: one
post-process shader with its values, its order and its layer in the post
chain, described in postEffect.yaml. It implements applicable: applying it
puts that shader in the chain for the applier.
Making one
A post effect names a post-process shader and states the values it runs with:
a shader of the world's own, or any post-process shader a world can reach. A
holder (a setup, a sky, a PostProcess entry) names the post effect and may
state values of its own for it, which are that holder's alone:
# <setup>.sceneSetup / sceneSetup.yaml
members:
- id: grade
source: "./grade.postEffect"
values: { saturation: 0.82 }
asset.list({ type = "postEffect" }) lists the post effects a world holds,
and ref:inputs() names the values each takes.
Where it lives
- Source:
<name>.postEffect/ - Identity:
<name>(the.postEffectsuffix strips from the identity) - Folder shape:
postEffect.yaml: the effect. Required.README.md: what it does to the picture. Required..metadata:descriptionandtags. Required.
# <name>.postEffect / postEffect.yaml
shader: "<post-process shader>" # any post-process shader
layer: scene # scene | all | "" (the shader's own space)
order: 120
values: { intensity: 0.3 }
Writing its shader
The shader a post effect names is a post-process shader: one
fn fragment(in: PostInput) -> vec4<f32> over the rendered frame, its
properties in properties.yaml. Besides in.uv and in.frag_coord, it reads:
zero_sample_scene(uv): the rendered scene colour atuv;zero_scene_depth(uv): the scene depth atuv(reversed: 1 is the near plane, 0 the far plane and empty sky), andzero_linear_depth(d, near, far)for it in metres;zero_scene_motion(uv), the per-pixel motion;engine.time:xthe elapsed seconds,ythe frame'sdt,zthe frame index: an effect that moves (a scan line, a pulse, drifting grain) animates by it;engine.resolution:xandythe target's width and height,zandwtheir reciprocals;engine.view_proj,engine.prev_view_proj,engine.inv_view_proj: the camera the frame was drawn from, this frame and the last.
The shader type's README, "Post-process & screen shaders", has the whole
surface: every helper, multi-pass shaders and the space an effect declares.
Parameters
Its parameters are its shader's properties, each with the Field descriptor of
its kind, defaulting to what values states (else the property's own default):
| Property kind | Field |
|---|---|
float with a min or max, range | Field.range |
float | Field.number |
float2 / float3 | Field.vec2 / Field.vec3 |
float4 | a four-number Field.struct (x, y, z, w) |
color | Field.color |
bool | Field.bool |
texture | Field.resource("texture") |
and the chain's two inputs every post effect has: order (where it runs in the
post chain, lower first) and layer (scene, all, or empty for the shader's
own space). A shader property of a kind a post effect does not take
(texture_array, buffer), or one named order or layer, is refused by
name (postEffect.definition from asset.validate, and an error from
ref:inputs() and apply).
Applying it
Each application puts the shader in the post chain under the name
"<asset guid>/<owner>" (ref:effectName(owner) answers it), at its
effective order and layer, with the effective values written to its
properties: the asset's saved values, its live values (appliedSystem.setLive), then
what the owner states. Applying it again for the same owner changes the values
of that running application: ref:as("applicable"):apply(owner, { intensity = 0.5 }) writes the new value to the standing entry, and a change of order or
layer registers it again. Turning the application off
disables the entry; dropping it removes it. Post effects combine in chain
order, so every application of every post effect draws at once.
The entry is registered under the component origin, so a scene freeze never
turns an applied post effect into scene content: what puts it in force (a
setup, a PostProcess entry, code) is what the scene keeps.
In a PostProcess region
An effects entry of PostProcess names either a shader (registered as a
plain chain entry) or a post effect in effect, exactly one. An effect entry
is an application of the post effect, owned by "<entity id>/effects/<index>",
with the entry's values and textures as its stated values, its layer
stated when not empty, and the region's priority added to the effect's
order. A post effect applied by a setup and the same one named in a
PostProcess entry draw the same, and a live change reaches both.