载入中...
搜索中...
未找到
CaveDifferentialErosion.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 ^ 0xa511e9b3u;
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
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 const float phase = seedPhase(input.seed);
32 const float c = std::cos(phase);
33 const float s = std::sin(phase);
34 const float u = input.x * c + input.z * s;
35 const float v = -input.x * s + input.z * c;
36
37 // Two gently warped vein sets leave an intersecting boxwork. Their narrow
38 // resistant cores stand proud only because the surrounding host rock retreats.
39 const float veinA = std::fabs(std::sin((u + input.y * 0.22f) * 3.4f * Pi + phase));
40 const float veinB = std::fabs(std::sin((v - input.y * 0.17f) * 2.7f * Pi - phase * 0.61f));
41 const float network = std::max(1.f - smoothstep(0.035f, 0.16f, veinA), 1.f - smoothstep(0.035f, 0.16f, veinB));
42 const float patch = smoothstep(0.2f, 0.78f,
43 0.5f + 0.27f * std::sin(input.x * 2.1f + input.y * 1.3f + phase) +
44 0.23f * std::sin(input.z * 2.6f - input.y * 0.8f - phase * 0.7f));
45 const float wallMask = 1.f - smoothstep(input.radius * 1.1f, input.radius * 2.1f, input.distance);
46
47 result.veinProtection = strength * patch * wallMask * network;
48 const float exposedHost = strength * patch * wallMask * (1.f - 0.94f * network);
49 result.hostRetreat = std::min(0.04f, 0.038f * exposedHost);
50 return result;
51}
52
53} // namespace eve::procgen
double value
const std::string & s
float phase
Definition CaveMesh.cpp:58
EvpackChunkInput input
Definition Evpack.cpp:170
float u
Definition Grass.cpp:233
float v
std::int32_t c
std::uint32_t seed
Definition PointSet.cpp:807
float t
CaveDifferentialErosionSample sampleCaveDifferentialVeinErosion(const CaveDifferentialErosionInput &input)
Sample host-rock retreat around resistant intersecting mineral veins.
CaveDifferentialErosionInput public API.
CaveDifferentialErosionSample public API.