Voxel Terrain Planet Generation

I am trying to create a voxel terrain planet generated using perlin noise.

I have gotten to the point where my terrain generates in a flat rectangular shape. Now I am trying to map that terrain around a spherical shape. Here is what I have so far:

local angle = 0
local layer = 0
local diameter = mapSize

		local position = CFrame.Angles(math.rad(angle), math.rad(-layer), math.rad(0)) * CFrame.new(0, 0, math.abs(diameter / 2))		
		local height, material = terrainModule.GetTerrain(position.X, position.Z)

		workspace.Terrain:FillBlock(position + Vector3.new(0, (-diameter / 2), 0), Vector3.new(30, 30, 10), material)
		angle = angle + 1
	until angle == 360
	angle = 0
	layer = layer + 1
until layer == 270

The script above creates a perfect sphere. If I change the position used in the FillBlock() function to blockPosition:

local blockPosition = CFrame.new(position.X, position.Y + height, position.Z)

workspace.Terrain:FillBlock(blockPosition + Vector3.new(0, (-diameter / 2), 0), Vector3.new(30, 30, 10), material)

The script, of course, only applies the height straight up in the Y direction. So, I need to somehow apply this height value at an angle around the sphere, which would require more than simply adding to position's Y value. How can I do this?

This is the result of this script:

Here is the same terrain seed except flat to help visualize:

I haven’t taken trigonometry or calculus yet, so the math is unknown to me. If you could explain your answer to me a little more abstract that would be great. Thanks!


I think you’d be better off just generating with 3D perlin noise and write voxels, then subtract based on the distance from the center.

1 Like

I have considered doing that, and have seen that approach pop up a few times online. If this method ends up not working out I will try using 3D perlin noise, but I feel that I am so close to finishing it this way I don’t wanna change methods yet, as I would have to rewrite a lot of code.

1 Like