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

rsharr

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Tasharen Fog of War
« Reply #45 on: December 06, 2013, 09:16:53 AM »
did you ever end up getting my email or pm?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #46 on: December 07, 2013, 12:51:20 AM »
Oh, yes I did, sorry. Swamped as usual. Unfortunately I don't have the time right now.

valbery

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Tasharen Fog of War
« Reply #47 on: January 15, 2014, 06:50:02 PM »
Hi,

I want buy this product but i must ask a question. Is there a way to make a building only "visible" in the fog of war?

Regards

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #48 on: January 15, 2014, 10:35:14 PM »
I am not sure what you mean. Make a building visible only in the fog of war? Fog of war hides things, not makes them visible.

valbery

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Tasharen Fog of War
« Reply #49 on: January 16, 2014, 12:36:27 PM »
Hello ArenMook,

We are developing a rts game as Age Of Empires. Our players can make building with mouse click where can they click on Terrain. Bu they must make their building only explored area in the Terrain. Are you support this feature?

Regards

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #50 on: January 17, 2014, 12:50:14 AM »
You can query to see if the specified target position is visible using FoW and prevent building if it's not.

plabrie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Tasharen Fog of War
« Reply #51 on: January 23, 2014, 01:20:58 AM »
Hi Aren,

right to business: how do you decide the texture size ?
My world is big enough and initially with the setting by default, it didn't work at all because the x,y position it took were negative and not fitting in the texture, something like this. I had to change to 2048 size, and it "works" but the texture doesn't align with my view, like a dark patch fit in a in an alley, but is offset on top of the building. (I could provide texture tomorrow possibly) But still, how do you pick your texture size ? Do I really need to update it so it fit perfectly ?

also, i would think it would be better to have the details of all the variables expose in the FOW system in the readme ?

Thank you very much.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #52 on: January 23, 2014, 07:38:05 AM »
Decide the texture size? I'm not sure what you mean. FoW will use the dimensions of the texture you specified, stretched over the region of your choice (in all directions, using transform's position as the center).

plabrie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Tasharen Fog of War
« Reply #53 on: January 23, 2014, 12:04:49 PM »
So, the issue was with the y being inverted...

http://www.tasharen.com/forum/index.php?topic=6468.0
So I fixed it with what is written in that post.

Next issue I have encounter now, is when I have the SSAOEffect enabled from Unity with the FogImage Effect. It create artifact that stay on screen. If I disable the SSAO and bring it back, it make the current artifact dissapear and new one appear.
My feeling when I see it: It seems that when the SSAO Effect is enabled, it create the texture that is blended on top, and then doesn't update it again, so when I move, it seems to move that texture on top of my scene.

I attached an image of my issue.

I can have SSAO enabled, then I enabled the FOW, disable it, and the SSAO will have that issue. I disable the SSAO, reenable it, everything work fine. Enable FOW, same issue, etc.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #54 on: January 24, 2014, 10:48:11 AM »
The new FoW version I pushed has two example scripts of how to do FoW without the post-process effect. If Unity's SSAO conflicts with other post process effects, you can adjust your object shaders to sample FoW textures instead using the provided shaders as an example. It's a simple modification, also explained here: http://www.tasharen.com/forum/index.php?topic=7662.msg36228#msg36228

ounick

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Tasharen Fog of War
« Reply #55 on: January 25, 2014, 11:50:43 AM »
I am using the fog of war system with the non-postprocess method.  It has been working pretty well.  However, I started lightmapping my levels, and everything no longer reacts to the fog of war shading.  I looked at my shader and the lightmapped pass is incomplete for the fog of war. 
Can anyone please help finish this shader to support the non-postprocess fog of war and lightmapping?

I am shader illiterate and I think my brain is about to enter melt-down.

