Skip to content

Light a game with a style ​

Goal ​

Give a game a look (a sunny day, a golden evening, a dark noir room) by naming a lighting style in its settings, then move its sun. The place, the meshes and the exported characters all take the same light.

Files you will edit ​

One of these, where the game keeps its settings:

  • src/game.ts: a game made from a template (fps, third-person), as defineGame({ lighting }).
  • settings.json: a bundle on the common Gameable player (templates/blank).

The block is the same in both. The examples below show settings.json; in src/game.ts the same object goes in defineGame:

ts
import { defineGame } from 'gameable';

export default defineGame({
  lighting: { style: 'golden-hour', sun: { elevation: 20, azimuth: 90 } },
});

Steps ​

  1. Add a lighting block beside features and name a style: captured, daylight, golden-hour, overcast, night, studio, noir or neon.
json
{
  "schemaVersion": 1,
  "name": "My game",
  "features": {},
  "lighting": { "style": "golden-hour" }
}
  1. Override any one value of the style beside it. Here the sun stands higher and comes from the right (azimuth is degrees clockwise from -z, the way the default camera looks):
json
{
  "lighting": {
    "style": "golden-hour",
    "sun": { "elevation": 20, "azimuth": 90 }
  }
}
  1. Keep more of the place's captured light if the style darkens it too much: captured is the share kept (0 to 1), relight how strongly the sun and sky light it (0 to 2).
json
{
  "lighting": {
    "style": "golden-hour",
    "sun": { "elevation": 20, "azimuth": 90 },
    "place": { "captured": 0.5 }
  }
}

Verify ​

A template game: npm run dev and open http://localhost:5173. A bundle: from the game root run npm run build (in this checkout, npm run build -w templates/blank) and open it in the common Gameable player (examples/play/README.md). The place turns orange, and a character's shadow falls long, away from the sun. Change style to "sunny" and build again: the build stops with Invalid settings.lighting.style: one of captured, daylight, ….

See also ​