A performance friendly method of creating a building's lights "powering on" and back off?

I’m working on a 3d performance friendly game intended to run in webGL. In the level I’m working on, players defend an electrical generator and repair it when it goes down. When the generator fails, I want the lights to flicker off and dim to emergency lights. Similarly, when the generator is brought back up, I want the lights to flicker back on. What I’m having trouble with is doing this in a way that is as performance friendly as I want.

I don’t want to use real time lights, as I’m trying to keep the pixel light count to 3 (the 2 players’ flashlights and the moon). I could use vertex lights, but they aren’t free to render and I can only have 8.

I’ve considered having three static pieces of scene geometry (powered on, emergency lighting, and powered off) but that looks bad in-game because there is no transition between states.

In Unreal, it’s possible to have a baked stationary light change intensity and color as long as it has no indirect lighting (my understanding is this works because none of the shadows move position, so you can change “brightness” by just tweaking properties of a baked light map.) I think I could replicate this behavior in Unity by having all of the level geometry share one emission map that I could change the intensity of to simulate lights powering on and off, but that requires a lot of work by baking lighting in Blender and requires unique UVs for every piece of geometry in the level.

I feel like I must be missing something here. I’m using the old render pipeline. Any tips or ideas are appreciated.

Light probes might work here. Just don’t use way too many, otherwise it might cause performance drops.

PS: I have no idea how your building level looks, if it is a single story, or multi story building. So my advice might be a rough suggestion.:stuck_out_tongue:

perhaps the bake concept works for that but using addition between two lighting concepts in a single shader

(IIRC is similar to lightprobes as a simplified operation )

  • env_OFF pre-rendered to look the way you want
  • env_On is the lit version added to env_OFF texture

env_ON as simple addition evaluated from objects position with a falloff; If the object locations send color as a Tint multiplication for emergency lighting they can be animated with a state machine to transition with color/flickering off to = 0

Shader would read from an array of objects that track color, position, and even scale so they can animate.
output = Env_OFF.color + Env_ON.color * tint.color * scale_falloff

  • I wonder if it can be evaluated from screen space based on world location to try to eliminate processing?

But this is provided shadows are never moving from dynamics; If so doesn’t seem to me you can’t fill a shader with both environments and LERP them from a Tint operation.

The maximum performance:
Use light projectors

The maximum optimization:
Just disable shadows for the lights

WebGL is not limited like mobiles, because it’s running on a pc