Here I am not talking about how to render fog of war, but how to model exploring of terrain in a more sophisticated way.

In a straight-forward approach, terrain explored by a game unit is simply represented by a circle whose radius is how far this unit can see. And visible area is just union of isometric circles. But I can tell that it is not the case in popular games.

Please take a look at the following screenshot from League of Legends, for example.

The sight of view is anisotropic. The shape of surrounding terrain is also taken in to account.

Any idea how this can be done?


3 Answers 3


The shape is irregular because of the obstacles.

If you shoot a ray in every direction (360 cicle around unit), you determine if you hit an obstacle, and if yes, at what distance. If the ray does not encounter any obstacles before reaching the line of sight distance, then it stops, otherwise it stops at the point of encounter. This is by no means efficient or conclusive, but I hope it helps.

You can then create a smooth path that passes through the ray endpoints.

If your units have a direction, you could also reduce the maximum line of sight distance by applying an angle-based reduction:

max_los_distance *= dot( normalized_unit_direction, normalized_ray_direction)*0.2 + 0.8

With the above, rays towards the direction of the player use the full los, while rays shot towards the back of the player use 60% of the los.


The main point is obviously to "somehow" include visibility data. You can cast rays from the unit through the terrain at runtime (as noted in Babis's answer), but this is likely to be very expensive, at least if your terrain is fully 3D.

If your representation of terrain is tile-based (or if it is sufficiently regular so that it makes sense to project a grid on your terrain), you can precompute the visibility from each tile to others: either store all pairs in a matrix, or just store a list of nearby tiles with direct visibility for each tile. At runtime you just filter the precomputed visibility data for the current tile with the visibility distance for the unit and smooth the boundaries of the fog of war.

On the other hand, if your terrain is already tile based, than your raycasts would be probably very fast...


I reckon they're doing it in two parts.

The first is working out the boundary of the line of sight. There's lots of different ways of doing this and they're pretty well documented elsewhere.

The way the boundary of the line of sight is displayed is a different thing though. I think I've seen something like this in Unity using projectors (implemented using shaders).

See UnityChat's tutorial here https://www.youtube.com/watch?v=bE6DQdnfe3U&list=PLcGWkWha2wFd5Azr14ZJjvfnAmUKM_3E7&index=6

That approach projects a light onto the ground from above so it hugs the surface nicely - which seems to me to be the effect with which you are enamoured? That's implemented using a opengl shader something like this: http://wiki.unity3d.com/index.php?title=ProjectorAdditive


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .