Hi
I wanted to speed up my fog of war code and get it from c++ side to shader code, which is really like drawing alpha on texture. But I have one problem: I can’t really permanently draw on texture, it’s like on every frame shader resets texture and I can only see something in one frame:
Video
Im using DiffAlpha technique. My shader code is just modification of LitSolid with added:
if(diffColor.a > 0.01) //check if that part wasn't cleared yet
{
//if not, then get square of distances
float dX = cUnitPos.x - vTexCoord.x;
float dY = cUnitPos.y - vTexCoord.y;
float sqrD = dX*dX+dY*dY;
float sqrR = 0.01;
float sqrR2 = 0.02;
//if square is smaller than first radius clear fully
if(sqrD < sqrR)
{
diffColor.a = 0;
}
else if(sqrD < sqrR2) //otherwise if square is smaller than second radius clear partly
{
diffColor.a = (sqrD - sqrR)/(sqrR2 - sqrR);
diffColor.a = diffColor.a + ((rand(vTexCoord) / 4.0) * diffColor.a);
}
}
I have 1 uniform parameter that describes unit position in current frame. First radius describes range of full clear, second describes partly clear + Im adding some randomity.
From c++ side Im only updating cUnitPos with current mouse position.