Making games
Lighting and environment
Lights
| Light | Use it for |
|---|---|
| Directional Light | The sun or the moon: light from one direction, everywhere at once. Where it is doesn’t matter, only which way it faces. |
| Point Light | A bulb, a torch, a glowing pickup: light in every direction from a point, fading out by its Range. |
| Spot Light | A flashlight, a headlight, a stage light: a cone, sharp inside Inner angle and fading out to Outer angle. |
Each has a Color, an Intensity and an Enabled switch. Scene → Light creates a point light; add the others with Add Component.
Shadows
A directional light always casts shadows. They’re drawn in four cascades, sharp close to the camera and coarser far away, so a shadow is crisp at your feet and still there on a distant hill.
Point and spot lights cast shadows when you turn on their Cast shadows. They’re off by default because each one is another pass over the scene (six, for a point light, one per direction). Each frame, the four spot lights and two point lights closest to the camera that ask for shadows get them.
Each Mesh Renderer decides whether it throws a shadow and whether it receives them.
How many lights
A scene can have hundreds of lights. The screen is divided into tiles 32 pixels square, and each tile into slices by distance from the camera; each of those pieces lists the lights whose Range reaches it, and a pixel works through only its own piece’s list. A street of lamps costs each pixel the few lamps near it, not all of them. Directional lights reach everywhere, so every piece lists them.
Two limits, in File → Project Settings → Rendering:
| Setting | Default | What it does |
|---|---|---|
| Max lights in view | 512 | The most lights the game lights with at once, out of those whose range reaches what the camera sees. Directional lights are kept first, then the point and spot lights nearest the camera; past the limit, the farthest are dark. |
| Max lights per cluster | 512 | The most lights one piece of the screen lists. Past it, that piece lights with the ones nearest the camera. Lowering it trades lights in a crowded spot for speed there. |
Both go up to 8192. When a limit is hit, the Console says so once, with how many lights it left out and which setting raises it, and says so again when everything is lit.
Seeing where the lights pile up
The layers button at the top right of the scene view, left of Snap, turns on a debug view drawn over the scene. Its first view is Lights per cluster: each pixel colored by how many lights it works through, dark blue for none, through green and yellow, to red at 32 or more, and magenta where a piece of the screen is at Max lights per cluster. The faint grid is the 32-pixel tiles. A spot that’s slow to draw because of its lights shows up warm.
While a debug view is on, the button is highlighted and the view’s name is shown in the top left corner of the scene view. Click the button again to turn it off; the arrow beside it opens the list of debug views. Only the scene view draws it: the game view and the built game never do.
The sky and ambient light
A World Environment component sets the scene’s sky and the light that fills it from everywhere. A scene without one uses a plain default sky.
| Property | What it does |
|---|---|
| Sky top / horizon / bottom color | The sky’s gradient: straight up, at the horizon, straight down. |
| Ambient source | Where the fill light comes from: Sky (the sky’s own colors), Color (one flat color), or Disabled. |
| Ambient intensity | How bright the fill light is. |
| Ambient sky contribution | With Sky, how much comes from the sky versus Ambient color: 1 is all sky. Lower it for an interior that sees a little daylight. |
| Ambient occlusion | Darkens corners and creases where the fill light can’t reach, so they read as corners. AO radius and AO intensity tune it. |
If a scene has several environments, the one with the highest Priority wins.
Reflections
Shiny surfaces reflect the sky. Indoors, that’s wrong: a polished floor in a room shouldn’t reflect a blue sky. A Reflection Probe captures what’s around it and gives reflections inside its box instead.
Place one in the middle of a room and set Half extents to half the room’s size. With Box projection on (the default), reflections line up with the room’s walls. Blend distance fades the probe out near the box’s edge.
Bloom and exposure
How bright the final picture is belongs to the camera: its Exposure, its tonemapping curve, and Bloom, the glow around bright things such as emissive materials and the sun.