include/terraingen/noise/noise_fields.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | /// @file | ||
| 4 | /// @brief The field lists of fractals and the names of the noise enums. | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "terraingen/noise/fractals.h" | ||
| 8 | #include "terraingen/util/option_fields.h" | ||
| 9 | |||
| 10 | #include <array> | ||
| 11 | |||
| 12 | namespace terraingen { | ||
| 13 | |||
| 14 | template <> struct EnumNames<NoiseBasis> { | ||
| 15 | static constexpr std::array<EnumEntry<NoiseBasis>, 7> kValues{{ | ||
| 16 | {"perlin", NoiseBasis::Perlin, | ||
| 17 | "Improved Perlin gradient noise: smooth, general-purpose relief."}, | ||
| 18 | {"simplex", NoiseBasis::Simplex, | ||
| 19 | "Simplex gradient noise: smooth relief, an alternative to Perlin."}, | ||
| 20 | {"value", NoiseBasis::Value, | ||
| 21 | "Value noise: random values interpolated over a lattice; blockier than gradient noise."}, | ||
| 22 | {"worley_f1", NoiseBasis::WorleyF1, | ||
| 23 | "Cellular noise from the distance to the nearest feature point: cones and basins."}, | ||
| 24 | {"worley_f2", NoiseBasis::WorleyF2, | ||
| 25 | "Cellular noise from the distance to the second-nearest feature point."}, | ||
| 26 | {"worley_f2_minus_f1", NoiseBasis::WorleyF2MinusF1, | ||
| 27 | "Cellular noise F2 - F1: ridges along cell borders, like cracked ground."}, | ||
| 28 | {"voronoi", NoiseBasis::Voronoi, | ||
| 29 | "Voronoi cells, each at one random height: flat polygonal plateaus and terraces."}, | ||
| 30 | }}; | ||
| 31 | }; | ||
| 32 | |||
| 33 | template <> struct EnumNames<FractalType> { | ||
| 34 | static constexpr std::array<EnumEntry<FractalType>, 4> kValues{{ | ||
| 35 | {"fbm", FractalType::Fbm, | ||
| 36 | "Fractional Brownian motion: a weighted sum of octaves, the general-purpose choice."}, | ||
| 37 | {"ridged", FractalType::Ridged, | ||
| 38 | "Ridged multifractal: sharp crests from inverted absolute noise, like eroded ridges."}, | ||
| 39 | {"billow", FractalType::Billow, "Sum of absolute-value octaves: rounded, puffy forms."}, | ||
| 40 | {"hybrid_multifractal", FractalType::HybridMultifractal, | ||
| 41 | "Hybrid multifractal: smooth lowlands and rough highlands."}, | ||
| 42 | }}; | ||
| 43 | }; | ||
| 44 | |||
| 45 | template <> struct EnumNames<FractalBlend> { | ||
| 46 | static constexpr std::array<EnumEntry<FractalBlend>, 4> kValues{{ | ||
| 47 | {"add", FractalBlend::Add, "Adds the layer to the height so far."}, | ||
| 48 | {"max", FractalBlend::Max, "Keeps the higher of the height so far and the layer."}, | ||
| 49 | {"min", FractalBlend::Min, "Keeps the lower of the height so far and the layer."}, | ||
| 50 | {"mask", FractalBlend::Mask, | ||
| 51 | "Multiplies the height so far by (layer / amplitude + 1) / 2, so the layer modulates " | ||
| 52 | "roughness by region."}, | ||
| 53 | }}; | ||
| 54 | }; | ||
| 55 | |||
| 56 | /// The fields of a fractal before its amplitude: whether it is on, its noise, blend, seed and | ||
| 57 | /// wavelength. | ||
| 58 | 2025 | template <typename IO> void FractalBaseFields(IO& io, Fractal& fractal) { | |
| 59 | 2025 | io("enabled", fractal.enabled, | |
| 60 | "Includes this layer in the stack; disabled layers are skipped."); | ||
| 61 | 2024 | io("basis", fractal.basis, "Single-octave noise the fractal is built from."); | |
| 62 | 2023 | io("fractal", fractal.type, "How the octaves of the basis noise are combined."); | |
| 63 | 2023 | io("blend", fractal.blend, | |
| 64 | "How this layer combines with the height of the layers before it; the first enabled layer " | ||
| 65 | "sets the height instead."); | ||
| 66 | 2023 | io("seed", fractal.seed, | |
| 67 | "Seed of the noise; changing it gives a different pattern of the same character."); | ||
| 68 | 2022 | io("wavelength_m", fractal.wavelength, | |
| 69 | "Wavelength of the first, broadest octave, in meters; sets the size of the largest " | ||
| 70 | "features.", | ||
| 71 | 2022 | "m", Above(0.0)); | |
| 72 | 2021 | } | |
| 73 | |||
| 74 | /// The fields of a fractal's octaves after its amplitude: their count, lacunarity and gain. | ||
| 75 | 2019 | template <typename IO> void FractalOctaveFields(IO& io, Fractal& fractal) { | |
| 76 | 2019 | io("octaves", fractal.octaves, | |
| 77 | "Number of octaves; each one adds detail at a shorter wavelength.", "", | ||
| 78 | 2019 | Between(1.0, kMaxFractalOctaves)); | |
| 79 | 2011 | io("lacunarity", fractal.lacunarity, "Frequency ratio between successive octaves.", "", | |
| 80 | 2011 | Above(1.0)); | |
| 81 | 2011 | io("gain", fractal.gain, | |
| 82 | "Weight ratio between successive octaves; higher values give rougher terrain. Unused when " | ||
| 83 | "the Hurst exponent is set.", | ||
| 84 | 2011 | "", Above(0.0)); | |
| 85 | 2010 | } | |
| 86 | |||
| 87 | /// The fields of a fractal's ridge offset and domain warp. | ||
| 88 | 2007 | template <typename IO> void FractalWarpFields(IO& io, Fractal& fractal) { | |
| 89 | 2007 | io("offset", fractal.offset, "Ridge offset of the ridged and hybrid multifractal types.", "", | |
| 90 | 2007 | Above(0.0)); | |
| 91 | 2007 | io("warp_amplitude_m", fractal.warpAmplitude, | |
| 92 | "Domain warp displacement in meters, which bends the noise into swirled shapes; 0 " | ||
| 93 | "disables warping.", | ||
| 94 | 2007 | "m", AtLeast(0.0)); | |
| 95 | 2003 | io("warp_wavelength_m", fractal.warpWavelength, "Wavelength of the warp field, in meters.", "m", | |
| 96 | 2003 | Above(0.0)); | |
| 97 | 2002 | } | |
| 98 | |||
| 99 | 1152 | template <typename IO> void Fields(IO& io, Fractal& fractal) { | |
| 100 | 1152 | FractalBaseFields(io, fractal); | |
| 101 | 1151 | io("amplitude_m", fractal.amplitude, "Largest height of the layer above or below 0, in meters.", | |
| 102 | "m"); | ||
| 103 | 1151 | FractalOctaveFields(io, fractal); | |
| 104 | 1147 | FractalWarpFields(io, fractal); | |
| 105 | 1142 | } | |
| 106 | |||
| 107 | } // namespace terraingen | ||
| 108 |