0
\$\begingroup\$

I’m working on terrain generation for a game of mine and has run into a slight problem. The terrain itself within the game procedurally generates as your character moves around. This means that all the world generation needs to somehow be based off of the position a certain tile—or region (chunk)—has in the world.

The world generation is rock solid so far and looks quite gorgeous! But I require one more component to make it complete—I need to somehow retrieve a random point within a piece of Perlin noise.

Let’s assume we had something like this:

int scale = 100;
float noise = perlinNoise.noise3(x / scale, y / scale, z / scale)

if(noise > .2f)
    setPixel(x, y, 0xffffff);

We’re drawing the result to the screen in form of pixels to try and see what happens. This way, we achieve regularly spaced out areas of noise. Now, what I would like to do is randomly generate one point located somewhere within a chunk of noise following the above “schematic”.

The above might look something along the lines of this:

xxxxxxxxxxxxx
xxxxxxxxxxxxx
xxxxxoooxxxxx
xxxxoooooxxxx
xxxxxoopooxxx
xxxooooooxxxx
xxxxxoooxxxxx
xxxxxxxxxxxxx

Where the x’s are what is not affected by the perlin noise in the above code example and o’s are affected—the o’s are plotted out on the screen by it—they’re the white pixels in the above example.

The little p as opposed to from the o’s and x’s, is the random point I’d like to have randomized inside every chunk of randomized Perlin noise, without having to pre-generate the world.

Is there a way in which this can be achieved? I’ve wrapped my mind inside out thinking of potential solutions—I’ve searched the web, but as though in vain. There appears to be nothing written on the subject.

\$\endgroup\$
  • \$\begingroup\$ The p is only allowed to go in a position where an o would be? \$\endgroup\$ – MichaelHouse Feb 1 '17 at 16:18
  • \$\begingroup\$ @Byte56 Yes—that’s correct! In fact, there needs be one—and exactly one—*p* as for every chunk of o’s. \$\endgroup\$ – D. Ataro Feb 1 '17 at 16:20
1
\$\begingroup\$

Using traditional Perlin noise, you cannot know in advance what values a 'section' will have without actually generating - underneath it all, you're using a PRNG & the very nature of a PRNG is you cannot predict future values (short of pre-generating the sequence or doing some serious math on the generating algorithm).

The two possible alternatives:

1) If you are building your noise with layers of octaves, traditionally, the first couple of octaves have the biggest influence on the outcome. thus, it might be possible to find candidate locations without fully pre-generating a region.

2) Decide in advance where you want the random 'p' locations to be & design your noise function to give you values to accommodate them.

\$\endgroup\$
0
\$\begingroup\$

Keep a list of the positions for os for each chunk. When the chunk done with the Perlin noise generation, select an o randomly from the list to be replaced by a p.

\$\endgroup\$
  • \$\begingroup\$ There’s no way of knowing whether or not the chunk of Perlin noise will be contained by a certain world region—or chunk. It could very well span multiple chunks. I can’t store things into arrays as every region is generated separately, without any knowledge of nearby chunks. One way to do it would certainly be using a flood fill to retrieve information about the chunk to locate the bottom left corner and use that as a seed for the random position—but that would seem very inefficient. \$\endgroup\$ – D. Ataro Feb 1 '17 at 16:41
  • \$\begingroup\$ I suppose it's not clear to me how you're generating this noise then. Do you not have chunks for data you're generating, each are supposed to contain one p? Are you generating chunks at some other time, then adding Perlin noise to them after? How do you not know which chunk Perlin noise is being introduced into? You don't need to know anything about surrounding chunks, because you're only concerned with a single chunk at a time, the noise you're adding to it and the single p you're adding. \$\endgroup\$ – MichaelHouse Feb 1 '17 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.