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

illumina

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Tasharen Fog of War
« Reply #15 on: March 08, 2013, 04:26:06 AM »
Thanks for the prompt response. Two things

1) our game is an action rpg, so the fog needs to be fairly responsive. Kind of like Starcraft. I don't think I can get away with 2 per second, but I'll double check again.

2) could you elaborate a bit on the shader strategy you're suggesting for iOS? Are you suggesting not to use a screen effect but instead use multi texturing and have each objects shader know whether to tint itself & do the blending?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,152
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #16 on: March 08, 2013, 05:03:30 AM »
Pretty much. Sample not just the material's main texture, but also the fog's texture at the world coordinates of the pixel.

valsimot

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: Tasharen Fog of War
« Reply #17 on: May 10, 2013, 09:54:39 AM »
Hi this is a great tool, but I have crazy draw calls issue when I enable FOWEffect script on camera.

This is with no FOW effect


And this is what happens when I enable it (no revealer on scene, but it's same with or without it)


There are few hundred unity cubes on the scene and draw calls where always less then 30. Can you tell me why this draw call issue happens with FOW?

Unity 4.1.2. Pro, Win 7.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,152
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #18 on: May 10, 2013, 11:39:21 PM »
You see the "saved by batching" part to the right of draw calls? Dynamic batching doesn't work in many situations. You need to use either static batching (mark objects as "static" so they get batched), or just find a way to not have such an obscene number of draw calls to begin with.

carfi

  • Guest
blocker
« Reply #19 on: May 25, 2013, 05:51:34 AM »
In Examples Scenes´╝ÜOutdoor
I add a cube and my object in the scenes.Like this:

They both have collider component.
They both in aaa layer.

But they don't block the line.Like this:

Where I set error?
I am a newbie.Please teach me how to add the blocker.
Thank you so much!
« Last Edit: May 26, 2013, 01:55:22 AM by carfi »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,152
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #20 on: May 25, 2013, 08:19:53 PM »
When do you add them? For this to work you have to add them before hitting Play.

carfi

  • Guest
Re: Tasharen Fog of War
« Reply #21 on: May 25, 2013, 09:55:10 PM »
My unity version is 4.0.1f2 pro
Import the package - open the "Outdoor" scene - add my object - set object layer - set raycast mask - play
Am I set error in other setting?
« Last Edit: May 25, 2013, 10:28:58 PM by carfi »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,152
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #22 on: May 26, 2013, 12:02:22 AM »
Nope, that's it. I just tried it myself to double check. Imported the package, added a cube to the scene, scaled it to 10, 10, 1, positioned it, hit Play -- works.

Added a new layer, changed the cube to be on that layer, and added this layer to the FOWSystem, hit Play -- works.

I did not modify anything else. I noticed you modified other properties -- such as Height Range. Your cube is likely taller than 8.6 units, so raycasts won't see it. I also did not modify the texture size -- default is 128, yours is at 56.

carfi

  • Guest
Re: Tasharen Fog of War
« Reply #23 on: May 26, 2013, 01:54:41 AM »
o~Thank you very much!!!!again and again!!!
I download the package again~~~~~it work~!!!!!

Thank you for your answer,I find my Problem!

cristiansr

  • Guest
Re: Tasharen Fog of War
« Reply #24 on: June 04, 2013, 12:56:40 PM »
I downloaded the "Unity Built-in Shaders" to take a look, and applied the code sent by @shiva.js for uses Fog in Mobile.
I attached the code to each object on the scene, but the terrain uses "Nature/Terrain/Diffuse" shader and I need adapt code for this shader...
I made some changes in the code, and now I have this:

  1. Shader "Mobile/Fog of War/Nature/Terrain/Diffuse" {
  2. Properties {
  3.         [HideInInspector] _Control ("Control (RGBA)", 2D) = "red" {}
  4.         [HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {}
  5.         [HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {}
  6.         [HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {}
  7.         [HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {}
  8.         // used in fallback on old cards & base map
  9.         [HideInInspector] _MainTex ("BaseMap (RGB)", 2D) = "white" {}
  10.         [HideInInspector] _Color ("Main Color", Color) = (1,1,1,1)
  11. }
  12.        
  13. SubShader {
  14.         Tags {
  15.                 "SplatCount" = "4"
  16.                 "Queue" = "Geometry-100"
  17.                 "RenderType" = "Opaque"
  18.         }
  19.         Pass
  20.         {
  21.                 CGPROGRAM
  22. //              #pragma surface surf Lambert
  23.                
  24.                 struct Input {
  25.                         float2 uv_Control : TEXCOORD0;
  26.                         float2 uv_Splat0 : TEXCOORD1;
  27.                         float2 uv_Splat1 : TEXCOORD2;
  28.                         float2 uv_Splat2 : TEXCOORD3;
  29.                         float2 uv_Splat3 : TEXCOORD4;
  30.                 };
  31.                
  32.                 sampler2D _Control;
  33.                 sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
  34.                
  35.                 void surf (Input IN, inout SurfaceOutput o) {
  36.                         fixed4 splat_control = tex2D (_Control, IN.uv_Control);
  37.                         fixed3 col;
  38.                         col  = splat_control.r * tex2D (_Splat0, IN.uv_Splat0).rgb;
  39.                         col += splat_control.g * tex2D (_Splat1, IN.uv_Splat1).rgb;
  40.                         col += splat_control.b * tex2D (_Splat2, IN.uv_Splat2).rgb;
  41.                         col += splat_control.a * tex2D (_Splat3, IN.uv_Splat3).rgb;
  42.                         o.Albedo = col;
  43.                         o.Alpha = 0.0;
  44.                 }
  45.                 ENDCG
  46.         }
  47.        
  48.         Pass
  49.         {
  50.                 CGPROGRAM
  51.                 #pragma vertex vert_surf
  52.                 #pragma fragment frag_surf
  53.                
  54.                 #include "UnityCG.cginc"
  55.        
  56.                 struct v2f_surf {
  57.                     float4  pos : SV_POSITION;
  58.                     float2  uv : TEXCOORD0;
  59.                    
  60.                     float2 fog : TEXCOORD2;
  61.                 };
  62.                
  63.                 float4 _Color;
  64.                 sampler2D _MainTex;
  65.                
  66.                 //begin regin FOG_OF_WAR
  67.                 sampler2D _FogTex0;
  68.                 sampler2D _FogTex1;
  69.                 uniform float4 _Params;
  70.                 uniform half4 _Unexplored;
  71.                 uniform half4 _Explored;
  72.                 //end regin
  73.                
  74.                 float4 _MainTex_ST;
  75.                
  76.                 v2f_surf vert_surf (appdata_full v) {
  77.                         v2f_surf o;
  78.                  
  79.                     o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
  80.                     o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
  81.                    
  82.                     float4 worldPos = mul (_Object2World, v.vertex);
  83.                     o.fog.xy = worldPos.xz * _Params.z + _Params.xy;
  84.                  
  85.                         return o;
  86.                 }
  87.                
  88.                 half4 frag_surf (v2f_surf IN) : COLOR
  89.                 {
  90.                         half4 c = tex2D (_MainTex, IN.uv);
  91.                        
  92.                         half4 fog = lerp(tex2D(_FogTex0, IN.fog), tex2D(_FogTex1, IN.fog), _Params.w);
  93.                         c= lerp(lerp(c * _Unexplored, c * _Explored, fog.g), c, fog.r);
  94.                  
  95.                         return c * _Color;
  96.                 }
  97.                 ENDCG
  98.         }
  99. }
  100.  
  101. Dependency "AddPassShader" = "Hidden/TerrainEngine/Splatmap/Lightmap-AddPass"
  102. Dependency "BaseMapShader" = "Diffuse"
  103.  
  104. Fallback "Mobile/Fog of War/Diffuse"
  105. }
  106.  

as it was before:
  1. Shader "Nature/Terrain/Diffuse" {
  2. Properties {
  3.         [HideInInspector] _Control ("Control (RGBA)", 2D) = "red" {}
  4.         [HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {}
  5.         [HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {}
  6.         [HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {}
  7.         [HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {}
  8.         // used in fallback on old cards & base map
  9.         [HideInInspector] _MainTex ("BaseMap (RGB)", 2D) = "white" {}
  10.         [HideInInspector] _Color ("Main Color", Color) = (1,1,1,1)
  11. }
  12.        
  13. SubShader {
  14.         Tags {
  15.                 "SplatCount" = "4"
  16.                 "Queue" = "Geometry-100"
  17.                 "RenderType" = "Opaque"
  18.         }
  19. CGPROGRAM
  20. #pragma surface surf Lambert
  21. struct Input {
  22.         float2 uv_Control : TEXCOORD0;
  23.         float2 uv_Splat0 : TEXCOORD1;
  24.         float2 uv_Splat1 : TEXCOORD2;
  25.         float2 uv_Splat2 : TEXCOORD3;
  26.         float2 uv_Splat3 : TEXCOORD4;
  27. };
  28.  
  29. sampler2D _Control;
  30. sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
  31.  
  32. void surf (Input IN, inout SurfaceOutput o) {
  33.         fixed4 splat_control = tex2D (_Control, IN.uv_Control);
  34.         fixed3 col;
  35.         col  = splat_control.r * tex2D (_Splat0, IN.uv_Splat0).rgb;
  36.         col += splat_control.g * tex2D (_Splat1, IN.uv_Splat1).rgb;
  37.         col += splat_control.b * tex2D (_Splat2, IN.uv_Splat2).rgb;
  38.         col += splat_control.a * tex2D (_Splat3, IN.uv_Splat3).rgb;
  39.         o.Albedo = col;
  40.         o.Alpha = 0.0;
  41. }
  42. ENDCG  
  43. }
  44.  
  45. Dependency "AddPassShader" = "Hidden/TerrainEngine/Splatmap/Lightmap-AddPass"
  46. Dependency "BaseMapShader" = "Diffuse"
  47.  
  48. // Fallback to Diffuse
  49. Fallback "Diffuse"
  50. }
  51.  

This is it, do you have any idea to solve that? (Especially in relation to the part of splats)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,152
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #25 on: June 06, 2013, 12:20:11 PM »
What are you trying to do here, and why did you add a second pass? Are you trying to add Fog of War to the terrain shader?

ounick

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Tasharen Fog of War
« Reply #26 on: August 26, 2013, 09:03:22 PM »
I currently implementing the system for mobile. 
I plan on turning it on and off cleanly at certain intervals in the game.  Do i need to find all the FOWRevealers and FOWRenderers and disable them?

Also, how do I go about using a texture (like Monaco does with their "foggy blueprint" overlay) to define the "unexplored color" instead of a solid color? Would I need to place an image plane over everything and modify its transparency?

Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,152
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #27 on: August 27, 2013, 12:46:34 PM »
The fog of war system works by changing the color, however you can have the unexplored color be fully transparent (alpha of 0), and have a background image behind it, Monaco-style. This way as you explore the map, it will slowly cover the unexplored texture. I did that with Windward, minus the background texture part.

jchowdown

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Tasharen Fog of War
« Reply #28 on: September 04, 2013, 07:02:09 PM »
The idea is to not have a post-processing effect (image effect), but to have the shader used on your game objects actually sample the fog inside.

Hi, I'm a shader newbie so please bear with my questions.

1) Assuming the fog texture has smooth transitions between explored/unexplored areas, do my shaders just sample the fog color at the position of my game object and then just color the pixels with the appropriate color? Can it be done on a per-pixel basis so that on large objects the fog colors at different points blend smoothly across the whole object?

2) How easy is it for game-level code to sample fog at a location?

3) Also, does this FOW package make it easily to have FOW that is cleared permanently (ie fog does not return to areas that are free of revealers)?

Thanks in advance,
Jeff

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,152
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #29 on: September 05, 2013, 04:29:09 AM »
FOW system has a function to check whether the object at the specified position is obscured by fog or not.

However, assuming you want the transition to be smooth, the sampling should be done in the shader, not in game code. If you're a shader newbie, then you likely won't be able to do it. There was a shader example posted on the Tasharen Fog of War thread on the Unity forums though.

As for #3 -- FOW has 3 states -- unexplored, explored, and visible. If the explored state matches your visible state, the units will remain visible even if you don't have revealers in the area.