2
\$\begingroup\$

I am trying to generate an island using Simplex Noise. To actually make a island shape i used Amitp's answers to the following questions:

1.Fast, simple procedural 2d island generation

2.Generating random Pools or lakes

Using them i have snippet of code for generation:(width/height is 128)

for(int y = 0; y < HEIGHT; y++) {
        for(int x = 0; x < WIDTH; x++) {
            // amitp's solution
            Vector2 vec = new Vector2(2 * x / WIDTH - 1, 2 * y / HEIGHT - 2);
            float d = Mathf.Sqrt(vec.x * vec.x + vec.y * vec.y);
            //
            float noise = Noise.Generate((float)x / WIDTH * 10, (float)y / HEIGHT * 10);

            // amitp's solution again
            mapData[x, y] = noise > 0.3 + 0.4*d*d ? noise * 10 : 0.0f;
            //

            colors[x + y * WIDTH] = new Color(mapData[x, y], mapData[x, y], mapData[x, y]);
        }
    }

This gives me the following unwanted result:

Wrong

How do i get fix it to generate properly?

Lastly i'm using Unity.

***EDIT:

Fixed/Changed a couple of things and now i am getting this(still not what i want):

changes/fixes

with this changed code:

for(int y = 0; y < HEIGHT; y++) {
        for(int x = 0; x < WIDTH; x++) {
            // amitp's solution
            Vector2 vec = new Vector2(((2 * x) / WIDTH) - 1, ((2 * y) / HEIGHT) - 1);
            float d = Mathf.Sqrt((vec.x * vec.x) + (vec.y * vec.y));
            //
            float noise = Noise.Generate((float)x / WIDTH, (float)y / HEIGHT);

            // amitp's solution again
            mapData[x, y] = noise > 0.3 + 0.4*d*d ? noise * 10 : 0.0f;
            //

            colors[x + y * WIDTH] = new Color(mapData[x, y], mapData[x, y], mapData[x, y]);
        }
    }
\$\endgroup\$
2
  • \$\begingroup\$ "(still not what I want)" - can you describe what it is that you do want? What would you like to change about the results you have now? I presume centering & scaling the island relative to the whole square, not just the top-right quadrant, and getting rid of the cropped edges. Anything else? \$\endgroup\$
    – DMGregory
    Commented Jul 3, 2015 at 20:28
  • \$\begingroup\$ Yeah, sorry. I want it to be centered, which i don't know why it is not doing that. As well as what you said, removed cropping and scale nicely. \$\endgroup\$
    – Stuart
    Commented Jul 3, 2015 at 21:29

1 Answer 1

5
\$\begingroup\$

I suggest this aproach. Let fs(x,y) be your simplex noise function. Let's introduce a second function : f(x,y) = ((float)Math.Sin(((float)x/(float)WIDTH) * Math.PI) ) * ((float)Math.Sin(((float)y / (float)WIDTH) * Math.PI) ) or any function that rassemble the following and that gives values from 0 to 1:

enter image description here

at this point take your simplex noise fs(x,y) :

enter image description here

and multiply per f(x,y) you get something like this :

enter image description here

finaly apply a colorgradient to obtain something like :

enter image description here

\$\endgroup\$
13
  • \$\begingroup\$ I am actually struggling to find a simplex noise implementation that returns values in the 0 to 1 range. Can any one lead me to one? \$\endgroup\$
    – Stuart
    Commented Jul 7, 2015 at 11:05
  • \$\begingroup\$ I saw you use unity : try Mathf.PerlinNoise docs.unity3d.com/ScriptReference/Mathf.PerlinNoise.html \$\endgroup\$ Commented Jul 7, 2015 at 11:21
  • \$\begingroup\$ I'm not very keen on Unity's Perlin Noise method. When i use it, it just seems to give repetition of 'rolling hills'. Maybe i am using it wrong, but. \$\endgroup\$
    – Stuart
    Commented Jul 7, 2015 at 16:01
  • \$\begingroup\$ Ok, found a way to use a perlin noise function that gives good results but returns in the range of -1 to 1. I then found a post that give a small formulae to change the -1 to 1 range into 0 to 255 range. Now just the matter of getting the mask formulae to work. \$\endgroup\$
    – Stuart
    Commented Jul 7, 2015 at 16:24
  • \$\begingroup\$ Ok, so the formlae : f(x,y) = WIDTH * (1 - (X * X + Y * Y)) : isnt giving me numbers in the range of 0 to 1, its giving me the range of 0 to large negative numbers. \$\endgroup\$
    – Stuart
    Commented Jul 7, 2015 at 16:35

You must log in to answer this question.

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