Skip to content

Commit 5e2096e

Browse files
authoredMar 22, 2018
Lua_api.txt: Improve noise documentation
1 parent cd6bcef commit 5e2096e

File tree

1 file changed

+103
-33
lines changed

1 file changed

+103
-33
lines changed
 

Diff for: ‎doc/lua_api.txt

+103-33
Original file line numberDiff line numberDiff line change
@@ -1118,54 +1118,112 @@ A box of a regular node would look like:
11181118

11191119
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
11201120

1121+
Perlin noise
1122+
------------
1123+
Perlin noise creates a continuously-varying value depending on the input values.
1124+
Usually in Minetest the input values are either 2D or 3D co-ordinates in nodes.
1125+
The result is used during map generation to create the terrain shape, vary heat
1126+
and humidity to distribute biomes, vary the density of decorations or vary the
1127+
structure of ores.
1128+
1129+
### Structure of perlin noise
1130+
An 'octave' is a simple noise generator that outputs a value between -1 and 1.
1131+
The smooth wavy noise it generates has a single characteristic scale, almost
1132+
like a 'wavelength', so on its own does not create fine detail.
1133+
Due to this perlin noise combines several octaves to create variation on
1134+
multiple scales. Each additional octave has a smaller 'wavelength' than the
1135+
previous.
1136+
1137+
This combination results in noise varying very roughly between -2.0 and 2.0 and
1138+
with an average value of 0.0, so `scale` and `offset` are then used to multiply
1139+
and offset the noise variation.
1140+
1141+
The final perlin noise variation is created as follows:
1142+
1143+
noise = offset + scale * (octave1 +
1144+
octave2 * persistence +
1145+
octave3 * persistence ^ 2 +
1146+
octave4 * persistence ^ 3 +
1147+
...)
1148+
11211149
Noise Parameters
11221150
----------------
1123-
Noise Parameters, or commonly called "`NoiseParams`", define the properties of
1124-
perlin noise.
1151+
Noise Parameters are commonly called `NoiseParams`.
11251152

11261153
### `offset`
1127-
Offset that the noise is translated by (i.e. added) after calculation.
1154+
After the multiplication by `scale` this is added to the result and is the final
1155+
step in creating the noise value.
1156+
Can be positive or negative.
11281157

11291158
### `scale`
1130-
Factor that the noise is scaled by (i.e. multiplied) after calculation.
1159+
Once all octaves have been combined, the result is multiplied by this.
1160+
Can be positive or negative.
11311161

11321162
### `spread`
1133-
Vector containing values by which each coordinate is divided by before
1134-
calculation.
1135-
Higher spread values result in larger noise features.
1163+
For octave1, this is roughly the change of input value needed for a very large
1164+
variation in the noise value generated by octave1. It is almost like a
1165+
'wavelength' for the wavy noise variation.
1166+
Each additional octave has a 'wavelength' that is smaller than the previous
1167+
octave, to create finer detail. `spread` will therefore roughly be the typical
1168+
size of the largest structures in the final noise variation.
11361169

1137-
A value of `{x=250, y=250, z=250}` is common.
1170+
`spread` is a vector with values for x, y, z to allow the noise variation to be
1171+
stretched or compressed in the desired axes.
1172+
Values are positive numbers.
11381173

11391174
### `seed`
1140-
Random seed for the noise. Add the world seed to a seed offset for world-unique
1141-
noise. In the case of `minetest.get_perlin()`, this value has the world seed
1142-
automatically added.
1175+
This is a whole number that determines the entire pattern of the noise
1176+
variation. Altering it enables different noise patterns to be created.
1177+
With other parameters equal, different seeds produce different noise patterns
1178+
and identical seeds produce identical noise patterns.
11431179

1144-
### `octaves`
1145-
Number of times the noise gradient is accumulated into the noise.
1180+
For this parameter you can randomly choose any whole number. Usually it is
1181+
preferable for this to be different from other seeds, but sometimes it is useful
1182+
to be able to create identical noise patterns.
11461183

1147-
Increase this number to increase the amount of detail in the resulting noise.
1184+
When used in mapgen this is actually a 'seed offset', it is added to the
1185+
'world seed' to create the seed used by the noise, to ensure the noise has a
1186+
different pattern in different worlds.
11481187

1149-
A value of `6` is common.
1188+
### `octaves`
1189+
The number of simple noise generators that are combined.
1190+
A whole number, 1 or more.
1191+
Each additional octave adds finer detail to the noise but also increases the
1192+
noise calculation load.
1193+
3 is a typical minimum for a high quality, complex and natural-looking noise
1194+
variation. 1 octave has a slight 'gridlike' appearence.
1195+
1196+
Choose the number of octaves according to the `spread` and `lacunarity`, and the
1197+
size of the finest detail you require. For example:
1198+
if `spread` is 512 nodes, `lacunarity` is 2.0 and finest detail required is 16
1199+
nodes, octaves will be 6 because the 'wavelengths' of the octaves will be
1200+
512, 256, 128, 64, 32, 16 nodes.
11501201

