Filters
Volver a la referencia

Filters

Effects run over what one object, and everything under it, draws: an outline, a glow, a drop shadow, or any screen effect kept to that object.

7 símbolos

nacatamalon/effects

dropShadowfunctionnacatamalon/effects

dropShadow(options: { offset, radius, color, amount }) => TBuiltinPostEffect<{ offset, radius, color, amount }>

A shadow of everything an object draws, fallen a little way off behind it: a panel lifted off the screen, a character over the ground. Made for a filter (useFilter); on the whole screen there is nothing see-through for it to fall on.

Parámetros

options{ offset, radius, color, amount }

offset how far it falls, in game pixels, as { x, y } (down and to the right are positive); radius how soft its edge is, in game pixels, 0 for a hard one as pixel art has it; color of the shadow; amount how dark, from 0, none, to 1.

Ejemplo

declare const panel: TGameObject;

useFilter({ effects: [dropShadow({ offset: { x: 2, y: 3 }, radius: 0 })] }).add(panel);
Ver el código · post/builtin/drop_shadow.ts:29

glowfunctionnacatamalon/effects

glow(options: { color, radius, intensity }) => TBuiltinPostEffect<{ color, radius, intensity }>

A soft light of one colour around everything an object draws, behind it: a coin that shines, a selected card, a ghost. Made for a filter (useFilter); on the whole screen there is nothing see-through for it to shine into. For what is bright on the screen to glow, bloom().

The object's shape is blurred at half its size and laid behind it in the colour, so the light is wide and cheap.

Parámetros

options{ color, radius, intensity }

color of the light; radius about how far it reaches, in game pixels; intensity how strong it is, 1 as bright as the object is solid and more for a harder glow.

Ejemplo

declare const coin: TGameObject;

const shine = useFilter({ effects: [glow({ color: '#ffd23f', radius: 6 })] });
shine.add(coin);
Ver el código · post/builtin/glow.ts:30

outlinefunctionnacatamalon/effects

outline(options: { color, thickness }) => TBuiltinPostEffect<{ color, thickness }>

Draws a line of one colour around everything an object draws, outside it: one line around a character made of pieces, not one per piece. Made for a filter (useFilter); on the whole screen there is nothing see-through for it to draw around.

Read pixel by pixel, so a contour of 1 around pixel art is one game pixel, hard, with no corner left out. What is half see-through counts as much as it is there.

Parámetros

options{ color, thickness }

color of the line; thickness how many game pixels wide it is, up to 8.

Ejemplo

declare const hero: TGameObject;

useFilter({ effects: [outline({ color: '#ffffff', thickness: 1 })] }).add(hero);
Ver el código · post/builtin/outline.ts:27

useFilterfunctionhooknacatamalon/effects

useFilter(options: TFilterOptions) => TFilter

Makes a filter: effects run over what an object, and everything under it, draws, before it is laid on the screen. A contour around a character made of pieces, one contour and not one per piece; a glow around a coin; a shadow under a panel; a television whose screen is a crt(). It filters nothing until it is added to something, and can be added to as many objects as want it, each filtered on its own.

  • effects are the engine's own spread in (outline(), glow(), dropShadow(), and every screen-wide one: blur(), crt(), paletteMatch()…), one written in place, or a file, in order, each reading what the one before it gave, as usePostProcess takes them.
  • They work on what the object draws, with room around it for what they draw beyond it. rect gives them a part of the screen instead, in the object's space: the television's screen, which a crt() then curves as a whole.
  • An effect keeps what is see-through see-through, unless drawing around it is what it is for.

Each object filtered costs a picture the size of the screen and the effects run over its part: for many enemies with the same contour, hang them from one object and filter that. An object has one filter; one inside another runs on its own part first. A mask on the same object keeps the filtered picture to it, glow and all. zIndex sorts what is filtered as it always did, and the pointer touches it as it is, not as it looks. A filter goes away with the object it was asked for in, and everything it filtered is drawn as it is again.

Its radii and widths are pixels of the screen, so they keep their size when the camera zooms. A model inside one keeps its depth: the rest of the scene hides it and is hidden by it pixel by pixel, and what an effect draws round it (a glow's halo) takes the depth of the nearest part of it, so the halo of a part that is hidden is hidden too. The halo is laid over the solid models drawn right after it as well; one drawn later still, past a sprite or a see-through model, is drawn over it. An effect that moves pixels (a wave) is still tested at the depth of where they were. crt() and lcd() fill the part they are given, as a screen does: give them a rect. An effect that reads its last frame (motionBlur, phosphor) reads the one it is handed instead, since an object's part of the screen moves and changes size.

Parámetros

optionsTFilterOptions

The effects, and what part of the screen they work on.

Ejemplo

const Hero = () => {
    createSprite({ texture: 'body' });
    createSprite({ texture: 'sword', transform: { x: 10, y: -4 } });
};

export const Level: TSceneFn = () => {
    const hero = useSpawn(Hero)();
    useFilter({ effects: [outline({ color: '#ffffff' }), dropShadow({ offset: { x: 2, y: 3 } })] }).add(hero);

    const coin = useSpawn(() => { createSprite({ texture: 'coin' }); })();
    const shine = useFilter({ effects: [glow({ color: '#ffd23f' })] });
    shine.add(coin);
    let time = 0;
    useUpdate((delta) => {
        time += delta;
        shine.effects[0]!.uniforms.intensity = 1.5 + Math.sin(time * 4) * 0.5;
    });

    return createScene();
};
Ver el código · hooks/filter/use_filter.ts:70

TFiltertypenacatamalon/effects

A filter: effects run over what one object, and everything under it, draws, before it is laid on the screen. A contour around a character made of pieces, a glow around a coin, a shadow under a panel. Made with useFilter, it filters nothing until it is added to something; each object it is added to is filtered on its own, and everything it says can be changed at any moment, for all of them at once.

Propiedades

type'filter'
idstring
effectsTPostEffect[]

The effects, in order. Their uniforms are read every frame, so writing a number into one animates it on every object the filter is on.

rectTFilterRect | null

The part of the screen the effects work on, in each object's space, or null for what it draws.

paddingnumber | null

Pixels of room around what the object draws, or null for what the effects ask.

enabledboolean
add
remove
has
boxestypeOperator

Every object it filters, in the order they were added.

Ver el código · filter/types/t_filter.ts:59

TFilterOptionstypenacatamalon/effects

How a filter is made: useFilter's options.

Propiedades

effectstypeOperator

The effects, in order, each reading what the one before it gave: the engine's own spread in (outline(), glow(), blur()…), one written in place with a fragment, or a file from useLoadShader, as usePostProcess takes them.

rectopcionalTFilterRect

The part of the screen the effects work on, in the space of each object the filter is on: a television's screen for a crt(). Left out, it is what the object draws, measured each frame, with room around it for what the effects draw beyond it.

paddingopcionalnumber

Pixels of room around what the object draws, for effects to draw into. Left out, each of the engine's own effects says how much it needs (a glow its radius, a shadow how far it falls), and the largest is taken. Ignored with a rect.

enabledopcionalboolean

Whether it filters at all. true by default; false draws the objects as they are for a while without taking the filter away.

Ver el código · filter/types/t_filter.ts:22

TFilterRecttypenacatamalon/effects

A rectangle in the space of the object a filter is on: where its own x: 0, y: 0 is, turned and grown with it.

Propiedades

xnumber
ynumber
widthnumber
heightnumber
Ver el código · filter/types/t_filter.ts:13