Support => Other Packages => Topic started by: CodinRonin on May 16, 2014, 04:31:51 AM
Title: Tasharen Fog Of War fixes.
Post by: CodinRonin 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)
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
int sx= cx+ Mathf.RoundToInt(v.x* worldToTex);
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
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
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
int size = Mathf.Max(Mathf.RoundToInt(xmax - xmin), Mathf.RoundToInt(ymax - ymin));
Title: Re: Tasharen Fog Of War fixes.
Post by: ArenMook 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.
Title: Re: Tasharen Fog Of War fixes.
Post by: CodinRonin 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.
v *= r.inner;
// From the FOWRevevaler
mRevealer.inner= range.x;
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
Title: Re: Tasharen Fog Of War fixes.
Post by: ArenMook 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.
Title: Re: Tasharen Fog Of War fixes.
Post by: CodinRonin 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.
Title: Re: Tasharen Fog Of War fixes.
Post by: ArenMook 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.