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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #105 on: July 08, 2014, 01:51:06 PM »
I vaguely remember something that had to be done differently... I'll look into it and let you know.

capitalj

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 88
    • View Profile
Re: Tasharen Fog of War
« Reply #106 on: July 08, 2014, 02:00:47 PM »
Ok that would be great. The game is done, so just have to get the android version ready for release :)

Chairwalker

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Tasharen Fog of War
« Reply #107 on: September 05, 2014, 06:32:33 AM »
Could you give me some pointers on how to create a custom CreateGrid function that only checks a certain part of the existing grid?

*edit*

Nevermind, figured it out by myself.
For anyone interested:

  1. protected virtual void UpdateGrid (Transform Updated, int Range)
  2.         {      
  3.                 float texToWorld = (float)worldSize / textureSize;
  4.                 Vector3 pos = mOrigin;
  5.                 pos.y += mSize.y;
  6.  
  7.                 bool useSphereCast = raycastRadius > 0f;
  8.                
  9.                 for (int z = 0; z < textureSize; ++z)
  10.                 {
  11.                         pos.z = mOrigin.z + z * texToWorld;
  12.                        
  13.                         for (int x = 0; x < textureSize; ++x)
  14.                         {
  15.                                 pos.x = mOrigin.x + x * texToWorld;
  16.  
  17.  
  18.                                 if ((pos.x > (Updated.position.x - Range)) && (pos.x < (Updated.position.x + Range)) && (pos.z > (Updated.position.z - Range)) && (pos.z < (Updated.position.z + Range)))
  19.                                 {
  20.                                         RaycastHit hit;
  21.                                         if (useSphereCast)
  22.                                         {
  23.                                                 if (Physics.SphereCast(new Ray(pos, Vector3.down), raycastRadius, out hit, mSize.y, raycastMask))
  24.                                                 {
  25.                                                         mHeights[x, z] = WorldToGridHeight(pos.y - hit.distance - raycastRadius);
  26.                                                         continue;
  27.                                                 }
  28.                                         }
  29.                                         else if (Physics.Raycast(new Ray(pos, Vector3.down), out hit, mSize.y, raycastMask))
  30.                                         {
  31.                                                 mHeights[x, z] = WorldToGridHeight(pos.y - hit.distance);
  32.                                                 continue;
  33.                                         }
  34.                                         mHeights[x, z] = 0;
  35.                                 }
  36.                         }
  37.                 }
  38.         }

Calling UpdateGrid(Object,8) should cast rays only in a 16x16 grid around the transform of Object.
« Last Edit: September 05, 2014, 08:06:01 AM by Chairwalker »

gekido

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: Tasharen Fog of War
« Reply #108 on: September 27, 2014, 11:50:16 PM »
Just a quick note, the BetterList implementation in the Fog of War package is out of sync with the one that is in the NGUI package.  If you import Fog of War into a project after NGUI, it breaks NGUI if you include the BetterList.cs file (which Unity will automatically overwrite).

