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:
    125
    You can use the Post Processing Stack v2 sample with the LWRP.
     
  2. unity_ppZWTHsqCWojkA

    unity_ppZWTHsqCWojkA

    Joined:
    Aug 26, 2019
    Posts:
    2
    BTW, ppsv2 sample under Universal RP seems not work~ Unity version is 2019.3.0a11. Thx for any help.
     

    Attached Files:

  3. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    Ah yes the universal RP will use the same post processing tech as the HDRP, but custom shaders are yet to be supported (even in the alpha). I'd recommend sticking with 2019.2 for now if you can. Unfortunately, there's not much I can do, but I do intend on supporting the URP when I can.
     
  4. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,507
    Hi. @stu_pidd_cow

    Have you thought about using RayCastCommand for raycasting? I think this asset will benefit a lot from it.
     
  5. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    Thanks for pointing this out. I think FoW can definitely benefit from this. I'll look into doing it asap.
     
  6. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,507
    Any idea when this asset be supporting hdrp 2019.2 or 2019.3?
     
  7. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    169
    I have found a problem, not sure if this is a Unity issue or an issue with your multi-threading code. Unfortunately I don't get any stack trace of the crash.

    As soon as I compile a build with (PC/Windows10/Net 4.x) IL2CPP and switch on multithreading in FogOfWarTeam, it will crash when I exit my game. Quitting the game works fine if I compile to Mono.

    I am currently using Unity 2018.4.9f1 and the newest version of FogOfWar.
     
  8. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    I think unity isn't intending on giving HDRP custom shader functionality in 2019.2, so FoW won't work with it until 2019.3. When the HDRP team has finalized the custom shader stuff, I'll be working on it as soon as I can.
     
  9. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    I haven't heard of this before. Some questions:
    • Do you see the fog at all?
    • Are you using legacy, LWRP or PPSv2?
    • Do you have a run time toggle that turns FoW multithreading on/off, and it only crashes when you turn it on?
     
  10. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    169
    • Yes it works totally fine all the time, just exiting the game crashes it.
    • I am using Standard Render Pipeline (legacy)
    • Multithreading is switched always on from the getgo, I do not change this while the game is running.
     
  11. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    I haven't been able to reproduce this. Does it happen if you have multithreading turned off?
     
  12. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    169
    Only happen with multithreading turned on and only in IL2CPP builds. Monobuilds are fine.
     
  13. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    It seems like an IL2CPP bug. I'll try to reproduce it and send unity a bug report. Thanks for pointing this out!
     
    DwinTeimlon likes this.
  14. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,507
    Great! Any news on this?

    Also, I know it is already doing threads, but I am not sure what part it is using thread for, so just want to ask if ECS + Jobs + Bust compiler can benefit this asset in anyway?
     
  15. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    FoW is using C#/mono threads to do the rendering part of the fog. The jobs system probably wouldn't help much with that, but it would help with the unit raycasting. I'm not too keen on jumping onto the ECS/Jobs bandwagon just yet since it is still in beta (as far as I can tell). I was planning on fiddling around with it and, if all goes well, have it as a toggleable option. So I wouldn't count on it happening anytime soon unfortunately.

    I'm happy to try and help with any performance-related issues. There's always a bunch of ways to improve performance!
     
  16. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,507
    Ok. So did you look into the raycastcommand?
     
  17. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    I have got a prototype working. I'll try to have it ready for the next release.
     
    DwinTeimlon likes this.
  18. Kobaltic1

    Kobaltic1

    Joined:
    Jan 22, 2015
    Posts:
    144
    I am trying to get the fog to cover the map again. As an example, I have a player. As the player walks the fog is lifted around the player but the path gets covered up again so the only spot that there is no fog is right around the player. How do I accomplish this task? Thanks

    NM. I figured out how to do exactly what I wanted by using the clear fog button on the camera and setting the layer to the correct layer.
     
    Last edited: Oct 7, 2019
  19. Kobaltic1

    Kobaltic1

    Joined:
    Jan 22, 2015
    Posts:
    144
    I am using the clear fog option. I have a clear fog mask layer picked. It works good but the fog is grey instead of the color I chose. I looked through the code but didn't see where it changed the color. How do I change this to use my color instead of the grey. Thanks.
     
  20. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    Are you saying that the fog is visibly gray, or that the fog values are gray (128)?
     
  21. Kobaltic1

    Kobaltic1

    Joined:
    Jan 22, 2015
    Posts:
    144
    The fog in the scene is gray.
    upload_2019-10-8_21-11-15.png

    The fog color is black (which is what I want)
    upload_2019-10-8_21-11-41.png

    If I turn off the clear fog check box I get the black color I want
    upload_2019-10-8_21-12-55.png
    I don't understand why I can't use the clear fog for the layer I want but still have it be black
     
  22. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    Ah I see what you mean. I think what you actually want to do is reset all the fog. You can do it in code with something like this:
    Code (CSharp):
    1. FogOfWarTeam.GetTeam(0).SetAll(0);
    That should completely reset the fog to be fully fogged.
     
  23. Kobaltic1

    Kobaltic1

    Joined:
    Jan 22, 2015
    Posts:
    144
    I don't want it to be fully fogged. I want the clear fog to happen on the layer I have selected (which it is doing correctly) it is just gray. I just want the color to be black. That is it. Change the gray fog to black fog.
     
  24. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    Sorry, I don't think I understand. So you are saying:
    • You have the fog set to black with clear fog turned off
    • You then turn clear fog on, then the fog appears gray
    Is this right?
     
  25. Kobaltic1

    Kobaltic1

    Joined:
    Jan 22, 2015
    Posts:
    144
    Correct. I can make a video of it happening if that would help.
     
  26. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    I've been fiddling around with the clear fog stuff and I've found a bunch of bugs. I suspect that you've come across one of them. If you send me an email then I can give you the latest unitypackage with the fixes.
     
  27. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    421
    Hello,
    1 - Is your Fow Authoritative ?
    I am making a moba game, i need a server side Fow
    2 - Can you make a webGL version to check ?
    Thanks
     
  28. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    I'm not sure what you are looking for specifically. Fog of War does not do any networking, so you might need to handle this yourself. If there is any part of this I can help with, let me know.
    I am working on a webGL demo. It will be out soon (hopefully).
     
  29. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    421
    usually the games that use fow are networked games, in a competitive game, often you need to make things happen on the server side only, so:
    - your FowManager
    - player1
    - player2
    FowManager calculate each frame if the player1 is in fow for player2 and reverse.
    when the player1 is not in the fow - FowManager sends informations to player2 that he can see it.
    Authoritative
    Because, if fow is calculated on local, the player2 can hack the Fow and see the player1 locally.
     
  30. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    What information would you want the server to be sending to the clients? Would it be:
    • The whole fog texture?
    • Where a unit is at a particular time?
    • What units can see each other?
    • Something else?

    For most of these, there is a way to do it with FoW's current system. But maybe you want something else?
     
  31. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    421
    every X seconds server would send:
    A unit is visible - react in local accordingly
    B unity is notVisible - react in local accordingly
    Client should never know from itself if the unit is visible or not.
    does your system handle teams ?
     
  32. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    Yes, this is possible to do. There is a FogOfWarTeam component which doesn't require any visuals to display for the server. You can then do something like this:

    Code (CSharp):
    1.  
    2. Vector3 unitPos = transfrom.position;
    3. byte fogValue = FoW.FogOfWarTeam.GetTeam(0).GetFogValue(unitPos);
    4. bool isVisible = fogValue > 128;
    5.  
    You can then send the isVisible over the network.
     
  33. Radu392

    Radu392

    Joined:
    Jan 6, 2016
    Posts:
    166
    Any ETA for when URP will be supported? I'm loving this asset, but I'm also loving Unity's new 2d lighting with URP. 2019.3 is in the 8th version right now I believe, which is extremely stable! It's almost out of the beta phase so it's unlikely it will get any new features.
     
    Last edited: Oct 28, 2019
    pixelR likes this.
  34. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    Unfortunately Unity still has released any info on custom post processing for the new URP tech (as far as I can tell) so I haven't been able to get started. I am exploring some other methods, but there's not much else I can do for now :oops:
     
  35. pixelR

    pixelR

    Joined:
    Sep 16, 2013
    Posts:
    38
    Just want to chime in and say it looks great but I also use URP already so I'm waiting for something to happen on URP support front. I'll keep my fingers crossed! :)
     
  36. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,507
    hi @stu_pidd_cow , I am trying out the fog of war events and although it seems to work, the respond time seems to be a bit slow. There seems to be some kind of delay somewhere.

    How does detecting algorithm works? Is it based on raycasting and hit? , if so , it shouldn't be that slow?

    Also is there going to be version with raycast command optimization?

    Cheers.
     
  37. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    Have you tried playing with the minFogStrength slider? What is consider visible fog is rather subjective, so that slider will let you say what amound of fog will enable visibility.
    Other than that, it should be instantaneous.
     
  38. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    Fog Of War v1.19 has just been uploaded to the asset store!
    Here's the release notes:
    • PPSv2: Made FoW render before the stack
    • Added checks for null or unsupported shaders
    • Removed old way to do clear fog, and added FogOfWarClearFog component to allow more flexibility
    • Fixed antiFlicker not working
    • Renamed antiFlicker to snapToPixelCenter in FogOfWarUnit
    • Added new FogOfWarMinimap component
    • Fixed HideInFog.minFogStrength not working properly
    • Split fade duration into fade in and fade out durations
    • Added option to multithread raycasts in FogOfWarUnit (utilizing RaycastCommand), required Unity 2018.1
    • Removed a lot of the duplicated shader code
    • Added FogOfWarTeam.outputToTexture
    • Fixed OutOfRange exception when calling FogOfWarTeam.SetFog()
    LWRP/URP will work, but it requires the Post Processing Stack v2 for now.
    HDRP can use the Post Processing Stack v2 for Unity 2018 and earlier. I'm still working on newer HDRP for newer versions (it's been a nightmare so far, but I haven't given up yet!).
     
    DwinTeimlon likes this.
  39. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    169
    Sounds like an awesome update. Keep up the great work. I will take a look into it over the weekend.
     
  40. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,507
    Is this updated on Asset Store yet? I still can't see it..
     
  41. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    It's still waiting for approval. Should be up in the next 48 hours I suspect.
     
    DwinTeimlon likes this.
  42. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,507
    Tried the latest one.. I was getting some flicking issue with settings I had for the old version, so I fiddled around with the setting and now I got :

    UnityException: EnableKeyword can only be called from the main thread.
    Constructors and field initializers will be executed from the loading thread when loading a scene.
    Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
    FoW.FogOfWarUtils.SetKeywordEnabled (UnityEngine.Material material, System.String keyword, System.Boolean enable) (at Assets/Standard Assets/FogOfWar/Core/FogOfWarUtils.cs:26)
    FoW.FogOfWarDrawerHardware.Draw (FoW.FogOfWarShape shape, System.Boolean ismultithreaded) (at Assets/Standard Assets/FogOfWar/Core/FogOfWarDrawerHardware.cs:173)
    FoW.FogOfWarDrawThreadTask.Run () (at Assets/Standard Assets/FogOfWar/Core/FogOfWarTeam.cs:33)
    FoW.FogOfWarThread.ThreadRun () (at Assets/Standard Assets/FogOfWar/Core/FogOfWarThreadPool.cs:43)
    UnityEngine.Debug:LogException(Exception)
    FoW.FogOfWarThread:ThreadRun() (at Assets/Standard Assets/FogOfWar/Core/FogOfWarThreadPool.cs:47)
    System.Threading.ThreadHelper:ThreadStart()

    Also enabling the snap to pixel center seems like it is forcing everything to be under partial fog..
    Disable output to texture also seems to be doing the same thing.
     
    Last edited: Dec 3, 2019
  43. Federfunk

    Federfunk

    Joined:
    Dec 5, 2014
    Posts:
    3
    Tried out 1.19 but I'm getting the below errors in FogOfWar3D_Legacy and FogOfWar3D_PPSv2 sample scenes. This is in a brand new project (2018.4.13f1 & PPSv2.2.2). Using the legacy built in renderer.

    FogOfWar3D_Legacy:
    Shader error in 'Hidden/FogOfWarLegacy': failed to open source file: '../../FogOfWarUtils.cginc' at line 21 (on d3d11)

    Compiling Vertex program with CAMERA_PERSPECTIVE PLANE_XZ FOG_TEXTURED_SCREEN FOGFARPLANE
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_LIGHTMAP_FULL_HDR

    FogOfWar3D_PPSv2:
    Shader error in 'Hidden/FogOfWarPPSv2': failed to open source file: '../../FogOfWarUtils.cginc' at line 14 (on d3d11)

    Compiling Vertex program with CAMERA_PERSPECTIVE PLANE_XZ FOG_TEXTURED_SCREEN FOGFARPLANE
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_LIGHTMAP_FULL_HDR
     
  44. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,507
    I also had those errors but that is because you dont have the ppv2 package installed. I deleted ppv2 related files because i dont use them at the moment and it all seems to be ok.
     
  45. Federfunk

    Federfunk

    Joined:
    Dec 5, 2014
    Posts:
    3
    Sorry I'm not sure what you mean? I do have the PPv2 package installed (2.2.2).
     
  46. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    Yes, if you do not have the PPv2 installed, you will have to delete the FogOfWar/Core/PPv2 folder. I have tested it with PPv2 2.2.2 and haven't had these errors.
    @Federfunk What OS and version of unity are you using?
     
  47. Federfunk

    Federfunk

    Joined:
    Dec 5, 2014
    Posts:
    3
    Windows 10 Pro and 2018.4.13f1

    This is happening in a brand new project. I just created the project, installed PPv2 2.2.2 via package manager, and imported FoW.
     
  48. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    For some reason, this error hasn't been appearing in my testing, but it is definitely real!
    The fix is to go into FogOfWarLegacy.shader and/or FogOfWarPPv2.shader and change this line:
    Code (CSharp):
    1. #include "../../FogOfWarUtils.cginc"
    to this:
    Code (CSharp):
    1. #include "../FogOfWarUtils.cginc"
    Thanks for pointing this out. I'll be putting out a fix for this ASAP.
     
    DwinTeimlon likes this.
  49. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,507
  50. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    125
    Damn, I seemed to have forgotten this. So Hardware and Multithreading aren't compatible with each other (because all hardware rendering needs to be done on the unity thread). The solution is to untick multithreading or switch to software. I'll have to do something to make this clear.
     
unityunity