12constexpr float kBeach = 0.6f;
13constexpr float kTreeLine = 12.0f;
14constexpr float kSnowLine = 19.0f;
17constexpr float kSteep = 0.8f;
22 if (height < kBeach) {
25 if (height > kSnowLine) {
28 if (height > kTreeLine || up < kSteep) {
52Color Vary(Color color, uint32_t hash) {
53 const float shade = 0.96f + 0.08f *
static_cast<float>(hash & 0xff) / 255.0f;
54 const auto scaled = [shade](
unsigned char value) {
55 return static_cast<unsigned char>(std::min(value * shade, 255.0f));
57 return {scaled(color.r), scaled(color.g), scaled(color.b), color.a};
60void AddFace(
Triangles& triangles,
const Look& look, Vector3 a, Vector3 b,
61 Vector3 c, uint32_t hash) {
62 const float height = (a.y + b.y + c.y) / 3.0f;
64 triangles.Add(a, b, c, Vary(color, hash));
70 int left,
int top,
int cells) {
71 const float half_size = terrain.
half_size();
72 const auto corner = [&](
int i,
int j) {
76 for (
int j = top; j < std::min(top + cells, terrain.
cells()); ++j) {
77 for (
int i = left; i < std::min(left + cells, terrain.
cells()); ++i) {
78 const Vector3 top_left = corner(i, j);
79 const Vector3 top_right = corner(i + 1, j);
80 const Vector3 bottom_left = corner(i, j + 1);
81 const Vector3 bottom_right = corner(i + 1, j + 1);
82 AddFace(triangles, look, top_left, bottom_right, top_right,
84 AddFace(triangles, look, top_left, bottom_left, bottom_right,
float half_size() const
From the middle to each side of the grid.
static constexpr float kCell
In metres. Each cell of the grid is two triangles.
float Corner(int i, int j) const
The height at a corner of the grid, from 0 to cells() along each side.
int cells() const
Along each side.
uint32_t Hash(uint32_t seed, int32_t x, int32_t z)
void AddGround(Triangles &triangles, const Terrain &terrain, const Look &look, int left, int top, int cells)
Color GroundColor(const Look &look, float height, float up)
The surface's colour in the look.
Surface SurfaceAt(float height, float up)
Vector3 FaceNormal(Vector3 a, Vector3 b, Vector3 c)
A land's colours: its atmosphere, and the colours that go into its meshes.