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:
    233
    Sure, pop me an email (you can find it in the user guide).
     
  2. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    233
    You can adjust the transparency by lowering the alpha on the fog color.
     
  3. betaFlux

    betaFlux

    Joined:
    Jan 7, 2013
    Posts:
    112
    Greetings. Is it possible to set up my own minimap image with FogOfWar?

    I followed the guide in the FAQs and created a minimap raw image, an ortho cam with FogOfWarLegacy component, etc.

    If I add the ground (terrain) to the camera culling everything looks smooth and beautiful, of course with all the disadvantages of this method, like unwanted lighting.

    I'd be glad for any advice on how to do this.
     
  4. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    233
    If you're rendering things to a render texture but don't want all the lighting effects, you might be better off rendering only a specific layermask. So you might have a layer called "Minimap" that just renders the terrain with an unlit shader, and all of the units with a special icon. This may require you to have minimap-specific object in the scene. Alternatively, you could try doing something fancy with shader passes, but that can be a bit more complex depending on the shaders you're using.
     
  5. betaFlux

    betaFlux

    Joined:
    Jan 7, 2013
    Posts:
    112
    Sorry, the lighting thing was a pointless argument from me. Rendering the terrain to the minimap isn't an option because I plan to add my own artistic style.

    I got it partially working. To reproduce:
    - Setup legacy FOW system (mode doesn't matter)
    - Create orthographic camera with rendertexture, FogOfWarLegacy component and empty culling list
    - Make sure there is at least one FogOfWarUnit in the scene within view of the minimap camera
    - Setup your UI minimap with custom image
    - Create RawImage at the same size as the custom image and add the rendertexture to it
    - Make sure the RawImage comes after the custom image in the hierarchy
    - Enter play mode

    This is as close as I can get. The revealed areas on the minimap are still a little bit dark and it seems the minimap fog updates only once at game start and ignores the unit movement afterwards.

    Any advice is very welcome.
     
  6. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    233
    Is there any chance you could send me a small version of your project with the issue? It might be easier for me to debug it that way.
     
  7. betaFlux

    betaFlux

    Joined:
    Jan 7, 2013
    Posts:
    112
    I've sent you a small project. Thanks for your help.
     
    stu_pidd_cow likes this.
  8. 5u

    5u

    Joined:
    Mar 22, 2015
    Posts:
    2
    Hi, what's the situation regarding URP support? Thanks
     
  9. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    233
    According to the URP roadmap, custom PP won't be coming until 2020.2, which is super frustrating. I have a few other avenues I'm looking at, so hopefully I can get something working sooner, but I can't guarantee anything unfortunately.
    Sorry, I know this is taking forever, but there's not a whole lot more I can do at this time.
     
    faolad likes this.
  10. 5u

    5u

    Joined:
    Mar 22, 2015
    Posts:
    2
    Thank you for the information. At least I voted for custom PP.
     
  11. boongea

    boongea

    Joined:
    Mar 2, 2015
    Posts:
    3
    First, Thanks for useful assets.
    Could you update for "URP / Volume" ? not a PPSv2
     
  12. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    233
    Unity still hasn't provided an official way to create custom post processing for URP. The moment they do, I'll be all over it. I believe it's on their roadmap for 2020.2.
     
    faolad likes this.
  13. joan_stark

    joan_stark

    Joined:
    Jul 24, 2018
    Posts:
    43
    Hey, any news regarding URP fog of war. I'm delaying my project because of this :(
     
  14. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    233
    Sorry, URP has been a train wreck to support. I've got another thread going to try and get solutions to the problems I'm having, but I have doubts it'll get anywhere soon. Unfortunately, that's all the optimism I have for now. :(:(

    EDIT: URP is looking good now! ;)
     
    Last edited: Jan 2, 2021
  15. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    233
    FogOfWar v1.23 has been uploaded to the asset store. This release features URP support! Sorry again for the long delay. The full list of features are:
    • URP support! (finally)Removed major memory allocation in hardware renderer
    • Optimised texture retrieval in hardware renderer
    • Fixed typo in demo scene
    • Fixed some inaccurate rounding errors with fog pixel/cell visibility calculations
    • Fixed sample scene having HDRP camera components on them
    • Fixed rare shader error about unknown "modepos"
    • Added lineOfSightRaycastAngle, lineOfSightRaycastOffset and lineOfSightSeeOutsideRange to FogOfWarUnit to reduce raycast count
    • Added CustomFogShader to demonstrate how to make a world-space shader that reacts to fog, as well as the FogOfWarTeam.ApplyToMaterial method
    • Added Manual Update button to FogOfWarTeam inspector
    • Added FogOfWarTeam.onTextureChanged event
    • Added mesh shape type for FogOfWarUnits
    • Added sample mesh for Mesh shape type
    It may take a few days for the asset store to publish the asset. If you need it sooner, feel free to send me an email.
     
    DwinTeimlon and yuliyF like this.
  16. yuliyF

    yuliyF

    Joined:
    Nov 15, 2012
    Posts:
    197
    Make a new video about new features! It will be a great.
     
  17. joan_stark

    joan_stark

    Joined:
    Jul 24, 2018
    Posts:
    43
    Ty man, you are awesome. Thanks for keeping the support for this. <3
     
    stu_pidd_cow likes this.
  18. Nikita500

    Nikita500

    Joined:
    Aug 18, 2015
    Posts:
    67
    hi i sended email. and post it here too if smth wrong with mails.
    It is stil Hdrp errors/ on 2019.4.17 Lts URP pipline
    https://prnt.sc/wg24wf
    p.s.
    hmm maybe it still loading previous version sorry then didnt saw that info



     
    Last edited: Jan 4, 2021
  19. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    233
    I've replied to your email. It looks like there is still a HDRP folder in the project.
     
  20. WiktorWasowski

    WiktorWasowski

    Joined:
    Dec 23, 2012
    Posts:
    15
    Hello,
    I've got a little problem - can't get Cell Based working. Without it I'm getting annoying irregularities despite having assets aligned to the grid:

    upload_2021-1-7_14-39-46.png

    I'm guessing Cell Based would help here, but stops detecting collisions when I switch to it:

    upload_2021-1-7_14-42-15.png

    I tried moving the Fog of War Unit or the environment up or down, as well as playing with all the options but nothing makes Cell Based work properly. Any suggestions what I might be doing wrong?


    EDIT:
    Nevermind, I figured it out - cells don't work with 3D physics.
     
    Last edited: Jan 8, 2021
    stu_pidd_cow likes this.
  21. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    233
    FogOfWar v1.24 has just uploaded to the asset store. This is just a small patch release. The changes are:
    • Fixed URP orthographic not working
    • Fixed HDRP error in URP sample file
    • Documentation improvements

    It may take a few days for it to appear in the asset store, so if you need these fixes sooner, send me an email.
     
    Nikita500 likes this.
  22. sahinyalabik77

    sahinyalabik77

    Joined:
    Mar 6, 2019
    Posts:
    2
    Hey, have a question regarding the line of sight raycast angle. My unit have a pretty narrow field of vision (like 20 degrees). I wanted to set the line of sight raycast angle to something similar, but the problem is, that angle does not rotate with the unit. So when my unit rotates, the field of vision is lost.
    The reason why I'm trying to reduce that line of sight raycast angle property is to improve performance. Is there a way to achieve that? If not, what purpose has the line of sight raycast angle?
     
  23. sahinyalabik77

    sahinyalabik77

    Joined:
    Mar 6, 2019
    Posts:
    2
    Nevermind, just realized that the offset value is used for that :)
     
    stu_pidd_cow likes this.
  24. stansison

    stansison

    Joined:
    Feb 20, 2016
    Posts:
    28
    Is it possible to configure the "fog" match unity's tiles in 3d physics? My project works with a tile based 3d game and I'd like to control the revealed areas of the fog by unity units.
     
  25. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    233
    FogOfWar only works with raycasts out of the box. You might be interested in overriding the behaviour in FogOfWarUnit.CalculateLineOfSightCells() to do exactly what you want. Feel free to email me if you're having any trouble with it.
     
  26. stansison

    stansison

    Joined:
    Feb 20, 2016
    Posts:
    28
    Does FOW 2d mode work with 2d Edge colliders? I’m testing with dynamically generated walls with line renderer + edge colliders in 2d mode. I’m seeing some sort of reaction but the fog shape is off.
     
  27. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    233
    Do you have a screen shot of what your trying and what's happening? My tests have shown edge colliders work like anything else.
     
  28. stansison

    stansison

    Joined:
    Feb 20, 2016
    Posts:
    28
    Thank you for the reply, with that confirmation I played around with the settings a bit more. A scaling transform was being applied to the collider by a parent. It's working now.
     
  29. tomph

    tomph

    Joined:
    Nov 6, 2013
    Posts:
    33
    Hey! What's the easiest method to "exclude" a layer from my fog so that it's always visible? I want my walls to be visible but not room contents...

    I tried to go down the route of putting a FogOfWarUnit component on my walls and using the Mesh shape, but I have a feeling this is overkill?
     
  30. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    233
    The best way is to have a child camera inside your main camera. The main camera will apply the fog, and the second will draw on top without the fog.
     
  31. tomph

    tomph

    Joined:
    Nov 6, 2013
    Posts:
    33
    Cool, thought this might be the case. Thanks!
     
  32. tomph

    tomph

    Joined:
    Nov 6, 2013
    Posts:
    33
    Actually, that's not going to work because it's going to draw my (3D) walls over the top of everything...
     
  33. tomph

    tomph

    Joined:
    Nov 6, 2013
    Posts:
    33
    I have a different question... How do I retain my Bloom effect in URP? As soon as I add alpha to my fog colour, it looses the Bloom effect
     
  34. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    233
    Hmmm it sounds like a render order thing. Could you try changing line 12 in FogOfWarURPFeature.cs from:
    Code (CSharp):
    1. _fowPass = new FogOfWarURPPass(RenderPassEvent.BeforeRenderingPostProcessing);
    to:
    Code (CSharp):
    1. _fowPass = new FogOfWarURPPass(RenderPassEvent.AfterRenderingPostProcessing);
    and see if that fixes it?
     
  35. tomph

    tomph

    Joined:
    Nov 6, 2013
    Posts:
    33
    Bingo! Thanks, that worked :)
     
    stu_pidd_cow likes this.
  36. Harjawalda

    Harjawalda

    Joined:
    Sep 1, 2018
    Posts:
    15
    Hi, I have troubles getting the LineOfSight feature to work. I'm using the legacy render pipeline with the PP SV2 set up. I added some occluders with colliders to a layer and set this as the designated line of sight mask but it has no effect. I tried to change their height to ensure they have an overlap with the fow-layer but that didnt do anything. Any ideas?
     
  37. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    233
    Some things to check:
    • Can you see a bunch of lines in the viewport around the unit? These indicate the rays that are being cast.
    • Ensure that the Physics option on the FogOfWarTeam component is set correctly.
    • Ensure the light of sight layer mask includes the collider's layer.
    If this doesn't work, could you send me a screenshot of you FogOfWarTeam and FogOfWarUnit component?
     
  38. Harjawalda

    Harjawalda

    Joined:
    Sep 1, 2018
    Posts:
    15
    Thanks for the reply, for some reason there where no raycasts sent. After I changed the settings from 3D/2D Software/Hardware it suddenly worked. Thanks
     
  39. Eck0

    Eck0

    Joined:
    Jun 6, 2017
    Posts:
    48
    Hello, I am interested in this package, I wanted to know if it is compatible with the different heights (users above can see the users below but not vice versa).
    Currently I use Ultimate fog of war but it is a bit slow when calculating the fog, I would like to know if this package is faster than ultimate fog of war, thanks
     
  40. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    233
    FogOfWar uses raycasting to check what is visible. So if the unit is raycasting from a higher point (and nothing is in the way), then should do as you want it to. For example, being on a hill will let you seem more than if you are at the bottom.

    I'm not familiar with ultimage fog of war's implementation. It seems like they have special shader requirements. FogOfWar is implemented as a post process, so it lets you use whatever shaders you want, has a constant performance cost, and has many options to optimise. If you have any issues with performance, I'm always happy to help you.
     
  41. Eck0

    Eck0

    Joined:
    Jun 6, 2017
    Posts:
    48
    hello, thanks for your prompt reply, being by raycast it worries me a lot since this method consumes a lot of resources.
     
  42. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    233
    It can be a concern if you have a large number of units, but you can disable it for units that don't need it, or modify the number of raycasts or even the layers that are affected.
     
  43. KD_Zugalu

    KD_Zugalu

    Joined:
    Jan 3, 2020
    Posts:
    6
    Hey, wondering how this works for Large maps the use multiple terrains. Right now our Game scene map is pretty huge at about 17 terrains wide by 10 high. The game will have a max 700 (per team) that would affect the fog of war and many stationery buildings. How would your FOG solution handle these kinds of numbers? The units themselves don't move very fast, if you wanted to walk the distance in real life it would take about the same amount of time.
     
  44. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    233
    It depends on the resolution of accuracy you're hoping to achieve. FogOfWar is implemented as a texture projected onto the world through a post process, so a larger texture will result in more processing. You can stretch that texture over a large area, but you might not be satisified with the blockiness of the fog.
    FogOfWar can update the fog over multiple frames which usually hides any performance hiccups, but may result in the fog being updated slower than you'd like (eg every 10 frames instead of every frame).
    Also, if you don't need the entire map activated at once, FogOfWar has a chunk manager that will automatically open and close chunks based on the position of a single unit. This may not be of use to you depending on the gameplay you're aiming for. If you can jump around to other units, then this probably won't work for you.

    Let me know if you have any other questions/concerns.
     
  45. KD_Zugalu

    KD_Zugalu

    Joined:
    Jan 3, 2020
    Posts:
    6
    The chunk feature seems promising, we turn off and on terrains except when fully zoomed out when FOG doesn't matter as much. We usually have 3x3 terrains open at one time. If possible it would be nice if it updated fast enough. Is it possible to buffer locations for when that area is reloaded? Thank you for your timely Response!
     
  46. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    233
    The chunk manager will buffer the different fog chunks for you. If it's not sufficient for what you want, you can also manage the chunking yourself by manually loading/unloading the chunks.
     
  47. KD_Zugalu

    KD_Zugalu

    Joined:
    Jan 3, 2020
    Posts:
    6
    Hey ended up downloading the asset, and having a bit of trouble with your Universal Render Pipeline 3D Sample scene, The Fog of war doesn't seem to be tracking the units correctly. I am currently on Unity version 2020.2.0f1

    By itself or with a bunch of the setting changed the scene doesn't seem to work properly. The clear area is never behind the unit unless looking from straight above the unit. Any clues or suggestions on how to fix this? or what I could be doing wrong, or maybe layers that are messed up because of the project's other uses.
     
  48. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    233
    Have you ticked the Depth Buffer tick box on the UniversalRenderPipelineAsset?
    Make sure you go through the setup steps in the user guide.
    Also, Is this just happening in editor or in a build?
     
  49. KD_Zugalu

    KD_Zugalu

    Joined:
    Jan 3, 2020
    Posts:
    6
    Do you mean Depth Texture? cause that is ticked, and I just built and it doesn't work in both editor or build.
     
  50. KD_Zugalu

    KD_Zugalu

    Joined:
    Jan 3, 2020
    Posts:
    6
    Ok so i made a new project and redid the setup and now its working in that project. Both URP, both the same version. I may have to look into this more to find the differences.