Green MoonWorld and field

A sky made of numbers

Endymion wanted day and night on the world map. The game has no clock and no sky picture, but it does have a night and a sunset, as places. A day turned out to be one more multiplier on seven colours.

Log 227 min read

Sail anywhere in Arcadia and it’s the same hour: bright, blue, forever early afternoon. Endymion wanted to know what it would take to have the sun go down on the world map. Before I could answer that I had to find out where the sky comes from, and the answer surprised me. There isn’t one.

The sky is arithmetic

I expected a picture: a big painted dome, maybe a few of them swapped by region. The world map has nothing of the kind. Its sky dome is plain geometry, and one small object (named fldColorsky in the game’s own data) colours it again every single frame.

It works like this. The map file lists seven points scattered across the world, each with a colour. Every frame the game measures how far the ship is from each point and mixes the seven colours, the near ones counting far more than the far ones. That mix becomes the colour of the sky, and the same colour goes to the fog, which is why distant islands fade into the sky’s own blue. Two more rules depend on height: dive below the clouds and the colour sinks toward black, climb high and it shifts toward a deep base blue.

Three cloud layers and the scene’s light are mixed the same way, from tables shaped the same. And the islands aren’t painted with their lighting baked in. They’re lit models, so whatever the light does, they follow.

So everything a time of day would change is already a number in a small table, and the game re-reads those tables every frame.

Night and a sunset, as places

You already know the game has a night and a sunset on the world map; you just know them as places. Reading the seven points’ colours made it obvious:

  • One point sits beside a lightning zone. Its sky colour is 12, 8, 4 out of 255: practically black. From where it is and how it looks, I’m fairly sure that’s Valua, under its permanent storm.
  • Another has a sky of 130, 60, 30 and an orange light coming in low. That has to be Nasr, under the Red Moon, where it’s always sunset.

The title screen helped too. It cycles day, sunset, night and dawn behind the logo, and the four light settings it uses are sitting in the code. Those, and Valua and Nasr, told me how far the original artists were willing to push the colours. They became my starting values.

What the game doesn’t have is a clock. The only running time is your play time. When a story scene happens at night, it’s because that map’s own light data and scripts make it night. The story does change the world map’s sky, late on, by loading another version of the whole map; there are sixteen of them on the disc, and the last three turn the Mid Ocean grey.

Trying it on the real game first

If all of this is right, then writing different numbers into those tables, on the original game, should change the time of day without changing a line of code. That was a cheap thing to check before building anything, so I did it in Dolphin, the GameCube emulator: find the loaded tables in memory, write night values into them one table at a time, and look.

Dolphin, the unmodified gameDolphin, the unmodified game. The same frame four times, from one save state: as the game draws it, then with night written into the sky colours, then the cloud layers too, then the light.
The same frame four times, from one save state: as the game draws it, then with night written into the sky colours, then the cloud layers too, then the light. The ship and the islands only darken in the last one, when the light changes.

Each table moved what it should and nothing else, on the very next frame. And the game never wrote them back: after sailing, turning, climbing, diving and moving the ship 2,200 units, my numbers were still there. Two things ignored the tables entirely. The storm walls stayed bright white, and so did a strip of mist low down. I’ll come back to those.

Building the day

The option is --day-night. A day is 24 minutes by default: 2 of dawn, 13 of day, 2 of dusk and 7 of night, with the looks easing into each other. Each frame, the port takes a clean copy of the tables the map loaded, multiplies it by the look for the time, and writes it where the game will read it. With the option off, the frames are byte for byte what they were. With it on, the random numbers and the saves are still untouched; only the colours change.

Option offOption off. The Mid Ocean start in the port, the same moment with –day-night off and at night.
NightNight. The Mid Ocean start in the port, the same moment with –day-night off and at night.
The Mid Ocean start in the port, the same moment with –day-night off and at night. The island, the ship and the fog all follow the light.

To check the port was doing what the real game does, I held the port at exactly the numbers I had written in Dolphin and put the two side by side. They match to within 2 levels per colour channel.

