December 07, 2019, 12:46:29 PM

Author Topic: Consistent noise  (Read 235 times)

Offline grindalf

  • Jr. Member
  • **
  • Posts: 87
Consistent noise
« on: November 22, 2019, 11:52:01 AM »
How do games like Minecraft always generate worlds the same. I know about seed numbers ect but I mean the noise generated.
The worlds are near infinite so its not all generated at once but if you travel north and find a village. but then delete the world recreate the world and travel south and go around in a massive circle so you approach the same village from the north it will still be the same.
Sorry for the weird long winded explanation there, I just don't know how else to explain what I mean :P

For my worlds in my game I always generate the whole world at startup otherwise I cant keep it consistently the same, but that of course means my worlds are extremely limited in size. For my terrains Im using a perlin noise algorithm from the blitz code archives so maybe I just don't understand how perlin works correctly.

Offline Derron

  • Hero Member
  • *****
  • Posts: 2607
Re: Consistent noise
« Reply #1 on: November 22, 2019, 01:14:42 PM »
You use a PRNG (Pseudo Random Number Generator) like MersenneTwister.

Given the same seed all following "give me a random number" would result in the same sequence. Think so far you did it know already.

Now this PRNG-instance should never be used for stuff "changing" between games or users - so do not use them for graphical particles, or so.
Now you generate your world with a given seed ... the world would always look the same.

If you generated your village in the same call, then it would always look the same and be at the same position.

You could create it on the fly when approaching a certain area. It generates new random numbers and so on - but every "random number generated" since "world creation" and "approaching a certain area" would make it generate another village as the random numbers will differ.

So if you want eg the village to always look the same (for this world) - but at a different position you just need a new PRNG-instance for "village creation".
At world creation you give the "village PRNG instance"-seed a new random value (which is the same amongst all worlds).

Now when you do your first village it will always get the same random numbers. The second village too ... and so on.


Essence: use different PRNG but set their seeds at the root (eg world creation).


bye
Ron

Offline grindalf

  • Jr. Member
  • **
  • Posts: 87
Re: Consistent noise
« Reply #2 on: November 22, 2019, 09:40:10 PM »
but that doesn't really solve the problem. Imagine I visit the second village first then travel back to the first. Now they have generated in the wrong sequence. Minecraft does not have this problem as no matter what direction you approach from or what things you visit first a world generated with the same seed always generates the exact same world.

My initial thought on this was about the noise. I think its Perlin noise in Minecraft but it could be simplex. I imagine there must be a way to continue the noise from a x-z coordinate point but Im just guessing.

Offline GaborD

  • Sr. Member
  • ****
  • Posts: 322
Re: Consistent noise
« Reply #3 on: November 22, 2019, 10:09:08 PM »
The perlin noise (same for simplex) shouln't use any random numbers that depend on previous values/sequences or the system timer but rather be completely based on a static random vector grid that doesn't change at all (could be implemented with a hash or a texture or by using a pseudo random function that only depends on it's direct inputs and nothing else), making sure that with the same seed offset you always get the same results back for the same coordinates.


Offline Matty

  • Hero Member
  • *****
  • Posts: 793
    • MattiesGames
Re: Consistent noise
« Reply #4 on: November 23, 2019, 02:33:19 AM »
Thinking I understand your problem this is how I do it in 'The Young Prince' when you visit a dungeon:

Each dungeon on the overland map has a seed associated with it. 

When you visit the dungeon - it creates the dungeon map from that seed, along with all associated bits and pieces such as creatures and treasure and so on.

When you leave the dungeon, the seed is retained for the dungeon so that if you visit it again, the same dungeon and contents can be recreated.

In my game the dungeons respawn everything if they are not 'completed' and if they are completed then they remain closed forever after that.

However - if you wished to recreate the dungeons upon returning with keeping the state of the dungeon intact as for when you left it then you need to store not only the seed but which components are now 'missing' (ie creatures and treasure), which secret doors are opened/unlocked, and if any additional bits and pieces (dropped inventory) are left behind.

Offline Derron

  • Hero Member
  • *****
  • Posts: 2607
Re: Consistent noise
« Reply #5 on: November 23, 2019, 07:29:42 AM »
Seems I do not understand what grindalf tries to achieve then.

Using different prng instances / initial seeds for stuff is what I proposed and what Matty is effectively using too (maybe he described it better).


Idea is to have a prng...and use the replay ability to build consistent stuff. It is up to you, to eg use the coordinate of there a village is to build as start seed of a prng. So the billage on a specific spot will always look the same.

Use a village counter to mix in...and you get always the same village if it is build at the same spot after you generated previous villages at their exact same spots.

Mix this approach to your likes.


Bye
Ron

Offline grindalf

  • Jr. Member
  • **
  • Posts: 87
Re: Consistent noise
« Reply #6 on: November 23, 2019, 09:41:46 AM »
@Derron the coordinate of the village is a good idea.
@GaborD I think what you are saying there is what I am trying to figure out but I guess I don't know Perlin well enough to be able to continue the noise from a point. Obviously only chunks within viewing range are generated and saved so when a new chunk is generated the noise must continue. Im using a perlin code from the code archives If I post it does anyone here know Perlin well enough to point out roughly what I need to do?

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1020
Re: Consistent noise
« Reply #7 on: November 29, 2019, 08:27:53 PM »
i have read an article on how they manage the generation in "no man's sky"
and the idea was to generate the small things (like plants) depending the big things (like trees) (and position them around them)

the problem is indeed how to save this data once it has been generated (to keep it looking the same way when you go back)
the small things properties depending on the big things properties seems like a good approach...

fo a heightmap it could be low detail grid for the low detail (10x10) and then consider this to generate the high detail version (1000x1000)
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0