4
\$\begingroup\$

The answers to this question explains fairly well how to create a big island in the center of the screen by setting up a gradient and then subtracting its value from a Perlin Noise.

Anyway they explain how to create only one gradient at the center of the screen to create a big, sort of circular island.

But what if I want to create an island which has more than one gradient to create a less regular shape, or if I want to create multiple separated islands by setting multiple gradients in different positions? What value should I subtract from the Perlin Noise function for each point? The sum of the distance from each gradient to that point? The average?

Edit: Jon's method of multiplying and normalizing worked, got this result with 4 gradient points:

4 gradients: one with center in the top-left corner, one on down-left, another is in the center and the last is a bit on the right of the center

\$\endgroup\$
6
  • \$\begingroup\$ Multiply the gradients, then normalize them. \$\endgroup\$
    – jgallant
    Apr 25, 2016 at 14:03
  • \$\begingroup\$ So, say I have one gradient at 0, 0, and one at 20, 0, for the point 10, 0 i take the distance from the first (10) and multiply for the distance from the second (10), obtaining 100, and then? \$\endgroup\$ Apr 25, 2016 at 14:31
  • \$\begingroup\$ No. You would blend both your gradient noises together using some kind of blend operation. I would suggest multiplying their values together in order to retain a nice gradient pattern. Then normalize the resulting blended data to make it easier to work with. \$\endgroup\$
    – jgallant
    Apr 25, 2016 at 14:33
  • \$\begingroup\$ The blend operation. That'exactly what I'm looking for .-. \$\endgroup\$ Apr 25, 2016 at 14:36
  • \$\begingroup\$ I added some sample code on how to blend noise data. It is pretty simple stuff, and you could write a nice wrapper to do the operations for you. Let me know if you have any questions about it. \$\endgroup\$
    – jgallant
    Apr 25, 2016 at 14:51

1 Answer 1

3
\$\begingroup\$

You can blend noise together easily, the concept is pretty simple. You essentially loop through each noise value, and perform an operation on the data, and then save the result. It is also a good idea to normalize this data as it makes it easier to use for future operations.

Here is a simple container class to hold resulting noise data:

public class MapData {

    public float[,] Data;
    public float Min { get; set; }
    public float Max { get; set; }

    public MapData(int width, int height)
    {
        Data = new float[width, height];
        Min = float.MaxValue;
        Max = float.MinValue;
    }
}

Using this class, we can generate and store our noise data. You don't have to use this, but it makes it easier to have something to manage your generated noise data. We will use this to blend the gradients together:

blendData = new MapData (Width, Height);

Grab your data and blend it, keeping track of your upper/lower limits:

// first pass - blend gradient values
for (var x = 0; x < Width; x++) {
    for (var y = 0; y < Height; y++) {

        // Get both gradient values
        float gradValue1 = (float)GradientMap1.Get (nx, ny);
        float gradValue2 = (float)GradientMap2.Get (nx, ny);

        // Multiply
        float blendValue = gradValue1 * gradValue2;

        // keep track of the max and min values found
        if (blendValue > blendData.Max) blendData.Max = blendValue;
        if (blendValue < blendData.Min) blendData.Min = blendValue;             

        blendData.Data[x,y] = blendValue;               
    }
}

Normalize the resulting data, so that you don't have crazy values to deal with in the future:

// secondary pass to normalize the blended values
for (var x = 0; x < Width; x++) {
    for (var y = 0; y < Height; y++) {
        blendData.Data[x,y] = (blendData.Data[x,y] - blendData.Min) / (blendData.Max - blendData.Min);
    }
}
\$\endgroup\$
3
  • \$\begingroup\$ This already looks clearer. Got to try this visually. \$\endgroup\$ Apr 25, 2016 at 15:02
  • \$\begingroup\$ Can you point out a link reference with some mathematical principles would help me to understand the second loop? \$\endgroup\$
    – MVCDS
    Apr 28, 2016 at 14:16
  • 1
    \$\begingroup\$ Never mind, it is feature scaling. \$\endgroup\$
    – MVCDS
    Apr 28, 2016 at 14:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .