Sunday, November 8, 2015

terrain - Cave generation with Perlin worms


I'm currently trying to generate a Minecraft like voxel terrain with 3D Simplex Noise and also want to implement caves.


I found the method of Perlin Worms in this thread, which generates really nice results. However, I have no clue on how to generate it on a chunk by chunk basis. Is this possible or are there any alternatives that produce a similar worm like cave on a chunk by chunk basis?



Edit: This is the problem which I don't know how to solve.


Edit2: This is the result from combining 2D Ridged Multifractal Noise with a Simplex Noise heightmap. Still needs some tweaking, but this is pretty much the result I wanted. Thanks to Byte56.



Answer



Most perlin noise algorithms will allow you to retrieve the noise value at any given location, with something like noise(x,y,z). This makes it fairly trivial to generate noise on a chunk by chunk basis. All you need to do is pass the global position, instead of the chunk position.


for(int i = 0; i < CHUNKMAX_X; i++)
for(int j = 0; j < CHUNKMAX_Y; j++)
for(int k = 0; k < CHUNKMAX_Z; k++)
if(isSolid(perlinNoise.get(chunkPosition.x + i,
chunkPosition.y + j,
chunkPosition.z + k))

thisChunk[i,j,k] = new Voxel(solid);
else
thisChunk[i,j,k] = new Voxel(air);

So you can see, we're generating terrain for the chunk, by iterating over the chunk bounds, and checking to see if that global position is solid or not. This is likely the same methodology you're using to generate the terrain in general.


perlinNoise.get takes a global position and returns its density. Where isSolid would just be a simple test to see if the voxel is "dense enough" to qualify for solid.


perlinNoise.get can be more complex than just a simple noise algorithm. You can have checks based on the depth of the voxel in your world. For example, if the voxel is below what you've decided is "absolute base ground level" then it can use the perlin worms algorithm to return a density, if it's above the absolute base, it can use a normal density function to give you more varied terrain. I would recommend some blending between the two however.


Combining different Perlin noise functions is just something you have to play with and see what works. It's best to set up your environment so that you can just change some values and hot-swap the terrain without needing to reload your game. Happy experimenting.


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...