0

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: Weight function

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: enter image description here

Any help would be very much appreciated!

rob5300
  • 138
  • 7
  • 1
    Did you try different resolutions? It looks like the resolution isn't fine enough. Increasing the resolution will take longer to process but give better details. – jdweng Mar 03 '19 at 16:43
  • @jdweng I considered this. The terrain within Unity supports resolution up to 4096 (and is what the example image was using [4096x4096]) but I imagine i can calculate into a larger sized array of nodes and then somehow downscale it? Though that part i'm not sure about currently. – rob5300 Mar 03 '19 at 16:46

0 Answers0