# Textures

Images on materials for logos, signs, screens, posters and tiles.

Declare each image once in `textures`, then map it onto a material with `map` (colour) or `emissive_map` (light).

```json title="apps/docs/examples/textures.json"
{
  "camera": { "position": [0, 2.2, 6.5], "target": [0, 0.8, 0], "fov": 40 },
  "lighting": { "rig": "studio_soft" },
  "environment": {
    "background": {
      "radial_gradient": { "inner": "#1b2233", "outer": "#07090f" }
    }
  },
  "post": { "bloom": 0.5 },
  "textures": {
    "checker": {
      "src": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAJElEQVR42mMQEZGDo/96R+AIlzjDINRAjCJk8cGoYTQeBoUGAFD+G5A9c+hMAAAAAElFTkSuQmCC"
    }
  },
  "materials": {
    "tiles": {
      "color": "#9aa0b0",
      "roughness": 0.6,
      "map": { "texture": "checker", "repeat": [6, 6] }
    },
    "screen": {
      "color": "#000000",
      "emissive": "#ffffff",
      "emissive_intensity": 2,
      "emissive_map": { "texture": "checker", "repeat": [2, 1] }
    }
  },
  "nodes": {
    "floor": {
      "mesh": {
        "geometry": { "plane": { "size": [6, 6] } },
        "material": "tiles"
      },
      "transform": { "rotation": [-90, 0, 0] }
    },
    "sign": {
      "transform": { "position": [0, 1.3, -1] },
      "mesh": {
        "geometry": { "plane": { "size": [2.4, 1.4] } },
        "material": "screen"
      }
    }
  }
}
```

![Render of textures](/renders/textures.jpg)

## Sources

`src` is a PNG or JPEG data URI, a path next to the scene file, or an https URL in the browser. In the browser, relative paths resolve against `textureBase`. Until an image loads, the material draws as plain colour.

## Gradients

A `src` can also be a CSS-style gradient. The renderer generates it, so there's no file to load, and it maps with the geometry's UVs like an image.

```json title="scene.json"
{
  "textures": {
    "sunrise": { "src": "linear-gradient(135deg, #ff6a3d, #ffb347 45%, #4a3f9a)" },
    "glow": { "src": "radial-gradient(at 50% 40%, #ffffff, #0a84ff 55%, #001a4a)" }
  }
}
```

- `linear-gradient(<angle>, <stops>)` uses CSS angles. `0deg` points up, `90deg` right, and the default `180deg` runs top to bottom.
- `radial-gradient(<stops>)` is a circle from the centre to the nearest edge. `at 30% 20%` moves the centre.
- Stops are hex colours with an optional `%` position. Stops without one spread evenly. Colours blend in sRGB, like browsers.
- A gradient that doesn't parse is an `invalid_gradient` error.

See [2D Motion Graphics](/docs/features/motion-graphics) for gradient cards.

## Patterns

A `src` can also be a procedural art-media pattern, which the renderer generates like a gradient. Patterns are near-white greys that multiply the material or node colour, and they tile seamlessly, so `repeat` sets their scale.

```json title="scene.json"
{
  "textures": {
    "paper": { "src": "paper(0.25)" },
    "wash": { "src": "watercolor(0.4, 3)" },
    "dry": { "src": "bristle(0.6)" }
  }
}
```

- `paper(<amount>)` is fibrous paper grain.
- `watercolor(<amount>)` gives soft pigment blotches, granulation and darker pooled edges.
- `bristle(<amount>)` draws streaks along U, with dry-brush gaps that open towards U = 1. Brush strokes run U along their length (see [Brush Ink and Paper](/docs/features/motion-graphics#brush-ink-and-paper)).
- `amount` runs from 0 to 1. An optional whole-number seed comes second: `paper(0.25, 7)`.
- A pattern that doesn't parse is an `invalid_pattern` error. Patterns come with the authoring bundle in the browser.

## Mapping

- `map` multiplies `color`, so keep `color` white for the image's own colours. Its alpha cuts the material out.
- `emissive_map` multiplies `emissive`, for lit signs, screens and windows.
- `repeat`, `offset` and `rotation` (degrees) transform the UVs.
- Planes show the image upright, facing +z.

## API Reference

### Texture

An image the scene loads once and materials map by name.

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `src` (required) | `string` | — | PNG or JPEG: a `data:image/...;base64,` URI, an `https://` URL (browser only; the CLI reads data URIs and files), or a file path relative to the scene. Or a CSS-style gradient the renderer generates (no file): `linear-gradient(90deg, #0a84ff, #ffffff00 80%)`, `radial-gradient(at 50% 40%, #ffffff, #0a84ff)`. |
### TextureMap

Where a texture lands on a surface: `uv' = rotate(uv * repeat) + offset`.

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `offset` | `[x, y]` | — | Shift in UV units, applied after repeat and rotation. |
| `repeat` | `[x, y]` | — | Tiles across U and V (images wrap). |
| `rotation` | `number` | — | Rotation in degrees, counter-clockwise around UV (0, 0). |
| `texture` (required) | `string` | — | Name in the scene's `textures`. |