11511202
### `persistence`
1152-
Factor by which the effect of the noise gradient function changes with each
1153-
successive octave.
1154-
1155-
Values less than `1` make the details of successive octaves' noise diminish,
1156-
while values greater than `1` make successive octaves stronger.
1157-
1158-
A value of `0.6` is common.
1203+
Each additional octave has an amplitude that is the amplitude of the previous
1204+
octave multiplied by `persistence`, to reduce the amplitude of finer details,
1205+
as is often helpful and natural to do so.
1206+
Since this controls the balance of fine detail to large-scale detail
1207+
`persistence` can be thought of as the 'roughness' of the noise.
1208+
1209+
A positive or negative non-zero number, often between 0.3 and 1.0.
1210+
A common medium value is 0.5, such that each octave has half the amplitude of
1211+
the previous octave.
1212+
This may need to be tuned when altering `lacunarity`; when doing so consider
1213+
that a common medium value is 1 / lacunarity.
11591214

11601215
### `lacunarity`
1161-
Factor by which the noise feature sizes change with each successive octave.
1216+
Each additional octave has a 'wavelength' that is the 'wavelength' of the
1217+
previous octave multiplied by 1 / lacunarity, to create finer detail.
1218+
'lacunarity' is often 2.0 so 'wavelength' often halves per octave.
11621219

1163-
A value of `2.0` is common.
1220+
A positive number no smaller than 1.0.
1221+
Values below 2.0 create higher quality noise at the expense of requiring more
1222+
octaves to cover a paticular range of 'wavelengths'.
11641223

11651224
### `flags`
11661225
Leave this field unset for no special handling.
1167-
1168-
Currently supported are `defaults`, `eased` and `absvalue`.
1226+
Currently supported are `defaults`, `eased` and `absvalue`:
11691227

11701228
#### `defaults`
11711229
Specify this if you would like to keep auto-selection of eased/not-eased while
@@ -1174,28 +1232,39 @@ specifying some other flags.
11741232
#### `eased`
11751233
Maps noise gradient values onto a quintic S-curve before performing
11761234
interpolation. This results in smooth, rolling noise.
1177-
Disable this (`noeased`) for sharp-looking noise.
1235+
Disable this (`noeased`) for sharp-looking noise with a slightly gridded
1236+
appearence.
11781237
If no flags are specified (or defaults is), 2D noise is eased and 3D noise is
11791238
not eased.
1239+
Easing a 3D noise significantly increases the noise calculation load, so use
1240+
with restraint.
11801241

11811242
#### `absvalue`
1182-
Accumulates the absolute value of each noise gradient result.
1243+
The absolute value of each octave's noise variation is used when combining the
1244+
octaves. The final perlin noise variation is created as follows:
11831245

1184-
Noise parameters format example for 2D or 3D perlin noise or perlin noise maps:
1246+
noise = offset + scale * (abs(octave1) +
1247+
abs(octave2) * persistence +
1248+
abs(octave3) * persistence ^ 2 +
1249+
abs(octave4) * persistence ^ 3 +
1250+
...)
1251+
1252+
###Format example
1253+
For 2D or 3D perlin noise or perlin noise maps:
11851254

11861255
np_terrain = {
11871256
offset = 0,
11881257
scale = 1,
1189-
spread = {x=500, y=500, z=500},
1258+
spread = {x = 500, y = 500, z = 500},
11901259
seed = 571347,
11911260
octaves = 5,
11921261
persist = 0.63,
11931262
lacunarity = 2.0,
1194-
flags = "defaults, absvalue"
1263+
flags = "defaults, absvalue",
11951264
}
1196-
^ A single noise parameter table can be used to get 2D or 3D noise,
1197-
when getting 2D noise spread.z is ignored.
11981265

1266+
For 2D noise the Z component of `spread` is still defined but is ignored.
1267+
A single noise parameter table can be used for 2D or 3D noise.
11991268

12001269
Ore types
12011270
---------
@@ -1268,6 +1337,7 @@ The following is a decent set of parameters to work from:
12681337
seed = 5390,
12691338
octaves = 4,
12701339
persist = 0.5,
1340+
lacunarity = 2.0,
12711341
flags = "eased",
12721342
},
12731343
noise_threshold = 1.6

0 commit comments

Comments
 (0)
Please sign in to comment.