Author Topic: Tasharen Fog of War  (Read 119737 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Tasharen Fog of War
« on: August 07, 2012, 10:16:31 PM »


Ever wanted high-quality smooth fog of war for your strategy game? How about a line-of-sight revealing system for a heist game like Monaco? Well, now you can have it in 3 simple steps:
  • Drag & drop the Fog of War prefab into your scene. You can find this prefab in Assets/Fog of War/FoW folder.
  • Add FOWEffect script to your Main Camera. Make sure it references the "Image Effects/Fog of War" shader.
  • Add FOWRevealer script to one or more game objects in your scene. It's best to add it to a game object located at around the unit's "eye level" in order for the fog of war to be accurate.

What makes it great?
  • It's fast. If you already render to depth (for example using Tasharen Water), then you likely won't even notice a performance drop. In fact, with proper use of FOWRenderers hiding renderers hidden by fog you can actually increase performance.
  • All line-of-sight calculations are done on a separate thread, so they don't affect your game's performance.
  • It's smooth -- and level of smoothness also doesn't affect performance as it's done on another thread.
  • You can specify how often it updates and how quickly it fades in and out, and the two work independently. Updating only twice per second will still give you perfectly smooth fading results.
  • You can easily check to see if a point is visible, explored, or not.
  • You can optimize the worker thread's performance even further by specifying that certain line-of-sight checks should only be performed once (stationary object).
  • You get a script that can automatically hide all renderers under the game object that's hidden from view (FOWRenderers).

Play the Demo: http://www.tasharen.com/windward/fow/
« Last Edit: March 28, 2014, 10:21:11 AM by ArenMook »

frarees

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Tasharen Fog of War
« Reply #1 on: November 07, 2012, 05:00:01 AM »
Is this package suitable for mobile platforms?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #2 on: November 07, 2012, 05:35:37 AM »
If you check the thread on the Unity forums, people have used this package with mobiles, however it has to be done by modifying the object shaders instead. The idea is to not have a post-processing effect (image effect), but to have the shader used on your game objects actually sample the fog inside. This way you reduce fillrate, making it suitable for mobile platforms with next to no performance loss over not having the fog enabled.

missyouangled

  • Guest
Re: Tasharen Fog of War
« Reply #3 on: November 24, 2012, 04:28:18 AM »


NOTE: This package requires Unity Pro

Ever wanted high-quality smooth fog of war for your strategy game? How about a line-of-sight revealing system for a heist game like Monaco? Well, now you can have it in 3 simple steps:
  • Drag & drop the Fog of War prefab into your scene. You can find this prefab in Assets/Fog of War/FoW folder.
  • Add FOWEffect script to your Main Camera. Make sure it references the "Image Effects/Fog of War" shader.
  • Add FOWRevealer script to one or more game objects in your scene. It's best to add it to a game object located at around the unit's "eye level" in order for the fog of war to be accurate.

What makes it great?
  • It's fast. If you already render to depth (for example using Tasharen Water), then you likely won't even notice a performance drop. In fact, with proper use of FOWRenderers hiding renderers hidden by fog you can actually increase performance.
  • All line-of-sight calculations are done on a separate thread, so they don't affect your game's performance.
  • It's smooth -- and level of smoothness also doesn't affect performance as it's done on another thread.
  • You can specify how often it updates and how quickly it fades in and out, and the two work independently. Updating only twice per second will still give you perfectly smooth fading results.
  • You can easily check to see if a point is visible, explored, or not.
  • You can optimize the worker thread's performance even further by specifying that certain line-of-sight checks should only be performed once (stationary object).
  • You get a script that can automatically hide all renderers under the game object that's hidden from view (FOWRenderers).

Play the Demo: http://www.tasharen.com/windward/fow/

vgiu

  • Guest
Re: Tasharen Fog of War
« Reply #4 on: January 21, 2013, 12:07:17 PM »
I'd like to know a few things about this:

- I suppose there is a viewing distance for the FOWRevealers, right?
- Is there a way of making it so that higher ground always see lower ground unities (no occlusion from a tall building's "shadow")
- How do we define what can and what cannot be seen by the fog of war? Can any object become an obstacle to sight, or only terrain?
- Is it possible to assert FoW information via scripting? (I'd use this for a server side fow that sends only information on objects that are seen by the clients)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #5 on: January 21, 2013, 12:36:14 PM »
Yup, there is a range on the FOWRevealer.

Higher ground will automatically give you better sight than lower ground. You can actually see that in the demo. You will be able to see over small obstacles.

By default everything can be "seen" (as in, nothing gets flat out hidden) -- but it will be shaded by the FOW's colors (ie: if a unit is hidden in the fog, it will be tinted accordingly). You can also attach the FOWRenderers script to units to automatically turn off the renderers when they are covered by the fog. In most cases you will want to use this script on all your movable units as it doesn't make sense to still be able to see them if they are supposed to be invisible.

You can pull FOW's topology information and do your own checks, I suppose... but if you're going with that route it might make sense to roll your own custom solution. I suggest keeping it simple. Send the info anyway and let the clients sort what can and cannot be seen.

vgiu

  • Guest
Re: Tasharen Fog of War
« Reply #6 on: January 21, 2013, 12:55:45 PM »
What I meant by the third question was whether I can have an object that can block the line of sight other than the terrain itself, if I put lots of buildings they are all taken into account so I'd be able to hide behind walls, or is it optimized to work, as in the demo, only with a terrain object and that is used to determine the fog of war?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #7 on: January 21, 2013, 03:40:30 PM »
Of course you can use objects. Terrain isn't the only blocker. It's up to you which layers will block the line of sight -- just specify them.

vgiu

  • Guest
Re: Tasharen Fog of War
« Reply #8 on: January 21, 2013, 03:54:51 PM »
Great! We just wanted to be sure, since the demo does not show that in action. Thanks for the reply :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #9 on: January 21, 2013, 03:57:16 PM »
Windward does. ;) If you play it you will notice that towers block line of sight.

samelgod

  • Guest
Re: Tasharen Fog of War
« Reply #10 on: February 21, 2013, 01:13:57 AM »
Hey, Its real good asset,
I'm trying to blend its fow texture with minimap picture
do you have a shader to do that (that will work with UITexture) ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #11 on: February 21, 2013, 04:27:23 AM »
Yeah, Windward has a minimap and it's affected by the fog, but I never made a package out of that Minimap... although I do get requests to do so every so often.

samelgod

  • Guest
Re: Tasharen Fog of War
« Reply #12 on: February 21, 2013, 07:10:37 AM »
could you post the shader or part of it?

I'm having hard time trying to make only visible/not-visible masking
and try to keep the explored areas not visible

illumina

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Tasharen Fog of War
« Reply #13 on: March 07, 2013, 10:22:10 PM »
Hey There,
I am using your fog of war system in an iPad3 game and am finding the performance to be horrendous.

I really like the system and have integrated it fairly deeply into my game, so I'd like to keep using it. I'm seeing a framerate of about 25FPS with the FOW system turned on. If I turn off the shader then I get around 80FPS. The FOWSystem.Update() causes substantial spikes every few seconds (6ms) too in addition.

Unity profiler shows my game is spending significant time(11-30ms) in Device.Present, so I am fairly certain the issue is the shader. I've attached two screenshots of the unity profiler with both Device.Present() and FOWSystem.Update() selected.

I've tried twiddling different configuration options in FOWSystem, but can't seem to find any that reduce perf impact. I'm using a 256 world size and 256 texture size, 0.1 update time, and 0.4 blend time. None of my objects are below Y=0, and i am using some line of sight. All works fine... just slow on device..

Have you tested this on iOS before? Am I doing something stupid?

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #14 on: March 08, 2013, 04:04:26 AM »
0.1 update time means you are updating your fog 10 times per second. This is highly unusual... I recommend you drop that to 1 per second, or twice at the most. Let blend time take care of the rest.

In Windward I had it set to 2 updates per second, blend time of 0.6, meaning the fade was slightly slower than the update. You can have the update be even less if your character doesn't move quickly.

For an iOS device I also suggest making custom shaders for objects, rather than using the Image Effect approach. You will significantly improve performance that way.