Author Topic: Tasharen Fog of War  (Read 105823 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #135 on: March 24, 2015, 03:38:32 PM »
To make it easier, I created a unitypackage for it. I'll include this example in the next update.

JOKaija

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: Tasharen Fog of War
« Reply #136 on: March 24, 2015, 04:16:32 PM »
Did I miss something.

I'm going to release my game as multiplatform game.

BUT!!! I can't compile it for Windows Store!

The reason is, that System.Threading doesn't include Thread definition.

HOWEVER, I can compile a native WP8 version without problem. And it works.
But, Micro$oft sucks (as you know), and I have to build Store acceptable
version of my game if I want to sell it on Micro$oft stores...

What to do?

ETM

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Tasharen Fog of War
« Reply #137 on: March 25, 2015, 05:30:45 AM »
Much obliged. It works, but I am stuck again. I am trying to get the output shader into ugui. I tried using the minimap fow material for the raw image, putting a camera above the quad to film it and then rendering a texture, but without any success. The raw image component paints a transparent image, when I click on the material, it looks fine in the inspector.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #138 on: March 25, 2015, 11:58:47 AM »
@JOKaija: You will need to figure out what's different between their APIs and where Threading now resides I suppose. That sounds like a question for Microsoft's documentation.

@ETM: Sorry, but I can't assist you with uGUI. If it was NGUI, I could. Keep in mind minimap in general is outside the scope of the Fog of War kit to begin with. I included the scripts simply because I already had to do it for Windward.

ETM

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Tasharen Fog of War
« Reply #139 on: March 26, 2015, 04:22:20 AM »
Understood. Would you consider lowering the price for this pack, because there are at least two assets with FOW and minimap support for about half the price?

Just curious.

piotrO

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Tasharen Fog of War
« Reply #140 on: March 27, 2015, 03:38:41 AM »
1. Yes, it will handle it just fine, especially if you stick to the image effect-based approach.

2. Depends on what you'd like to integrate. By default the kit will use an image-effect based approach, meaning it will just work as a post-process effect, without the need to create any shaders on your part.

Thanks Aren, the plugin works perfectly.

Sudarmin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Tasharen Fog of War
« Reply #141 on: April 16, 2015, 05:24:14 AM »
This plugin works great, but I have 1 issue, when my player gets near a wall, I can see both what's inside my room and what's inside the next room. How do I fix this? I don't want the player to be able to see pass through the wall when he is near it.
Below are the images. I've tried changing the X 'Range' value in FOW Revealer, but it makes the view darker

It works great in here, I can't see the surrounding that is blocked by the wall


I can see what's inside the next room and my room when the players is near the wall

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #142 on: April 16, 2015, 08:25:00 AM »
This can be caused by a few things off the top of my head:

1. Your sampled grid is not fine enough, so as your player gets close to the wall, it effectively overlaps with the wall's "node", thus being able to see through it due to being inside it.

2. The range's X parameter being set too large. It should be no larger than the radius of your character. Not sure what you meant by "view becoming darker" -- the Y parameter should be clearing that fog, not the X. If it isn't, then it leads to #3:

3. Your revealer may not be in the right place. It should be positioned at the character's eye level, and it needs to be above the floor but below the wall's height.

Sudarmin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Tasharen Fog of War
« Reply #143 on: April 16, 2015, 11:35:02 PM »
Hi Aren, thanks for the quick reply
I found the problem, it is because I accidentally put the Raycast Radius to more than 10, when I put it back to 0.5 and reduce the X range parameter to only the radius of the character, it works as I want it to be  :)
Thanks!!

yuni

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: Tasharen Fog of War
« Reply #144 on: May 19, 2015, 03:05:31 AM »
Hi
Shader compile error!
Please take a look at what the problem of this code.

