vkmEngine 1.0.15
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
terrain_brush.h
1#pragma once
2
3#include <cstdint>
4
5#include <glm/glm.hpp>
6
7#include "resource/asset/terrain_asset.h"
8
9namespace Vkm::Engine {
10
20namespace TerrainBrush {
21
25struct Region {
26 int i0 = 0;
27 int j0 = 0;
28 int i1 = -1;
29 int j1 = -1;
30
31 bool empty() const { return i1 < i0 || j1 < j0; }
32
34 void add(const Region& other);
35};
36
40struct Dab {
41 glm::vec2 centre{0.0f};
42 float radius = 4.0f;
43 float strength = 1.0f;
46 float hardness = 0.3f;
47};
48
56float falloff(const Dab& dab, float distance);
57
65Region reach(const TerrainAsset& terrain, const Dab& dab);
66
80bool hit(
81 const TerrainAsset& terrain,
82 const glm::vec3& origin,
83 const glm::vec3& direction,
84 float range,
85 float& t
86);
87
96Region raise(TerrainAsset& terrain, const Dab& dab, float metres);
97
105Region smooth(TerrainAsset& terrain, const Dab& dab);
106
115Region flatten(TerrainAsset& terrain, const Dab& dab, float height);
116
127Region paint(TerrainAsset& terrain, const Dab& dab, uint32_t layer);
128
140Region grow(TerrainAsset& terrain, const Dab& dab, uint32_t foliage, float target);
141
142} // namespace TerrainBrush
143
144} // namespace Vkm::Engine
The edits a brush makes to a terrain, one dab at a time: raise, smooth and flatten its heights,...
Definition terrain_brush.h:20
bool hit(const TerrainAsset &terrain, const glm::vec3 &origin, const glm::vec3 &direction, float range, float &t)
Where a ray first meets terrain's surface, over its grid.
Region grow(TerrainAsset &terrain, const Dab &dab, uint32_t foliage, float target)
Move the density of plant layer foliage under dab toward target.
Region paint(TerrainAsset &terrain, const Dab &dab, uint32_t layer)
Move each vertex's layer shares under dab toward all of layer.
float falloff(const Dab &dab, float distance)
How much of a dab's effect reaches distance from its centre.
Region smooth(TerrainAsset &terrain, const Dab &dab)
Pull each height under dab toward its neighbours' mean.
Region raise(TerrainAsset &terrain, const Dab &dab, float metres)
Raise the heights under dab, metres at its centre; negative lowers.
Region flatten(TerrainAsset &terrain, const Dab &dab, float height)
Pull each height under dab toward height.
Region reach(const TerrainAsset &terrain, const Dab &dab)
The grid vertices within dab, clamped to terrain's grid.
A terrain: a square grid of heights, the share of each of four materials painted at each grid vertex,...
Definition terrain_asset.h:54
One application of a brush: where, how wide, how much.
Definition terrain_brush.h:40
glm::vec2 centre
Local metres along X and Z.
Definition terrain_brush.h:41
float radius
Metres.
Definition terrain_brush.h:42
float hardness
Definition terrain_brush.h:46
float strength
Definition terrain_brush.h:43
Grid vertices [i0, i1] by [j0, j1], inclusive: what a dab touched.
Definition terrain_brush.h:25
void add(const Region &other)
Grow to hold other too.
int i1
Below i0 when nothing was touched.
Definition terrain_brush.h:28