载入中...
搜索中...
未找到
CaveFacets.cpp
浏览该文件的文档.
2
3#include <algorithm>
4#include <cmath>
5
6namespace eve::procgen {
7namespace {
8
9constexpr float Pi = 3.1415926535f;
10
11float smoothstep(float low, float high, float value) {
12 const float t = std::clamp((value - low) / (high - low), 0.f, 1.f);
13 return t * t * (3.f - 2.f * t);
14}
15
16float seedPhase(uint32_t seed) {
17 uint32_t value = seed ^ 0x9e3779b9u;
18 value ^= value >> 16u;
19 value *= 0x7feb352du;
20 value ^= value >> 15u;
21 return float(value & 0xffffu) * (2.f * Pi / 65536.f);
22}
23
24} // namespace
25
27 CaveFacetSample result;
28 if (input.strength <= 0.f || input.radius <= 0.f) return result;
29
30 const float strength = std::clamp(input.strength, 0.f, 1.f);
31 result.facetCount = 5 + int(input.seed % 3u);
32 const float sector = 2.f * Pi / float(result.facetCount);
33 const float phase = seedPhase(input.seed);
34 const float localAngle = std::remainder(input.angle + phase, sector);
35 const float wallMask = 1.f - smoothstep(input.radius * 1.15f, input.radius * 2.1f, input.distance);
36
37 // Slowly varying condensation/evaporation cells localize the otherwise planar
38 // corrosion envelope. Side walls remain active while ceilings receive a modest gain.
39 const float humidity = smoothstep(0.18f, 0.82f, 0.5f + 0.5f * std::sin(input.along * 5.3f + phase));
40 const float orientation = 0.68f + 0.32f * std::max(0.f, std::cos(input.angle));
41 result.planarWeight = strength * wallMask * humidity * orientation;
42 if (result.planarWeight <= 0.f) return result;
43
44 const float apothem = input.radius + 0.014f * strength;
45 const float polygonRadius = apothem / std::max(0.78f, std::cos(localAngle));
46 result.retreat = std::min(0.055f, std::max(0.f, polygonRadius - input.radius) * result.planarWeight);
47 return result;
48}
49
50} // namespace eve::procgen
double value
float phase
Definition CaveMesh.cpp:58
EvpackChunkInput input
Definition Evpack.cpp:170
std::uint32_t seed
Definition PointSet.cpp:807
float t
CaveFacetSample sampleCaveCondensationFacets(const CaveFacetInput &input)
Sample planar condensation-corrosion facets in passage-local coordinates.
CaveFacetInput public API.
Definition CaveFacets.h:10
CaveFacetSample public API.
Definition CaveFacets.h:20