Looking for a better solution: Shadows and Qualitylevel

Hey!

I have kind of a special problem I need your help with.

I’m working on a top down game (EDIT: 3D, actually) with procedural level gen that kind of relies on shadows very much. Rooms can be completely dark until you actually go in, which is a designated game mechanic.

Shadows are expensive, so on low quality I’d usually like to disable all shadows, but that’d mean I had a problem. Since its a topdown game, the player will see the light bleeding into otherwise dark rooms, either because a light source is near or because he points his flashlight there.

What I did now as a hack, but I’m not really satisfied is this:
First, I set shadows to be always enabled in the quality settings (hard shadows only in low quality though)
Then I wrote a manager component, which watches the quality level and invokes event on change. It waits for the level to be generated and then add a little controller script to all renderers in the scene (small footprint though, it gets disabled on awake and will listen to the managers change event). The controller script will then enable/disable shadow casting for its target renderer whenever quality level changes.

The idea is I added a layer that is ignored in this process so it will not change its shadow casting property. I add simple quads to back of the walls by code using that layer, so they keep casting shadows - so the problem is kinda solved now.

My main problem is: I cannot know when a new renderer is instantiated so whenever that happens, it won’t be included in the whole process. I also really don’t want to add this component to such prefabs all by hand.

The most simple solution would be if Unity had a feature that would enable/disable shadows by layer and quality level.

So what do you think? I could really need some advice here!

Thanks,
Philipp

Why not manually mask out rooms you haven’t entered / can’t see? Also look into fog of war, or 2d soft shadows, or postal portal based occlusion techniques.

edit: silly autocorrect

1 Like

Hey, thank you for your input. :slight_smile:
I just forgot to add that it is actually a 3D situation, so I fear I can’t really apply 2D solutions. I also aready thought about masking just by adding viewblocking planes on top of the rooms for as long as I didn’t enter the room, but still: As soon as I’m in there and reveal the room, light wlll bleed in from near lightsources. You can see how it is currently looking with all shadows enabled here:

https://www.youtube.com/watch?v=mo2C8jRNt5I

I did also had a talk with a coworker of mine who is much more into rendering techniques and he actually told me he had to apply the exact same solution for one of our projects. :roll_eyes:

I’m looking for something really simple and straightforward, either a built-in way similar to the one I had to implement - casting shadows based on layers or tags - or a way to register instantiation of new renderers so I have a reliable solution with small footprint.

There’s nothing there that would preclude a 2D solution, this is explicitly for hiding rooms you haven’t entered in, not trying to fix the shadowing issue (which cannot really be solved). I mean the easiest method would be your idea of putting a black transparent mesh over the top of every room that you fade out when you enter. Plus it means you can allow low end users to completely disable shadows with no impact on gameplay.

The main issue of solving the lack of shadowing using a built in solution is untenable. The built in solution is to turn on shadows, so it’s moot. You will have to come up with your own method, or try and find an asset on the store that might get you close. I really do think the 2D light solution is probably your best bet.

1 Like

Hmm yes, I also think the most simple and lightweight way would be stick to adding viewblocking meshes then and completely disable shadows. It’d be really just a workaround for low end machines so its fine. I guess I’m going to implement both techniques and add it to the ingame options.