# Dark scenes

> `@typegpu/kit` 0.1.0. If it is installed, read `node_modules/@typegpu/kit/docs/` instead.

Settings that keep a night scene dark, from the sky to the final pass.

The [lighting](../kit/lighting.md) defaults describe daylight. A pale blue sky lights every surface from above and shows in every reflection, and fog takes a pale grey-blue. In a night scene those values brighten the shadows and wash out the distance. Set the sky, the sun and the fog for the night, light the scene with lamps, and set the exposure for a dark picture:

```ts
import { bloom, finish } from '@typegpu/kit';

const night = lighting.create(root, {
  settings: {
    sunDirection: [-0.45, 0.75, -0.5], // the moon
    sunColor: [0.5, 0.65, 1],
    sunIntensity: 0.25,
    skyTop: [0.03, 0.06, 0.16],
    skyBottom: [0.02, 0.016, 0.014],
    fogColor: [0.03, 0.06, 0.13],
    fogDensity: 0.015,
    fogFalloff: 0.12,
  },
  points: { table: lamps },
});

const source = () => screen.textures.hdr;
const glow = bloom.create(root, { source, settings: { threshold: 1.2 } });
const final = finish.create(root, {
  format: surface.format,
  source,
  glow,
  settings: { exposure: 1.2 },
});
```

| Setting                    | At night                                                                                       |
| -------------------------- | ---------------------------------------------------------------------------------------------- |
| `skyTop`, `skyBottom`      | Dark blue above, near black below. They light every surface and fill every reflection.         |
| `sunColor`, `sunIntensity` | A pale blue moon from `0.05` to `0.25`.                                                        |
| `fogColor`                 | The sky's colour near the horizon. A pale fog brightens a dark scene at any density.           |
| bloom `threshold`          | `0.8` to `1.2`. Raise it until lit surfaces stop glowing and only lamps, flames and sparks do. |
| finish `exposure`          | `1.2`, or an [adapted exposure](#adapting-to-the-dark).                                        |

Point lights provide most of the light at night. Give a lantern or a fire an intensity near `8` and a range near `11`, and small lamps an intensity from `0.5` to `3`. See [point lights](../kit/lighting.md#point-lights) and [their shadows](../kit/lighting.md#point-and-spot-shadows).

## Adapting to the dark

An [adapted exposure](../kit/finish.md#adapting-exposure) aims the picture's average at `key`. The default, `0.18`, is a daylit scene's average. It brightens a night scene to the same average and lifts its shadows. Set `key` to the average the scene is lit for:

```ts
import { exposure, finish } from '@typegpu/kit';

const eye = exposure.create(root, { source, settings: { key: 0.04 } });
const final = finish.create(root, { format: surface.format, source, exposure: eye });
```

- A street lit by lamps and the moon averages about `0.04`. A night sky lit by fireworks averages about `0.007`.
- `highest` caps how far the exposure rises in a dark moment, such as a street whose fire went out. Set it a little above the exposure the scene looks right at.
- A flash brightens the average, and the exposure falls at `fall` to dim the picture around it.
