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:
    115
    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:
    115
    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,484
    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:
    115
    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,484
    Any idea when this asset be supporting hdrp 2019.2 or 2019.3?
     
  7. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    144
    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:
    115
    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:
    115
    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:
    144
    • 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:
    115
    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:
    144
    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:
    115
    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,484
    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:
    115
    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,484
    Ok. So did you look into the raycastcommand?
     
  17. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    115
    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:
    140
    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:
    140
    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:
    115
    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:
    140
    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:
    115
    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:
    140
    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:
    115
    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:
    140
    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:
    115
    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:
    115
    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:
    115
    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:
    115
    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.