How do you shade part of a moving scene outside of the game area?

Hi,
I’m posting this here as I’m unsure if it is done using shaders or is done some other way.

What I’d like to do is have a scrolling isometric scene with the area outside of that accessible by the player shaded/slightly darker. I can make a scene spawn prefabbed rows but so far I’m using normal prefabs that I applied a darker texture to (I haven’t learnt shaders yet so don’t know if it’s possible to apply them based on scene position) for the bits that are out of bounds. The closest example I have found to show the effect is in crossy road, where the player can’t access the darker area on the left.

If someone could tell me if there is a better/more efficient way so I know what tutorials to google I’d appreciate it. Note I’m not asking for code (though will take it if it is offered), I just don’t know what to search for to try & work it out myself.

Thanks

Well, a reasonable and quite simple way to do this would be to just throw up an overlay — that is, add a Canvas to your scene, stick an Image within that, and assign the image a nice big transparent PNG of your mask area.

To make it more efficient, you could make your PNG smaller but stretchable, or use several PNGs to carve up just the areas that need masked. Or if your masked areas happen to be rectangular, you need no PNG at all; the Image component alone, given a translucent color, will do the job without an actual image.

And yes, it could also be done with a shader, but that’s a lot harder and not necessarily more efficient.

I was going to suggest that, but it sounded way too hacky and I got embarrassed. :stuck_out_tongue:

But really, now that you pointed it out, it might even be the best way… If objects become “unshaded” when entering the play zone, changing shaders would probably be more costly than any UI performance issues.

I probably should have clarified that the greyed area is fixed on the top left/bottom right of the playable area. I.e bits of the scene in the shadow don’t scroll into the lit area when the player moves. Ignoring the camera angle, the player can move forward & back freely but will be clamped between the x-boundaries. I wanted the greyed area to also be clamped to the tiles it is on even thought the player will not change their position on screen, so the lit area scrolls forward/back unaffected but as the player moves left or right the amount of greyed area onscreen will change accordingly.
Sorry, I’m having trouble actually wording it. But I will start looking for overlays as well. Thanks :slight_smile:

It’s not cheating if it works.

It could be done with a single shader for all objects. It just needs to take the world position of the object into consideration, then apply (or not apply) some shadowing technique.

Thanks, I will try to find out how to do that & then compare the 2 if I can get them working.