Perlina noise as a percentage

I am coding a perlin noise-based map generator and have run into a problem:

Suppose I would like to get 30% water and 70% dirt. There are no problems with a regular random generator:

tile = rnd.nextFloat() < 0.7f ? DIRT : WATER;

But perlin noise is normally distributed (-1 to 1, average at 0), so it's not that simple.

Does anyone know a way to convert normal to a uniform distribution, or in another way, could I get a percentage of the noise value?

EDIT: 70% is just an example, I would like to use a dynamic dynamic value, with an accuracy of 0.1% at best.

EDIT2: I want to convert perlin noise to a uniform distribution, not a normal one (which already looks like).

+5
source share
6 answers

, : -, 100 000 000 perlin . , 10 000 . , 1,000 .

:

, .

:

, . -, 10 , 50% - 49,5%, 50,5% ( , = ). -, (4kb ). , .

:

final PerlinNoiseGenerator perlin = new PerlinNoiseGenerator(new Random().nextInt());

final int size = 10000; //Size gets sqared, so it actually 100,000,000

final float[] values = new float[size * size];
for (int x = 0; x < size; x++)
    for (int y = 0; y < size; y++) {
        final float value = perlin.noise2(x / 10f, y / 10f);
        values[x * size + y] = value;
    }
System.out.println("Calculated");

Arrays.sort(values);
System.out.println("Sorted");

final float[] steps = new float[1000];
steps[999] = 1;
for (int i = 0; i < 999; i++)
    steps[i] = values[size * size / 1000 * (i + 1)];
System.out.println("Calculated steps");

for (int i = 0; i < 10; i++) {
    System.out.println();
    for (int j = 0; j < 100; j++)
        System.out.print(steps[i * 100 + j] + "f, "); //Output usuable for array initialization
    System.out.println();
    System.out.println();
}

:

public final static float[] perlinThresholds = new float[]{}; //Initialize it with the generated thresholds.

public static float getThreshold(float percent) {
    return perlinThresholds[(int)(percent * 1000)];
}

public static float getThreshold(int promill) {
    return perlinThresholds[promill];
}

X
+4

30% ( - ), .

  • .
  • .
  • .
  • , 30% , .
+6

Perlin , .

, , 0,1 ( ).

~ 0,1, 70% 30% .

+4

, . , , , cdf(x)

cdf(x) = sum(histogram[i] for all i < x)

Wolfram Alpha cdf(x) . :

function F(x) { return (((((0.745671 * x + 0.00309887) * x - 1.53841) * x - 0.00343488) * x + 1.29551) * x) + 0.500516;

x ^ 5 + 0,00309887 x ^ 4-1,53841 x ^ 3-0,00343488 x ^ 2 + 1.29551 x + 0.500516 u = (u + 0,002591009999999949)/1.0055419999999997;//cross (0,0) (1,1)

F(x) = 0.745671 x^5 + 0.00309887 x^4 - 1.53841 x^3 - 0.00343488 x^2 + 1.29551 x + 0.500516

F(perlin.noise2(...)) .

(-1,0) (1,1),

F1(x) = (F(x) + 0.002591009999999949) / 1.0055419999999997

1 x = 1 0 x = -1, 0 1, .

F2(x) = max(min(F1(x), 1), 0)

( , , . , .)

+2

1 2? 0,5 0 1.

: , 70% 30%, , x, , x 0,7. , , -1 1, . , -∞ + ∞. , @paxinum, , .

0

All Articles