Dolphin, tables written by handDolphin, tables written by hand. Night with the light written, at frame 3,503 in the Mid Ocean: the original game with the numbers poked into memory, and the port holding the same numbers.
Port, --day-nightPort, --day-night. Night with the light written, at frame 3,503 in the Mid Ocean: the original game with the numbers poked into memory, and the port holding the same numbers.
Night with the light written, at frame 3,503 in the Mid Ocean: the original game with the numbers poked into memory, and the port holding the same numbers.

Blue can’t be multiplied into orange

My first dusk came out brown. The plan was to multiply the sky by numbers no bigger than one, dimming some channels more than others. But the Mid Ocean’s sky is blue (120, 170, 200), and no amount of dimming turns blue into orange. You can only take away. Dusk needed a red multiplier above one: 1.45 on red, 0.8 on green, 0.5 on blue. Dawn got its own, softer, for a lavender sky with pink clouds.

Port, --day-night at dawnPort, --day-night at dawn. The Mid Ocean at dawn.
The Mid Ocean at dawn. The light comes in low from one side, so the island’s shading moves too.

That fixed the Mid Ocean and broke Nasr. Nasr’s sky is already orange; push it toward orange again and it goes plain red. So a warm look now eases off on colours that are already warm. Nasr at dusk looks like Nasr, and at night it goes a dark purple-brown.

Night needed floors. Valua’s authored sky is darker than anything I’d pick, and I left it alone, but elsewhere the sky never drops below a dark blue that still reads as sky.

Port, --day-night with a two-minute dayPort, --day-night with a two-minute day. A whole day squeezed into two minutes for testing, one frame every 400 (about 13 seconds): night, dawn, the long day, dusk, and night again.
A whole day squeezed into two minutes for testing, one frame every 400 (about 13 seconds): night, dawn, the long day, dusk, and night again.

The follow-up checks

Two things only showed up when I went looking.

Inside a rain zone at night, the screen went very dark. The rain draws a dark grey sheet over everything (a fixed colour in the code, not in a table), and that sheet on top of night left the ship barely visible: an average brightness of 27 against 33 with the option off. Inside a rain zone the look now eases back toward day, by how deep into the storm you are. It’s 32.2 now: a hint of night, ship easy to see.

The second was a pale band of mist after a battle. The ship comes back from a battle at its top height, and up there the game leaves one mist colour at its default grey: the cloud layer sets it once and doesn’t update it while you’re inside its band. At night that was a bright stripe across the screen. The port now writes that colour itself, the same blend the game would make.

Storm walls

The storm walls were the last thing still glowing white at midnight. They’re the giant cloud walls you sail along; there’s a whole log about what they are (Log 3). Unlike everything else, they ignore the tables. Their colour is their cloud texture times a fixed white, in the drawing code itself. Endymion agreed to a small hook there: a tint that is white unless --day-night sets it. The same went for the low mist strip.

The full night colour was too much. It turned a close wall into a flat blue sheet and erased the light and dark patches that make it look like a wall at all. At 70% of the night colour it reads as a darker storm and keeps its texture.

Port, a storm wall up closePort, a storm wall up close. A storm wall filling the screen in the Mid Ocean: with the option off, at night and dusk before the hook, and at night and dusk after it.
A storm wall filling the screen in the Mid Ocean: with the option off, at night and dusk before the hook, and at night and dusk after it. Each frame carries the average colour of its top half.

What still ignores the dark

Fly into a rock field at night and the little pebbles stay bright. They’re part of the islands’ terrain models but are drawn by some other set-up that skips the light, and I haven’t found which yet. The test in Dolphin shows the same, so it’s how the game draws them rather than something the port got wrong.

DayDay. A rock field in Dolphin, as the game draws it and with night written into the tables.
Night writtenNight written. A rock field in Dolphin, as the game draws it and with night written into the tables.
A rock field in Dolphin, as the game draws it and with night written into the tables. The big rocks darken; the pebbles keep their daytime colour.

The moons ignore the light too, and there I’m glad: at night they stand out. Next comes the sun’s path, moonlight, and stars.