载入中...
搜索中...
未找到
CavePlucking.cpp
浏览该文件的文档.
2
3#include <algorithm>
4#include <cmath>
5
6namespace eve::procgen {
7namespace {
8
9float smoothstep(float lo, float hi, float value) {
10 const float t = std::clamp((value - lo) / std::max(hi - lo, 1e-6f), 0.f, 1.f);
11 return t * t * (3.f - 2.f * t);
12}
13
14uint32_t hash(uint32_t value) {
15 value ^= value >> 16u;
16 value *= 0x7feb352du;
17 value ^= value >> 15u;
18 value *= 0x846ca68bu;
19 return value ^ (value >> 16u);
20}
21
22uint32_t cellKey(int value) { return value >= 0 ? uint32_t(value) * 2u : uint32_t(-value) * 2u - 1u; }
23
24} // namespace
25
27 CavePluckingSample result;
28 const float primary = std::clamp(input.primaryFractureMask, 0.f, 1.f);
29 const float secondary = std::clamp(input.secondaryFractureMask, 0.f, primary);
30 // One strongly exposed discontinuity can release a slab; intersecting planes
31 // further increase the chance of a hydraulically extractable block.
32 result.fracturePredisposition = std::clamp(primary * 0.58f + std::sqrt(primary * secondary) * 0.62f, 0.f, 1.f);
33 if (result.fracturePredisposition <= 0.f) return result;
34
35 result.hydraulicActivation = smoothstep(0.48f, 1.05f, input.hydraulicIntensity);
36 const float nearBed = std::clamp(std::pow(std::max(0.f, -std::cos(input.angle)), 1.2f) +
37 std::pow(std::fabs(std::sin(input.angle)), 1.7f) * 0.24f,
38 0.f, 1.f);
39
40 const float scale = std::max(input.blockScale, 0.02f);
41 const float gx = input.x / scale;
42 const float gy = input.y / (scale * 0.72f);
43 const float gz = input.z / (scale * 1.18f);
44 const int ix = int(std::floor(gx));
45 const int iy = int(std::floor(gy));
46 const int iz = int(std::floor(gz));
47 const float lx = std::fabs((gx - std::floor(gx)) * 2.f - 1.f);
48 const float ly = std::fabs((gy - std::floor(gy)) * 2.f - 1.f);
49 const float lz = std::fabs((gz - std::floor(gz)) * 2.f - 1.f);
50 const float cuboid = 1.f - smoothstep(0.58f, 0.94f, std::max({lx, ly, lz}));
51 const uint32_t key =
52 hash(input.seed ^ cellKey(ix) * 0x9e3779b9u ^ cellKey(iy) * 0x85ebca6bu ^ cellKey(iz) * 0xc2b2ae35u);
53 const float cellSelection = smoothstep(0.62f, 0.88f, float(key & 0xffffu) / 65535.f);
54 result.blockMask = cuboid * cellSelection;
55
56 const float release = smoothstep(0.22f, 0.78f, result.fracturePredisposition * result.hydraulicActivation);
57 result.erosion = std::clamp(nearBed * result.blockMask * release, 0.f, 1.f);
58 return result;
59}
60
61} // namespace eve::procgen
double value
std::array< std::uint8_t, 32 > hash
Definition Evpack.cpp:172
EvpackChunkInput input
Definition Evpack.cpp:170
std::uint32_t key
int secondary
std::array< float, 3 > scale
std::function< eve::Result< void >()> release
Definition Procgen.cpp:86
float t
CavePluckingSample sampleCaveFloodPlucking(const CavePluckingInput &input)
Sample thresholded removal of blocks bounded by one or more exposed fractures.
Inputs for flood plucking of fracture-bounded cave-floor blocks.
Local fracture predisposition, hydraulic threshold, and block removal response.