Adding Custom Structures Into Perlin Noise? / Voxel Generation

Hello, I am wanting to make a game such as No Mans Sky and Minecraft. However, I am unsure on how I can add custom structures into Perlin Noise.

  1. What do you want to achieve?

I want to make a Perlin Noise Terrain generator with, custom structures.

  1. What is the issue?

I do not know how to implement custom structures into Perlin Noise.

  1. What solutions have you tried so far?

I have asked in Discords and searched on the Dev Hub and YouTube.

Structures that need to be added:

local function fibonacci_spiral_sphere(num_points)
	local vectors = {}
	local gr = (math.sqrt(5) + 1) / 2
	local ga = (2 - gr) * (2 * math.pi)
	
	for i = 1, num_points do
		local lat = math.asin(-1 + 2 * i / (num_points + 1))
		local lon = ga * i
		
		local x = math.cos(lon) * math.cos(lat)
		local y = math.sin(lon) * math.cos(lat)
		local z = math.sin(lat)
		
		table.insert(vectors, Vector3.new(x, y, z))
	end
	
	return vectors
end

local radius = 10

local ref = Instance.new("Part")
ref.Anchored = true
ref.Size = Vector3.new(0.2, 0.2, 0.2)

local vec = fibonacci_spiral_sphere(1024)
for _, v in ipairs(vec) do
	local part = ref:Clone()
	part.CFrame = CFrame.new(v.Unit * radius)
	part.Parent = workspace
	wait()
end

So, can anyone help me to add to my generator custom structures?

Just gonna BUMP this back up because still remains unsolved!

A probably crude way is to separate the factors that determine how the terrain is generated.

You can generate the base terrain via some noise function using the X, Y, and Z components, but then have separate components, lets say W; which can represent other data.

Lets say W represents our chance for structures to spawn in a given area. We could generate a noise value for W and then compare that number to some other number to determine whether a custom building should be placed.

A probably bad code example:

local function PerlinXYZ(X, Y, Z)
    --// Do magic to return terrain info with XYZ
end

local function GenerateTerrain(X, Y, Z, W)
    --// blah blah generate terrain at XYZ

    if (W > .95) then
        RandomStructure()
    end
end

for X = 0, ... do
    for Y = 0, ... do
        for Z = 0, ... do
            local _X, _Y, _Z = PerlinXYZ(X, Y, Z)
            local W = Noise(0, 1)

            GenerateTerrain(_X, _Y, _Z, W)
        end
    end
end

How would I make a 25% chance of structures spawning though?

Noise is not random so a “25%” chance does not make much sense.

You would want to define W as W = math.random() then;

if (W <= .25) then

end

or

if (W >= .75) then

end

Both work.

How does this help? What do I do with tihas