Skip to content

Tutorials · Light and Shadow · Chapter 3

Shadows

20 minutes Uses: Occluder, TileMap

By the end

  • An Occluder on each pillar, 24 by 64, inside its 32 by 72 picture
  • The left pillar’s shadow fanning away from the lantern across the floor
  • Why the floor layer’s Occluder flag stays off, and how far a shadow reaches
On this page

Something to block the light

Light passes through everything until something blocks it, and a sprite blocks nothing, however solid it looks. An Occluder is what blocks. Occluder lists its fields.

  1. Select pillar_left, press Add component, type occluder, and choose OccluderComponent.
  2. Set its Size to 24 and 64. Leave Outline empty.
  3. Do the same on pillar_right: OccluderComponent, Size 24 and 64.
  4. Press Ctrl+S.

In the Viewport a selected box Occluder shows a handle at each corner of its box: drag one to set its Size. The box grows about the node, so the opposite corner moves the other way.

pillar_left selected, its Inspector narrowed to its Occluder: Enabled ticked, Size 24.0 and 64.0, Outline with no items; in the Viewport the pillar has a pale-blue frame, its own outline, and a smaller blue box inside it, the Occluder, with a small square handle on each of its four corners, while the other pillar shows its blue box alone, without handles; a dark shadow runs from the left pillar across the floor, away from the first lantern

The Viewport draws an Occluder’s box in blue, inside the pillar’s own outline: it is the box that blocks, not the picture. The hall shows the difference.

The left pillar and the floor beside it before the pillars have Occluders: the pillar lit by the lantern on its left, its cap warm yellow, and no shadow on the floor caps to its right
Before: the light passes through the pillar.
The same view after: the pillar dark where it blocks the light, and a dark wedge running from its top across the floor caps to its right, away from the lantern
After: the pillar casts its shadow away from the lantern.
Enabled
Whether this blocks light. Off, the node is a picture again, and light passes through it.
Size
The box that blocks, in world units, centred on the node. It turns and scales with the node. Make it a little smaller than the thing it stands for, as the next section shows: 24 by 64 here, four units inside the pillar’s 32 by 72 picture on every side.
Outline
Three points or more, which replace the box when there are any. Empty here: chapter 8 draws one for the arch.

Why the box is smaller than the pillar

The left pillar with an Occluder of its whole size, 32 by 72: the pillar entirely black, its cap too, and a dark wedge running off to its right across the floor
For comparison, Size 32 by 72, the picture’s own: the whole pillar is black.
The left pillar with the Occluder at 24 by 64: the pillar’s body still dark, but the left end of its cap lit warm yellow, a thin green rim down its left edge, and the dark wedge running off to its right
Size 24 by 64, the value you set: the cap’s lit end and the rim facing the lamp stay lit.

A shadow ends where the light does

A shadow is only light that did not arrive. It is as dark as the ambient, plus any other light that reaches it, and never darker: a second light shining into it lights it, as chapter 4 shows. And it runs out to the light’s Radius and no further, because past the Radius there is no light for the pillar to block.

The left pillar and the floor with the lantern at Radius 400: the pillar’s shadow running on across the floor caps to the right, well past where it faded out at Radius 260
For comparison, the lantern at Radius 400: the shadow runs on with the light.

The floor stays lit

Tiles cast shadows too, when their layer is marked Occluder. The floor’s layer is not, and the hall shows why it must not be.

  1. Select floor and open the Tilemap panel, the tab beside the Inspector.
  2. Under Layers, find the floor row and click the gear at its right end. Tick Occluder: the gear’s label gains an O and reads SNO.
  3. Look at the hall.
  4. Click the gear again and untick Occluder, so the label reads SN.
  5. Press Ctrl+S.
The hall with the floor layer’s Occluder ticked: the stone caps along the bottom dull and the stone below them black, the lantern’s light stopping at the top of the floor, the first lantern’s bricks and the pillar’s shadow as before
With the floor’s Occluder ticked: the floor black, the lantern stopping at its top edge.
The floor selected with the Tilemap panel open: the Layers list shows two layers, back and floor, each at z 0, with a gear at the right end of each row; the floor’s gear reads SNO
Occluder
A tile layer’s flag, in its gear’s menu: its tiles cast shadows from every light that reaches them. The gear’s label shows the initials of the flags that are on: S for Solid, 1 for One-way, N for Blocks nav and O for Occluder.

The pillar’s shadow

FieldValue
Occluder on pillar_left and pillar_rightSize 24, 64, inside a 32 by 72 picture
Outlineempty
The floor layer’s Occluder flagoff
How far the shadow reachesthe light’s Radius, 260

Check it works