#devblog

Sharing, ranting, showing-off :)

Cabin lights and lamps

Jan 16, 2021

I was finishing work on Friday, back of my mind was already working on the Turbolet’s CWS lamps. The logic was already there but couldn’t test it properly without the actual lamps in the cockpit.

So I jumped into Blender, added lots of lamps, baked the LIT texture for the CWS, added the lighting properties and Datarefs, quick export and was a bit disappointed how “flat” it looked. I mean the lamps itself was fine, but it looked like a 5-year-old trying to play with Photoshop for the first time :)

I realised these are LAMPS! They do light up the surroundings! Your brain expects something to be there… but missing. It’s confusing and makes you feel “disappointed” what you get.

I did a test a few months ago when working on the instrument lights: added four lamps for each instrument to light them up as in real-world - instead of baking the LIT texture. It looked amazing, so realistic - until I saw the FPS counter: dropped about 30-50% depending on how many dynamic lights needs rendering. And sadly most of them were in the default pilot view. So that was a no-go.

The Turbolet has 62 lamps on the CWD: 16 each block (x4), minus 2 - which is unused. Showing 62 dynamic light will surely kill the FPS :) But I had to test. Added all the lights in Blender, quick export, reload the plane in X-Plane and… FPS dropped to 40-45 from 60! I expected a way worse result!

I did some reading and turned out you can have loads of lights in the cockpit - if you keep them relatively small. You can easily kill the FPS having only a few, but huge lights.

Time to try that pudding: I made the lamps a bit smaller, and there was only a 5 FPS drop - that’s promising so far. Also realised: there’s no way that all the lamps will illuminate on a normal flight. Even when you switch on only one of the battery switches, only 12 laps will light up!

With that in mind, the FPS test showed almost no or just a few FPS drop!

It was time for adding the logic. Using Internal cockpit spill lights, added indexes for all the lamps, then reloaded the plane and that’s when everything went wrong: about the half of the lights showed when it shouldn’t. After a bit of digging found that sim/cockpit2/switches/instrument_brightness_ratio[INDEX] array has only 32 items. That was quite disappointing since I was already using 10 for other lights in the cockpit and the cabin.

So how do you add 62 new lights into your cockpit when X-Plane can only handle 32? :) Well, you start hackin’ :)

The solution

You need to group the lamps. Either by colour or logic or position, whatever works for you. For me, the easiest way was to group by colours:

Now how do you light up the ones you actually need to? Simple - using show/hide animation. Hide the lamp if the Dataref is between 0 - 0.1 and show if in between 0.1 - 1. Since I’m animating the lamps on/off states by 0.1, it was perfect!

The trick is to create an OR logic for each group: if any of these lamps should be on, then turn ON that group - e.g. if any of the amber lights should show up, then set sim/cockpit2/switches/instrument_brightness_ratio[11] to 1, otherwise, set it to 0.

Done! The show/hide animation will take care of each individual light, and the code will take care of the Datarefs value.

local instrument_lights = globalPropertyfa("sim/cockpit2/switches/instrument_brightness_ratio")

local amber_light_value = get(ann_battery) + get(ann_oil_pressure_low_0) + get(ann_oil_pressure_low_1) + ...
local red_light_value = get(ann_stall_warning) + get(ann_eng_fire_0) + ...
local green_light_value = get(ann_auto_feather_arm_0) + get(ann_auto_feather_arm_1) + ... 
local white_light_value = get(ann_cabin_call) + ... 

animDataRef(instrument_lights, red_light_value, 10)
animDataRef(instrument_lights, amber_light_value, 11)
animDataRef(instrument_lights, green_light_value, 12) 
animDataRef(instrument_lights, white_light_value, 13) 

So e.g. amber_light_value will get a value of 5, but since sim/cockpit2/switches/instrument_brightness_ratio[] can only take float values from 0 to 1 it will automatically set to 1 - so we don’t have to make lots of if statements.

With this small trick, you can add as many lamps as you like to your cockpit objects and don’t have to worry about X-Plane limits. As long as you can group them by some logic, you’re good to go.

Here’s how the result looks in X-Plane:

Let L-410 Turbolet - Cabin lights and lamps

Let L-410 Turbolet - Cabin lights and lamps

Let L-410 Turbolet - Cabin lights and lamps


Comments

Recent posts

  • Behind the Scenes - Adventures in 3D Scanning of the L-410
    Nov 19, 2023

    Our new journey took an unexpected turn as we dove deep into reworking our 3D model. The challenges were real, but so was our determination to achieve a level of quality that would redefine the standards in our upcoming 2.0 version.

  • The Devil is in the details
    Mar 7, 2022

    In the past months, even I wasn’t sharing much - loads of things have happened.

  • Why the Turbolet?
    Apr 11, 2021

    While I'm working on one of the most boring parts of the plane - the electric system - I'm trying to break the long silence

  • Cabin lights and lamps
    Jan 16, 2021

    I was finishing work on Friday, back of my mind was already working on the Turbolet’s CWS lamps. The logic was already there but couldn’t test it properly without the actual lamps in the cockpit.

  • Visual update 2 - cockpit and cabin
    Dec 14, 2020

    We all know how crazy this year was. But I'd like to talk about the progress we made with the Turbolet :)

  • Engines, and it's limitations
    Nov 15, 2020

    The Let L-410 is powered by two Walter/General Electric Turbo-Propeller engines. The engines have several protections and redundancy mechanisms and are equipped with a water injection system...

  • Systems - Central Warning Display (CWD)
    Nov 1, 2020

    In this post we go through the Central Warning Display annunciators...

  • Systems - How deicing works
    Jul 13, 2020

    The Turbolet has the following systems on the aircraft front sections as the protection against the ice formation...

  • Textures, animations and love!
    May 30, 2020

    After a long hesitation, I teamed up with a 3D/texture artist, Andrei Nastasa. He re-did all the external textures and made it look exceptionally realistic!