1
\$\begingroup\$

I've found a few pieces of code around, where Java code for Simplex noise (based on this widely quoted paper) was coupled with octaves to get a heightmap. However those classes/snippets are NOT in the -1,1 range despite saying so, so I had to add some modifications.

By trial and error and some brain work I got to a version that produces an output within -1 and 1, here (could you sanity check it please? It this correct?):

public static float[][] generateOctavedSimplexNoise(final int width,
                                                    final int height,
                                                    final int octaves,
                                                    final float roughness,
                                                    final float scale)
{
    final float[][] totalNoise = new float[width][height];
    float layerFrequency = scale;
    float layerWeight = 1f;
    float weightSum = 0f;

    for (int octave = 0; octave < octaves; octave++)
    {
        // Calculate single layer/octave of simplex noise, then add it to total noise
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                totalNoise[x][y] += (float) noise(x * layerFrequency, y * layerFrequency) * layerWeight;
            }
        }

        // Increase variables with each incrementing octave
        layerFrequency *= 2f;
        weightSum += layerWeight;
        layerWeight *= roughness;
    }

    // scale output between -1 and 1, as we are doing
    // a weighted average
    for (int x = 0; x < width; x++)
    {
        for (int y = 0; y < height; y++)
        {
            totalNoise[x][y] /= weightSum;
        }
    }

    return totalNoise;
}

My understanding is that "roughness" must vary between 0 and 1, and influences the "flatness" of the final image. What "scale" is I cannot fathom yet - any help?. Also, more than 6-7 octaves seems useless in my tests, hopefully this is expected.

But most of all my question is: how do I work in a top-down way? That is, knowing the kind of map I roughly want (a big island in the ocean, with a few lakes and a few mountains, but mostly plain and hills) how do I choose parameters and the thresholds for terrain types?

I've tried a lot, but I can't seem to control the function to produce a nice map..

\$\endgroup\$
1
  • \$\begingroup\$ As a side note, it occurred to me that some people may intentionally have an output outside the -1,1 range, and then clamp it. This would be a sort of "zoom" within the noise map.. but I'm not sure if it makes sense nor if it's needed (shouldn't that be achievable with "scale"?). \$\endgroup\$
    – Fabio
    Oct 11 '15 at 14:38
0
\$\begingroup\$

A long search brought me to this tutorial and respective code of the C++ library libnoise. With pictures, formulas and code it's a bit clearer (although much work and study still has to go into this, for me to understand how to create a map with specific characteristics.. but that's beyond "noise", I fear).

This does use Perlin noise instead of Simplex noise, so I'm not sure I'll be able to reproduce all I'm reading.. but well, hopefully this is useful to someone else.

\$\endgroup\$

You must log in to answer this question.

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