Search Unity

Fog of War

Discussion in 'Assets and Asset Store' started by stu_pidd_cow, Oct 11, 2016.

  1. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    FogOfWar
    Asset Store | User Guide
    Add Fog of War to your 3D RTS to hide elements from the player. FogOfWar is highly customizable to meet the needs of any RTS or adventure game that needs a thick shroud of mist around it.

    Features:
    - Works with 2D and 3D
    - Varying map size
    - Different fog colors and filters
    - Queue-friendly tools
    - Multithreading options
    - Good performance
    - Objects blocking line of sight
    - View cones (using angles)
    - Clear Fog (ie see through to background)
    - See-through ground
    - Works for both Orthographic and Perspective cameras
    - Render to multiple cameras
    - Save and load fog between plays
    - Compatible with mobile devices

    Feel free to ask any questions or request features!










    Third Party Support
    Fog Of War is now completely compatible with the RTS Engine asset. You can find the integration package here.
     
    Last edited: Mar 10, 2018
  2. Pillowseller

    Pillowseller

    Joined:
    Jun 27, 2013
    Posts:
    12
    Hello, a while ago I downloaded this for my RTS. It's working great, except that if my program loses focus and regains it, the fog becomes entire darkness permanently. Can you do/teach me something about it?

    Thanks.
     
  3. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    Hi Pillowseller,

    I have heard about this issue, but I haven't been able to reproduce it.
    Is it happening in the unity editor or in your build?
     
  4. Pillowseller

    Pillowseller

    Joined:
    Jun 27, 2013
    Posts:
    12
    Thanks for responding. It's happening in the test run. Haven't tested the actual build.

    Unity version is 5.4.0f3 Personal. The OS is Win 10.
     
  5. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    I have exactly the same setup but it doesn't seem to happen for me.

    Can you try this for me: make the fog permanently dark again, but then untick the FogOfWar component and tick it again. See if the fog turns on and off.
    If that doesn't work, there is a Reinitialize button at the bottom of the FogOfWar component while playing. Tick that and see if it resets the fog.
    Let me know how it goes!
     
  6. Pillowseller

    Pillowseller

    Joined:
    Jun 27, 2013
    Posts:
    12
    Before ; I use SetAll() to make it transparent:


    After regaining focus:



    I forgot to say this doesn't happen in your test scene, and I just updated your package.

    Ticking FowOfWar component turns fog (or rather, the black color) on and off. But when it's on, the entire zone is filled with black and FogOfWarUnit does nothing.

    I don't see the Reinitialize button you are talking about.

     
    Last edited: Nov 17, 2016
  7. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    Ah sorry, for the Reinitalize button to appear, you need to put this script into an Editor folder (I have attached the script). The button should appear when you press play.

    Another thing to try, set the color of the fog to something like red, and see what color it is after unity loses focus.
     
  8. Pillowseller

    Pillowseller

    Joined:
    Jun 27, 2013
    Posts:
    12
    Yes, reinitializing gets it back to the working state. The units restarted to clear the fog,

    And the color of the "dead state" fog changes.
     
  9. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    Hmmm ok. I've attached a new FogOfWar script. Just replace it with the old one.
    Hopefully that will address the issue!
     
  10. Pillowseller

    Pillowseller

    Joined:
    Jun 27, 2013
    Posts:
    12
    Yeeeesss.... that did the trick! Thanks a lot, it's doing fine now!
     
  11. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    Ah fantastic! I've been trying to solve this for a while. Thanks for helping me out with this.
    I'll put the fix in for v1.9.
     
  12. EliteSniperx16

    EliteSniperx16

    Joined:
    Apr 9, 2014
    Posts:
    68
    Working on a RTS is there a way i can make it where Player 2 cant see my units? The players are using the Same Camera with the Same units and buildings able to build so once the match starts everyone can see everyone
     
  13. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    At the moment, the only way to achieve this is by using seperate cameras, or by disabling/removing the FogOfWarUnit components from the units that don't belong to the current player.

    I am hoping to add a feature in the next release to greatly simplify this!
     
  14. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    I just uploaded a big update (v1.11) to the asset store. It includes the much needed features of multithreading and texture shapes for units!
    It probably comes with some bonus bugs :( so take care when upgrading while I iron out the issues. :D
     
  15. Jet-Woods-Lim

    Jet-Woods-Lim

    Joined:
    Mar 27, 2015
    Posts:
    4
    how to save and load fog of war?
    "You can access all of the fog values by FoW.FogOfWar.current.fogValues. This is a byte array and the size will depend on the mapResolution variable. You can read/write to this at any time." in your guid. but it's not working.
     
  16. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    What exactly isn't working?
     
  17. Jet-Woods-Lim

    Jet-Woods-Lim

    Joined:
    Mar 27, 2015
    Posts:
    4
    I save "FoW.FogOfWar.current.fogValues" for test scene, and load "FoW.FogOfWar.current.fogValues" after comeback to test scene. It's not working, but when I save and load "FogOfWarDrawerSoftware._values" is worked.
     
  18. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    Ah yes, you are right, thanks for finding this!
    Your solution to use FogOfWarDrawerSoftware._values is a good temporary fix.
    I've pushed a fix to the asset store for approval. It should be up in the next few days.
     
  19. bbgames100

    bbgames100

    Joined:
    Mar 24, 2015
    Posts:
    2
    Nice asset, but some issues.

    Unity 5.6.1f1 pro
    When using multi threading, the texture of the line of sight fog for the unit itself changes from a "vision cone" to a simple box or disappears entirely (depends on whether you enable it before or during play).

    I had to make several modifications to scripts to get the asset to import correctly. Basically, I had to change a number of references (mostly in Trigger.cs, but also one in ITriggerWindowContainer.cs and of course UIWindowEditor.cs) from UIWindow to the explicit Devdog.General.UI.UIWindow class. Unity was confusing yours with its internal UIWindow and refusing to build.


    All in all, it seems like a great concept, and performance is noticeably improved in multithreading... but multithreading especially is not ready for primetime yet.
     
  20. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    I'm not sure what Trigger.cs or any of the other script files you mentioned are. They are not included in the Fog of War package.

    But you are right that there are some issues when switching shapes during runtime in multithreading. I'll have to look into it.
    Thanks for finding this!
     
  21. ransuz

    ransuz

    Joined:
    May 22, 2017
    Posts:
    5
    Do you plan to add the blur feature?
    Although it is possible in filter mode. I was a bit disappointed because the fog was not smooth enough.
     
  22. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    Adding blur should be easy enough. I'll try to get it in for the next release.
    Thanks for the suggestion!
     
  23. ransuz

    ransuz

    Joined:
    May 22, 2017
    Posts:
    5
    Thank you so much for trying :)
    Oh. And I found one bug.
    If you look at the attached screenshot, there is fog on top and right.
    It does not disappear anyhow.



    The same phenomenon is happening in my current project.
    Please check this.

    I bought this plugin today and it was really nice to use it. Thank you.
     

    Attached Files:

  24. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    Yeah, I've noticed that there is some pixel inaccuracies, although this one appears to be on the map border. They are probably related. I'll definitely look into it. Thanks for finding this.
     
  25. SquareZhao

    SquareZhao

    Joined:
    Aug 28, 2015
    Posts:
    3
    I just purchased this package, but it is useless to me. The author says it support orthographic camera, and it does only when the camera is absolutely vertical to ground. In my situation, the camera uses orthographic mode and is a little tilt to ground, then the game scene become like the image I upload. In addition, I found camera clipping plaines property has influence. Apologize for my poor English, but I am disappointed with this package, it cannot solve my problem at all.
     

    Attached Files:

  26. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    Orthographic cameras definitely work for me. What version of unity are you using? And what OS are you testing on?
     
  27. TheKingBoggart

    TheKingBoggart

    Joined:
    Dec 26, 2016
    Posts:
    1
    Wondering if there is a way to get less distortion on angled pixels, while using the circle shape type? I am using the circle shape type to build a cone.
     
  28. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    You can reduce aliasing by using bilinear filtering and increasing the resolution of the map. A better solution is to use a texture shape, where you give it a grayscale texture. Then you will have more control over the aliasing.

    Texture shapes aren't supported on multithreading at the moment, but the next version should fix that!
     
  29. DoritoDog

    DoritoDog

    Joined:
    Feb 20, 2016
    Posts:
    7
    My fog only works on an orthographic camera from top down. Otherwise the revealed parts aren't aligned with the units. Am I doing something wrong?
     
  30. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    I have heard of this happening. What OS and unity version are you using?
     
  31. DoritoDog

    DoritoDog

    Joined:
    Feb 20, 2016
    Posts:
    7
    I'm using 2017.1.0f3 Personal (64-bit) and Windows 7. I'm running the editor in dx9.
     
  32. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    I have attached a new shader that goes in the FogOfWar/Resources folder that should fix this issue. The issue was with DX9. Let me know if it works.

    Also, I'm not sure if you've read this: https://blogs.unity3d.com/2017/07/10/deprecating-directx-9/
     

    Attached Files:

  33. DoritoDog

    DoritoDog

    Joined:
    Feb 20, 2016
    Posts:
    7
    I didn't notice any difference with the new shader but I tried starting the editor in DX11 and that's when it worked. It looks like I'll just get a new PC soon because I'm working with a pretty old laptop here and I don't blame you for not supporting very low end hardware.
     
  34. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    You might be able to switch to OpenGL as an alternative for the meantime. Weird that the shader didn't work. I'll dig around some more to see what else could be causing it.
     
  35. DoritoDog

    DoritoDog

    Joined:
    Feb 20, 2016
    Posts:
    7
    How do you enable OpenGL? I've tried launching unity with the -force-opengl and -force-glcore command line arguements but unity doesn't start. This is an android project by the way.
     
  36. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    For android, I think your only options are OpenGL ES and Vulkan.

    To change the graphics API, try this:
    1. Edit -> Project Settings -> Player
    2. In the Other Settings section, untick the Graphics APIs for Windows
    3. Click on the + and choose one of the OpenGL APIs
    4. Drag it to the top of the list
    That will usually take effect immediately (a message box will pop up saying it needs to reload stuff). If that doesn't work, it's possible your GPU might not support the graphics API (usually OpenGL is pretty well supported though).
     
  37. Pandur1982

    Pandur1982

    Joined:
    Jun 16, 2015
    Posts:
    238
  38. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    I have fixed the link in the first post of this thread. Unfortunately it is a web player (which doesn't work on most browsers anymore as unity dropped support for it). I'm meaning to update the demos and fancy them up soon.

    As for the difference between UFoW (trying to be as unbiased as possible since I'm the creator of FoW), I would argue that FoW has been around longer, has a larger user base, is priced significantly lower and has some cool features like infinitely sized maps and lots of options to customise the visuals. I don't want to say much more, but maybe someone else can give you a less-biased opinion.
     
  39. SiliconAvatar

    SiliconAvatar

    Joined:
    Mar 23, 2014
    Posts:
    48
    Has anyone tried this in conjunction with one of the tile map editor assets - specifically Super Tile Map Editor?

    My 2 cents as a fresh pair of eyes (trying to be helpful here):

    The demo link you just gave takes me to a dropbox that just shows some HTML (so nothing happens). This is the first thing a customer clicks on and they're not getting anything.

    The user guide link at the top of this thread goes to a dropbox that gives a "file not found" error. The user guide link from the product page works though. You should probably fix the broken link.

    The support link and the publisher's website link on the product page both go to a blog that has not been updated in 3 years. This makes the project look abandoned.
     
    Last edited: Sep 4, 2017
  40. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    Yes you a right about all of this:oops:. I have removed the links to the demo (I'll try to get a new demo up soon hopefully). All the other links should be a little better now (asset store page stuff may take a few days to kick in). Thanks for finding these!
     
    SiliconAvatar likes this.
  41. SiliconAvatar

    SiliconAvatar

    Joined:
    Mar 23, 2014
    Posts:
    48
    For those interested, this asset does work with the Super Tilemap Editor asset.

    I was able to get a 255x255 map going with line of sight using a combination of those two assets.
     
  42. RamonDevs

    RamonDevs

    Joined:
    Apr 11, 2015
    Posts:
    9
    I have 2D assets in a 3D collider world. My characters can't see anything and I've followed every step on the (not too expansive) user guide. Help please?

    Edit: The red square is the actual fog. Just figured it out... you should reflect that in the docs :)
     
    Last edited: Sep 26, 2017
  43. RamonDevs

    RamonDevs

    Joined:
    Apr 11, 2015
    Posts:
    9
    Ok, now I have a legitimate question. How to skip a gameobject, making it render over the fog?
     
  44. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    Done!

    Because the fog is implemented as an image effect, everything in the scene is affected by the fog. But you can still achieve this with a separate camera. Try this:
    1. Put the objects you want to be affected on a different layer
    2. Create a new camera and put it as a child of the main camera (make sure the transform is set to zero and the camera component is identical to the main camera)
    3. Set the camera’s depth to a higher value than the main camera
    4. Set the camera’s culling mask to render only the new layer
    5. The objects should now be drawn on top of the fog!
    Let me know if you need more help with this!
     
  45. Fdudka

    Fdudka

    Joined:
    Jul 27, 2015
    Posts:
    15
    Hi!
    Is it possible to change the Fog Color during run time? I get a weird bug every time i changed with script.
    Everything becomes pitch black and i see some lights sparks here and there.

    Is there some kind of settings?

    I'm doing it with:

    fManager.fogColor = new Color (0,0,0,180);
    fManager.FogColor = Color.Black;

    Thanks
     
  46. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    That's super odd. It is definitely just FogOfWar.fogColor to set the color. What happens if you change it at runtime directly on the FogOfWar component?
    Another thing to try: If you open FogOfWarTestScene.unity, you can change the fog color through the UI (which changes it through a script).
     
  47. StSergeant

    StSergeant

    Joined:
    Aug 27, 2013
    Posts:
    2
    Hi!
    The author declares: ..."- Compatible with mobile devices"...
    I purchased this package and created a test project. Builded a apk.
    But only one device out of three correctly displayed the fog of war.. ( Look attached screenshots ).
    Help me to understand the reason!
     

    Attached Files:

    Last edited: Oct 13, 2017
  48. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    113
    Going by the screenshots, it looks like one is distorted and the other isn't appearing at. This could indicate a flipped depth buffer. Unfortunately, I don't have a lot of android phones to test on. Could you send me an email and I will give you some files to try to debug the issue.
     
  49. StSergeant

    StSergeant

    Joined:
    Aug 27, 2013
    Posts:
    2
    I duplicated the message to your e-mail address on the same day.
    The screenshots are not distorted. So I see the image on the devices. All three devices use the same apk.
    I hope that you will find the solution.
    Thanks.
     
    Last edited: Oct 14, 2017
  50. Fdudka

    Fdudka

    Joined:
    Jul 27, 2015
    Posts:
    15
    Changing it manually with works good, but not at runtime. I get a really strang black screen with some border highlights. But it’s fine, I just decided to let the color stay black all the time.