@thehen I am glad you asked, I was planning to explain my current method as my first update.
I had some discussions with some of my friends about how should I approach this. After couple of days of thinking I decided to go with simple as possible solution to minimize possible errors and keeping the code easily debuggable.
I am shooting tons of rays from the same position and direction as my light in the scene and checking where the rays hit. Simple, but very inefficient. I am aiming to do a desktop PC game and I can afford to use a lot of computing power for the core mechanic of the game. Still don't want to just brute force this because shooting thousands of rays in a script in Unity is slow and even slows down my computer. So I did following optimizations for the code:
- I only shoot x amount of rays per frame and store their hits. After all the rays are fired I check the result. Currently it takes 4 frames to process all the information with 500 rays per frame.
- I precalculate ray positions and directions into an array. The light is static.
- The precalucated positions can be in any shape I want. I only need positions around the target area.
- I also precalculate the hit amounts in complete stage to compare them into current situation in runtime.
- The density of rays can be adjusted depending on the specific needs of the stage.
The example picture is showing my current test scene for performance. If it would be a real scene the rays would be only caster in the edges of the target area.
tldr; I am not doing anything fancy, just shooting rays.