i’m using Unity Built-in Render Pipeline 2020.3.5.
I have a large map with several buildings with interiors and I use a switch to turn the lights (point lights) on and off. This has given me a problem with performance as there are several point lights that I use.
Is there any alternative I can use?
The point lights have to use shadows otherwise the light go through the walls.
Are you, or a team member, comfortable writing shaders and knowledgeable of GPU internals?
Do you have 2-3 man-months to dedicate to this?
If you answered “yes” to all of the above, consider volumetric/stencil shadows! This is an ancient technique passed down in secret from father to son from the mythical civilization of the 1990s (also said to be the origin of Pogs and Marky Mark). It’s been shunned by mainstream graphics devs due to its complexity, CPU costs (which can be moved to compute shaders) and overdraw issues, so most info you look up on it will be 15+ years old.
You can have your main directional light using screen-space shadow maps, then add in volume shadows for just the object+light combos you want shadows for, meaning it’s as scalable as you want it to be (as long as you’re willing to do culling, batching, etc, all on your own – Unity’s pipeline won’t help).
If you want to know more…
There’s an asset store asset here: Sharp Shadows Toolkit | VFX Shaders | Unity Asset Store . You’re going to need to modify it to support built-in, and modify it some more for point light support. It also breaks on certain skinned meshes (if you have skinny arms or legs like me, the shadows will cause artifacts). I tried using it for a bit, but the technique did not work for me; it might do for you.
I am implementing a compute-shader version of it. Slowly, and buggily, but this is a for-fun project and it’s been a good learning experience, so why not? It’s on URP, but not really using SRP features much. You can track my progress here: https://gitlab.com/burningmime/burning-rpg-framework/-/tree/master/Assets/src/graphics . But there are almost no comments and tons of bugs, so really you should just ask me and I will try to provide more info if you’re actually interested.
You can use a depth-aware screen-space blur to fake soft shadows; this was done in FEAR. There’s also a few techniques like Penumbral Wedges, which I haven’t looked into much, but seems like a performance nightmare.
I think anything is going to take some work to integrate and get right. And it’s not clear from the screenshots what techniques they’re using to get the silhouette of the objects. I’d only buy that asset if you want what that asset shows it will provide (light rays), which doesn’t seem like what you are after.
This isn’t really something that can be fixed with an asset from the asset store. Point light shadows are expensive.
@burningmime 's suggestion of using stencil volume shadows are an option for some games / setups, but it’s not viable for all use cases.
@AcidArrow 's suggestion of using a spot light instead of a point light when possible is going to be one of the best options. Even two spotlights will generally be faster than a single point light, though you’ll definitely want to use deferred if you start going that route.
You might get slightly better performance using deferred rendering, but even that’s not going to help a ton since the shadows are the expensive part and deferred rendering doesn’t change how those work.
The “best” solution is to use baked lighting with the Mixed Lighting’s Lighting Mode set to “Shadowmask” and set the lights you need to turn on and off to be Mode “Mixed”. This will also require you enable light map UVs on all of your static objects, and bake lighting, but it’s currently the only way to get this to work well with a lot of shadow casting lights. This will let the lights be toggled on and off individually, and as long as there aren’t too many overlapping lights this won’t be that expensive. Note, these lights will still render real time shadow maps if there are dynamic shadow receiving or casting objects within their range, so you’ll want to limit the number of those objects you keep in the scene and the range of your dynamic lights.
TLDR: There are tricks, they all take a lot of effort and time to implement.
I would suggest for each point light, baking a reflection probe there, for a cubemap cookie. It’s easily tooled-for as well. Then this cookie mask is your extremely cheap shadow.
As with all tricks, the devil will be in the details.