In my game, players are able to place lights wherever they like in the bases they construct. The lights are PointLightComponents.
I’ve already implemented some very basic performance handling whereby I disable shadow casting if performance starts to drop. However I’d like to revisit this with some better solutions.
2 things I’m considering:
1) Have some manager class that batches lights in close proximity to each other (at a given distance from the player), such that 5 lights close to each other would choose to use only one, and increase it’s radius and translation appropriately.
2) Using some kind of fake lighting fx in the materials emissive channel of the building pieces.
I’ve seen other games such as Ark Survival Evolved that also allow players to add unlimited lights, and they seem to manage the performance cost well.
Just putting this out there in case anyone has other ideas.
Cheers
Edit: Forgetting about shadow casting, is there no way to cache the lighting cast (without having to recompute each frame)?
I like idea #1. And you could also turn off shadow casting for the big light because presumably all of the lights in the area will illuminate each other’s shadows.
Idea #2 is what I went with for my day-night cycle. It works very well for me and it’s very performant. But making the fake lighting was a HUGE project. And the way it works in my game, everything that shares a material instance gets its lighting updated at the same time. I made a Kismet sequence action that changes the “Time” scalar parameter in a bunch of material instances together, and the effect works really well.
It might be more complicated for you because you would have to make a different material instance for each base piece, because each piece could be affected by different lights. And then each time you add a light, you would check to see which base pieces are in the lighting radius, and update their material instances.
As far as I know, there is no way to cache the shadows. You can change which side of the material gets lit, based on dot product of the lighting vector with the surface normal, but you can’t fake the shadows.
First I’m lowering the MaxShadowResolution. But I don’t think this does much.
Then I turn off shadows.
Finally I turn off the light (I keep a self-illuminated material so that something can be seen).
What I have seen is that the performance decreases a lot, besides when there are several lights, when there are many meshes affected.
I don’t have a magic solution, except the one used by many games, deactivating shadows in lights that are not very important in the scene. Having one or two with shadows, and the rest without.
@Nathaniel3W That’s not quite true as (i believe) you can parent another material instance and add the light changes to the one master parent mat inst. You can derive the ObjectWorldPosition in the material and pass in the location of the light sources via material parameters to the master mat inst.
As far as I can tell, there’s no way to pass an array of vectors (for the various light source locations) into the material. However you could setup a finite number of vectors (via manually setting up x number of vector params), and then handle the finite limit via US logic.