载入中...
搜索中...
未找到
CaveGenerationSample.cpp
浏览该文件的文档.
2
4
6 density = std::vector<float>(size_t(nx) * size_t(ny) * size_t(nz), 1.f);
7 reactiveRate = std::vector<float>(density.size(), 1.f);
8 hydraulicExposure = std::vector<float>(density.size(), 1.f);
9 flowDirection = std::vector<CaveHydrologyVec3>(density.size(), {1.f, 0.f, 0.f});
28 maximumWallRelief = -1.f;
67 maximumWakeScour = 0.f;
78 auto carvePath = [](Vec3 p, const std::vector<PassagePoint>& path, float current) {
79 for (size_t i = 1; i < path.size(); ++i) {
80 const float radius = 0.5f * (path[i - 1].radius + path[i].radius);
82 }
83 return current;
84 };
85 for (int z = 0; z < nz; ++z) {
86 for (int y = 0; y < ny; ++y) {
87 for (int x = 0; x < nx; ++x) {
88 const Vec3 p{float(x) / float(nx - 1) * 2.f - 1.f, float(y) / float(ny - 1) * 2.f - 1.f,
89 float(z) / float(nz - 1) * 2.f - 1.f};
90 float d = carvePath(p, spine, 1.f);
91 for (const auto& branch : branches) d = carvePath(p, branch.points, d);
93 for (size_t branch = 0; branch < branches.size(); ++branch) {
94 const CavePassageFrame candidate =
96 if (candidate.distance < passage.distance) passage = candidate;
97 }
98
99 // After a phreatic tube drains, gravity-driven streams incise a narrower
100 // canyon into its floor. This second connected carve preserves traversability.
101 const float effectiveVadose = genesis == "hypogene" ? 0.f : vadoseIncision;
102 if (effectiveVadose > 0.f) {
103 const Vec3 incisedPoint{p.x, p.y + tunnelRadius * (0.55f + 0.55f * vadoseIncision), p.z};
104 float incision = 1.f;
105 for (size_t i = 1; i < spine.size(); ++i) {
106 const float radius = 0.5f * (spine[i - 1].radius + spine[i].radius) *
107 (0.38f + 0.22f * vadoseIncision) * std::sqrt(hydrology.trunk[i - 1]);
108 incision = std::min(
109 incision,
110 distanceToSegment(incisedPoint, spine[i - 1].position, spine[i].position) - radius);
111 }
112 for (size_t branch = 0; branch < branches.size(); ++branch) {
113 const auto& path = branches[branch].points;
114 for (size_t i = 1; i < path.size(); ++i) {
115 const float radius = 0.5f * (path[i - 1].radius + path[i].radius) *
116 (0.30f + 0.18f * vadoseIncision) *
117 std::sqrt(hydrology.branches[branch][i - 1]);
118 incision = std::min(
119 incision,
120 distanceToSegment(incisedPoint, path[i - 1].position, path[i].position) - radius);
121 }
122 }
123 d = std::min(d, incision);
124 }
125 for (const Chamber& chamber : chambers) {
126 d = std::min(d, ellipsoidDistance(p, chamber));
127 }
128 for (const Chamber& cupola : cupolas) d = std::min(d, ellipsoidDistance(p, cupola));
129 for (const RisingConduit& feeder : feeders)
130 d = std::min(d, distanceToSegment(p, feeder.start, feeder.end) - feeder.radius);
131 for (const RisingConduit& channel : ceilingChannels)
132 d = std::min(d, distanceToSegment(p, channel.start, channel.end) - channel.radius);
133 const float legacyStrata =
134 latticeNoise((p.x + 2.f) * 5.5f, (p.y + 3.f) * 3.2f, (p.z + 5.f) * 5.5f, params.getSeed());
135 float strata = legacyStrata;
136 if (multiscaleRoughness > 0.f) {
137 const CaveRoughnessSample spectrum = sampleCaveWallRoughness({p.x, p.y, p.z, params.getSeed()});
138 strata = legacyStrata * (1.f - multiscaleRoughness) + spectrum.relief * multiscaleRoughness;
139 }
140 minimumWallRelief = std::min(minimumWallRelief, strata);
141 maximumWallRelief = std::max(maximumWallRelief, strata);
142 d += strata * roughness * 0.32f;
144 d = carveCaveParagenesis(p.x, p.y, p.z, d, sedimentSet);
145
146 // Apply dissolution only in a shell around the connected void. Bedding bands
147 // produce horizontal notches, joints produce tall slots, and positive fine
148 // noise creates solution pockets/scallops instead of uniformly inflating rock.
149 const float shell = 1.f - smoothstep(0.025f, 0.22f, std::fabs(d));
150 const float beddingWarp =
151 latticeNoise(p.x * 2.3f, p.y * 1.1f, p.z * 2.3f, params.getSeed() ^ 0x51a7u) * 0.12f;
152 const float beddingWave = std::fabs(std::sin((p.y + beddingWarp) * 8.f * 3.1415926535f));
153 const float beddingMask = 1.f - smoothstep(0.05f, 0.42f, beddingWave);
154 float fractureMask = 0.f;
155 float secondaryFractureMask = 0.f;
156 float fractureAperture = 1.f;
157 float secondaryFractureAperture = 1.f;
158 for (const CaveFracture& fracture : fractures) {
161 params.getSeed()});
162 if (sample.mask > fractureMask) {
163 secondaryFractureMask = fractureMask;
164 secondaryFractureAperture = fractureAperture;
165 fractureMask = sample.mask;
166 fractureAperture = sample.apertureMultiplier;
167 } else {
168 if (sample.mask > secondaryFractureMask) {
169 secondaryFractureMask = sample.mask;
170 secondaryFractureAperture = sample.apertureMultiplier;
171 }
172 }
173 minimumFractureAperture = std::min(minimumFractureAperture, sample.apertureMultiplier);
174 maximumFractureAperture = std::max(maximumFractureAperture, sample.apertureMultiplier);
176 }
177 const float pockets =
178 std::max(0.f, latticeNoise(p.x * 15.f, p.y * 11.f, p.z * 15.f, params.getSeed() ^ 0xb5297a4du));
179 // Fowler's boundary-layer model motivates travelling, cusp-edged scallops.
180 // Local flow and passage curvature add hydraulic scale and outer-bank bias.
182 {{passage.along, passage.angle, passage.distance, passage.radius, passage.hydraulicIntensity,
186 if (scallops.youngerErosion > 1e-6f) {
193 }
194 const CaveBiogenicCorrosionSample biogenic =
195 sampleCaveBiogenicCorrosion({passage.along, passage.angle, passage.distance, passage.radius,
197 const CaveFacetSample facets =
198 sampleCaveCondensationFacets({passage.along, passage.angle, passage.distance, passage.radius,
201 {p.x, p.y, p.z, passage.distance, passage.radius, differentialVeinErosion, params.getSeed()});
202 const float mineralSupply = genesis == "hypogene" ? 1.f : (genesis == "mixed" ? 0.72f : 0.28f);
204 const bool chemicalArmoringPotential =
205 erosion > 0.f || biogenicCorrosion > 0.f || waterTableCorrosion > 0.f || mixingCorrosion > 0.f ||
207 if (mineralArmoring > 0.f && chemicalArmoringPotential) {
208 armoring = sampleCaveMineralArmoring(
209 {passage.along, passage.angle, passage.hydraulicIntensity, mineralSupply, params.getSeed()});
210 }
211 const float chemicalRetention = 1.f - mineralArmoring * (1.f - armoring.dissolutionRetention);
212 CaveRoughnessTransferSample roughnessTransfer;
213 if (roughnessFlowCoupling > 0.f && multiscaleRoughness > 0.f && roughness > 0.f &&
214 chemicalArmoringPotential) {
215 roughnessTransfer =
217 }
218 const float chemicalMassTransfer = roughnessTransfer.massTransferMultiplier;
219 if (shell > 1e-4f && std::fabs(chemicalMassTransfer - 1.f) > 1e-6f) {
221 minimumRoughnessTransfer = std::min(minimumRoughnessTransfer, chemicalMassTransfer);
222 maximumRoughnessTransfer = std::max(maximumRoughnessTransfer, chemicalMassTransfer);
223 maximumRidgeExposure = std::max(maximumRidgeExposure, roughnessTransfer.ridgeExposure);
224 maximumRecessShelter = std::max(maximumRecessShelter, roughnessTransfer.recessShelter);
225 }
226 CaveWaterTableSample waterTable;
227 if (waterTableCorrosion > 0.f && genesis != "hypogene") {
228 waterTable = sampleCaveWaterTableCorrosion({p.y, passage.angle, passage.along, waterTableLevel,
230 params.getSeed()});
231 }
234 const CaveLithologySample lithology =
235 sampleCaveLithology({p.x, p.y, p.z, passage.along, passage.hydraulicIntensity,
237 CaveAbrasionSample abrasion;
238 if (floodAbrasion > 0.f && genesis != "hypogene") {
239 abrasion = sampleCaveFloodAbrasion({passage.along, passage.angle, passage.hydraulicIntensity,
240 passage.bendStrength, passage.outerBankAngle, sedimentLoad,
241 params.getSeed()});
242 }
243 CavePluckingSample plucking;
244 if (floodPlucking > 0.f && genesis != "hypogene" && fractures.size() >= 2) {
245 plucking =
246 sampleCaveFloodPlucking({p.x, p.y, p.z, passage.angle, passage.hydraulicIntensity, fractureMask,
247 secondaryFractureMask, pluckingBlockScale, params.getSeed()});
248 }
249 CaveConstrictionScourSample constriction;
250 if (constrictionScour > 0.f && genesis != "hypogene") {
252 }
253 CaveKnickpointSample knickpoint;
254 if (knickpointErosion > 0.f && genesis != "hypogene") {
256 }
257 CaveKarrenSample karren;
258 if (streamBedKarren > 0.f && genesis != "hypogene" && fractures.size() >= 2) {
259 karren = sampleCaveStreamKarren(
260 {passage.angle, passage.hydraulicIntensity, fractureMask, secondaryFractureMask});
261 }
262 CavePotholeSample pothole;
263 if (eddyPotholes > 0.f && genesis != "hypogene") {
265 }
266 CaveObstacleScourSample obstacleScour;
267 if (breakdownScour > 0.f && genesis != "hypogene") {
269 }
270 CaveFractureChannelizationSample fractureChannel;
272 fractureChannel = sampleCaveFractureChannelization(
273 {fractureMask, secondaryFractureMask, fractureAperture, secondaryFractureAperture,
275 }
276 if (facets.retreat > 1e-6f) {
278 maximumFacetRetreat = std::max(maximumFacetRetreat, facets.retreat);
279 }
280 if (biogenic.erosion > 1e-6f) {
284 totalBiogenicErosion += biogenic.erosion;
285 }
286 if (differentialVeins.hostRetreat > 1e-6f) {
289 std::max(maximumDifferentialVeinRetreat, differentialVeins.hostRetreat);
290 maximumVeinProtection = std::max(maximumVeinProtection, differentialVeins.veinProtection);
291 }
292 const float dissolution = bedding * beddingMask * 0.055f + fractureDissolution * fractureMask * 0.075f +
293 pockets * 0.032f +
294 scallopErosion * scallops.erosion * biogenic.fluvialScallopRetention *
295 0.045f * (genesis == "hypogene" ? 0.35f : 1.f);
298 // Preferential paths transport fresher undersaturated water. Their local
299 // permeability co-evolves with accessible reactive surface instead of
300 // treating every limestone voxel as chemically identical.
301 const float flowWeightedDissolution =
302 dissolution * rock.reactiveSurface *
303 std::clamp(passage.hydraulicIntensity * rock.permeability, 0.2f, 1.7f);
304 const float biogenicDissolution = biogenic.erosion * rock.reactiveSurface * 0.052f;
305 d -= shell * chemicalRetention * chemicalMassTransfer *
306 (erosion * flowWeightedDissolution + biogenicDissolution);
307 if (shell > 1e-4f && chemicalRetention < 0.999999f) {
313 std::min(minimumArmoredDissolutionRetention, chemicalRetention);
314 }
315 const float fractureChannelRetreat = shell * chemicalMassTransfer * erosion * fractureDissolution *
316 fractureFlowFeedback * fractureChannel.erosion * 0.062f;
317 d -= fractureChannelRetreat;
318 if (fractureChannelRetreat > 1e-6f) {
320 maximumFractureChannelRetreat = std::max(maximumFractureChannelRetreat, fractureChannelRetreat);
322 std::max(maximumFractureFlowConcentration, fractureChannel.flowConcentration);
326 std::min(minimumFractureReactantAccess, fractureChannel.reactantAccess);
327 }
328 const float waterTableRetreat = shell * chemicalRetention * chemicalMassTransfer * waterTableCorrosion *
329 waterTable.erosion * 0.065f;
330 d -= waterTableRetreat;
331 if (waterTableRetreat > 1e-6f) {
333 maximumWaterTableRetreat = std::max(maximumWaterTableRetreat, waterTableRetreat);
334 }
335 const float mixingRetreat =
336 shell * chemicalRetention * chemicalMassTransfer * mixingCorrosion * mixing.erosion * 0.07f;
337 d -= mixingRetreat;
338 if (mixingRetreat > 1e-6f) {
341 }
342 const float lithologyRetreat =
343 shell * chemicalRetention * chemicalMassTransfer * bedding * lithology.retreat * 0.052f;
344 d -= lithologyRetreat;
345 if (lithologyRetreat > 1e-6f) {
347 if (lithology.styloliteMask > 0.05f) ++styloliteAffectedVoxels;
349 maximumLithologyRetreat = std::max(maximumLithologyRetreat, lithologyRetreat);
350 }
351 const float abrasionRetreat = shell * floodAbrasion * abrasion.erosion * 0.058f;
352 d -= abrasionRetreat;
353 if (abrasionRetreat > 1e-6f) {
355 maximumAbrasionRetreat = std::max(maximumAbrasionRetreat, abrasionRetreat);
356 maximumAbrasionVortex = std::max(maximumAbrasionVortex, abrasion.vortexMask);
357 }
358 const float pluckingRetreat = shell * floodPlucking * plucking.erosion * 0.082f;
359 d -= pluckingRetreat;
360 if (pluckingRetreat > 1e-6f) {
362 maximumPluckingRetreat = std::max(maximumPluckingRetreat, pluckingRetreat);
365 }
366 const float constrictionRetreat = shell * constrictionScour * constriction.erosion * 0.115f;
367 d -= constrictionRetreat;
368 if (constrictionRetreat > 1e-6f) {
373 }
374 const float knickpointRetreat = shell * knickpointErosion * knickpoint.erosion * 0.12f;
375 d -= knickpointRetreat;
376 if (knickpointRetreat > 1e-6f) {
378 maximumKnickpointRetreat = std::max(maximumKnickpointRetreat, knickpointRetreat);
381 std::max(maximumKnickpointDrop, knickpointSites[size_t(knickpoint.siteIndex)].drop);
382 }
383 const float karrenRetreat = shell * streamBedKarren * karren.erosion * 0.052f;
384 d -= karrenRetreat;
385 if (karrenRetreat > 1e-6f) {
391 }
392 const float potholeRetreat = shell * eddyPotholes * pothole.erosion * 0.09f;
393 d -= potholeRetreat;
394 if (potholeRetreat > 1e-6f) {
396 maximumPotholeRetreat = std::max(maximumPotholeRetreat, potholeRetreat);
400 potholeSites[size_t(pothole.siteIndex)].fractureIntersection);
401 }
402 const float obstacleScourRetreat = shell * breakdownScour * obstacleScour.erosion * 0.082f;
403 d -= obstacleScourRetreat;
404 if (obstacleScourRetreat > 1e-6f) {
406 maximumObstacleScourRetreat = std::max(maximumObstacleScourRetreat, obstacleScourRetreat);
408 maximumWakeScour = std::max(maximumWakeScour, obstacleScour.wakeScour);
411 }
412 d -= shell * chemicalRetention * chemicalMassTransfer * facets.retreat;
413 d -= shell * chemicalRetention * chemicalMassTransfer * differentialVeins.hostRetreat;
414 const size_t voxel = size_t(x) + size_t(y) * size_t(nx) + size_t(z) * size_t(nx) * size_t(ny);
415 density[voxel] = d;
416 const float exposedRate =
417 rock.reactiveSurface * std::clamp(passage.hydraulicIntensity * rock.permeability, 0.2f, 1.7f);
418 reactiveRate[voxel] = std::clamp(1.f + reactiveSurfaceCoupling * (exposedRate - 1.f), 0.25f, 2.5f);
419 hydraulicExposure[voxel] = passage.hydraulicIntensity;
420 flowDirection[voxel] = passage.tangent;
421 }
422 }
423 }
424
425
426 return Result<void>::success();
427}
428
429} // namespace eve::procgen::cave_detail
double z
double y
double x
glm::vec4 p[6]
std::array< float, 3 > position
double radius
Definition MeleeHit.cpp:42
std::string path
Definition PlayHost.cpp:111
std::shared_ptr< const std::vector< glm::vec2 > > points
float d
double current
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
uint32_t getSeed() const
Return the deterministic generation seed.
Definition Params.cpp:140
float latticeNoise(float x, float y, float z, uint32_t seed)
float ellipsoidDistance(Vec3 point, const Chamber &shape)
float distanceToSegment(Vec3 point, Vec3 a, Vec3 b)
float smoothstep(float edge0, float edge1, float value)
CaveRoughnessTransferSample sampleCaveRoughnessTransfer(const CaveRoughnessTransferInput &input)
Estimate local reactive transport over a rough carbonate wall.
CaveRoughnessSample sampleCaveWallRoughness(const CaveRoughnessInput &input)
Sample a three-band, spatially correlated cave-wall relief field.
CaveFractureChannelizationSample sampleCaveFractureChannelization(const CaveFractureChannelizationInput &input)
Approximate fracture aperture-flow-dissolution feedback at one cave-wall sample.
CaveMixingCorrosionSample sampleCaveMixingCorrosion(CaveHydrologyVec3 point, const std::vector< CaveMixingSite > &sites)
Sample localized shell retreat around branch-to-trunk mixing sites.
CaveFacetSample sampleCaveCondensationFacets(const CaveFacetInput &input)
Sample planar condensation-corrosion facets in passage-local coordinates.
CaveObstacleScourSample sampleCaveObstacleScour(CaveHydrologyVec3 point, const std::vector< CaveObstacleScourSite > &sites)
Sample deep upstream horseshoe scour and shallower elongated wake erosion.
CaveScallopHistorySample sampleCaveScallopHistory(const CaveScallopHistoryInput &input)
Sample cumulative erosion from two spatially partitioned cave-flow stages.
CaveAbrasionSample sampleCaveFloodAbrasion(const CaveAbrasionInput &input)
Sample mechanical erosion by sediment-laden floods near the passage bed.
CaveWaterTableSample sampleCaveWaterTableCorrosion(const CaveWaterTableInput &input)
Sample laterally continuous corrosion belts left by one or more water-table stages.
CaveDifferentialErosionSample sampleCaveDifferentialVeinErosion(const CaveDifferentialErosionInput &input)
Sample host-rock retreat around resistant intersecting mineral veins.
float carveCaveParagenesis(float x, float y, float z, float current, const CaveSedimentSet &sediment)
Carve flow-aligned antigravitative ceiling channels above generated sediment bars.
CaveKnickpointSample sampleCaveKnickpointErosion(CaveHydrologyVec3 point, const std::vector< CaveKnickpointSite > &sites)
Sample plunge-pool drilling and lower-headwall erosion around derived knickpoints.
CaveFractureSample sampleCaveFracture(const CaveFractureInput &input)
Sample a spatially correlated fracture aperture and stress-split dissolution front.
CavePassageFrame nearestCavePassageFrame(const CaveHydrologyVec3 &point, const std::vector< CaveHydrologyPoint > &path, const std::vector< float > &hydraulicIntensity)
Nearest cave passage frame.
CaveLithologySample sampleCaveLithology(const CaveLithologyInput &input)
Sample flow-accessible dissolution caused by contrasting beds and clustered stylolites.
CaveMineralArmoringSample sampleCaveMineralArmoring(const CaveMineralArmoringInput &input)
Sample patchy secondary-mineral coating and its protection of carbonate wall rock.
CaveKarrenSample sampleCaveStreamKarren(const CaveKarrenInput &input)
Sample stream-bed solution grooves guided by the two strongest local fracture sets.
CavePluckingSample sampleCaveFloodPlucking(const CavePluckingInput &input)
Sample thresholded removal of blocks bounded by one or more exposed fractures.
CaveMicrostructureSample sampleCaveMicrostructure(float x, float y, float z, uint32_t seed, float heterogeneity, float microporosityAccess, float permeabilityContrast)
Sample cave microstructure.
CavePotholeSample sampleCavePotholeErosion(CaveHydrologyVec3 point, const std::vector< CavePotholeSite > &sites)
Sample gravel-size-dependent pothole abrasion around derived sites.
CaveConstrictionScourSample sampleCaveConstrictionScour(CaveHydrologyVec3 point, const std::vector< CaveConstrictionScourSite > &sites)
Sample bed scour downstream of a constriction and lateral erosion near the pool exit.
float carveCaveBreakdownScars(float x, float y, float z, float current, const CaveBreakdownSet &breakdown)
Carve the event's shallow ceiling detachment scars from a cave SDF.
CaveBiogenicCorrosionSample sampleCaveBiogenicCorrosion(const CaveBiogenicCorrosionInput &input)
Sample an airflow-aligned, guano-ammonia biogenic corrosion overprint.
Near-bed abrasion, sediment cover, and coherent vortex-cell response.
CaveBiogenicCorrosionSample public API.
Local plunging-flow scour and exit-widening response.
CaveDifferentialErosionSample public API.
CaveFacetSample public API.
Definition CaveFacets.h:20
Observable local state of aperture-flow-dissolution feedback.
Observable local state of a sampled dissolving fracture.
One deterministic structural fracture plane in normalized cave space.
CaveHydrologyVec3 public API.
std::vector< std::vector< float > > branches
Observable stream-bed karren response at one cave-space sample.
Definition CaveKarren.h:16
Local vertical drilling and headwall-undercut response at a cave-stream knickpoint.
Local bed resistance, stylolite exposure, and selective retreat.
CaveMicrostructureSample public API.
Observable local state of a retained secondary-mineral coating.
Local corrosion strength and the contributing mixing-water potential.
Local upstream horseshoe and downstream wake erosion response.
CavePassageFrame public API.
Local fracture predisposition, hydraulic threshold, and block removal response.
Local primary and compound pothole erosion response.
Multi-scale wall relief and its separated spatial-frequency bands.
Bounded mass-transfer response of an exposed ridge or sheltered recess.
Observable combination of preserved older and younger scallop generations.
Local staged water-table corrosion and the dominant historical level.
std::vector< CaveConstrictionScourSite > constrictionScourSites
std::vector< RisingConduit > ceilingChannels
std::vector< CaveFracture > fractures
std::vector< CaveHydrologyBranch > branches
std::vector< CaveHydrologyVec3 > flowDirection
std::vector< CaveKnickpointSite > knickpointSites
std::vector< CaveObstacleScourSite > obstacleScourSites
std::vector< CavePotholeSite > potholeSites
std::vector< RisingConduit > feeders
std::vector< CaveMixingSite > mixingSites
std::vector< PassagePoint > spine