Skip to content

Time of day

The DS games keep a real-time clock, and their towns look different at dawn, at noon, at dusk and at night. Nothing is drawn twice. The same models and textures are drawn under a different light, and the light is chosen by the hour. This page explains how the generation-4 and generation-5 games do it, how older games did the same with palettes, and how PokeLoom models all of them as one feature. What a creator writes is on Light, time of day and weather; how the hardware computes a lit colour is on Lights and materials.

A game cuts the day into periods. Each period starts at a time and lasts until the next one starts. Two kinds of period exist side by side in the games:

  • Named parts of the day (morning, day, evening, night, late night) that the game’s rules read: which creatures appear in the grass, whether a battle uses its night scene, which people stand in a town.
  • Light periods, usually many more, that only decide how things are lit. There are several around dawn and dusk, where the light changes fastest, and few in the middle of the day and the night.

Keeping them apart lets the light change in small steps while the rules see only a few broad parts of the day.

The generation-4 and generation-5 games light their maps with the DS’s 3D hardware. For each light period a table holds:

Part What it is
Up to four lights each on or off, with a colour and a direction
Material colours the diffuse, ambient, specular and emission colours that lit surfaces reflect
(generation 5) the colour behind everything and the fog’s colour, so the sky and the haze change with the light

The hardware lights each vertex of a lit polygon from its normal: a face turned toward a light takes its colour, a face turned away takes only the ambient part. So which faces of a building are in shade changes as the light’s direction changes through the day. The rules of that sum are on Lights and materials.

A game has several such tables. Generation 4 has a few: one that changes through the day for outdoor places, and constant ones for interiors and caves. Generation 5 has many, chosen by area, and the season changes which hours begin each period.

At night the towns’ windows are lit. This is not a second texture. Materials choose which of the four lights touch them. Most of a building takes only the sun. Window glass and lamp glass take only a separate light used as a lamp: dull and cool by day, warm and bright in the evening, off again late at night. A sign that should never change takes a constant white light. One table and the right choice per material are enough to light a whole town at dusk.

Generation 4 steps: when the clock passes the end of a period, the next period’s lights are applied at once. Dawn and dusk still look gradual because their periods are only half an hour or an hour apart. Generation 5 fades between periods instead.

Interiors and most caves in generation 4 do not change with the hour. Their lights come from a constant table, and many interior models carry their light baked into their vertex colours, so only their lit props respond at all. A place that should always be night (a scene’s map, a dark wood) can be held at one period.

The Game Boy Color games of generation 2 have no 3D hardware. They do the same thing with palettes: a set of background and sprite palettes for each environment and each period (morning, day, night, and a dark set for caves), with a swap and a fade when the period changes. Roofs and some tilesets have their own day and night colours. The GBA games of generation 3 have no day and night light in the field at all; their dark caves are a circle of light that the flash move widens.

A map names a light table. A table has 1 to 16 periods; each period starts at a time of day and holds:

Part Used for
sun a colour that multiplies the palettes of everything lit by the main light
lamp, glow the lamp colour of window and lantern materials, and how strongly pools of light show
night whether the rules count this period as night
lights, material (optional) the hardware’s four lights and the material colours, for models with normals
clear, fog (optional) the colour behind everything and the fog’s colour in this period

The engine has four tables of its own. day has fourteen periods, stepping more often around dawn and dusk, with lamps lit from the evening until midnight. bright is white at every hour with lamps lit, for interiors. dim and warm are constant. Outdoor maps default to day, indoor maps and caves to bright. A project adds or replaces tables in lights.toml. A map may also be fixed at an hour (light = "21:00"), which holds it in that hour’s period.

Each material in a piece says which light it takes: sun, lamp, constant or glow. This is the same choice the DS games make per material, and it is how a project’s windows light up at night without a script.

PokeLoom draws light in two ways, chosen by data:

  • Palette light. The 3D hardware multiplies a texture’s colour by its vertex colour, so a palette multiplied by a light’s colour is that light on everything drawn with it. When the period changes, the engine multiplies each palette again from its own colours. This costs nothing per frame and suits painted pieces with their shading drawn in.
  • Hardware light. A period that gives lights and material sets the DS’s four lights and material colours, and materials that name them are lit from their normals, on the DS by its geometry engine and on desktop by the same rule. Imported generation-4 and generation-5 games light their models this way, from the original’s own tables in the creator’s private import.

The two do not yet stack. Under hardware lights, a map’s grade, the weather’s tint and a script’s tint have no effect.

Planned (plan 42): one light model. Every map has one record a period with its lights, material colours, palette tint, lamp, clear and fog colours and the light the characters take; the grade, weather and script tint stack on top on every map; the built-in tables become shipped lights.toml defaults. Both the software renderer and the planned GPU renderer read only that record.

The generation-4 games also change the soft shadow under each character with the hour: wider by day, fainter at night. [world.shadow] in game.toml gives a row from each hour with the shadow’s opacity and size. See Flat characters and their shadows.

Planned (plan 25): light tables chosen by area, and by area and season, as generation 5 chooses its sets; a light direction that turns through the day for palette-lit maps.

Fading from one period into the next, as generation 5 does, is not in any plan yet. Today every table steps.

Planned (plan 25): seasons, a saved value from the clock by a rule, changed only at a map change with a banner, read by light, textures, map variants, encounters and music.

Planned (plan 35): palette sets by environment and period for tile-map games drawn as the Game Boy Color games are. See How GBA tile worlds work.

PokeLoom does not know that one game steps its light and another fades it, or that one cuts its day finer than another. A game is a set of light tables and the rule that picks one for a map. Platinum’s look, HeartGold’s look and an original game’s own day are each a set of tables. A map can take a table from one and a camera from another, and nothing in the engine needs to change.