# Reference: effects

What a scene imports from `framescript` and calls, in the order the module exports it. Each entry has its signature, what it does, and the examples that use it; the types its signatures name are [at the end](#types).

Explained in [Effects](/docs/framework/scene/effects.md).

## `bloom`

```ts
function bloom(
  options?: Partial<Pick<Bloom, "strength" | "radius" | "threshold" | "amount">>
): Bloom
```

Makes a bloom effect.

- `options`: Strength, radius and threshold.
- Returns: The effect, to be put on the timeline with `add`.

Examples: effects/bloom-and-tone

## `chromaticAberration`

```ts
function chromaticAberration(
  options?: Partial<Pick<ChromaticAberration, "offset" | "amount">>
): ChromaticAberration
```

Makes a chromatic aberration.

- `options`: The offset.
- Returns: The effect, to be put on the timeline with `add`.

Examples: effects/lens

## `depthOfField`

```ts
function depthOfField(
  options?: Partial<
    Pick<DepthOfField, "focus" | "aperture" | "maxBlur" | "amount">
  >
): DepthOfField
```

Makes a depth-of-field effect.

- `options`: The focus distance, the aperture and the largest blur.
- Returns: The effect, to be put on the timeline with `add`.

Examples: effects/focus

## `directionalBlur`

```ts
function directionalBlur(
  options?: Partial<Pick<DirectionalBlur, "angle" | "strength" | "amount">>
): DirectionalBlur
```

Makes a directional blur.

- `options`: The direction and the strength.
- Returns: The effect, to be put on the timeline with `add`.

Examples: camera/whip-pan, effects/blurs

## `distortion`

```ts
function distortion(
  options?: Partial<Pick<Distortion, "strength" | "amount">>
): Distortion
```

Makes a lens distortion.

- `options`: The strength.
- Returns: The effect, to be put on the timeline with `add`.

Examples: effects/lens

## `environment`

```ts
function environment(
  options?: Partial<
    Pick<
      Environment,
      "map" | "intensity" | "rotation" | "background" | "blur" | "amount"
    >
  >
): Environment
```

Makes an environment.

- `options`: The surroundings, their brightness and turn, and whether they show behind the scene.
- Returns: The environment, to be put on the timeline with `add`.

Examples: loading/assets, fills/fills

## `glitch`

```ts
function glitch(
  options?: Partial<
    Pick<Glitch, "strength" | "slices" | "seed" | "hold" | "amount">
  >
): Glitch
```

Makes a glitch.

- `options`: Its strength, its rows, its seed and how long a pattern holds.
- Returns: The effect, to be put on the timeline with `add`.

Examples: effects/more-effects

## `glow`

```ts
function glow(
  target: object,
  options?: Partial<Pick<Glow, "strength" | "radius" | "color" | "amount">>
): Glow
```

Makes one object glow. Unlike `bloom`, which makes everything bright glow, this belongs to the object it is given, however bright or dark that is. The glow lies over the picture: it is not hidden by what stands in front of the object.

- `target`: The object that glows, with everything under it.
- `options`: Its strength, its reach and its colour.
- Returns: The effect, to be put on the timeline with `add`.

Examples: effects/more-effects

## `grade`

```ts
function grade(
  options?: Partial<
    Pick<
      Grade,
      | "curve"
      | "contrast"
      | "saturation"
      | "brightness"
      | "temperature"
      | "amount"
    >
  >
): Grade
```

Makes a colour grade. At an `amount` of 0 the frame is left exactly as it is.

- `options`: The curve and how much contrast, colour, brightness and warmth there is.
- Returns: The effect, to be put on the timeline with `add`.

Examples: controls/grading, effects/more-effects

## `grain`

```ts
function grain(
  options?: Partial<Pick<Grain, "intensity" | "seed" | "amount">>
): Grain
```

Makes video grain.

- `options`: The intensity and the seed.
- Returns: The effect, to be put on the timeline with `add`.

Examples: export/sections, effects/lens

## `lookup`

```ts
function lookup(
  options: Pick<Lookup, "table"> & Partial<Pick<Lookup, "amount">>
): Lookup
```

Makes a colour grade from a lookup table, such as a `.cube` file a grading program wrote. At an `amount` of 0 the frame is left as it is; between 0 and 1 it is that far towards the table's colours.

- `options`: The table from `load.lut`, and how much of it.
- Returns: The effect, to be put on the timeline with `add`.

Examples: effects/more-effects

## `pixelate`

```ts
function pixelate(
  options?: Partial<Pick<Pixelate, "size" | "amount">>
): Pixelate
```

Makes the picture blocky.

- `options`: The size of a block.
- Returns: The effect, to be put on the timeline with `add`.

Examples: effects/more-effects

## `toneMapping`

```ts
function toneMapping(
  options?: Partial<Pick<ToneMapping, "mode" | "exposure">>
): ToneMapping
```

Makes a tone mapping. Without one the picture is not tone mapped. It has no `amount`: it is on from the moment it is added, and what is animated is its `exposure`.

- `options`: The curve and the exposure.
- Returns: The effect, to be put on the timeline with `add`.

Examples: effects/bloom-and-tone

## `viewport`

```ts
function viewport(
  size: Pick<Viewport, "width" | "height"> &
    Partial<Pick<Viewport, "x" | "y" | "amount">>
): Viewport
```

Makes the place of the scene's own picture on the screen something that can be animated: at first it is the whole frame, and a tween of its `x`, `y`, `width` and `height` draws the picture back into a part of it, a scene inside the scene. Outside the picture the frame is black until a layer on the screen covers it. The picture is drawn with the camera's proportions: a viewport that rests in other proportions than the frame's, a square beside a chat for one, takes a camera whose aspect is its own (width over height).

- `size`: The scene's size, which the picture starts with: the timeline's `stage` has it. `x` and `y` may be given too.
- Returns: The effect, to be put on the timeline with `add`.

Examples: effects/viewport

## `vignette`

```ts
function vignette(
  options?: Partial<Pick<Vignette, "darkness" | "offset" | "amount">>
): Vignette
```

Makes a vignette.

- `options`: The darkness and where it starts.
- Returns: The effect, to be put on the timeline with `add`.

Examples: effects/lens

## `zoomBlur`

```ts
function zoomBlur(
  options?: Partial<
    Pick<ZoomBlur, "centerX" | "centerY" | "strength" | "amount">
  >
): ZoomBlur
```

Makes a zoom blur.

- `options`: The centre and the strength.
- Returns: The effect, to be put on the timeline with `add`.

Examples: effects/blurs, transitions/zoom-through

## `blur`

```ts
function blur(
  target: object,
  options?: Partial<Pick<Blur, "radius" | "amount">>
): Blur
```

Makes a blur that belongs to one object. The object must have been added with `{ flatten: true }`: the blur softens the picture the object is drawn into, with everything under it, and leaves the rest of the frame sharp. Its `radius` and `amount` are tween targets, so a thing can come into focus or go out of it. When several blurs of one object are present, their reaches add up.

- `target`: The flattened object to blur.
- `options`: How far the blur reaches, and how much of it.
- Returns: The effect, to be put on the timeline with `add`.

Examples: layers/blur

## `motionBlur`

```ts
function motionBlur(
  options?: Partial<Pick<MotionBlur, "shutter" | "samples" | "amount">>
): MotionBlur
```

Makes motion blur. A frame is then the average of several drawings of the scene, at moments spread over the time the shutter is open, from the frame's own time on. It is applied to every exported frame and to a still drawn in full quality, and left out while a scene is played and scrubbed as a draft. A frame costs `samples` times what it costs without, so it is off unless a scene adds it; with an `amount` of 0 it costs nothing.

- `options`: The shutter, the number of samples and how much of it.
- Returns: The effect, to be put on the timeline with `add`.

Examples: effects/motion-blur

## `focusOn`

```ts
function focusOn(
  effect: DepthOfField,
  object: object | null
): Step<void>
```

Keeps an object in focus from now on: at every frame the depth of field's focus is the object's distance from the camera, wherever both have moved.

- `effect`: A depth of field that was added.
- `object`: The object to keep sharp, or `null` to go back to the effect's own `focus` distance.
- Returns: A step that ends at once.

Examples: effects/focus

## `rackFocus`

```ts
function rackFocus(
  effect: DepthOfField,
  to: object,
  duration: number,
  options?: TweenOptions
): Step<void>
```

Pulls the focus from what is sharp now to another object, over a duration. It starts from the object in focus, or from the effect's `focus` distance when it follows none, and ends following the new object.

- `effect`: A depth of field that was added.
- `to`: The object the focus ends on.
- `duration`: How long the pull takes, in seconds.
- `options`: Easing and timing, as for a tween.
- Returns: A step that lasts as long as the pull.

Examples: effects/focus

## Types

### `Bloom`

```ts
interface Bloom extends StageEffect<"bloom"> {
  /** How strong the glow is; 0 leaves the picture as it is. */
  strength: number
  /** How far the glow spreads, from 0 to 1. */
  radius: number
  /** How bright a pixel must be to glow, from 0 to 1. */
  threshold: number
}
```

### `Blur`

```ts
interface Blur extends StageEffect<"blur"> {
  /** The object that is blurred: one that was added with `flatten`. */
  readonly target: object
  /** How far the blur reaches, as a share of the frame's height. */
  radius: number
}
```

### `ChromaticAberration`

```ts
interface ChromaticAberration extends StageEffect<"chromaticAberration"> {
  /** How far red and blue part at the edge, as a share of the width. */
  offset: number
}
```

### `DepthOfField`

```ts
interface DepthOfField extends StageEffect<"depthOfField"> {
  /** The distance from the camera that is sharp, in world units. */
  focus: number
  /**
   * How quickly things go soft away from the focus: the lens opening. 0 is
   * sharp everywhere.
   */
  aperture: number
  /** The largest blur, as a share of the picture's height. */
  maxBlur: number
  /**
   * An object to keep in focus. While it is set, `focus` is its distance
   * from the camera at every frame. Set it with `focusOn`.
   */
  target: object | null
  /** The object the focus is leaving, during a rack focus. */
  targetFrom: object | null
  /** How far a rack focus has gone from `targetFrom` to `target`, 0 to 1. */
  rack: number
}
```

### `DirectionalBlur`

```ts
interface DirectionalBlur extends StageEffect<"directionalBlur"> {
  /** The direction, in degrees: 0 is horizontal, 90 vertical. */
  angle: number
  /** How long the smear is, as a share of the picture's width. */
  strength: number
}
```

### `Distortion`

```ts
interface Distortion extends StageEffect<"distortion"> {
  /** Above 0 the picture bulges (barrel); below, it pinches (pincushion). */
  strength: number
}
```

### `Environment`

```ts
interface Environment extends StageEffect<"environment"> {
  /**
   * The surroundings, as an equirectangular texture from
   * `load.environment`. With `null`, a neutral studio room is used.
   */
  map: object | null
  /** How bright the surroundings light the scene. */
  intensity: number
  /** A turn of the surroundings about the vertical, in degrees. */
  rotation: number
  /** How visible the surroundings are behind the scene, from 0 to 1. */
  background: number
  /** How soft the surroundings look behind the scene, from 0 to 1. */
  blur: number
}
```

### `Glitch`

```ts
interface Glitch extends StageEffect<"glitch"> {
  /** How far rows jump and colours part, from 0 to 1. */
  strength: number
  /** How many rows the picture is cut into. */
  slices: number
  /**
   * What the jumps are made from. A frame's glitch is a function of this
   * and the frame's number, so it is the same on every run.
   */
  seed: number
  /** For how many frames one pattern of jumps holds. */
  hold: number
}
```

### `Glow`

```ts
interface Glow extends StageEffect<"glow"> {
  /** The object that glows. */
  readonly target: object
  /** How bright the glow is; 0 is none. */
  strength: number
  /** How far it reaches, as a share of the frame's height. */
  radius: number
  /**
   * The glow's colour, or `null` for the object's own colours. Defaults
   * to `null`.
   */
  readonly color: string | null
}
```

### `Grade`

```ts
interface Grade extends StageEffect<"grade"> {
  /**
   * A tone curve: points a tone passes through, each as what it is and
   * what it becomes, from 0 (black) to 1 (white). `[[0.25, 0.18], [0.75,
   * 0.85]]` darkens the shadows and lifts the lights. With no points the
   * tones stay as they are.
   */
  readonly curve: ReadonlyArray<readonly [from: number, to: number]>
  /** The contrast about the middle grey; 1 leaves it as it is. */
  contrast: number
  /** How much colour there is; 0 is grey, 1 as it is, more is stronger. */
  saturation: number
  /** A shift of every tone, from -1 (to black) to 1 (to white). */
  brightness: number
  /** From cooler, below 0, to warmer, above it; 0 leaves it as it is. */
  temperature: number
}
```

### `Grain`

```ts
interface Grain extends StageEffect<"grain"> {
  /** How visible the grain is, from 0 to 1. */
  intensity: number
  /**
   * What the noise is made from. A frame's grain is a function of this and
   * the frame's number, so it is the same on every run.
   */
  seed: number
}
```

### `Lookup`

```ts
interface Lookup extends StageEffect<"lookup"> {
  /** The table, as `load.lut` gives it. */
  readonly table: object
}
```

### `MotionBlur`

```ts
interface MotionBlur extends StageEffect<"motionBlur"> {
  /**
   * For how much of a frame's length the shutter is open, from 0 (closed:
   * no blur) to 1 (the whole time until the next frame). 0.5 is the half
   * turn of a video camera.
   */
  shutter: number
  /**
   * How many times the frame is drawn, at moments spread evenly over the
   * time the shutter is open. More is smoother and costs as much more.
   */
  samples: number
}
```

### `Pixelate`

```ts
interface Pixelate extends StageEffect<"pixelate"> {
  /** The size of one block, in pixels of the scene. */
  size: number
}
```

### `StageEffect`

```ts
interface StageEffect<Kind extends string = string> {
  /** Which effect this is, such as `bloom`. */
  readonly framescriptEffect: Kind
  /** The name the studio shows, which is the kind. */
  readonly name: string
  /** Always `Effect`, so the schedule lists it apart from scene objects. */
  readonly type: "Effect"
  /** How much of the effect is applied, from 0 (none) to 1 (all of it). */
  amount: number
}
```

### `Step`

```ts
interface Step<A> {
  readonly [result]?: A
  [Symbol.iterator](): Iterator<unknown, A>
}
```

### `ToneMapping`

```ts
interface ToneMapping extends StageEffect<"toneMapping"> {
  /**
   * The curve: `aces` and `agx` are filmic; `neutral` keeps hues and
   * saturation, and like the filmic ones it deepens what is nearly black,
   * so a very dark background becomes black; `reinhard` leaves dark tones
   * as they are and only brings down the bright ones.
   */
  mode: "aces" | "agx" | "neutral" | "reinhard" | "linear"
  /** How bright the picture is before the curve. */
  exposure: number
}
```

### `TweenOptions`

```ts
type TweenOptions = EasingInput | TweenSettings
```

### `TweenSettings`

```ts
interface TweenSettings {
  /** The easing of each leg. Defaults to `easeOut`. */
  readonly ease?: EasingInput
  /** Seconds to wait before starting, as part of the same span. */
  readonly delay?: number
  /** How many more times to play. `Infinity` belongs inside `background`. */
  readonly repeat?: number
  /** Play every second pass backwards. */
  readonly yoyo?: boolean
  /**
   * Where each keyframe sits, from 0 to 1: one entry for each keyframe,
   * the first included. Evenly spaced by default.
   */
  readonly times?: ReadonlyArray<number>
  /**
   * Starts at the speed the property has at that moment, from the tween
   * before it or one it interrupts, instead of from rest, so that there is
   * no kink. A spring keeps its feel; any other easing is replaced by one
   * that slows from that speed to rest. A spring given by its physics does
   * this without being asked.
   */
  readonly carry?: boolean
}
```

### `Viewport`

```ts
interface Viewport extends StageEffect<"viewport"> {
  /** The middle of the picture, in pixels to the right of the frame's. */
  x: number
  /** The middle of the picture, in pixels above the frame's. */
  y: number
  /** The picture's width, in the scene's pixels. */
  width: number
  /** The picture's height, in the scene's pixels. */
  height: number
}
```

### `Vignette`

```ts
interface Vignette extends StageEffect<"vignette"> {
  /** How dark the corners get, from 0 to 1. */
  darkness: number
  /** How far from the centre the darkening starts, from 0 to 1. */
  offset: number
}
```

### `ZoomBlur`

```ts
interface ZoomBlur extends StageEffect<"zoomBlur"> {
  /** The point that stays sharp, from 0 at the left edge to 1 at the right. */
  centerX: number
  /** The point that stays sharp, from 0 at the top edge to 1 at the bottom. */
  centerY: number
  /** How long the streaks are at the edge, as a share of the distance. */
  strength: number
}
```
