HD-2D lighting: day/night cycle, Blender-authored lights and cel shading
Devlog #2. In the first post we showed the engine's stack — C#/.NET 9, ECS, Silk.NET, a ~9MB build. Today: how we light the world, and why lighting ended up driving gameplay too.
The constraint: stylized HD-2D
Our target look mixes 3D meshes (houses, terrain, props) with billboarded pixel-art characters — a top-down world that needs to feel hand-crafted, not photoreal. That ruled out the usual "throw a physically correct pipeline at it" approach. Everything below is chosen, not defaulted.
A day that lasts 8 minutes
One in-game day runs 480 real seconds. The clock interpolates between authored keyframes — sun direction, ambient color, sun tint, sky zenith/horizon gradient, fog color. Dusk genuinely shifts purple→orange instead of dimming the blue. We opted for keyframes over simulation: an artist controls every hour's mood, no physically-based sky fighting the art direction.
A map opts into the cycle with one ambience flag (light: "horario") — fixed presets (day/dusk/night/overcast) still work for interiors or scripted scenes.
Lights authored in Blender, not in code
Point lights are placed inside Blender scenes and exported in the .glb through the KHR_lights_punctual extension — position, color, intensity and range arrive with the asset. A lantern prop lights the street where it sits because the artist put the light there, not because a programmer hard-coded coordinates. This is the same philosophy as our collision volumes (COL_* nodes in the mesh): art carries semantics.
Shadows: real sun shadows + fake cloud cover
- Shadow mapping — an orthographic depth pass follows the camera; the sun is just
-lightDir. PCF 3×3 softens edges, slope-scaled bias kills acne. Outside the shadow box we fall back to full light — cheap and safe. - Cloud shadows — no cloud geometry exists. A noise field scrolls across the ground with wind direction and dims sunlight where "clouds" pass. The whole sky moves for the cost of one noise texture lookup.
Characters: cel shading with a half-Lambert trick
Props get hard Lambert. Characters get a 2-band cel shader: hard terminator on raw Lambert + a binarized projected shadow — flat, readable bands that survive the top-down camera. Skin uses a half-Lambert wrap (nl * 0.35 + 0.65) — a cheap SSS approximation so necks and shoulders don't blow out against vertical surfaces. The pixel-art sprite and the lit mesh read as one world.
The part we didn't plan: light drives the simulation
The clock doesn't just tint pixels. Zones carry a <turno:A-B> notetag — a patrol route only spawns targets inside its shift (a 22-6 shift correctly wraps midnight). Guards actually change shifts, markets open by day, alleys get busy at night. Ambient particles resolve by light preset too: pollen by day, golden pollen at dusk, fireflies at night.
That's the real win of building the engine: one system (the world clock) feeding rendering, particles and NPC routines — no glue code between three plugins.
What's next
Devlog #3: how a Blender script generates whole city blocks — terrain, walls, doors — as placements the engine reads directly.