# Attempt at normalizing noisemap while having biome transition

Trying to make normalized noiseMaps with transition based on temperature decided biomes.

1. What do you want to achieve? Seamless natural looking transition.

2. What is the issue? I am trying to generate biome supporting normalized terrain but I get weird cuts in terrain and unnatural looking transitions.

3. What solutions have you tried so far? I tried to manually set max and min but I got the same results.

Noise calculation

``````local CONFIGURATION = require(script.Parent.Parent.Configuration)

local OCTAVES = 3
local SCALE = 100
local OFFSET = Vector2.new(0, 0)

local octaveOffsets = {}
for i = 0, OCTAVES - 1 do
octaveOffsets[i] = Vector2.new(
(math.random() + .5) * OFFSET.X,
(math.random() + .5) * OFFSET.Y
)
end

local module = {}

-- Used for the normalization of the noiseMap
local minNoiseHeight = 0
local maxNoiseHeight = 0

function inverseLerp(x, y, a)
return math.clamp((a - x) / (y - x), 0, 1)
end

function module:CalculateNoise(x, z, modifiers)
local amplitude = 1
local frequency = 1
local noiseHeight = 0

for i = 0, OCTAVES - 1 do
local sampleX = (x - CONFIGURATION.ChunkSize/2) / modifiers.SCALE * frequency + octaveOffsets[i].X
local sampleZ = (z - CONFIGURATION.ChunkSize/2) / modifiers.SCALE * frequency + octaveOffsets[i].Y

local noise = math.clamp(math.noise(sampleX, sampleZ), -.5, .5) + .5
noiseHeight += noise * amplitude

amplitude *= modifiers.PERSISTANCE
frequency *= modifiers.LACUNARITY
end

if noiseHeight > maxNoiseHeight then maxNoiseHeight = noiseHeight end
if noiseHeight < minNoiseHeight then minNoiseHeight = noiseHeight end

return math.clamp(inverseLerp(minNoiseHeight, maxNoiseHeight, noiseHeight), 0, 1)
end

return module
``````

Chunk generator

``````local CONFIGURATION = require(script.Parent.Configuration)
local NOISE_CALCULATOR = require(script.Parent.Calculations.NoiseCalculator)
local TEMPERATURE_GENERATOR = require(script.Parent.Calculations.TemperatureGenerator)
local BIOME_CALCULATOR = require(script.Parent.Calculations.BiomeCalculator)

local module = {}

function module:CreateChunk(chunkX, chunkZ)
-- Attempt at setting a max and min 2D noise value.
for x = -CONFIGURATION.ChunkSize, CONFIGURATION.ChunkSize do
for z = -CONFIGURATION.ChunkSize, CONFIGURATION.ChunkSize do
local _x = x + (chunkX*CONFIGURATION.ChunkSize)
local _z = z + (chunkZ*CONFIGURATION.ChunkSize)

-- Gets the temperature value for the biome assigning.
local temperature = TEMPERATURE_GENERATOR:GenerateTemperature(_x, _z)
-- Gets the biome based on temperature.
local biome = BIOME_CALCULATOR:BiomeFromTemperature(temperature)

if #biome == 2 then
NOISE_CALCULATOR:CalculateNoise(_x, _z, biome[1])
NOISE_CALCULATOR:CalculateNoise(_x, _z, biome[2])
else
NOISE_CALCULATOR:CalculateNoise(_x, _z, biome[1])
end
end
end

for x = 1, CONFIGURATION.ChunkSize do
for z = 1, CONFIGURATION.ChunkSize do
local _x = x + (chunkX*CONFIGURATION.ChunkSize)
local _z = z + (chunkZ*CONFIGURATION.ChunkSize)

-- Gets the temperature value for the biome assigning.
local temperature = TEMPERATURE_GENERATOR:GenerateTemperature(_x, _z)
-- Gets the biome based on temperature.
local biome = BIOME_CALCULATOR:BiomeFromTemperature(temperature)

local p = Instance.new('Part')
p.Anchored = true
p.Position = Vector3.new(_x, 1, _z)
p.Size = Vector3.new(1, 1, 1)
p.Name = temperature

local noise
local height
local grayscaleColor = Color3.new(.5, 0, 0)
if #biome == 2 then
local grayscale = (biome[2].TEMPERATURE - temperature) * 10
if grayscale <= .8 then
-- Arranges grayscale to be 0 to 1
grayscale /= .8
-- Calculates noise using the biomeModifier.
local noise1 = NOISE_CALCULATOR:CalculateNoise(_x, _z, biome[1])
local noise2 = NOISE_CALCULATOR:CalculateNoise(_x, _z, biome[2])
-- Lerps the noise using grayscale.
noise = noise1 + (noise2 - noise1) * grayscale

grayscaleColor = Color3.new(grayscale, grayscale, grayscale)
else
-- Calculates noise using the biomeModifier.
noise = NOISE_CALCULATOR:CalculateNoise(_x, _z, biome[1])

grayscaleColor = Color3.new(noise, noise, noise)
end
else
-- Calculates noise using the biomeModifier.
noise = NOISE_CALCULATOR:CalculateNoise(_x, _z, biome[1])
grayscaleColor = Color3.new(noise, noise, noise)
end

local temperatureColor = Color3.new(0, 0, 1):Lerp(Color3.new(1, 0, 0), temperature)
local noiseColor = Color3.new(noise, noise, noise)

p.Color = noiseColor
p.Parent = workspace.Terrain
end
end
end

return module
``````

Temperature calculation

``````local CONFIGURATION = require(script.Parent.Parent.Configuration)
local BIOMES = require(script.Parent.Parent.BiomeModifiers)

local DISTILLATION = 200
local FREQUENCY = 3

local module = {}

function module:GenerateTemperature(x, z)
local noise = math.clamp(math.noise(
(x - CONFIGURATION.ChunkSize/2) / CONFIGURATION.ChunkSize / DISTILLATION * FREQUENCY,
(z - CONFIGURATION.ChunkSize/2) / CONFIGURATION.ChunkSize / DISTILLATION * FREQUENCY
), -.5, .5) + .5

return noise -- math.clamp(math.round(noise / .1) * .1, 0, 1)
end

return module
``````

Biome modifiers

``````return {
{
TEMPERATURE = 1,

PERSISTANCE = .5,
LACUNARITY = 2,
HEIGHT_MULTIPLIER = 10,

SCALE = 100
},
{
TEMPERATURE = .5,

PERSISTANCE = .5,
LACUNARITY = 2,
HEIGHT_MULTIPLIER = 10,

SCALE = 100
},
{
TEMPERATURE = 0,

PERSISTANCE = .5,
LACUNARITY = 2,
HEIGHT_MULTIPLIER = 5,

SCALE = 100
},
}
``````

Anything I should change in my post to get a chance for anyone to help?