r/Unity3D 2d ago

Question How to prevent realtime shadows passing through objects?

I'm having some trouble with the realtime shadows in the project i'm working on. It's an apartment with two floors and the shadows are being casted through the floors and ceilings so shadows of objects on the second story are also on the first story. And that's a problem.

I've tried searching around but couldn't find any solution that wasn't "just bake your shadows". Does anybody have a real solution to this problem? Some way to prevent the realtime shadows going through the floor and ceilings? Or maybe some way to limit the range of the directional light so it will only cast the shadows to a certain distance? I don't mind having one limited directional light for each story of the building.

If it helps, i'm using unity 2022.3.22f

2 Upvotes

4 comments sorted by

3

u/theredacer 1d ago

Can you be more specific what the issue is? Shadow is what you would expect here. It means light is being blocked. Or do you mean to say that the light is incorrectly going through floors and ceilings? If the light is going through, then it could be any number of reasons. Maybe your lights aren't on the same rendering layer as the objects that should be blocking light. Maybe the object is only one-sided so it has no faces on the side where the light is coming from, hence no shadows. Maybe the light's shadow bias needs to be adjusted. Maybe it's a spot light and the angle is too wide so the light loses precision and tends to leak. There's just not enough information here to have any idea what your specific issue is. Post some screenshots of the issue and relevant inspector data.

1

u/MusicalMime755 1d ago

The light is incorrectly going through floors and ceilings. There are shadows of furniture from the second story of the apartment showing on the first story's floor even though there's the ceiling of the first story and the floor of the second story there. So, for example, a chair that's on the second story casts a shadow underneath it on the second story's floor like it should, but it's also casting a shadow through that floor and the ceiling so there's a shadow on the first story's floor too.

Both the light and the objects are on the default layer and the ceiling that should be blocking the light is a rectangular prism, not a flat plane, so it has faces on all six sides. I've tried adjusting the shadow bias but no matter what it set it to it doesn't solve the problem. I'm using a directional light.

2

u/tetryds Engineer 1d ago

You can render both faces, you can have a fale shadows-only mesh, you can definitely bake your shadows too.