layers/noise_relief.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /// @file | ||
| 2 | /// @brief `NoiseRelief`, a stack of noise layers added to the terrain, and `NoiseLayersAt`. | ||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #include "terraingen/layers/kernels/noise_relief.h" | ||
| 6 | #include "terraingen/layers/layer.h" | ||
| 7 | #include "terraingen/noise/noise_layers.h" | ||
| 8 | #include "terraingen/sources/synthetic_terrain.h" | ||
| 9 | #include "terraingen/util/geometry.h" | ||
| 10 | #include "terraingen/util/surface.h" | ||
| 11 | |||
| 12 | #include <vector> | ||
| 13 | |||
| 14 | namespace terraingen { | ||
| 15 | |||
| 16 | /// The summed noise of `layers` at surface (x, y): 2D relative to `origin` on a plane (keeping | ||
| 17 | /// single precision accurate), 3D at the point's 3D position on a sphere. | ||
| 18 | /// @param origin Where plane coordinates are measured from; unused on a sphere. | ||
| 19 | float NoiseLayersAt(const std::vector<NoiseLayer>& layers, const Vec2d& origin, | ||
| 20 | const Surface& surface, double x, double y); | ||
| 21 | |||
| 22 | /// A stack of noise layers added to the terrain: rolling relief on a flat source, or detail on a | ||
| 23 | /// DEM. Each sample gets `NoiseLayersAt`, seamless on a sphere. | ||
| 24 | /// | ||
| 25 | /// On a plane the relief is a kernel, so grids follow the context's backend; on a sphere it | ||
| 26 | /// is evaluated in 3D on the CPU. | ||
| 27 | class NoiseRelief final : public Layer { | ||
| 28 | public: | ||
| 29 | /// @param origin Where plane coordinates are measured from; unused on a sphere. | ||
| 30 | /// @throws std::invalid_argument if `params` are invalid. | ||
| 31 | explicit NoiseRelief(SyntheticTerrainParams params, Vec2d origin = {}, Surface surface = {}); | ||
| 32 | |||
| 33 | /// The noise layers the layer was made with. | ||
| 34 | 1 | const SyntheticTerrainParams& Params() const { | |
| 35 | 1 | return params_; | |
| 36 | } | ||
| 37 | |||
| 38 | protected: | ||
| 39 | void ApplySamples(SampleBlock& samples, const LayerContext& context) const override; | ||
| 40 | |||
| 41 | private: | ||
| 42 | SyntheticTerrainParams params_; | ||
| 43 | Vec2d origin_; | ||
| 44 | Surface surface_; | ||
| 45 | NoiseReliefKernel kernel_; | ||
| 46 | }; | ||
| 47 | |||
| 48 | } // namespace terraingen | ||
| 49 |