I am trying to utilize a weight function from a paper titled "Dijkstra-based Terrain Generation Using Advanced Weight Functions". I have taken a weight function they provide and I have tried to implement it in C#. The output I am getting appears to be working but not completely. My knowledge of maths is not good enough for me to work out a solution.
Here is the weight function from the paper. The paper also defines a method for selecting nodes and calculating the weights but I don't believe this is required if I wish to just use this in isolation:
My current C# code. The data is being output into a Unity Terrain object.
for (int y = 0; y < Resolution; y++)
{
for (int x = 0; x < Resolution; x++)
{
//I tried to inteprite the expression here, this is probably not correct.
float dot = Vector3.Dot(WindDirection.normalized, new Vector3(x, y));
float ri = ReverseInterpolate(dot);
float inter = Interpolate(ri);
terrainheights[y, x] = Weight * inter;
}
}
My methods for Interpolation:
private float Interpolate(float value)
{
float x1 = 0;
float x2 = 1;
float y1 = 0;
float y2 = Weight;
float y = y1 + (value - x1) / (x2 - x1) * (y2 - y1);
return y;
}
private float ReverseInterpolate(float x)
{
float x1 = -1;
float x2 = 1;
float y1 = 0;
float y2 = 1;
float y = y1 + (x - x1)/ (x2 - x1) * (y2 - y1);
return y;
}
Finally is the result I get and the values for Weight and Wind Direction. as you can see, the effect is working slightly but not to the degree that I was hoping:
Any help would be very much appreciated!