I'm attempting to create a sphere with terrain (aka planet). I managed to procedurally create an icosahedron, and I am able to subdivide it (yay), but now I'm stuck on terrain.
My current idea iswas to create a Perlin like "3D Noise Field" and sample noisedensity where each of the spheres vertices fall (as a height-map value). this way i should be able to tweak the noise (add octaves, etc) to roughen the "NoiseField" and thus the spheres surface.
pseudo example and result:
public void Terrain(float Scale)
{
if (Scale < 0.01) return;
List<Vector3> terrain = new List<Vector3>();
for ( int i = 0; i < surface.vertices.Count; i++)
{
Vector3 vert = Original[i];sphere.verts[i];
Vector3 direction = vert.normalized;
Vector3 newpoint = vert * Sample3DNoise(direction, Scale);
terrain.Add(newpoint);
}
//this line replaces the original shape!
surface.vertices = terrain;
Debug.Log("terrain Update");
}
public float Sample3DNoise(Vector3 point, float scale)
{
//Vector3 direction = point.normalized;
float u = point.normalized.x * scale;
float v = point.normalized.y * scale;
float w = point.normalized.z * scale;
//poor attempt at 3d noise field
//PerlinNoise(float, float );
float x = Mathf.PerlinNoise(u , 0f);
float y = Mathf.PerlinNoise(0f, v);
float z = Mathf.PerlinNoise(u , v);
//the average of the coords, returns "density at this point"
return (x + y + z) / 3;
}
edit:
so while it appears i was able to achieve this, it's is clearly not the "terrain on surface of sphere" look I was lookingaiming for. Any suggestions on how can I change the "noise field" so my surface is more planet like? or how else can i achieve this?