Hello,
I’ve been working on a procedural terrain generator for a big project i have coming. I finished the generator but i have an issue with Roblox terrain, it sticks out in weird lines which make it look unnatural:
This isn’t some render optimization issue because it still retains the lines when the camera is close and the quality level is set to max.
Perlin noise generator
function Noise2D.new(WidthX, WidthZ, Seed, Scale, Amplitude, Frequency, Octaves, Persistance, Lacunarity)
local self = Map2D.new(WidthX, WidthZ)
local MaxHeight = -math.huge
local MinHeight = math.huge
for X = 0, WidthX do
for Z = 0, WidthZ do
local Amplitude = 5
local Frequency = 1
local Height = 0
for Index = 0, Octaves do
local SampleX = X / Scale * Frequency
local SampleZ = Z / Scale * Frequency
local Noise = math.noise(SampleX, SampleZ, Seed)
Height += Noise * Amplitude
Amplitude *= Persistance
Frequency *= Lacunarity
end
if Height > MaxHeight then
MaxHeight = Height
elseif Height < MinHeight then
MinHeight = Height
end
self[X][Z] = Height
end
end
for X = 0, WidthX do
for Z = 0, WidthZ do
self[X][Z] = InverseLerp(MinHeight, MaxHeight, self[X][Z]) * Amplitude
end
end
return self
end
Terrain script
local function Generate(WidthX, WidthZ, Seed, Scale, Amplitude, Frequency, Octaves, Persistance, Lacunarity)
local Map = Noise2D.new(WidthX, WidthZ, Seed, Scale, Amplitude, Frequency, Octaves, Persistance, Lacunarity)
for X = 0, WidthX do
for Z = 0, WidthZ do
local Y = Map[X][Z]
local Block = CFrame.new(Vector3.new(X, Y, Z))
Terrain:FillBlock(Block, Vector3.new(2, 5, 2), Enum.Material.Grass)
end
RunService.Heartbeat:Wait()
end
end
Generate(1000, 1000, math.random(), 200, 50, 20, 10, 10, 1)
-- SizeX, SizeZ, Seed, Scale, Amplitude, Frequency, Octaves, Persistance, Lacunarity --
Any help is appreciated!