Shader "Fog of War/4TexturesDiffuseFastFow"
{
   Properties
   {
      _Color ("Main Color", Color) = (1,1,1,1)
      _Layer1 ("Layer1 (RGB)", 2D) = "white" {}
      _Layer2 ("Layer2 (RGB)", 2D) = "white" {}
      _Layer3 ("Layer3 (RGB)", 2D) = "white" {}
      _Layer4 ("Layer4 (RGB)", 2D) = "white" {}
      _MainTex ("Mask (RGB)", 2D)  = "white" {}   
   }

   SubShader
   {
      Tags
      {
            "SplatCount"      = "4"
            "Queue"         = "Geometry-100"
            "RenderType"      = "Opaque"
      }                   

      CGPROGRAM
      #pragma surface surf Lambert exclude_path:prepass   noforwardadd halfasview novertexlights approxview   
   
      sampler2D _MainTex;
      sampler2D _Layer1, _Layer2, _Layer3,_Layer4;
      fixed4    _Color;

      sampler2D _FOWTex0, _FOWTex1;
      uniform float4    _FOWParams;
      uniform half4     _FOWUnexplored;
      uniform half4     _FOWExplored;      

      struct Input
      {
         float2 uv_MainTex : TEXCOORD0;
         float2 uv_Layer1  : TEXCOORD1;
         float2 uv_Layer2  : TEXCOORD2;
         float2 uv_Layer3  : TEXCOORD3;
         float2 uv_Layer4  : TEXCOORD4;

         float2 fog        : TEXCOORD5;
      };   

      void vert (inout appdata_full v, out Input o)
      {
         UNITY_INITIALIZE_OUTPUT(Input, o);
         
         float4 worldPos = mul (_Object2World, v.vertex);
         o.fog.xy = worldPos.xz * _FOWParams.z + _FOWParams.xy;
      }
                                            
      void surf (Input IN, inout SurfaceOutput o)
      {     
         fixed4 Mask = tex2D(_MainTex, IN.uv_MainTex);
         half4 col;
         col  = Mask.r * tex2D (_Layer1, IN.uv_Layer1);
         col += Mask.g * tex2D (_Layer2, IN.uv_Layer2);
         col += Mask.b * tex2D (_Layer3, IN.uv_Layer3);
         col += Mask.a * tex2D (_Layer4, IN.uv_Layer4);

         half4 fog = lerp(tex2D(_FOWTex0, IN.fog), tex2D(_FOWTex1, IN.fog), _FOWParams.w);

         //col = lerp(lerp(col * _FOWUnexplored, col * _FOWExplored, fog.g), col, fog.r);   <-- this code problem

         o.Albedo = col.rgb;
         o.Alpha  = col.a;
      
      }         
   
      ENDCG
   }
}





ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #145 on: June 01, 2015, 09:48:07 PM »
That line isn't causing any issues, but the terrain shader does have problems with Unity 5. I don't know what they changed on their end but the shader that works fine in Unity 4 no longer has enough interpolator units and fails to work in Unity 5. It's on the list of things for me to look into at some point, but right now I am extremely busy with Windward.

I suggest sticking with the image-effect based approach, it works fine.

directedchaos

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Tasharen Fog of War
« Reply #146 on: June 20, 2015, 10:51:10 PM »
It's a great effect, and using the provided shaders (terrain and diffuse) I got a simple scene running seemingly without a framerate hit on an iPhone 5.  Awesome!  I know it's not your target platform, but you might include some simple notes/suggestions.  For example, here's how I got it working (probably obvious to those more experienced with shaders):
  • You have to go to Terrain Settings and set the Material to a material that uses the shader Fog of War/Terrain
  • It only seems to support 4 textures on a  terrain.  Textures after that were always full brightness.
  • You have to set the shader for anything with Diffuse shaders that you want to have this effect to Fog of War/Diffuse
Using those shaders was a bit of a breakthrough for me.  Using the effect on the camera showed cool results, but really hit the framerate hard on mobile.

I have two questions:
  • Can you include more shaders, particularly Transparent/Cutout/Diffuse?  Or has anybody else created one that samples the Fog of War texture properly?
  • How does the memory footprint scale?  I mean, does it just increase with the World Size and Texture Size parameters, not with the size of the objects (like terrain) that use the shaders?
Again, it's a great effect, and I'm excited about using it!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #147 on: June 21, 2015, 09:47:12 PM »
You should be able to use the Fog of War/Diffuse shader as an example to create your own version of any shader you need. Check the shader's code: there are 4 things that need to be added for the fog to work, and all 4 are commented for you.

