#how to prevent light leaking
1 messages · Page 1 of 1 (latest)
The floor to me does look a lot like it has small gaps in it. If the whole wall is lit by that light, you would need to enable shadows for it. Without shadows the light will lit up everything within the range regardless of something obstructing the light path
yea i just realized i had shadows disabled 💀 but because the house has many small lights i get a warning about not fit in the atlas or smth like that
If this is URP, you can either increase the atlas size in the URP asset or decrease the shadow resolution for the lights. In URP all of the lights render to single shadow map which is the atlas. With a lot of lights it also requires quite large texture to fit all the shadows in it
i had it increased at max but still had the warning. i think i also had set the light res at low but will try again thank u
How many lights are we talking and what is the resolution of each (the resolutions corresponding to each level can be changed from the URP asset too iirc)?
around 30 lol. ive set em all to low but i can see the fps drop already. i didnt get the warning tho. whats the smallest res i can go without ruining the visual
It is not up to me to decide. Use the smallest value that looks fine to you. Also only the lights that necessarily need shadows should have them on
yea smallest is 128 but still it ain viable its lagging
even with shadows theres still leakin and i closed the gaps
I would say that the performance hit of shadows rarely come from the resolution alone. Each light with a shadow basically acts as a camera which must render to the shadowmap to update it. As far as I know, URP doesn't do any shadowmap caching, so every shadow caster is updated every frame. The amount of shadow casting lights should usually be kept at minimum
i managed to reduce the leakin by settin the depth and normal bias to 0
Be careful with that, there is a reason for those options to exist. Without any bias, you probably will see some "shadow acne" appear
normal bias actually didnt do anything but i put depth bias to 0.1
If the floor ends right at the wall, there is a change some light might sneak through especially with the bias which messes with the shadow casting objects when they are rendered to the shadowmap. If the floor extended little bit inside the wall, that could fix the leakage. Overlap usually adds some error margin to the shadowmapping process. Another bit hacky solution would be to use a separate shadow casting object like a thin box inside the floor to block the light if you don't want to go modify the house model itself. To avoid that object being visible (and there's no point rendering that anyways) from some angle, you could set it to render only shadows from the mesh renderer
Shadowmapping is a process full of edge cases. Often literally happening at the edges of the objects. Especially flat shaded objects are very prone to issues where light can sneak through places they shouldn't.
is there a way to overcome the performance problem?
Other than minimizing the amount of lights that cast shadows there probably aren't many good ways. Making the light radius smaller should have some impact though the size is probably decided by visual preferences, not performance considerations. If the whole building was a one 3D model, splitting it up to a smaller pieces might also help. If it was one piece, basically every light inside the building would hit it and therefore the same building would need to be rendered once for each light sources shadows (maybe even 6 times for point lights, I don't know if that is how they work in URP). The splitting of objects especially is something that is really hard to tell from distance whether it is good or bad for performance to begin with. More objects is generally more draw calls though the SRP batcher in URP makes those very fast
First step thought would be to verify it is the shadows that makes your game slow. That should be easy to test by enabling and disabling all shadows and seeing how that affects performance. If it happens to be something else, you are probably doing more harm than good trying to optimize the shadow performance
yea its the shadows the fps dropped once i enabled them. i currently have deferred+ would it be better to use forward+?
I don't think that affects shadow rendering much
yea the shadows literally drop fps in half
its ok cause i have the wall torches that are the majority and the hanging lights which have the shadows
Better to avoid having to use extreme light bias values by giving the walls/floors thickness or otherwise avoid polygon-thin shadowcasting surfaces
For realtime shadowcasting you should prefer spot light instead of point lights, as point lights have to render 6 shadowmaps as opposed to 1
Light layers can be used to separate lights between adjactent rooms in stead of shadowscasting
Baked shadows would be an ideal solution for performance, if your lighting can be static
i tried but they look wrong cause i need 360 lighting and spotligts are only half sphere
update: i managed to do it, it looks good but spot light seem to have a problem with shadows tied to angle, intensity and range. if those three arent set properly it gives crazy weird shadows
Yes, there's a limitation to it regarding spot angle
If it goes above 90 degrees the shadowmap starts getting progressively more distorted
That's because the shadowmap is rendered like a camera, and a perspective camera also starts getting progressively more distorted above 90 fov
Point lights avoid this by rendering the 90 fov perspective 6 times, once along each axis
Thanks for the explanation 🙏
It's often worth it to get a bit clever when designing lighting
Like for example I've sometimes used a shadowing spot light that points down, and a shadowless that points up a short distance below to fake the way a hanging lamp's light should bounce back up from the room
Lights can also have cookies which shape the light and can be used to fake some shadows
A point light with a 3D cookie can make it look like a spot light that has an angle over 180 degrees, which is useful with this double light trick
Though these help more with optimization and looks, not specifically with the issue of lights getting from one room to the next
For that I'd still consider light layers and baked lightmap workflow as the most surefire solutions
I can't goe baked due to procedural creation but I've seen light layers in the settings many times what do they do exactly?
Rendering Layers they're called officially
Much like the name implies if a light and a mesh are not on the same rendering layer, they won't affect each other
I just put the object in a specific layer and uncheck it from the light component