Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Fog of War

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

  1. crocodilepp

    crocodilepp

    Joined:
    Apr 1, 2013
    Posts:
    1
    I'm running URP + WebGL and got some problems.
    Unity version is 2021.3.2f1

    1. In the FogOfWarURP shader, target shader model is 4.5
    Code (CSharp):
    1. pragma target 4.5
    I have to change it to 3.5, otherwise it will pop this error
    Code (CSharp):
    1. Fog Of War: The following shader is not supported: Hidden/FogOfWarURP
    Is there any features from shader model 4.0+ being used? Since WebGL 2.0 only supports OpenGL ES 3.0, I'm guessing targeting beyond 3.5 won't work for WebGL

    2. Once I changed #pragma target 4.5 to 3.5, there's still no fog when running in Firefox firefox.png
    However when running in Chrome, I can see fog but whole screen turns upside-down
    chrome.png

    Any help would be appreciated.
     
  2. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    210
    I believe I've fixed this issue but it hasn't been released yet. Could you send me an email (you can find it on the asset store page or in the user guide) and I'll send you an updated unitypackage.
     
  3. betaFlux

    betaFlux

    Joined:
    Jan 7, 2013
    Posts:
    110
    Greetings! I encountered a little issue. In Unity 2022.1.0f1 with URP 13.1.8, as soon as I add the FogOfWarURPFeature I get spammed with following error:


    You can only call cameraColorTarget inside the scope of a ScriptableRenderPass. Otherwise the pipeline camera target texture might have not been created or might have already been disposed.
    UnityEngine.Rendering.Universal.ScriptableRenderer:get_cameraColorTarget ()
    FoW.FogOfWarURPFeature:AddRenderPasses (UnityEngine.Rendering.Universal.ScriptableRenderer,UnityEngine.Rendering.Universal.RenderingData&) (at Assets/FogOfWar/Core/URP/FogOfWarURPFeature.cs:17)
    UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)


    I can still enter play mode, but seeing this red line all the time freaks me out! :) I guess it's a compatibility issue?
     
  4. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    210
    Thanks for pointing this out!
    I have a fix for this. Could you send me an email (you can find it on the asset store page or in the user guide) and I'll send you a unity package with the fix.
     
  5. betaFlux

    betaFlux

    Joined:
    Jan 7, 2013
    Posts:
    110
    Sent! Thank you for your support and this great, reliable asset!
     
    stu_pidd_cow likes this.
  6. dmit0820

    dmit0820

    Joined:
    Jun 28, 2021
    Posts:
    3
    Thanks for the awesome asset! I am having one issue though. When using URP and building for the Quest 2 it gets stuck at the Unity logo, which flashes and is frozen in place. It works in the editor and on the Quest 2 when I switch from multi-view to multi-pass, but multi-pass is very slow and has it's own issues. I've tried both hardware and software mode and still no luck getting it to work with multi-view. Any ideas?
     
  7. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    210
    I've had trouble with multi-pass in the past, but last I heard it was working (although performance may be worse).
    Are you able to see logs of what is happening?
     
  8. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    210
    There appears to be a compatability issue with Unity 2021.3+ in URP when using SSAO or Screenspace Shadows. Turning these off on the Universal Render Data will make Fog Of War work properly. I'm currently looking into a fix for the issue.
     
    Rodakai likes this.
  9. dmit0820

    dmit0820

    Joined:
    Jun 28, 2021
    Posts:
    3
    Here's the error that comes up and a related thread, it looks like it's Oculus specific and possibly related to an OnGui call. I'm using Unity 2020.3.34. Maybe there's some kind of work around?

    Edit: On Vulcan it starts without error and the profiler shows everything is running, although the screen is grey.
     

    Attached Files:

    Last edited: May 26, 2022
  10. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    210
    Interesting. As far as I can tell from some dead end forum posts, it looks like this might be on unity's end.

    Could you try using a different renderer? You can do this in Player Settings > Other Setting and changing the order of items in the Graphics API list.

    Unfortunately, I don't have a Quest 2 to test this so I can't do this myself :(
     
  11. dmit0820

    dmit0820

    Joined:
    Jun 28, 2021
    Posts:
    3
    On OpenGLES2 it has a black screen and this error:
    OpenGLES2.PNG
    On OpenGLES3 it has a black screen and this error:
    OpenGLES3.PNG
    On Vulcan everything seems to be working according to the profiler and there are no errors, but the screen is completely gray. I notice a significant FPS increase when I look up(away from all the units), so presumably they're being rendered but are not visible.
     
  12. endseeker2

    endseeker2

    Joined:
    May 19, 2021
    Posts:
    2
    when you draw on the hardware, there is a step to read from the render texture then do the fade and blur on CPU, reading from the renderer is very slow, if you dont have to read from the renderer and do everything on the GPU this will be much faster.
    upload_2022-5-26_17-30-56.png
     
  13. bugcamper

    bugcamper

    Joined:
    Mar 15, 2022
    Posts:
    11
    the Semaphore.WaitForSignal is huge chunk of time, @stu_pidd_cow I hope you will find time to optimize it.
     
    Last edited: May 27, 2022
  14. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    210
    Semaphore.WaitForSignal is a symptom of the issue, rather than the issue itself.

    Yes, this is currently an issue for hardware mode but is required due to the CPU needing to query the fog texture (usually by FogOfWarUnit to test for visibility). I'm currently working on a solution that erradicates this, but it will require a rewrite of some of the more complex areas of the system.
    In the meantime, I recommend sticking to software mode, or keeping your Map Resolution as low as possible. You should also disable Output To Texture for any FogOfWarTeams that are not currently visible.
     
    bugcamper likes this.
  15. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    210
    This OpenGLES2 error sounds promising. According to here, depth buffers aren't supported on RenderTextures. This should be easy to test. Could you try the following:
    1. Remove any FogOfWarClearFog scripts in the scene.
    2. Go to FogOfWarDrawerHardware.cs and change the following line in OnInitialise() from:
      Code (CSharp):
      1. _renderTexture = new RenderTexture(_map.resolution.x, _map.resolution.y, 16, RenderTextureFormat.ARGB32);
      to:
      Code (CSharp):
      1. _renderTexture = new RenderTexture(_map.resolution.x, _map.resolution.y, 0, RenderTextureFormat.ARGB32);
    Hopefully that will fix the issue. I'll try to come up with a better solution for the clear fog in the meantime.
     
  16. Kairge

    Kairge

    Joined:
    Jul 19, 2016
    Posts:
    1
    upload_2022-6-5_12-31-55.png
    in 2020.3.18f ,urp upload_2022-6-5_12-32-31.png ,and just like this
     
  17. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    210
    I have tested with 2020.3.34f1 and it appears to work fine. Could you send me an email and I'll try sending you general fix that may rectify this?
     
  18. schorsch_unity

    schorsch_unity

    Joined:
    May 9, 2022
    Posts:
    1
    Since there is still no officially released fix, you can fix it by applying the following changes (in version 1.24):

    Code (CSharp):
    1. Index: Assets/FogOfWar/Core/URP/FogOfWarURPFeature.cs
    2. ===================================================================
    3. diff --git a/Assets/FogOfWar/Core/URP/FogOfWarURPFeature.cs b/Assets/FogOfWar/Core/URP/FogOfWarURPFeature.cs
    4. --- a/Assets/FogOfWar/Core/URP/FogOfWarURPFeature.cs    (revision original)
    5. +++ b/Assets/FogOfWar/Core/URP/FogOfWarURPFeature.cs    (date 1660475479570)
    6. @@ -14,7 +14,7 @@
    7.          public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    8.          {
    9. -            _fowPass.Setup(renderer.cameraColorTarget);
    10. +            // _fowPass.Setup(renderer.cameraColorTarget);
    11.              renderer.EnqueuePass(_fowPass);
    12.          }
    13.      }
    14. Index: Assets/FogOfWar/Core/URP/FogOfWarURPPass.cs
    15. ===================================================================
    16. diff --git a/Assets/FogOfWar/Core/URP/FogOfWarURPPass.cs b/Assets/FogOfWar/Core/URP/FogOfWarURPPass.cs
    17. --- a/Assets/FogOfWar/Core/URP/FogOfWarURPPass.cs    (revision original)
    18. +++ b/Assets/FogOfWar/Core/URP/FogOfWarURPPass.cs    (date 1660477145891)
    19. @@ -100,6 +100,7 @@
    20.              CommandBuffer cmd = CommandBufferPool.Get("FogOfWarURP");
    21. +            _postProcess.sourceTarget = renderingData.cameraData.renderer.cameraColorTargetHandle.nameID;
    22.              _postProcess.Setup(cmd, ref context, ref renderingData);
    23.              _postProcess.team = _fowURP.team.value;
    24.              _postProcess.camera = renderingData.cameraData.camera;
    25.  
     
    sarahnorthway and stu_pidd_cow like this.
  19. Philipp3p

    Philipp3p

    Joined:
    Nov 15, 2017
    Posts:
    3
    Is there any way to make a fog of war similar to the one in the image? (as if it were smoke)

     
    Last edited: Mar 2, 2023
  20. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    210
    I think the best way to achieve this would be to have a slightly grey-colored fog, and on the FogOfWarUnit component, have a large radius with a small inner radius (so that there is more falloff). You can also experiment with the clear fog functionality to have a more non-uniform smokey look.
     
  21. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    255
    Is there a way to set a specific fog value for a shape (e.g. I have a hex shape using a texture) instead of just bounds like in FogOfWarTeam.SetFog?
     
  22. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    210
    Are you talking about the brightness of the shape, or the shape itself?
    There is the Brightness slider on the FogOfWarUnit component to adjust that.
    For the shape, you can input a single channel texture into the Texture field on the FogOfWarUnit component.
    upload_2023-3-28_10-36-58.png
     
  23. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    255
    Thanks. I am aware of this. I was looking for a function which clears fog from 255 down to a certain value without using a FogOfWarUnit like the SetFog function in FogOfWarTeam, but using a texture or a mesh.
     
  24. stu_pidd_cow

    stu_pidd_cow

    Joined:
    Aug 4, 2014
    Posts:
    210
    There's nothing to do this out of the box. I'd recommend just instantiating a FogOfWarUnit and placing it where you want. You can hide it again after a single frame to reuse it for later.
    If you still want to go the code route, you can modify the code in FogOfWarTeam.ProcessUnits() (especially where it calls FogOfWarUnit.GetShape()). You would want to create your own FogOfWarShape to send to the drawer. Feel free to email me if you want help with it.