Texture size will naturally increase the memory footprint and will also make the FOW's logic slower as it will need to update more pixels. Larger textures also take longer to upload to the GPU, possibly causing stutters when they need to get updated.

directedchaos

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Tasharen Fog of War
« Reply #148 on: June 22, 2015, 11:10:36 PM »
Thanks for getting back to me!  Unfortunately I know very little about shaders, and my simple copy-paste of those 4 sections to the built-in "Transparent/Cutout/Diffuse" (download built-in shaders source code, AlphaTest-Diffuse.shader) results in odd stripes.  I suspect step 3 doesn't apply cleanly to the cutout shader.  I've played with all kinds of conversions (float, half, fixed), nothing seemed to change it, but if I force the fog.g and fog.r properties I can see it is blending properly.  So I think it's just not mapping to the right spot in the fog texture.  Also odd, the striping seems to change with the camera (the revealer isn't moving, just the camera).

Here's what I have:
  1. Shader "Custom/Cutout Diffuse (FoW)" {
  2. Properties {
  3.         _Color ("Main Color", Color) = (1,1,1,1)
  4.         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
  5.         _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
  6. }
  7.  
  8. SubShader {
  9.         Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
  10.         LOD 200
  11.        
  12. CGPROGRAM
  13. #pragma surface surf Lambert alphatest:_Cutoff
  14.  
  15. sampler2D _MainTex;
  16. fixed4 _Color;
  17.  
  18. // FOW #1: Requires parameters (set by FOWSystem)
  19. sampler2D _FOWTex0, _FOWTex1;
  20. float4 _FOWParams;
  21. half4 _FOWUnexplored, _FOWExplored;
  22.  
  23. struct Input {
  24.         float2 uv_MainTex;
  25.  
  26.         // FOW #2: Fog texture coordinates
  27.         float2 fog : TEXCOORD2;
  28. };
  29.  
  30. void vert (inout appdata_full v, out Input o)
  31. {
  32.         UNITY_INITIALIZE_OUTPUT(Input, o);
  33.  
  34.         // FOW #3: Set the fog texture coordinates
  35.         float4 worldPos = mul (_Object2World, v.vertex);
  36.         o.fog.xy = worldPos.xz * _FOWParams.z + _FOWParams.xy;
  37. }
  38.  
  39. void surf (Input IN, inout SurfaceOutput o) {
  40.         fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  41.        
  42.         // FOW #4: Tint the final color by the Fog of War
  43.         half4 fog = lerp(tex2D(_FOWTex0, IN.fog), tex2D(_FOWTex1, IN.fog), _FOWParams.w);
  44.         c.rgb = lerp(lerp(c.rgb * _FOWUnexplored, c.rgb * _FOWExplored, fog.g), c.rgb, fog.r);
  45.  
  46.         o.Albedo = c.rgb;
  47.         o.Alpha = c.a;
  48. }
  49. ENDCG
  50. }
  51.  
  52. Fallback "Transparent/Cutout/Diffuse"
  53. }
  54.  

Here's Unity's built-in shader I'm trying to add Fog of War to:
  1. Shader "Transparent/Cutout/Diffuse" {
  2. Properties {
  3.         _Color ("Main Color", Color) = (1,1,1,1)
  4.         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
  5.         _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
  6. }
  7.  
  8. SubShader {
  9.         Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
  10.         LOD 200
  11.        
  12. CGPROGRAM
  13. #pragma surface surf Lambert alphatest:_Cutoff
  14.  
  15. sampler2D _MainTex;
  16. fixed4 _Color;
  17.  
  18. struct Input {
  19.         float2 uv_MainTex;
  20. };
  21.  
  22. void surf (Input IN, inout SurfaceOutput o) {
  23.         fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  24.         o.Albedo = c.rgb;
  25.         o.Alpha = c.a;
  26. }
  27. ENDCG
  28. }
  29.  
  30. Fallback "Transparent/Cutout/VertexLit"
  31. }
  32.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #149 on: June 25, 2015, 09:45:46 PM »
You forgot to specify the vertex shader in your #pragma define:
  1. #pragma surface surf Lambert alphatest:_Cutoff
should be:
  1. #pragma surface surf Lambert vertex:vert alphatest:_Cutoff