# 12. Bloom post-processing, explained

**Goal:** make bright, emissive objects glow with `UnrealBloomPass`, and learn how the post-processing chain works.

## How post-processing works

Instead of drawing straight to the screen, the scene is rendered into an off-screen texture. Each **pass** reads the previous result, applies an effect, and writes a new texture. The last pass writes to the screen.

```text
RenderPass  ->  UnrealBloomPass  ->  OutputPass  ->  screen
(draw scene)    (blur bright parts,   (tone mapping +
                 add them back)        sRGB conversion)
```

## Walkthrough

```js
new THREE.MeshStandardMaterial({ color: 0x000000, emissive: hex, emissiveIntensity: 3 })
```
`emissive` is light the surface gives off by itself (it does not light other objects). An `emissiveIntensity` above 1 makes the pixels brighter than white in the linear working space, which is exactly what bloom's threshold picks up.

```js
const composer = new EffectComposer(renderer);
composer.addPass(new RenderPass(scene, camera));
```
`EffectComposer` manages the chain and its render targets. `RenderPass` renders the scene as usual, but into a texture.

```js
const bloom = new UnrealBloomPass(new THREE.Vector2(window.innerWidth, window.innerHeight), 1.2, 0.4, 0.1);
```
Arguments: resolution, **strength** (how strong the glow is), **radius** (how far it spreads), **threshold** (only pixels brighter than this glow). Raise the threshold so only emissive objects bloom and the rest of the scene stays crisp.

```js
composer.addPass(new OutputPass());
```
When rendering to the screen directly, the renderer applies tone mapping and color space conversion. With a composer, `OutputPass` does that, so it should be the **last** pass. Missing it is the usual reason post-processed scenes look darker or more saturated than expected.

```js
composer.setSize(window.innerWidth, window.innerHeight);
composer.render();
```
Resize the composer together with the renderer, and call `composer.render()` instead of `renderer.render()`.

## Common passes in `three/addons/postprocessing/`

| Pass | Effect |
| --- | --- |
| `UnrealBloomPass` | Glow around bright areas |
| `OutlinePass` | Outline selected objects |
| `SSAOPass` / `GTAOPass` | Ambient occlusion (contact shadows) |
| `BokehPass` | Depth of field |
| `FilmPass` | Film grain and scanlines |
| `GlitchPass` | Digital glitch |
| `SMAAPass` / `FXAAPass` | Anti-aliasing after post-processing |
| `ShaderPass` | Your own full-screen fragment shader |
| `OutputPass` | Tone mapping and color space conversion (put last) |

## Performance notes

- Every pass is a full-screen draw. On phones, keep the chain short and consider rendering the composer at a lower pixel ratio.
- MSAA from `antialias: true` does not apply to the composer's render targets by default; add an anti-aliasing pass (or pass a multisampled render target) if edges look jagged.
- For selective bloom (only some objects glow regardless of brightness), render with layers or use the selective bloom approach shown in the official three.js examples.

## Try this

1. Set the bloom threshold to 0 and see everything glow.
2. Add `new FilmPass()` (from `three/addons/postprocessing/FilmPass.js`) before `OutputPass`.
3. Remove `OutputPass` and compare the colors.
