Performance issues with visibility detection and object transparency
Posted
by
maul
on Game Development
See other posts from Game Development
or by maul
Published on 2012-12-06T19:35:12Z
Indexed on
2012/12/06
23:28 UTC
Read the original article
Hit count: 364
I'm working on a 3d game that has a view similar to classic isometric games (diablo, etc.). One of the things I'm trying to implement is the effect of turning walls transparent when the player walks behind them. By itself this is not a huge issue, but I'm having trouble determining which walls should be transparent exactly.
I can't use a circle or square mask. There are a lot of cases where the wall piece at the same (relative) position has different visibility depending on the surrounding area.
With the help of a friend I came up with this algorithm:
Create a grid around the player that contains a lot of "visibility points" (my game is semi tile-based so I create one point for every tile on the grid) - the size of the square's side is close to the radius where I make objects transparent. I found 6x6 to be a good value, so that's 36 visibility points total.
For every visibility point on the grid, check if that point is in the player's line of sight.
For every visibility point that is in the LOS, cast a ray from the camera to that point and mark all objects the ray hits as transparent.
This algorithm works - not perfectly, but only requires some tuning - however this is very slow. As you can see, it requries 36 ray casts minimum, but most of the time 60-70 depending on the position. That's simply too much for the CPU.
Is there a better way to do this?
I'm using Unity 3D but I'm not looking for an engine-specific solution.
© Game Development or respective owner