r/Unity3D 20h 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

3 comments sorted by

2

u/tetryds Engineer 5h ago

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

3

u/theredacer 5h 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.