Help with Procedural generation (Falloff filter)

Hello,

I wanted to create a survival game. So I started creating the procedural generation map and wanted to add a falloff filter to the map but I couldn’t find any tutorials or any docs about the falloff filter on the Roblox Developer Docs. And I tried to create the falloff filter by hand but it’s impossible to create.

Here is the code:

for z = 1,200,1 do
	for x = 1,200,1 do
		local Block = game.ServerStorage.Block:Clone()
		Block.Parent = game.Workspace.Map.Blocks
		Block.Locked = false
		Block.Anchored = true
		Block.CanCollide = true
		Block.CastShadow = false
		Block.Position = Vector3.new(-0.5,0.5,-0.5)
		Block.CFrame = Block.CFrame + Vector3.new(x*1,0,z*1)
		Block.CFrame = Block.CFrame + Vector3.new(0,math.floor(math.abs(math.noise(x/20,z/20)*10)),0)
		
		if Block.CFrame.Y >= 1.5 then
			Block.Material = "Grass"
			Block.BrickColor = BrickColor.new("Artichoke")
		else
			Block.Material = "Slate"
			Block.BrickColor = BrickColor.new("Medium stone grey")
		end
	end
end

for i, v in pairs(game.Workspace.Map.Blocks:GetChildren()) do
	if v.CFrame.Y < 1.5 then
		local Clone = v:Clone()
		Clone.Parent = game.Workspace.Map.Blocks
		Clone.Material = "Sand"
		Clone.BrickColor = BrickColor.new("Bright blue")
		Clone.CFrame = v.CFrame + Vector3.new(0,1,0)
	end
end

What is a falloff filter? charscharschars

Map without falloff filter:

Map with falloff filter:

It basically creates a border and with that border, you can subtract that with the Perlin noise (Procedural Generation Map) to create some form of an island.

I also experimented with Perlin noise map generation. Although I haven’t tested this idea yet; You could start using the perlin nouse when the part is above a certain Y cooridinate, below a certain Y cooridinate, right of a certain X cooridinate and left of a certain X cooridinate.

Basically have the parts at sea-level/water until they are inside certain cooridinates, where you can apply perlin noise to it.

I have tried multiple times and many ways to add a falloff filter to the procedural generation map but it’s literally impossible to create a falloff filter by hand. I think it should be a feature in the game engine.

looping through different perlin noise imputs could get you to the right imputs for the perlin noise.

I have tried looping the Perlin noise. I even tried to create a falloff filter by creating a local falloff with a table of 4 values and with each value it would go down by decreasing it if greater than 190 on z and x or in a different value if less than 10 on z and x it would go up by increasing it. At some point, the code I wrote was about 300+ lines of code. So creating a falloff filter by hand is literally impossible in my experience.

I will try in my own terrain generator and send a screenshot here. But in my Generator it works a bit differently. Anything below sea-level is deleted and the SeaLevel is 1 part covering the map at sea level

I implemented it to my terrain generator and I now get what you mean:
image

I added if x>10 and x<ROWs-10 and y>10 and y<COLs-10 then to my generator. It adds a sort-off Falloff filter, by cutting the noise, but the coastline isn’t smooth. Detecting coastline and fading it may help. But that would make terrain generation rather slow.

It’s more like smoothing out the edges so it could become an island. For example. Games like Minecraft or muck.

Yes, I get the concept, I just don’t get how to implement it.

I also don’t know how to implement this I had some concepts but all of them failed.

:sob:

Detecting the noise of the parts around the current part to check if it is on the coast, and then smooth that part and surrounding parts down might work, but I am not sure.

There’s several ways to do it. One way is to multiply the output of your height function by a function that returns 1 at the center and approaches 0 near the edges. The simplest such function is just a falling linear function, i.e. -x + 1, where x is the distance of a point from the center:

Here I’ve pictured it from -1 to 1 although obviously there are no negative distances. It’s still useful though because it shows the discontinuity around x=0, which might be visible in the terrain. A function that fixes that is smoothstep, 1 - (3x^2 - 2x^3)

There’s also smootherstep, 1 - (6x^5 - 15x^4 + 10x^3):

A down side of using these function is that they influence the height of the map a lot, meaning they’ll make it so there’s more often tall mountains near the center and more flat terrain near the edges. This may be fine, but it’d be nice if you could control when the falloff begins, e.g. halfway from the center to the edge. This can be accomplished by just outputting 1 before the falloff radius, and then outputting the smootherstep function after the falloff radius, but shifted and scaled on the X axis to go from 1 to 0 between the falloff radius and 1:

Although you don’t really want these functions to go to 0 when distance = 1, you want it to go to 0 when distance = radius of the map, so just divide the distance by the radius and use that as the x value to the falloff functions:

local MAP_RADIUS = 128
local FALLOFF_RADIUS = MAP_RADIUS * 0.5

function smoothstep(x)
    return 6 * math.pow(x, 5) - 15 * math.pow(x, 4) + 10 * math.pow(x, 3)
end

function smootherstep(x)
    return 3 * math.pow(x, 2) - 2 * math.pow(x, 3)
end

function heightFalloff(distance)
    if distance < FALLOFF_RADIUS then return 1 end
    
    local x = ( (distance - FALLOFF_RADIUS) / MAP_RADIUS ) / (1 - FALLOFF_RADIUS / MAP_RADIUS)
    x = math.clamp(x, 0, 1)
    return 1 - smootherstep(x)
end

Testing it like this

for i = 0, MAP_RADIUS*1.25, MAP_RADIUS/10 do
    print(i / MAP_RADIUS, heightFalloff(i))
end

yields this:

0.000 1.000
0.100 1.000
0.200 1.000
0.300 1.000
0.400 1.000
0.500 1.000
0.600 0.896
0.700 0.648
0.800 0.352
0.900 0.104
1.000 0.000
1.100 0.000
1.200 0.000

which has the behavior I described. You can use it with the smoothstep function as well, and even the linear falloff if you like that better.

Hope this helps!

3 Likes

After some messing about with the implementation I got it to work with 3D Perlin noise/Caves.
It yields pretty nice results and makes the end of the map natural. I have a boolean to reverse the falloff for floating islands instead of filled in terrain!

Just wanted to say Thank you!

2 Likes