Monday, May 28, 2018

algorithm - How to remove floating terrain when generated with 3D Perlin Noise?



I'm currently using 3D Perlin Noise to generate random terrain in combination with Marching Cubes.


My issue seems to lie in scaling the noise function to get reasonable heights in my terrain. If only one octave is used, all points in relation to the noise are obviously interpolated which results in fairly smooth data. However, to get overhangs/caves/jagged terrain, I have to use multiple octaves with varying amplitudes and/or scale the resulting values to my 'max' height I want of the map.


I might be missing something, but by using marching cubes with 3D perlin noise, I regularly get floating bits of terrain.


Any ideas on how I could correct this or if there's other noise functions I might use to get results like I'm describing? I'm wanting hills/valleys/mountains/lakes/etc. No need for floating bits segregated from the rest of the map. I believe this is a similar issue to what Minecraft has when it has terrain that just floats around in the sky occasionally upon generation.


Thanks for any assistance, Mythics



Answer



Probably the only way to completely get rid of floating terrain is to test for connectivity. Depending on the size of you map, that might be an option. You can do that by picking base point, like the very bottom of your world. Then ensure all your voxels are either:



  1. Connected to the base.

  2. Connected to a voxel that's connected to the base.



Likely starting at a known connected point (like the bottom of your world) then doing a breadth first traversal of connected voxels would work pretty well. Make sure you're flagging voxels as connected while you go. You can do this per-chunk.


Additionally, there are less expensive ways to minimize, but not completely remove the floating terrain.




  • Gradient bias: You can bias the placement of solid voxels with a gradient. The gradient function would fall off somewhat sharply after you're above the "ground level". This article talks about using a gradient and has some other neat tips.




  • Height map noise: You can generate noise as a height map instead. This would remove the overhangs and caves, but you can simulate those with an additional subtractive noise layer.





  • Less noisy noise: Use fewer octaves in your terrain noise and generate subtractive noise to get overhangs and caves.




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...