载入中...
搜索中...
未找到
CaveGenerationDeposit.cpp
浏览该文件的文档.
2
4
6 // Deposits are generated from stable seeded candidates, but attach only after all
7 // wall-retreat stages have produced the final host surface. This prevents the old
8 // analytic chamber boundary from leaving calcite floating in evolved cave air.
9 voxelSize = 2.f / float(std::min({nx - 1, ny - 1, nz - 1}));
10 embedDepth = voxelSize * 1.15f;
14
15 anchoredDripstones.reserve(dripstones.size());
16 for (size_t i = 0; i + 1 < dripstones.size(); i += 2) {
17 const Dripstone& ceilingCandidate = dripstones[i];
18 const Dripstone& floorCandidate = dripstones[i + 1];
19 const float preferredY = (ceilingCandidate.start.y + floorCandidate.start.y) * 0.5f;
20 const auto span =
21 findCaveVerticalSpan(density, nx, ny, nz, ceilingCandidate.start.x, ceilingCandidate.start.z, preferredY);
22 if (!span) {
24 continue;
25 }
26 const float gap = span->ceiling.position.y - span->floor.position.y;
27 bool column = ceilingCandidate.endRadius > ceilingCandidate.startRadius * 0.5f &&
28 floorCandidate.endRadius > floorCandidate.startRadius * 0.5f;
29 if (column) {
30 const float clearanceRadius = std::max(ceilingCandidate.startRadius, floorCandidate.startRadius) * 1.18f;
31 for (int sampleIndex = 1; sampleIndex < 12 && column; ++sampleIndex) {
32 const float sampleY = span->floor.position.y + gap * float(sampleIndex) / 12.f;
33 for (int angleIndex = 0; angleIndex < 8; ++angleIndex) {
34 const float angle = float(angleIndex) * 0.7853981634f;
35 const CaveFieldPoint clearancePoint{ceilingCandidate.start.x + std::cos(angle) * clearanceRadius,
36 sampleY,
37 ceilingCandidate.start.z + std::sin(angle) * clearanceRadius};
38 if (sampleCaveDensity(density, nx, ny, nz, clearancePoint) > -voxelSize * 0.35f) {
39 column = false;
40 break;
41 }
42 }
43 }
44 }
45 const float maximumLength = gap * (column ? 0.515f : 0.42f);
46 const float ceilingLength =
47 column ? maximumLength
48 : std::min(std::abs(ceilingCandidate.end.y - ceilingCandidate.start.y), maximumLength);
49 const float floorLength =
50 column ? maximumLength : std::min(std::abs(floorCandidate.end.y - floorCandidate.start.y), maximumLength);
51 if (ceilingLength < embedDepth * 1.5f || floorLength < embedDepth * 1.5f) {
53 continue;
54 }
55 const Vec3 ceiling{span->ceiling.position.x, span->ceiling.position.y, span->ceiling.position.z};
56 const Vec3 floor{span->floor.position.x, span->floor.position.y, span->floor.position.z};
57 if (column) {
58 // A mature column is one continuous implicit body. Two overlapping
59 // tapered segments produced a false waist, discontinuous normals and
60 // a self-shadowing ring even when their endpoints overlapped.
61 anchoredDripstones.push_back({add(ceiling, {0.f, embedDepth, 0.f}), add(floor, {0.f, -embedDepth, 0.f}),
62 std::max(ceilingCandidate.startRadius, minimumFeatureRadius),
63 std::max(floorCandidate.startRadius, minimumFeatureRadius)});
64 anchoredDripstones.back().profileAmplitude = 0.055f;
65 anchoredDripstones.back().profileFrequency = 2.5f;
66 anchoredDripstones.back().profilePhase =
67 std::fmod(std::abs(ceiling.x * 19.7f + ceiling.z * 31.1f), 6.283185307f);
69 continue;
70 }
71 anchoredDripstones.push_back({add(ceiling, {0.f, embedDepth, 0.f}), add(ceiling, {0.f, -ceilingLength, 0.f}),
72 std::max(ceilingCandidate.startRadius, minimumFeatureRadius),
73 std::max(ceilingCandidate.endRadius, minimumFeatureRadius * 0.24f)});
74 anchoredDripstones.back().profileAmplitude = 0.08f;
75 anchoredDripstones.back().profileFrequency = 1.5f;
76 anchoredDripstones.back().profilePhase =
77 std::fmod(std::abs(ceiling.x * 17.3f + ceiling.z * 23.9f), 6.283185307f);
78 anchoredDripstones.push_back({add(floor, {0.f, -embedDepth, 0.f}), add(floor, {0.f, floorLength, 0.f}),
79 std::max(floorCandidate.startRadius, minimumFeatureRadius),
80 std::max(floorCandidate.endRadius, minimumFeatureRadius * 0.30f)});
81 anchoredDripstones.back().profileAmplitude = 0.11f;
82 anchoredDripstones.back().profileFrequency = 2.f;
83 anchoredDripstones.back().profilePhase = std::fmod(std::abs(floor.x * 29.3f + floor.z * 13.7f), 6.283185307f);
85 }
86 dripstones = std::move(anchoredDripstones);
87
89
90 anchoredFlowstones.reserve(flowstones.size());
91 for (Flowstone flowstone : flowstones) {
92 const auto anchor = projectToFinalCaveSurface(
93 density, nx, ny, nz, {flowstone.center.x, flowstone.center.y, flowstone.center.z}, 0.24f);
94 if (!anchor || std::abs(anchor->rockNormal.y) > 0.82f) {
96 continue;
97 }
98 flowstone.normal = {anchor->rockNormal.x, anchor->rockNormal.y, anchor->rockNormal.z};
99 Vec3 tangent{-flowstone.normal.z, 0.f, flowstone.normal.x};
100 const float tangentLength = std::sqrt(dot(tangent, tangent));
101 if (tangentLength < 1e-4f) {
103 continue;
104 }
105 flowstone.tangent = mul(tangent, 1.f / tangentLength);
106 flowstone.center =
107 add({anchor->position.x, anchor->position.y, anchor->position.z}, mul(flowstone.normal, embedDepth));
108 flowstone.thickness = std::max(flowstone.thickness, minimumFeatureRadius);
109 anchoredFlowstones.push_back(flowstone);
110 }
111 flowstones = std::move(anchoredFlowstones);
112
114
115 anchoredCurtains.reserve(curtains.size());
116 for (Curtain curtain : curtains) {
117 const auto span =
118 findCaveVerticalSpan(density, nx, ny, nz, curtain.anchor.x, curtain.anchor.z, curtain.anchor.y);
119 if (!span || span->ceiling.rockNormal.y < 0.35f) {
121 continue;
122 }
123 curtain.anchor = {span->ceiling.position.x, span->ceiling.position.y + embedDepth, span->ceiling.position.z};
124 curtain.length = std::min(curtain.length, (span->ceiling.position.y - span->floor.position.y) * 0.36f);
125 curtain.thickness = std::max(curtain.thickness, minimumFeatureRadius);
126 if (curtain.length < embedDepth * 2.f) {
128 continue;
129 }
130 anchoredCurtains.push_back(curtain);
131 }
132 curtains = std::move(anchoredCurtains);
133 depositDelta = std::vector<float>(density.size(), 0.f);
134 for (int z = 0; z < nz; ++z) {
135 for (int y = 0; y < ny; ++y) {
136 for (int x = 0; x < nx; ++x) {
137 const Vec3 p{float(x) / float(nx - 1) * 2.f - 1.f, float(y) / float(ny - 1) * 2.f - 1.f,
138 float(z) / float(nz - 1) * 2.f - 1.f};
139 float& d = density[size_t(x) + size_t(y) * size_t(nx) + size_t(z) * size_t(nx) * size_t(ny)];
140 const float densityBeforeDeposits = d;
141 for (const Dripstone& dripstone : dripstones)
142 d = smoothMaximum(d, -taperedSegmentDistance(p, dripstone, width / height, depth / height), 0.010f);
143 for (const Flowstone& flowstone : flowstones)
144 d = smoothMaximum(d, -flowstoneDistance(p, flowstone), 0.008f);
145 for (const Curtain& curtain : curtains) d = smoothMaximum(d, -curtainDistance(p, curtain), 0.006f);
146 depositDelta[size_t(x) + size_t(y) * size_t(nx) + size_t(z) * size_t(nx) * size_t(ny)] =
147 std::max(0.f, d - densityBeforeDeposits);
149 d = addCaveSediment(p.x, p.y, p.z, d, sedimentSet);
150 }
151 }
152 }
153
154
155 return Result<void>::success();
156}
157
158} // namespace eve::procgen::cave_detail
double z
double y
double x
float gap
glm::vec4 p[6]
float d
unsigned column
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
Vec3 add(Vec3 a, Vec3 b)
float curtainDistance(Vec3 point, const Curtain &shape)
float smoothMaximum(float a, float b, float blendRadius)
float taperedSegmentDistance(Vec3 point, const Dripstone &shape, float horizontalX=1.f, float horizontalZ=1.f)
float flowstoneDistance(Vec3 point, const Flowstone &shape)
Vec3 mul(Vec3 a, float scale)
float dot(Vec3 a, Vec3 b)
std::optional< CaveSurfaceAnchor > projectToFinalCaveSurface(const std::vector< float > &density, int nx, int ny, int nz, CaveFieldPoint point, float maximumDistance)
Projects a nearby field-space point to the final cave zero isosurface.
std::optional< CaveVerticalSpan > findCaveVerticalSpan(const std::vector< float > &density, int nx, int ny, int nz, float x, float z, float preferredY)
Finds the first connected cave-air interval intersected by a vertical ray.
float addCaveBreakdownBlocks(float x, float y, float z, float current, const CaveBreakdownSet &breakdown)
Union the event's landed breakdown blocks into a cave SDF.
float sampleCaveDensity(const std::vector< float > &density, int nx, int ny, int nz, CaveFieldPoint point)
Sample cave density.
float addCaveSediment(float x, float y, float z, float current, const CaveSedimentSet &sediment)
Union sediment bars and imbricated clasts into a cave SDF.
CaveFieldPoint public API.
CaveHydrologyVec3 public API.
std::vector< Flowstone > anchoredFlowstones
std::vector< Curtain > anchoredCurtains
std::vector< Flowstone > flowstones
std::vector< Dripstone > anchoredDripstones
std::vector< Dripstone > dripstones