7

I've got one little question: Is there any code or sample which shows how the simplex noise works? I cannot find anything about it... How should I implement it, without the knowledge how the algorithm works?...

The other question is: Is the simplex noise a good algorithm for island generation? I need huge islands (really huge), with different layers (sand, gras, stone) and clearly visible height-differences, which have soft-edges, so you can go out/into water without jumping over uneven surfaces.

Nate
  • 5,054
  • 2
  • 29
  • 46
SharpShade
  • 193
  • 1
  • 1
  • 9
  • Check out http://gamedev.stackexchange.com/questions/4628/huge-procedurally-generated-wilderness-worlds Also, are you looking for specifically simplex noise? I have a noise sample I wrote myself, but it's not simplex (or perlin really..it's the so-called 'value' noise, which looks close enough) – PrettyPrincessKitty FS Jun 08 '11 at 18:18
  • hmm, there is no more information about simplex noise... or nevertheless? The sample would be helpful :) maybe you can give it to me? thanks :) – SharpShade Jun 08 '11 at 18:26
  • I do not want this to be an answer because its not my work, but you can get the Research article on Simplex Noise that Ken wrote at: http://www.cs.umbc.edu/~olano/s2002c36/ch02.pdf (This link was from the bottom of the wikipedia article linked to from the article you posted below.) PS: It include code for C and Java at the end of the article. – James Jun 08 '11 at 22:14

3 Answers3

1

My noise generator in C#, based off this:

static class NoiseGenerator
{
    public static int Seed { get; private set; }

    public static int Octaves { get; set; }

    public static double Amplitude { get; set; }

    public static double Persistence { get; set; }

    public static double Frequency { get; set; }

    static NoiseGenerator()
    {
        Random r = new Random();
        //LOOOL
        NoiseGenerator.Seed = r.Next(Int32.MaxValue);
        NoiseGenerator.Octaves = 8;
        NoiseGenerator.Amplitude = 1;
        NoiseGenerator.Frequency = 0.015;
        NoiseGenerator.Persistence = 0.65;
    }

    public static double Noise(int x, int y)
    {
        //returns -1 to 1
        double total = 0.0;
        double freq = NoiseGenerator.Frequency, amp = NoiseGenerator.Amplitude;
        for (int i = 0; i < NoiseGenerator.Octaves; ++i)
        {
            total = total + NoiseGenerator.Smooth(x * freq, y * freq) * amp;
            freq *= 2;
            amp *= NoiseGenerator.Persistence;
        }
        if (total < -2.4) total = -2.4;
        else if (total > 2.4) total = 2.4;

        return (total/ 2.4);
    }

    public static double NoiseGeneration(int x, int y)
    {
        int n = x + y * 57;
        n = (n << 13) ^ n;

        return (1.0 - ((n * (n * n * 15731 + 789221) + NoiseGenerator.Seed) & 0x7fffffff) / 1073741824.0);
    }

    private static double Interpolate(double x, double y, double a)
    {
        double value = (1 - Math.Cos(a * Math.PI)) * 0.5;
        return x * (1 - value) + y * value;
    }

    private static double Smooth(double x, double y)
    {
        double n1 = NoiseGeneration((int)x, (int)y);
        double n2 = NoiseGeneration((int)x + 1, (int)y);
        double n3 = NoiseGeneration((int)x, (int)y + 1);
        double n4 = NoiseGeneration((int)x + 1, (int)y + 1);

        double i1 = Interpolate(n1, n2, x - (int)x);
        double i2 = Interpolate(n3, n4, x - (int)x);

        return Interpolate(i1, i2, y - (int)y);
    }
}

It isn't commented, but the main parts:

Seed is a value used to make it random - so you don't generate the same thing each time. Here I have put it in the NoiseGenerator.

Amplitude, Frequency, Persistence, and Octaves are explained in the article - they basically affect what the resulting noise looks like.

