---
title: "chosenBy"
description: "Picks one whole effect recipe from a select prop, decided when the shader compiles."
group: "paint"
groupTitle: "Painting"
categoryId: "patterns"
categorySlug: "patterns"
categoryTitle: "Patterns & tiling"
kind: "function"
sourceUrl: "https://github.com/shader-effects-inc/shaders/blob/main/packages/core/src/std/paint/patterns.ts#L983"
---

# chosenBy

Picks one whole effect recipe from a select prop, decided when the shader compiles.

```ts
chosenBy<K extends string>(
  prop: PropRef,
  read: (raw: unknown) =,
> K, recipes: Record<K, GatherEffect>): GatherEffect
```

Import `patterns` from `shaders/std` and use `patterns.chosenBy`.

`prop` must be a `compileTime: true` prop. `read` turns its raw value into one of the keys of `recipes`; accept both the option string and its transformed value. Every recipe must be a gather effect with the same alpha handling and no setup step, or this throws as soon as it is called.

## Parameters

| Name | Type | Notes |
|---|---|---|
| `prop` | `PropRef` |  |
| `read` | `(raw: unknown) => K` |  |
| `recipes` | `Record<K, GatherEffect>` |  |

## Example

```ts
effect: chosenBy(p('style'), (raw) => (raw === 'cmyk' || raw === 1 ? 'cmyk' : 'classic'), {classic: dotScreen({angle: p('angle'), frequency: p('frequency')}), cmyk: cmykPress({paper: p('paperColor'), frequency: p('frequency'), misprint: p('misprint'), misprintAngle: p('misprintAngle'), plates})})
```

> **Tip.** Changing the prop recompiles the shader, which is the point: each style pays only for its own code.

## See also

- [`dotScreen`](/docs/primitives/patterns/dotscreen) — A classic halftone filter: the layer inside it redrawn as a grid of dots that grow where it is bright.
- [`cmykPress`](/docs/primitives/patterns/cmykpress) — A four-color print filter: the layer inside it separated into ink plates, each screened into dots at its own angle and laid down on paper in order.

## Used by

[Halftone](/docs/components/halftone)