Using shadows as Triggers?

Hi,

At the moment I am working on a new game of mine, with the overall idea in a nutshell being that you have to stay in the shadows and not get caught. Almost all of the game is complete, minus the crucial part, being that when you step out of the shadows in to the light you are caught. Is there any possible way (through scripting) that you can have the shadows/light acting as some form of ‘Trigger’ or is the only solution the long winded process of placing individual colliders everywhere?

Thanks

I first thought about light probes, but you probably want to have dynamic lights and having only certain points raycast checked may fail (what if corners of AABB are in the shadow, but really just corners?)
And then i got this idea: to use rendering to detect light in the area. I won’t give you an exact solution, but i don’t see a reason why this shouldn’t work. So:

Create a camera with black background. This camera will be set to filter everything but an object you will use as a light sensor. Could be cube or capsule of a player size, or the player object itself. But rendered with a special shader, that renders both front and backfaces, with additive blending (and lighting enabled)

This camera will look at the sensor object from closeup (so it takes most of the “screen”) render into a texture (very small resolution is enough). The camera will also do a very strong blur on the postprocessing, so strong so the whole texture gets almost average color.

Then, simply get the renderTexture and get pixels out of it (since the color is almost average everywhere, only one or few, spread across its surface, will be enough). Average these colors and you will get some data about how much your character is lit.

Another modification would be to render the light sensor with special lighting shader (no surface shaders for lighting) so that you would calculate detection threshold per pixel, and make the pixels either completely white or black. In this case, the pixels you pick from the texture would have to be anything above zero and you’d safely say the sensor was lit over the threshold intensity somewhere.

This type of detection would work mesh-wise.

Again, i’ve never tested anything like this.