Heya, all.
I’m currently in the pre-production stage of a project and was hoping to get some tips and tricks on 2D lighting before getting started.
I foresee the small game having a lot of 2D lights as we’re hoping to plaster the scene with a bunch of neon signs.
Having never worked with the 2D lights in Unity, I was hoping to get some insights on optimisation tips and tricks or simply things to avoid before starting, as I’m afraid performance might start to tank due to the sheer amount of lights in the scene.
For this, it matters a lot if you’re targeting mobile: if so, you may need to plan your scenes so that it still looks good with a few lights. If not mobile, then lights aren’t too expensive.
Depending on the severity of the situation, here are some tips which you should only implement if you find you’re actually having performance issues on your target platform. These are all compromises you may want to avoid unless necessary.
-
Replace lights with semi-transparent sprites.
-
Avoid shadows or fake them with semi-transparent dark sprites. The current iteration of shadows are quite expensive.
-
Fake lights with emission. Use an emissive shader with Bloom postprocessing effect. Tuning the bloom can be quite important to get things looking just right. Experiment. Remove bloom if emission itself sufficient. Bake “emission” into MainTex’s color to avoid special shader altogether. Fake bloom by baking that in as well.
-
Use only global light, or a few real lights, the others as fakes.
-
No normals.
-
Limit size of both real and fake lights you have.
-
Avoid overdraw wherever possible. Overlapping transparency can be quite expensive.
-
Use Unlit materials wherever possible. For example, if you have a Particle System, a Lit material may produce the best look, but alternatively you could also adjust its color / alpha so it matches to scene without the expense.
-
Examine your scenes in the Frame Debugger. Are there decisions you could make to do something like: (a) render unlit stuff, (b) render lit stuff sharing the same material/textures, (c) render unlit stuff also sharing same material/textures. This can limit the # of draw calls if you can get away with it.
It also matters a great deal what kind of game it is and what visuals you’re going for. Since there’s such a wide variety in how scenes are laid out, general advice can only go so far.
Neon signs, in particular, may not need to be Lit at all. Bloom with an unlit material may be quite convincing. Try both.
There are also settings on the 2D Renderer Asset worth mentioning: you can reduce the size of its Render Texture if that doesn’t degrade quality too much, you can turn off Depth/Stencil if not using masks.