I’m trying to make a 2D top-down game, where seeing the area that is visible to the player is an important component. For example, if the player is blocked by a wall, the volume should show the area behind the wall as dark, but the area up to the wall as light. It would be sufficient to be able to draw a region (e.g. a circle), and subtract out those parts that are blocked by the level geometry from the circle to create the area.
A simple algorithm that works is to find all blocking objects within the radius of the circle, finding all of the 2D vertexes of those objects within the circle, and doing a line trace to each of them. Assuming that if you trace a line to the corner of the object that would not block it, that the trace will go out to the edge of the circle, you keep track of all of the trace collision points. You can then sort them by angle, and then draw the area that those points surround (modulo those at the edge of the circle). Here’s a short article about the general problem
I can’t figure out an efficient way to represent this, or calculate it. The default top-down game is of course a full 3D map, and there’s no easy way to find the collision vertexes on a plane around my character, which I need for the input the the ray casting algorithm above. I could make the level geometry out of meshes that have extra components to represent their 2D intersection area, but there’s a lot of manual work I’d have to do to get that working, and I’m not even particularly sure it would do what I’d actually like. Any advice for implementing these algorithms?