Asylum Dev Diary 35 -Solving the lights
Yet another post about those all important lights. My apologise, but this is the key element to the atmosphere of the game and it has to be done right.
Last week I got to the point where I had resolved the bottleneck issue but had ended with a bug regarding the lighting of the doors. Well, after investigating it more deeply this week I discovered that the lights just weren’t updating even though they were toggled to do so. After some head scratching I decided to change the approach entirely, but still using some of the bottleneck solving code.
I created a series of light placeholder elements: LightRecStatic, LightRecDynamic, LightWindow, LightSlit, LightSlitFlicker. These all display in wireframe on the map editor so that I can see what’s going on, and they are placeholders. The placeholders are used during the game to keep track of where lights are when they are off screen but they do not process as a light and so don’t get involved in all the complexity therein. When the placeholder enters the screen they are invisble switched into their light enabled counterpart.
Previously I was attempting to automatically switch lights from static to dynamic as the player approached them or when a door was triggered near them, this was an attempt to make sure only the lights involved in realtime shadows were updated and the others were left as static (not updating shadow maps) until they are needed. When the player moves away from the light they would switch back to static. This method did not work.
With the new method all the lights that are on the screen are set to either static or dynamic and I purposefully place the static or dynamic light depending on the objects in the environment. So, if a light is in a corridor that has doors or other interactive elements the light is dynamic, otherwise it’s static. This works nicely and the number of lights on screen at any one time is somewhere between 2 and 6, maintaining a framerate of over 150 (in VM compilation not native compilation). I also added a bit more cleverness by only switching the placeholder to a light when the player is in line of sight; so if a light is behind a door but on screen it isn’t a light until the door is opened.
Using placeholders also means that whereas before any lights that the player had triggered would stay active regardless of distance, the lights outside of the players view are switched off again until they are once again needed (kind of like turning light switches on and off as you leave and enter rooms).
If you’re wondering what LightSlit and LightSlitFlicker are. This light is used for subtle direction lights such as under doors or televisions. The latter being used for a TV on static to give a nice flickery light effect.
Below is a screenshot from the map editor showing the new arrangement and configuration of the light elements. If you saw last weeks image you’ll be able to see how much cleaner this new method is. Orange outlined boxes indicate a dynamic light placeholder, yellow for static. You can also see the window light caster on the right (3 parallel shafts).