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:
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):
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]);
}
}
Answer
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:
at this point take your simplex noise fs(x,y) :
and multiply per f(x,y) you get something like this :
finaly apply a colorgradient to obtain something like :
No comments:
Post a Comment