Unity Community


Page 1 of 3 123 LastLast
Results 1 to 20 of 48

  1. Location
    Toronto, ON
    Posts
    1,901

    Tasharen Fog of War



    NOTE: This package requires Unity Pro.

    Ever wanted high-quality smooth fog of war for your strategy game? How about a line-of-sight revealing system for a heist game like Monaco? Well, now you can have it in 3 simple steps:
    1. Drag & drop the Fog of War prefab into your scene. You can find this prefab in Assets/Fog of War/FoW folder.
    2. Add FOWEffect script to your Main Camera. Make sure it references the "Image Effects/Fog of War" shader.
    3. Add FOWRevealer script to one or more game objects in your scene. It's best to add it to a game object located at around the unit's "eye level" in order for the fog of war to be accurate.
    4. Running on a mobile device or don't have Pro? You can adapt your object and environment shaders to eliminate the need for an image effect, making it perfectly suitable for mobile devices: http://forum.unity3d.com/threads/146...=1#post1022831


    What makes it great?
    • It's fast. If you already render to depth (for example using Tasharen Water), then you likely won't even notice a performance drop. In fact, with proper use of FOWRenderers hiding renderers hidden by fog you can actually increase performance.
    • All line-of-sight calculations are done on a separate thread, so they don't affect your game's performance.
    • It's smooth -- and level of smoothness also doesn't affect performance as it's done on another thread.
    • You can specify how often it updates and how quickly it fades in and out, and the two work independently. Updating only twice per second will still give you perfectly smooth fading results.
    • You can easily check to see if a point is visible, explored, or not.
    • You can optimize the worker thread's performance even further by specifying that certain line-of-sight checks should only be performed once (stationary object).
    • You get a script that can automatically hide all renderers under the game object that's hidden from view (FOWRenderers).


    Play the Demo: http://www.tasharen.com/windward/fow/
    Last edited by ArenMook; 11-18-2012 at 08:06 PM.
    NGUI Resources: Documentation | Forum | Release Notes
    Want to get notified when NGUI gets updated? Subscribe to this thread.


  2. Location
    Toronto, ON
    Posts
    1,901
    NGUI Resources: Documentation | Forum | Release Notes
    Want to get notified when NGUI gets updated? Subscribe to this thread.


  3. Posts
    13
    Great plugin. I had it integrated and working well within an hour.
    For anyone interested in this plugin for mobile devices, I opted to modify my environment shaders to lookup the fog textures instead of using the provided image effect (there are issues with sampling depth here anyway, though workarounds exist if you need to persist for whatever reason).

    Top quality, highly recommended!


  4. Location
    Toronto, ON
    Posts
    1,901
    Quote Originally Posted by shiva.js View Post
    For anyone interested in this plugin for mobile devices, I opted to modify my environment shaders to lookup the fog textures instead of using the provided image effect
    That's actually pretty clever. It's true, if you can modify the environment / unit shaders to read the fog texture, you get fog of war without the image effect, and basically completely free as far as performance cost goes.
    NGUI Resources: Documentation | Forum | Release Notes
    Want to get notified when NGUI gets updated? Subscribe to this thread.


  5. Posts
    214
    Your assets kind of makes one wanna create a strategy game instead of a shooter-like one ^^. This is definitely on the radar as well as the water, when I finished my current project I am definitely going to make a strategy game.


  6. Posts
    4
    I'm finding a bizarre issue where running in the editor by pressing "play" can execute without having a compiled shader (I think). It seems to just cause the whole screen to fade in/out instead of jus the area on the map that is revealed.

    Have you seen this happening? In particular I have TWO unity editor open when playing (networked game). Not sure if this happens with one editor open only. Building the game to run in a player seems to fix the problem for a little while. Not sure what I'm doing that breaks it again...


  7. Location
    Toronto, ON
    Posts
    1,901
    Nope, can't say I've ever seen that. Is it one of Unity 4's issues?
    NGUI Resources: Documentation | Forum | Release Notes
    Want to get notified when NGUI gets updated? Subscribe to this thread.


  8. Posts
    4
    Nope, Unity 3.5.5. I saw it happening with the example scene as well. Is there some kind of step that needs to happen in order to make sure the shaders are always compiled before running in preview from the editor?


  9. Location
    Toronto, ON
    Posts
    1,901
    Unity's bottom right corner has a spinner when something is compiling, although I'm not sure if it works properly for shaders.
    NGUI Resources: Documentation | Forum | Release Notes
    Want to get notified when NGUI gets updated? Subscribe to this thread.


  10. Posts
    4
    Looks like it has to do with running two unity instances. It seems that unity occasionally deletes the temp files (including compiled shaders) and gets confused across instances. Bummer.

    Anyway, the fog of war system is awesome. Trying to figure out the nuances of how it works... mostly so far so good. Of course documentation would be nice

    Thanks for putting this together. NGUI is awesome too.


  11. Location
    Toronto, ON
    Posts
    1,901
    I'll make a video when I have some time. Unfortunately I'm stupidly busy until October.
    NGUI Resources: Documentation | Forum | Release Notes
    Want to get notified when NGUI gets updated? Subscribe to this thread.


  12. Posts
    4
    Found a bug, do you have some kind of tool you use for reporting them?

    Basically, in FOWSystem.RevealIntoCache I have a situation where my cachedBuffer isn't square. Looks like it's due to having everything at funky floating point locations in the world. Getting a hard crash expecting to have 7 rows as opposed to 6.


  13. Location
    Cincinnati
    Posts
    92
    ArenMook,

    Does this fog work with multiple players/cameras? I'm not sure if multiplayer was built into your game or not.

    Thanks in advance


  14. Location
    Toronto, ON
    Posts
    1,901
    @illumina: not square? It's created as "size * size", which is always square. What do you mean by funky floating point locations?

    @AdamWaters: The fog is drawn as an image effect, so any camera with that effect on it will have the fog.
    NGUI Resources: Documentation | Forum | Release Notes
    Want to get notified when NGUI gets updated? Subscribe to this thread.


  15. Posts
    4
    Quote Originally Posted by shiva.js View Post
    Great plugin. I had it integrated and working well within an hour.
    For anyone interested in this plugin for mobile devices, I opted to modify my environment shaders to lookup the fog textures instead of using the provided image effect (there are issues with sampling depth here anyway, though workarounds exist if you need to persist for whatever reason).

    Top quality, highly recommended!

    Hi @ArenMook @shiva.js ,

    I bought this plugin this morning, the integration time is great , but I got trouble for mobile devices.
    The image effect shader is really a frame killer and I can't follow your solution in the quote above.

    Could you explain the solution in detail , please?


  16. Location
    Toronto, ON
    Posts
    1,901
    Just pasting my email response, for reference:
    I can't promise it soon, but there will be an update for mobile support and examples coming. I'm currently on a tight deadline (October 1st) with an insane amount of work that needs to be done by then, so I don't think I'll have much time to spend on this. Perhaps you can PM shiva.js for some code examples on what he did? The way it works is -- the fog of war system generates a pair of textures. Either one can be used, or both if you want really smooth fog of war like in the example. The idea is to get the world position and use its XZ coordinates to sample the fog of war's texture. All the code you need for that is there in the FOW.shader. You just need to use it in a surface shader that will be used by your in-game models. It would be a single pass shader without any alpha blending, so it will be very fast on mobiles.
    NGUI Resources: Documentation | Forum | Release Notes
    Want to get notified when NGUI gets updated? Subscribe to this thread.


  17. Posts
    13
    Hope this helps...


    add the following to your environment shader/s:

    Code:  
    1. sampler2D _FogTex0;
    2. sampler2D _FogTex1;
    3.  
    4. uniform float4 _Params;
    5. uniform half4 _Unexplored;
    6. uniform half4 _Explored;

    still in your shader, modify your vertex to fragment struct to include fog coords, kinda like:

    Code:  
    1. struct v2f_surf
    2. {
    3.   float4 pos : SV_POSITION;
    4.   float2 uv0 : TEXCOORD0;
    5.   float2 lmap : TEXCOORD1;
    6.   float2 fog : TEXCOORD2; // this is the new line to add
    7. };

    add the following to your vertex function:

    Code:  
    1. float4 worldPos = mul (_Object2World, v.vertex);
    2. o.fog.xy = worldPos.xz * _Params.z + _Params.xy;

    add the following to your fragment function:

    Code:  
    1. half4 fog = lerp(tex2D(_FogTex0, IN.fog), tex2D(_FogTex1, IN.fog), _Params.w);
    2. c = lerp(lerp(c * _Unexplored, c * _Explored, fog.g), c, fog.r); // where c is the fixed4 that you will return


    now, in FOWEffect.cs, replace the function with this one (note it's now a regular MonoBehaviour using OnPreRender):

    Code:  
    1. {
    2.     if (mFog == null)
    3.     {
    4.         mFog = FOWSystem.instance;
    5.         if (mFog == null) mFog = FindObjectOfType(typeof(FOWSystem)) as FOWSystem;
    6.     }
    7.  
    8.     if (mFog == null || !mFog.enabled)
    9.     {
    10.         enabled = false;
    11.         return;
    12.     }
    13.  
    14.     float invScale = 1f / mFog.worldSize;
    15.     Transform t = mFog.transform;
    16.     float x = t.position.x - mFog.worldSize * 0.5f;
    17.     float z = t.position.z - mFog.worldSize * 0.5f;
    18.     Vector4 p = new Vector4(-x * invScale, -z * invScale, invScale, mFog.blendFactor);
    19.  
    20.     Shader.SetGlobalColor("_Unexplored", unexploredColor);
    21.     Shader.SetGlobalColor("_Explored", exploredColor);
    22.     Shader.SetGlobalVector("_Params", p);
    23.     Shader.SetGlobalTexture("_FogTex0", mFog.texture0);
    24.     Shader.SetGlobalTexture("_FogTex1", mFog.texture1);
    25. }

    Let me know how it goes


  18. Location
    Toronto, ON
    Posts
    1,901
    Thank you for sharing
    NGUI Resources: Documentation | Forum | Release Notes
    Want to get notified when NGUI gets updated? Subscribe to this thread.


  19. Posts
    4
    Thank you, @shiva.js!

    I've make the plugin work on the ShadowGun Sample with your solution.
    Running great on the mobile device.



  20. Posts
    1
    The demo looks great. I have a question here, can I use the FOW texture for minimap? Or the FOW texture is only for camera view?

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •