Lighting Toilets

Lighting in Starmancer is a personal favorite of mine. It adds a lot of visual depth and immersion to the game.

Simple Lighting

Here is a toilet being lit by an imaginary light source.

Colonists can now urinate in the dark

Colonists can now urinate in the dark

Internally we multiply the color of the object by the color of the light in a shader.

color = color * lightColor;

This is the basis of the lighting system.

Height Intensity

It would make sense that objects closer to the light source would be lit a bit brighter.

In Starmancer the light source is assumed to be in the ceiling, so we light high pixels a bit more strongly than low pixels.

Higher pixels are lit a bit more strongly

Higher pixels are lit a bit more strongly

In the example I was toggling the y position intensity on and off.

The top of the wall is a bit brighter than the floor and the base of the wall. (The light source was dark red)


You may have noticed that bottom of the wall was bright blue even though the light source was dark red.

Walls, like most of our objects, have lights and terminals.

These lights and terminals are self-lit, regardless of how dark the room is.

Biomass is nutritious and it glows in the dark

Biomass is nutritious and it glows in the dark

Here’s the same scene without any self-lighting.

A boring and disgusting gif

A boring and disgusting gif

Emission Map

The self-lighting is implemented with an “emission” texture. The emission texture has the exact same dimensions as the normal texture, but instead of colors it contains alpha values.

Our lighting shader “self lights” objects based on the intensity of that alpha value.

Here’s the part of the emission texture for the lights at the bottom of walls

Emission texture for walls

Emission texture for walls

How It (Mostly) Works

The internal implementation is fairly simple.

Objects exist in rooms. When an object is placed, it gets added to a room. The light source of the room is passed to the object so that the shader can correctly light the object.

Whenever the light source is changed, all objects in the room need to be told. This can be performance intensive if there are lots and lots of objects.

It’s also a bit more complicated because multiple rooms can have different light values and you have to merge them correctly. Rooms can also become split and all objects need to be moved to their new room. This can be very performance intensive if you get too carried away.

Light sources are slowly merged

Light sources are slowly merged


Doors are probably the hardest object to correctly light, because they’re the only object that can exist in multiple rooms.

I hate them.

Toilets are much nicer, but we can’t all be toilets.

Each side of the door is lit differently

Each side of the door is lit differently

The doors also have to tell their adjacent wall sides about the correct lighting values.

Dynamic Lights

We have a system in place for more traditional lights as well. This is used when a door is opened between 2 rooms that have different light values.

The intensity of this light is slowly increased from 0% to 100%. This is to simulate an increased brightness as the door is opened wider.

Toilet, dynamically lit

Toilet, dynamically lit

That’s It

This post became more show than tell, but that’s because lighting is so visual.

We’ll be taking off about 10 days for Christmas and New Year’s. We’ll be back next year.

Thanks everyone


Change Log

Here’s everything that we did this week (that’s worth mentioning).


  1. Fixed an issue where doors weren’t rendered properly with the delete material

  2. Implemented UserInputAction system

  3. Fixed an issue with wall sides not being paintable if you deleted a wall that was next to another wall.

  4. Implemented visual selection box

  5. Implemented FMOD Zoom snapshot variable

  6. Identified a performance issue with placing many floors and walls at the same time.

  7. Mouse input will now be ignored if the cursor is over any UI elements.


  1. Changed offset of dead colonist sprite

  2. Designed visual selection box

  3. Designed visual for object selection

  4. Adjusted sleeping heads

  5. Condensed walls, floors, and foundation tool into a single menu category

  6. Changed morgue drawer model so that it no longer opens out

  7. Designed in-game window (for colonists, objects, etc)


  1. Fixed a pathfinding bug with certain access position locations.

  2. Doors will now more consistently refresh their adjacent walls’ lighting values when deleted

  3. Created access position component for matching AI reason to specific access position

  4. Changed how sprites are internally changed

  5. Internal item containers are now transferred whenever items are consolidated or split.

  6. Colonists now work with the lighting system

  7. Text can now be translated

  8. Wrote this list