Tuesday, February 26, 2019

procedural - Generating terrain using Marching Cubes


I searched around the web but I found nothing that could help me, so I'm asking here.



I'm trying to procedurally generate terrain using the marching cubes algorithm, and I can generate a mesh. The problem is that the mesh that may be anything!


https://www.dropbox.com/s/w99lvynrfra2a5v/question.JPG


As you can see in that screenshot, everything is messed up.


Is this a problem with the noise function? I'm using a simple Perlin noise function. How can I achive a result like this:


http://www.youtube.com/watch?v=-hJkrr5Slv8


If the problem is with the noise, what do I need to change to achieve this? I want to create natural terrain with hills, mountains, plains etc.


(I'm using Unity3D, but I don't think this makes any difference.)



Answer



I suggest scaling down the vertical component of the sample point before sampling the noise function.


The starting point of the voxel terrain in the video looks like a heightmap, so they may have multiplied the component by 0.



Also, you have to add the vertical component to the field function.


so your field function should look something like this:


const float noise_vertical_scale = 0.2;
const float field_vertical_scale = 0.01;
const float iso_surface = 0.5;

/*
* returns field at point (pos):
* negative = inside
* 0 = surface

* positive = outside
*/
float sampleField(vector3 pos)
{
vector3 sample_pos = pos;
sample_pos.y *= scale;
return noise3D(sample_pos) + pos.y * field_height_scale - iso_surface;
}

Hope that helps.



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