---
title: "Lens"
description: "Words for the color fringing a real lens leaves behind: the red, green and blue copies of the layer inside pushed apart, or fanned out into a whole spectrum."
group: "effects"
groupTitle: "Filters & effects"
categoryId: "effects.lens"
categorySlug: "effects-lens"
wordCount: 2
curated: true
sourceUrl: "https://github.com/shader-effects-inc/shaders/blob/main/packages/core/src/std/effects/lens.ts"
editUrl: "https://github.com/shader-effects-inc/shaders/edit/main/packages/core/docs/std/effects.lens.md"
---

# Lens

Words for the color fringing a real lens leaves behind: the red, green and blue copies of
the layer inside pushed apart, or fanned out into a whole spectrum. Because they read the
child at several places per pixel, these are **gather effects**: the child is rendered to a
texture first and the effect samples it. [`chromaticFan`](/docs/primitives/effects-lens/chromaticfan) is a sampling stage; hand it to
`gatherStack` (from `effects.blurs`) to turn it into the `effect:` of a filter definition,
optionally followed by more stages. [`spectralLens`](/docs/primitives/effects-lens/spectrallens) is a complete fragment for a `gpu:`
definition, with the lens warp, focus zones and grain built in.

Angles are in degrees and go through `transformAngle`. Strengths are 0–1.

```ts
import {effects} from 'shaders/std'
```

## Reach for it when

| When you need | Use |
|---|---|
| a subtle RGB split along one direction | [`chromaticFan`](/docs/primitives/effects-lens/chromaticfan) inside `gatherStack` |
| the full prism look: many color copies, a bulging lens, swirl and grain | [`spectralLens`](/docs/primitives/effects-lens/spectrallens) |

## Example

```ts
import {defineShader, p, effects, transformAngle} from 'shaders/std'

const {chromaticFan} = effects.lens
const {gatherStack} = effects.blurs

// Chromatic aberration: red and blue pulled apart along an angle, green held in place.
export const Fringe = defineShader({
  name: 'Fringe',
  props: {
    strength: {default: 0.2, ui: {type: 'range', min: 0, max: 1, step: 0.01}},
    angle: {default: 0, transform: transformAngle, ui: {type: 'range', min: 0, max: 360, step: 1}},
    redOffset: {default: -1, ui: {type: 'range', min: -2, max: 2, step: 0.1}},
    greenOffset: {default: 0, ui: {type: 'range', min: -2, max: 2, step: 0.1}},
    blueOffset: {default: 1, ui: {type: 'range', min: -2, max: 2, step: 0.1}},
  },
  effect: gatherStack(chromaticFan({
    strength: p('strength'),
    angle: p('angle'),
    red: p('redOffset'),
    green: p('greenOffset'),
    blue: p('blueOffset'),
  }), []),
  missingChildMessage: 'Fringe needs a child to split.',
})
```

## Types

| Type | What it is |
|---|---|
| `SpectralLensSlots` | The props `spectralLens` reads. |

## Words

- [`chromaticFan`](/docs/primitives/effects-lens/chromaticfan) — Split the child into red, green and blue copies pushed apart along one direction.
- [`spectralLens`](/docs/primitives/effects-lens/spectrallens) — Fan the child out into many color-shifted copies through a warped lens, the spectral-lens look.