Voxel generation

It’s a level of density. If the density at a point is > 0, then we generate a block. UNLESS it’s above this lower_threshold. Which, thinking about it makes it sound like a pretty confusing variable name. You might want to come up with something better :stuck_out_tongue: This means where before our terrain was filled in all the way through, now it will only be filled in when the density is between 0 and this threshold. This lets us avoid generating unnecessary blocks that we later have to check with the “number of neighbors” method.

That makes sense XD Few tweaking of things and I managed to also figure out how to make dirt go on blocks below green ones (doesn’t always work, but I guess it’s close enough :smiley: ) :+1:

If you know of a way to actually make blocks below the green ones brown 100% then that would be amazing

Changed the parts to be models too :smiley:


Can see that the grass parts still spawn below other grass parts tho :confused:

if d > 0 and d < 0.04 then
					local block
					if d > 0.0175 then
						block = script.Dirt:Clone()
					else
						block = script.Grass:Clone()
					end
					
					block:SetPrimaryPartCFrame(CFrame.new(x * 4, y * 4, z * 4))
					block.Parent = workspace
				end

And what about getting different heights? Ways to see how high the actual blocks are, allowing change to color based on height, or overhangs? Instead of just being hills

And is there a faster way to generate the land? If I have it so the player doesnt spawn till all the land has been created then it takes forever? Would I be best to say ‘create’ the land via the code, but not insert the blocks unless the player is within a certain radious of the blocks?

‘hillnessNoise’ would be what exactly? just math.noise??

Yeah, the y coordinate is the height.

for x = 1, mapSize do
	for y = 1, mapSize/2 do
		for z = 1, mapSize do
                local height = y
		end
	end
end

You can use this if you want all horizontal layers to be a specific color/block type.

If you want to see how “deep” into the ground a block is, accounting for both horizontal and vertical depth, I can’t think of a really good way of doing it. Points where the density function is higher will usually be deeper, but there’s no obvious way to see how far away a block is from the nearest air block. A simple flood fill might work, but will take a while to run for every block.

You’re not getting any overhangs because you aren’t twirling the coordinates enough. Here’s the density function from the original script I posted:

function density(x, y, z)
	--If you twirl with power 0, you'll just get a plain heightmap
	local tX, tY, tZ = twirlCoordinates(x, y, z, 1)
	tZ = tZ / (1 + y)
	tX = tX / (1 + y)
	local densityOffset = 0.5 + heightMap(tX, tZ) - y --Add 0.5 density so that there's a guaranteed bottom layer
	return densityOffset
end

You might want to increase the “twirl power” if you haven’t tried that yet.

You could make your own “chunk” system a la Minecraft. Or check out StreamingEnabled to see if that’s an option for you.

I’m not sure, but with a chunk system you can avoid having to generate the whole world at a time, instead generating it when it becomes relevant (e.g. when a player moves closer to it).

1 Like

ik its like a year later so this may not be so relevant, but how would i make it so the terrain is mostly around a specific height then occasionally there would be a huge mountain?

1 Like

Check out this page, especially under “Redistribution”.

You can get a similar result by multiplying the height value at a given point by the “height value” of a different noise function, assuming the second one is between 0 and 1.

6 Likes

ik this is an old thread but you could do a system like minecraft where blocks turn into dirt if they are under something or grass if they arent then just run it at like 1000x times speed when game first starts

Something else that made voxel generation run much faster for me is checking the surrounding blocks for a transparent block e.g. air, glass and if they r there it renders the block, otherwise it’s just kept in a table. When a block is broken it should update the surrounding blocks to see if they should be rendered.

This method increased my frame rate by tons.

1 Like