Thanks, Nick

  1. // Unlit shader. Simplest possible textured shader.
  2. // - SUPPORTS lightmap
  3. // - no lighting
  4. // - no per-material color
  5.  
  6. Shader "Mobile/UnlitFoW(Supports Lightmap)" {
  7.         Properties {
  8.        
  9.                 _MainTex ("Base (RGB)", 2D) = "white" {}
  10.                
  11.         }
  12.        
  13.         SubShader {
  14.                 Tags { "RenderType"="Opaque" }
  15.                 LOD 100
  16.                
  17.                 // Non-lightmapped
  18.                 Pass {
  19.                         Tags { "LightMode" = "Vertex" }
  20.                         Lighting Off
  21.                         CGPROGRAM
  22.                
  23.                         #pragma vertex vert
  24.                
  25.                         #pragma fragment frag
  26.                
  27.                         #include "UnityCG.cginc"
  28.                        
  29.                         float4 _Color;
  30.                        
  31.                         sampler2D _MainTex;
  32.                        
  33.                         sampler2D _FogTex0; //fog texture variable
  34.        
  35.                         sampler2D _FogTex1; //fog texture variable
  36.        
  37.                         uniform float4 _Params; //fog variable
  38.        
  39.                         uniform half4 _Unexplored; //fog variable
  40.        
  41.                         uniform half4 _Explored; //fog variable
  42.                        
  43.                         float4 _MainTex_ST;
  44.                        
  45.                         struct v2f
  46.                         {
  47.                        
  48.                                 float4 pos : SV_POSITION;
  49.                                
  50.                                 float2 uv : TEXCOORD0;
  51.                                
  52.                                 float2 lmap : TEXCOORD1;
  53.                                
  54.                                 float2 fog : TEXCOORD2; // this is a new line
  55.                        
  56.                         };
  57.                        
  58.                         half4 frag (v2f i) : COLOR
  59.                         {
  60.                        
  61.                             half4 c = tex2D (_MainTex, i.uv);
  62.                        
  63.                             half4 fog = lerp(tex2D(_FogTex0, i.fog), tex2D(_FogTex1, i.fog), _Params.w);
  64.                        
  65.                             c = lerp(lerp(c * _Unexplored, c * _Explored, fog.g), c, fog.r); // where c is the fixed4 to return
  66.                        
  67.                             return c;// * _Color;
  68.                        
  69.                         }
  70.                        
  71.                         v2f vert (appdata_base v)
  72.                         {
  73.                        
  74.                             v2f o;
  75.                        
  76.                             o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
  77.                        
  78.                             o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
  79.                        
  80.                             float4 worldPos = mul (_Object2World, v.vertex);
  81.                        
  82.                             o.fog.xy = worldPos.xz * _Params.z + _Params.xy;
  83.                        
  84.                             return o;
  85.                
  86.                         }
  87.                         ENDCG
  88.                         //SetTexture [_MainTex] { combine texture }
  89.                 }
  90.                
  91.                 // Lightmapped, encoded as dLDR
  92.                 Pass {
  93.                         Tags { "LightMode" = "VertexLM" }
  94.        
  95.                         Lighting Off
  96.                         BindChannels {
  97.                                 Bind "Vertex", vertex
  98.                                 Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
  99.                                 Bind "texcoord", texcoord1 // main uses 1st uv
  100.                         }
  101.                        
  102.                         SetTexture [unity_Lightmap] {
  103.                                 matrix [unity_LightmapMatrix]
  104.                                 combine texture
  105.                         }
  106.                         SetTexture [_MainTex] {
  107.                                 combine texture * previous DOUBLE, texture * primary
  108.                         }
  109.                 }
  110.                
  111.                 // Lightmapped, encoded as RGBM
  112.                 Pass {
  113.                         Tags { "LightMode" = "VertexLMRGBM" }
  114.                        
  115.                         Lighting Off
  116.                         BindChannels {
  117.                                 Bind "Vertex", vertex
  118.                                 Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
  119.                                 Bind "texcoord", texcoord1 // main uses 1st uv
  120.                         }
  121.                        
  122.                         SetTexture [unity_Lightmap] {
  123.                                 matrix [unity_LightmapMatrix]
  124.                                 combine texture * texture alpha DOUBLE
  125.                         }
  126.                         SetTexture [_MainTex] {
  127.                                 combine texture * previous QUAD, texture * primary
  128.                         }
  129.                 }      
  130.                
  131.         }
  132. }
  133.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #56 on: January 25, 2014, 04:11:18 PM »
You need to convert this:
  1.             BindChannels {
  2.                 Bind "Vertex", vertex
  3.                 Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
  4.                 Bind "texcoord", texcoord1 // main uses 1st uv
  5.             }
  6.            
  7.             SetTexture [unity_Lightmap] {
  8.                 matrix [unity_LightmapMatrix]
  9.                 combine texture
  10.             }
  11.             SetTexture [_MainTex] {
  12.                 combine texture * previous DOUBLE, texture * primary
  13.             }