NoiseGenerator function is literally a PRNG - give it an input, and it generates a random number with that as a seed.

Noise is what you call to get a noise value. I found the values were around -2.4 to 2.4 (actually about 2.40032483 or something so they are clamped) and I fixed them to doubles between -1 and 1.

I have not had any speed problems with this. I was rendering a 400x400 grid of 1x1 sprites with values set by this and was getting only minor lag (and that was recalculating noise each frame).

For the island generation, check out this question - in particular, this link is almost exactly what you want, albeit in AS3.

PrettyPrincessKitty FS
  • 10,315
  • 8
  • 43
  • 68
  • Ehm, sorry i forgot to say that i need a generator which generates a heightmap. Or how can i use this to generate terrain? At the moment, i generate a heightmap (i tried various algorithms ...) and then calculate the vertices.

    The big thing is, i need a generation algorithm that generates good looking isles :-/ i know, i´m difficult, but i don´t know how i should make this ...

    – SharpShade Jun 08 '11 at 19:00
  • @Razer Use the coordinates of your heightmap - say x,y - as the input to the Noise function. It will assign each point a value between -1 and 1, so you may need to do some normalizing ((value+1)*127.5f works to get it between 0 and 255) – PrettyPrincessKitty FS Jun 08 '11 at 20:07
  • It works, but not very nice... What i want is something like this: http://hazelmckendrick.com/demos/terrain-generation-tropical-island – SharpShade Jun 08 '11 at 21:10
  • 1
    @Razer Why not use that source? – PrettyPrincessKitty FS Jun 09 '11 at 09:03
  • Because there is no description of the used algorithms, no code and nothing. Yes i know, source is included, but it´s c++. I don´t understand C++ :-/ – SharpShade Jun 09 '11 at 15:35
  • @Razer What's wrong with what I've given you then? There's a noise sample for C#, and the article/question linked explains how to separate between sand, grass, etc..you just need to replace the ASCII with your textures. – PrettyPrincessKitty FS Jun 09 '11 at 16:08
  • Hmm, currently the problem is, that the terrain is way to smooth. there are only slight height-differences, or with different values the terrain looks like a nail board ...

    I need visible height-differences, which looks real. The terrain should be recognized as an island, not as a nail board ^^

    The video on this site is exactly what i want. But how do i generate such terrains? :-/

    – SharpShade Jun 09 '11 at 16:37
  • @Razer fiddle with the amplitude and frequency. I can't remember exactly which, but one certainly makes it appear more terrain-y. – PrettyPrincessKitty FS Jun 09 '11 at 16:51
  • I tried it. But the results are not very pleasing: http://img52.imageshack.us/img52/4434/terraingeneration.png Also i have a big problem. There are many graphic bugs... and one big triangle which is always visible (depthbuffer is enabled). One vertex of this triangle is at 0,0,0. But such vertex never gets generated o.O

    I want something like in the video, but that´s ... no. It´s only noise ;) How can i generate real islands surrounded by water?

    – SharpShade Jun 09 '11 at 17:15
  • Are you trying the steps in the article, or just assigning the noise to the heightmap? – PrettyPrincessKitty FS Jun 09 '11 at 17:27
  • No i just assigned it to the heightmap... – SharpShade Jun 15 '11 at 12:49
  • @Razer if you follow the steps in the article, you'll achieve a heightmap similar to the end product :P – PrettyPrincessKitty FS Jun 15 '11 at 15:07
  • Ok. I´ll try it ;) – SharpShade Jun 15 '11 at 19:48
1

Ok thanks to all for the help :)

2 days ago i found "Libnoise" and a good C# port. I will take this one, because there´s a renderer which renders smoother heightmaps :)

SharpShade
  • 193
  • 1
  • 1
  • 9
0

If you haven't come across it already, Stefan Gustavson's Simplex Noise Demystified is a good explanation of how the algorithm works.

Rob Agar
  • 151
  • 2