# Perlin noise terrain generation with integer (discrete) elevation levels results in artifacts at rounding boundaries

I am trying to generate terrain with discrete height levels using Unity's built in 2D Perlin noise function. The output is a float in [0,1]. I then scale the float linearly to a range [minimum Height, Maximum Height], and round it to the nearest integer.

The problem is that this results in artifacts at rounding boundaries, as can be seen in the following image: As you can see, the ridge line partially marked in red should not be there. It is created because that's the rounding boundary, meaning that this is the line between x.49 and x.50 (x is integer), so the x.49 is rounded to x, while the x.50 is rounded to x+1.

I'll demonstrate that by zooming to a part of the image and showing the height value of different blocks: The height of Block 1 is 14.48

The height of Block 2 is 14.52

The height of Block 3 is 15.6

The height of Block 4 is 14.6

As you can see, the only reason there is a ridge between Block 1 and Block 2, is because 1's height is rounded to 14, while 2's height is rounded to 15. This is unlike Blocks 3 and 4, which should have an elevation difference between them as per the Perlin noise function.

I can of course use Floor or Ceil or other methods to turn the float result from the Perlin Noise function into an integer, but that simply results in artifact lines appearing at other places.

Any help in solving this issue would be greatly appreciated.

Thank you.

Edit:

Here is how I get the height of each column:

float grassHeightFloat = WorldGenMath.getNoise(x + grassHeightRandOffSet, z + grassHeightRandOffSet,
grassSmoothness, grassMinHeight, grassMaxHeight)

uint grassHeight = Convert.ToUInt32(grassHeightFloat);


WorldGenMath is:

private static float scaleNoise(float value, float minScale, float maxScale)
{
return scale(value, 0, 1, minScale, maxScale);
}
private static float scale(float value, float min, float max, float minScale, float maxScale)
{
float scaled = minScale + (float)(value - min) / (max - min) * (maxScale - minScale);
return scaled;
}
public static float getNoise(uint x, uint z, float smoothFactor, int minScale, int maxScale)
{
float noise = Mathf.PerlinNoise(x * smoothFactor, z * smoothFactor);
return scaleNoise(noise, minScale, maxScale);
}
public static float getNoise(long x, long z, float smoothFactor, int minScale, int maxScale) {
return getNoise(Convert.ToUInt32(x), Convert.ToUInt32(z), smoothFactor, minScale, maxScale);
}

• The coordinates for each tile are (x,y,z), with y being the height. To find out the height of each column, I simply input them into the Perlin noise function, meaning y = PerlinNoise(x,z). Is that not correct? Aug 19, 2017 at 17:21
• I added the code to my post. Aug 19, 2017 at 17:30
• The shape is selected later, and is not the issue. Please ignore the shapes of the tiles. The issue would still be there even if all the tiles were cubic. Please look at tiles number 1 and 2 in the image. The difference between their heights is minimal, but because one is rounded up and one is rounded down (since one is >0.5 while the other is <0.5), there is a noticeable height difference in the discrete solution. I'm trying to get rid of that difference, and only have tiles at different heights when there is a large difference (like in tiles 3 and 4). Sorry if that wasn't clear before. Aug 19, 2017 at 18:16
• Ahh, I'd misunderstood which effect in the image you were trying to eliminate. The rounding between 1 and 2 shouldn't be any different than the rounding between 3 and 4 though, should it? Does this suggest the shape of the noise function itself has a bump in it that the terracing of the rounding is making more noticeable? Maybe an amplitude very close to your terrace step, so it manifests as just one big ring instead of an orderly set of nested curves like the greater amplitudes… Aug 19, 2017 at 18:28
• I'm not recommending a solution, I'm speculating on the source of the problem. Noise functions are often summations of multiple different components. A component whose intensity is very close to your rounding interval will make seemingly standalone features that only cross the rounding interval once, rather than stacking up in nested staircases. The arc you're seeing could be such a feature from a low-amplitude component. Aug 19, 2017 at 19:12