Add infrared noise

This commit is contained in:
Starbeamrainbowlabs 2021-07-13 00:54:52 +01:00
parent 8891c47e98
commit 03038689e2
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
4 changed files with 42 additions and 3 deletions

View file

@ -519,7 +519,8 @@ Algorithm | Description
`perlin` | Perlin noise. Functional, but currently contains artefacts I'm having difficulty tracking down. `perlin` | Perlin noise. Functional, but currently contains artefacts I'm having difficulty tracking down.
`sin` | A sine wave created with `math.sin()`. `sin` | A sine wave created with `math.sin()`.
`white` | Random white noise. `white` | Random white noise.
`red` | Red noise - has a lower frequency than white noise. `red` | Red noise - has a lower frequency than white noise.
`infrared` | Even smoother than red noise. Tends to also be quite flat unless you use a slightly higher `apply` value (e.g. `20`).
When specifying algorithm names, the `algorithm` parameter name is optional. For example, the following are both equivalent: When specifying algorithm names, the `algorithm` parameter name is optional. For example, the following are both equivalent:

View file

@ -0,0 +1,35 @@
local wea = worldeditadditions
local White = dofile(wea.modpath.."/lib/noise/engines/white.lua")
local Infrared = {}
Infrared.__index = Infrared
function Infrared.new(seed)
local result = {
seed = seed or math.random(),
white = White.new(seed),
window = 2
}
setmetatable(result, Infrared)
return result
end
function Infrared:noise( x, y, z )
local values = { }
for nx=x-self.window,x+self.window do
for ny=y-self.window,y+self.window do
for nz=z-self.window,z+self.window do
table.insert(values, self.white:noise(nx, ny, nz))
print("DEBUG nx", nx, "ny", ny, "nz", nz, "value", value)
end
end
end
for i,value in ipairs(values) do
end
return wea.average(values)
end
return Infrared

View file

@ -2,10 +2,11 @@ local wea = worldeditadditions
return { return {
available = { "perlin", "sin", "white", "red" }, available = { "perlin", "sin", "white", "red", "infrared" },
Perlin = dofile(wea.modpath.."/lib/noise/engines/perlin.lua"), Perlin = dofile(wea.modpath.."/lib/noise/engines/perlin.lua"),
Sin = dofile(wea.modpath.."/lib/noise/engines/sin.lua"), Sin = dofile(wea.modpath.."/lib/noise/engines/sin.lua"),
White = dofile(wea.modpath.."/lib/noise/engines/white.lua"), White = dofile(wea.modpath.."/lib/noise/engines/white.lua"),
Red = dofile(wea.modpath.."/lib/noise/engines/red.lua") Red = dofile(wea.modpath.."/lib/noise/engines/red.lua"),
Infrared = dofile(wea.modpath.."/lib/noise/engines/infrared.lua")
-- TODO: Follow https://www.redblobgames.com/articles/noise/introduction.html and implement different colours of noise (*especially* red and pink noise) -- TODO: Follow https://www.redblobgames.com/articles/noise/introduction.html and implement different colours of noise (*especially* red and pink noise)
} }

View file

@ -23,6 +23,8 @@ function worldeditadditions.noise.make_2d(size, start_pos, params)
generator = wea.noise.engines.White.new() generator = wea.noise.engines.White.new()
elseif layer.algorithm == "red" then elseif layer.algorithm == "red" then
generator = wea.noise.engines.Red.new() generator = wea.noise.engines.Red.new()
elseif layer.algorithm == "infrared" then
generator = wea.noise.engines.Infrared.new()
else -- We don't have any other generators just yet else -- We don't have any other generators just yet
return false, "Error: Unknown noise algorithm '"..tostring(layer.algorithm).."' in layer "..layer_i.." of "..#params.." (available algorithms: "..table.concat(wea.noise.engines.available, ", ")..")." return false, "Error: Unknown noise algorithm '"..tostring(layer.algorithm).."' in layer "..layer_i.." of "..#params.." (available algorithms: "..table.concat(wea.noise.engines.available, ", ")..")."
end end