"Squashing" effect for 3d Perlin Noise

Hello I’m a new developer currently exploring procedural terrain generation. I have already implemented a 3d Perlin noise generator and made it generate a 3d map tho it look like this: (looks very swiss cheesy)

I have found this video at timestamp 27:58 he explains “squashing” however Idk how to properly implement it . (btw shout out to Henrik he’s a great resource for procedural generation)

Here’s a snippet of the code:

--SERVICES
local WS = game:GetService("Workspace")

--OBJECTS
local Chunks_Folder = WS:WaitForChild("Chunks")

--VARIABLES
local chunkName = "Chunk_%d X_%d Y_%d Z"

--SETTINGS
local CHUNK_SIZE = 32
local SEED = 0
local RESOLUTION = 10
local AMPLITUDE = 10
local MIN_DENSENESS = 1
local SQUASHING = 1

--FUNCTIONS
local function generateChunk(x: number, y: number, z: number)
	--Model container
	local chunk = Instance.new("Model")
	chunk.Name = string.format(chunkName, x, y, z)
	
	--Generating the blocks
	for x = x, x + CHUNK_SIZE - 1 do
		for y = y, y + CHUNK_SIZE - 1 do
			for z = z, z + CHUNK_SIZE - 1 do
				local X = math.noise(y / RESOLUTION, z / RESOLUTION, SEED) * AMPLITUDE
				local Y = math.noise(x / RESOLUTION, z / RESOLUTION, SEED) * AMPLITUDE
				local Z = math.noise(x / RESOLUTION, y / RESOLUTION, SEED) * AMPLITUDE
				
				local density = X + Y + Z
				
				if density >= MIN_DENSENESS then
					local part = Instance.new("Part")
					part.Anchored = true
					part.Size = Vector3.new(1, 1, 1)
					part.Position = Vector3.new(x, y, z)
					part.Parent = chunk
				end
			end
		end
	end
	
	chunk.Parent = WS
end

--RUN CODE
generateChunk(0, -CHUNK_SIZE, 0)
generateChunk(CHUNK_SIZE, -CHUNK_SIZE, 0)
generateChunk(0, -CHUNK_SIZE, CHUNK_SIZE)
generateChunk(CHUNK_SIZE, -CHUNK_SIZE, CHUNK_SIZE)

i think he means to pass the noise values into a function that changes the values to be lower as height increases

you can mess around with different types of functions for better results

--linear example
local function squash(x : number, height : number) : number
  return x - height
end

--usage example
local X = math.noise(y / RESOLUTION, z / RESOLUTION, SEED)
X = squash(X, y)
1 Like

yea I have this idea to implement a “water line” here’s a visualization:

Basically anything above and below water line will get squished or “pulled” to the water line.

I think this might be one of the answers but lmk.

Anyways tysm for sharing your idea imma try it out and let everyone know tmr (cuz my timezone is at gmt+8)