It's amazing how I tend to get sucked into projects or think up new projects when I already have too many (including such projects as a web portal, multiplayer game, a proof for an algorithm to find a p-like cycle in polynomial time, etc.). However I find the procedural texture project to be the one that interests me the most. Anyway, I've been looking back through FxGen again and found an interesting function, Dilate. A rework of the code, in C#, can be found below:
namespace Graphics
{
class Dilate
{
public static float[,] Process(float[,] Data, int Width, int Height,int Iterations)
{
float[,] FinalValues = new float[Width, Height];
for(int i=0;i<Iterations;++i)
{
for(int y=0;y<Height;++y)
{
for (int x = 0; x < Width; ++x)
{
float Threshold = Data[x, y];
FinalValues[x, y] = Threshold;
for (int u = -1; u < 2; ++u)
{
for (int v = -1; v < 2; ++v)
{
int XIndex = (x + Width + u) % Width;
XIndex = GlobalFunctions.ClampValue(XIndex, Width, 0);
int YIndex = (y + Height + v) % Height;
YIndex = GlobalFunctions.ClampValue(YIndex, Height, 0);
if (Data[XIndex, YIndex] > Threshold)
{
Threshold = Data[XIndex, YIndex];
FinalValues[x, y] = Data[XIndex, YIndex];
}
}
}
}
}
Data=FinalValues;
FinalValues = new float[Width, Height];
}
return Data;
}
}
}
The basic concept is we got through and check each pixel against its neighbors and whichever neighbor is the highest, we set the pixel to that value. In turn it gives a result similar to the one below:
It's probably not the most useful function, but it has its uses. Anyway, check out the code, leave feedback, and happy coding.
86535dcb-2532-49bd-9873-68e97230120b|1|4.0