S
S
Stanislav Silin2014-10-13 15:03:02
Algorithms
Stanislav Silin, 2014-10-13 15:03:02

How to create Fog of War, any ideas?

Hello, I'm making RTS on Unity3D, it came to the Fog of War. Having rummaged on the Internet, I saw a lot, as in my opinion, "bydlokoderskih" implementation options. Of these, I would like to single out the most worthy ones:
1. Take the texture, place it above the ground and make holes (alpha) in the right places using the shader.
2. Fill the entire map with triggers and, depending on the intersection, apply fog with colliders.
3. We take two textures, fog and a heightmap, place them above the ground and make holes in the right places, taking into account the heightmap.
The first and third methods suit me in their implementation, but there is not enough functionality ... For example, if there is a "tree", then the fog should disappear only between the unit and the tree, but not behind it (the tree). In the third way, you can dynamically add/remove "trees" from the heightmap, but wouldn't that be resource intensive? As far as I understand, it will be necessary to iterate over all texture points between the position of the unit and the current pixel in search of an obstacle, and there can be many units and they can also look far away...
The second one suits me in terms of functionality, but not the implementation... The same example with tree, to take into account this situation, you can send a beam to the trigger, if it reaches it, then we open the fog, if not, then we don’t change anything. If there are a lot of units, then all this will turn into a hell of triggers, colliders and rays.
Now I'm more inclined to modernize the first or third way.
Are there any other decent implementations?
UPD. Here is a diagram to explain the situation with the tree.
0db00eeda7c747dbb202b08f8c7d63b6.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
CENTUR10N, 2014-10-13
@byme

Alternatively, what if an additional object is attached to each unit, a circle of the required size with a tag that makes it invisible to the main camera, but visible to the additional one, which renders these objects into a texture via Render Texture? Then you can use the resulting texture for the fog shader. These "circles" may already have translucencies and more complex shapes. In theory, everything should work quickly, but you need Unity Pro. I understand that this is practically your first option, it may come in handy.
Please describe in more detail your example with a tree, I did not understand much.

W
wlastas, 2014-10-23
@wlastas

have you watched unity fog of war? everything is well written and works as it should
www.youtube.com/watch?v=x40TDCjC4DY
www.youtube.com/watch?v=tV6vcn2Ndec
in your case (as in the picture) there should not be fog - you have seen at least one rts where there are trees give such an effect? What if there are multiple trees? will the entire visibility zone be in the shadows from the trunks? And if our unit is not alone, and they stand at different angles to the tree? It can be easy to calculate which of the enemy units is not visible to more than one ally and give it 100% transparency, for example, and open the fog immediately to the viewing radius (this is how it is implemented in the example on the 2nd link)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question