(issue is in the BetterList<Transform>.CompareFunc call in UIGrid.cs for what it's worth)

Might want to namepsace and/or rename the file in the Fog of War package maybe?  The newer BetterList in NGUI seems backwards compatibile with the other one, but not the other way around.

Cheers!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #109 on: September 29, 2014, 07:30:15 AM »
Sounds like I need to update it at some point... thanks!

jpcoombs

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Tasharen Fog of War
« Reply #110 on: November 07, 2014, 02:59:31 PM »
Love the FOW - works great right out of the box.

However we have a game where players a building walls and dropping objects that should be affected by FoW. Reading through the Forums it looks like after PLAY the FoW collision zone is determined and won't be updated (our tests with generating new objects supports this). Is there a way to clear the cache/resimulate upon placement of new objects in the scene?

Cheers!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #111 on: November 07, 2014, 04:18:28 PM »
You would need to call FOWSystem's CreateGrid() function. Although looking at it, it's protected so you will need to make it public first.

jpcoombs

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Tasharen Fog of War
« Reply #112 on: November 07, 2014, 05:21:34 PM »
Awesome! Worked great!

jpcoombs

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Tasharen Fog of War
« Reply #113 on: November 08, 2014, 10:35:34 AM »
Aren, one more question -

Do you have any advice for updating the CreateGrid () but essentially removing the complete refresh of the discovered areas - perhaps a third level of FoW that retains discovered areas and overrides the refresh? We got the function to redraw every time that we place a new wall but the fog renewal is a little odd.

Cheers, and thanks for all your support and hard work on the package! Super happy with it.

ounick

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Tasharen Fog of War
« Reply #114 on: November 08, 2014, 05:41:30 PM »
Hi.  My screenshots are just from the editor and not while playing but I just wanted to illustrate the positioning. Everything is working correctly for me when my FOWSystem's transform is positioned at the origin(shown in the left screenshot).  However, I am having an issue where whenever I position my FOWSystem's transform to the center of my environment, everything stops working correctly(shown in the right screenshot).  Do you have any idea how to fix my problem? 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #115 on: November 09, 2014, 09:55:36 PM »
@jpcoombs: What do you mean by complete refresh of discovered areas? CreateGrid shouldn't change the fog of war, just the height map. Looking at the code, that's all it does.

@ounick: When do you move the FoW? It caches its origin position in its Start() function.

jpcoombs

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Tasharen Fog of War
« Reply #116 on: November 10, 2014, 02:48:48 PM »
@Aren

Right now we run the CreateGrid function every time we place an object (like building a new wall). As soon as the wall is built, CreateGrid is essentially refreshing the entire map and in that process refreshing all of the "Explored" area. Characters with FOWRevealer have to be clicked and refreshed to reveal the area they are currently in - if that makes sense.

Before and after CreateGrid pictured here.


 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #117 on: November 10, 2014, 11:18:33 PM »
Looking at the code on my end, absolutely nothing is touching the buffers. CreateGrid() simply changes the heightmap (mHeights array).
  1.         public virtual void CreateGrid ()
  2.         {
  3.                 Vector3 pos = mOrigin;
  4.                 pos.y += mSize.y;
  5.                 float texToWorld = (float)worldSize / textureSize;
  6.                 bool useSphereCast = raycastRadius > 0f;
  7.  
  8.                 for (int z = 0; z < textureSize; ++z)
  9.                 {
  10.                         pos.z = mOrigin.z + z * texToWorld;
  11.  
  12.                         for (int x = 0; x < textureSize; ++x)
  13.                         {
  14.                                 pos.x = mOrigin.x + x * texToWorld;
  15.  
  16.                                 if (raycastMask != 0)
  17.                                 {
  18.                                         RaycastHit hit;
  19.  
  20.                                         if (useSphereCast)
  21.                                         {
  22.                                                 if (Physics.SphereCast(new Ray(pos, Vector3.down), raycastRadius, out hit, mSize.y, raycastMask))
  23.                                                 {
  24.                                                         mHeights[x, z] = WorldToGridHeight(pos.y - hit.distance - raycastRadius);
  25.                                                         continue;
  26.                                                 }
  27.                                         }
  28.                                         else if (Physics.Raycast(new Ray(pos, Vector3.down), out hit, mSize.y, raycastMask))
  29.                                         {
  30.                                                 mHeights[x, z] = WorldToGridHeight(pos.y - hit.distance);
  31.                                                 continue;
  32.                                         }
  33.                                 }
  34.                                 mHeights[x, z] = 0;
  35.                         }
  36.                 }
  37.         }

ounick

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Tasharen Fog of War
« Reply #118 on: November 11, 2014, 02:12:37 PM »
I am moving the system's transform only in editor mode.  I am going to start comparing grid to world coordinate values today and maybe that will lead me somewhere.

FuriousBroccoli

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Tasharen Fog of War - Linear Color Space
« Reply #119 on: February 05, 2015, 05:27:48 PM »
Hi - I noticed that the fog of war reveal interpolation, with Linear color space, flickers.  This problem does not occur in Gamma space.

I'm no good with Unity shaders - is there an easy fix to make this work smoothly with a linear color space?

Thanks!