...into actual shader code instead, like you have above for the vertex lit shader. I can't give you any pointers here though as I am not familiar with the lightmapping logic Unity uses. The basic idea is to blend the previous result with the light map though -- so you don't need to write a surface shader -- just a vertex and fragment shader combo (in other words same as you have above).

ounick

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Tasharen Fog of War
« Reply #57 on: January 25, 2014, 11:03:57 PM »
Thanks.  I will give it a shot.  If any shader pros out there, feel free to chime in  ;)

ounick

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Tasharen Fog of War
« Reply #58 on: January 26, 2014, 12:21:13 AM »
For anyone interested, I think I got it.  *updated*
  1. Pass {
  2.                         Tags { "LightMode" = "VertexLM" "LightMode" = "VertexLMRGBM"}
  3.        
  4.                         Lighting Off
  5.                        
  6.                         CGPROGRAM
  7.                
  8.                         #pragma vertex vert
  9.                
  10.                         #pragma fragment frag
  11.                
  12.                         #include "UnityCG.cginc"
  13.                        
  14.                         float4 _Color;
  15.                        
  16.                         sampler2D _MainTex;
  17.                        
  18.                         sampler2D   unity_Lightmap;
  19.                         float4          unity_LightmapST;
  20.                        
  21.                         sampler2D _FogTex0; //fog texture variable
  22.        
  23.                         sampler2D _FogTex1; //fog texture variable
  24.        
  25.                         uniform float4 _Params; //fog variable
  26.        
  27.                         uniform half4 _Unexplored; //fog variable
  28.        
  29.                         uniform half4 _Explored; //fog variable
  30.                        
  31.                         float4 _MainTex_ST;
  32.                        
  33.                         struct v2f
  34.                         {
  35.                        
  36.                                 float4 pos : SV_POSITION;
  37.                                
  38.                                 float2 uv : TEXCOORD0;
  39.                                
  40.                                 float2 lmap : TEXCOORD1;
  41.                                
  42.                                 float2 fog : TEXCOORD2; // this is a new line
  43.                        
  44.                         };
  45.                        
  46.                         struct VertInput
  47.             {
  48.                 float4 vertex   : POSITION;
  49.                 float2 texcoord : TEXCOORD0;
  50.                                 float4 texcoord1: TEXCOORD1;
  51.  
  52.             };
  53.                        
  54.                         half4 frag (v2f i) : COLOR
  55.                         {
  56.                        
  57.                             half4 c = tex2D (_MainTex, i.uv);
  58.                        
  59.                             half4 fog = lerp(tex2D(_FogTex0, i.fog), tex2D(_FogTex1, i.fog), _Params.w);
  60.                        
  61.                             c = lerp(lerp(c * _Unexplored, c * _Explored, fog.g), c, fog.r); // where c is the fixed4 to return
  62.                            
  63.                                 return half4 ( c.xyz * DecodeLightmap ( tex2D ( unity_Lightmap, i.lmap ) ), c.w );
  64.                         }
  65.                        
  66.                         v2f vert (VertInput v)
  67.                         {
  68.                        
  69.                             v2f o;
  70.                        
  71.                             o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
  72.                        
  73.                             o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
  74.                            
  75.                             o.lmap      = ( unity_LightmapST.xy * v.texcoord1.xy ) + unity_LightmapST.zw;
  76.                        
  77.                             float4 worldPos = mul (_Object2World, v.vertex);
  78.                        
  79.                             o.fog.xy = worldPos.xz * _Params.z + _Params.xy;
  80.                        
  81.                             return o;
  82.                
  83.                         }
  84.                         ENDCG
  85.                
« Last Edit: January 28, 2014, 04:57:43 AM by ounick »

GrimmGames

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Tasharen Fog of War
« Reply #59 on: March 07, 2014, 08:36:48 AM »
Hi.  I have two questions.

1) Is it possible to save and load the fog of war state?  i.e. I don't want the player to have to uncover the same areas twice between play sessions.

2) Is it possible to have dynamic LoS objects like doors or other objects that might be moved. i.e. I want things like doors to block the LoS check locally until they are opened or removed.

Thanks!