WriteVoxels Occupancy Issue With Noise

I’m currently trying to make procedural terrain generation using the Terrain:WriteVoxels() function.

Everything is almost 100% perfect except for the terrain smoothing. I just can’t figure out how to make it look normal. Here is what it looks like:

I’ve tried messing around with my math function a little bit (no surprise it didn’t work) so I’m basically just looking for help with that.

This is the code for determining the occupancy. VOXEL_SIZE is 4 and gridHeight is just a y-value aligned to multiples of 4

local averageHeight = (
	getHeightFromPosition(x - 0.5, z - 0.5, config) +
	getHeightFromPosition(x - 3.5, z - 0.5, config) +
	getHeightFromPosition(x - 0.5, z - 3.5, config) +
	getHeightFromPosition(x - 3.5, z - 3.5, config)
) / 4
			
local gridHeight = math.ceil(averageHeight / VOXEL_SIZE) * VOXEL_SIZE
local occupancy = (gridHeight - averageHeight) / VOXEL_SIZE
			
local mappedX = (x - chunkX + 4) / 4
local mappedZ = (z - chunkZ + 4) / 4
			
local position = Vector3.new(mappedX, gridHeight/4, mappedZ)
local material = getMaterialFromPosition(position, config)
			
if gridHeight > height then
	height = gridHeight
end
			
mapData[position] = {
	Occupancy = occupancy,
	Material = material
}

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

The reason why it’s not smooth is because the terrain is too spaced out on the Y axis, try making it closer together height wise

Can I get something more descriptive than that? I remember someone told me to use a bilinear Lerp function but I’m not sure how to implement that into my code currently

The voxels are too far away from each other on the Y axis, if you make it so that they’re closer together on the Y axis then Roblox will automatically smooth out the terrain for you

if that still doesnt help then i can send some images later when im on roblox studio

What if I want steep terrain that’s smooth?

idk if this explanation will make sense but make the voxels smaller so you have more voxels to move up

I thought Roblox only allowed 4x4x4 Voxel size though