Author Topic: Tasharen Fog Of War fixes.  (Read 3507 times)

CodinRonin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Tasharen Fog Of War fixes.
« on: May 16, 2014, 04:31:51 AM »
First of all, Great packages , using extensively FoW and HudText.

Just noticed 2 issues with Tasharen Fog Of War.

1. In the FowSystem class in RevealUsingLOS() and RevealUsingCache() methods there is incositency in the dimensioning of the variables,  in the case of (dist < maxRange)

  1. Vector2 v = new Vector2(xd, yd);
  2. v.Normalize();
  3. v *= r.inner;
  4.  
  5. int sx= cx+ Mathf.RoundToInt(v.x);
  6. int sy= cy+ Mathf.RoundToInt(v.y);
  7.  

all the variables are declared in "texture" space (i.e. multiplied with worldtoTex), except the r.inner value which is declared in "real world" value.  So , the fix is to multiply them by worldToTex also

  1. int sx= cx+ Mathf.RoundToInt(v.x * worldToTex);
  2. int sy= cy+ Mathf.RoundToInt(v.y * worldToTex);


2. The second one is more of a special case handling. For instance I'm having a huge world (size), with a relatively small texture size for the fog texture. So in a specific scenario it is possible for the revealer cache calculations to have errors in the approximation. Namely the RevealIntoCache method works with


Test Scenario :

Fow System :
position in real world {{7500,120,7300}}
World size : 178000
Texturesize : 1024
Position of revealer in "FoW" world : {(2615.0, 59.0, 6079.0)} , radius inner: 1200 , outer :1250

worldToTex = 0,05752809

  1. int size = Mathf.RoundToInt(xmax - xmin);
  2. r.cachedBuffer = new bool[size * size];
  3. r.cachedSize = size;

the calculation of xmin , xmax , ymin, ymax suffers a loss in precision and the cache buffer is smaller.
(IE , Mathf.RoundToInt(xmax - xmin) == 143 while Mathf.RoundToInt(ymax - ymin) == 144)
 , so the line
  1. r.cachedBuffer[(x - xmin) + (y - ymin) * size] = true;

fails.

As a safety precaution (temp fix) i formed a buffer from the largest of the min-max range
  1. int size = Mathf.Max(Mathf.RoundToInt(xmax - xmin), Mathf.RoundToInt(ymax - ymin));

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog Of War fixes.
« Reply #1 on: May 16, 2014, 03:25:59 PM »
#1 seems wrong to me. The 'v' value is derived from 'x - cx' and 'y - cy'. X and Y come from 'xmin' and 'ymin', which both already include worldToTex conversion. 'cx' and 'cy' are already using pixels.

#2 seems reasonable.

CodinRonin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Tasharen Fog Of War fixes.
« Reply #2 on: May 16, 2014, 04:37:31 PM »
For (1) , the Vector2 v , after normalization is applied a magnitude(multiplication) expressed in real world coordinates from the FOWRevealer class.

  1. v *= r.inner;

  1. // From the FOWRevevaler
  2. mRevealer.inner = range.x;
  3. mRevealer.outer = range.y;

So when calculating sx and sy , they have cx/cy part which is in pixel coordinates, and Mathf.RoundToInt(v.x/vy) part of a vector in game world coordinates




ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog Of War fixes.
« Reply #3 on: May 17, 2014, 07:49:26 PM »
Ah, interesting... so how did you notice this? What issue was it causing? I've been using the system for quite a while and didn't see anything amiss.

CodinRonin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Tasharen Fog Of War fixes.
« Reply #4 on: May 18, 2014, 02:33:47 PM »
Well the issue manifested something like in the attached image. Wrong side of the object was "fogged".

The issue was kinda hard to spot if youre working with small maps where pixel space can be mapped 1:1 to world space since the worldToTex factor is ~1 , but in my case i was working with very small worldToTex factor so it was noticeable.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog Of War fixes.
« Reply #5 on: May 18, 2014, 04:48:25 PM »
Alright, thanks. I've added your changes locally and will put them in the next update if I don't run into anything on the side.