载入中...
搜索中...
未找到
TerrainMask.cpp
浏览该文件的文档.
2#include <array>
3#include <cstdint>
4#include <numbers>
8
9namespace eve::procgen {
10using namespace raster_detail;
11
14 if (!validRaster(target) || !validRaster(heights) || !validRaster(baseCosts) ||
15 target.getWidth() != heights.getWidth() || target.getHeight() != heights.getHeight() ||
16 target.getWidth() != baseCosts.getWidth() || target.getHeight() != baseCosts.getHeight() ||
17 !std::isfinite(settings.spacingX) || settings.spacingX <= 0 || !std::isfinite(settings.spacingZ) ||
18 settings.spacingZ <= 0 || !std::isfinite(settings.heightScale) || settings.heightScale < 0 ||
19 !std::isfinite(settings.maxSlopeDegrees) || settings.maxSlopeDegrees < 0 || settings.maxSlopeDegrees > 90 ||
20 !std::isfinite(settings.slopeCost) || settings.slopeCost < 0)
21 return invalid("terrain.traversalCosts: matching finite rasters and valid world-space policy required");
22 std::vector<float> candidate(target.data().size());
23 for (int z = 0; z < heights.getHeight(); ++z) {
24 for (int x = 0; x < heights.getWidth(); ++x) {
25 const double base = baseCosts.height(x, z);
26 if (base > 0 && base < 1)
27 return invalid("terrain.traversalCosts: positive base costs must be at least one");
28 double gx = 0, gz = 0;
29 const double h = heights.height(x, z);
30 for (int d : {-1, 1}) {
31 if (x + d >= 0 && x + d < heights.getWidth())
32 gx = std::max(
33 gx, std::abs(double(heights.height(x + d, z)) - h) * settings.heightScale / settings.spacingX);
34 if (z + d >= 0 && z + d < heights.getHeight())
35 gz = std::max(
36 gz, std::abs(double(heights.height(x, z + d)) - h) * settings.heightScale / settings.spacingZ);
37 }
38 const double gradient = std::hypot(gx, gz);
39 const double slope = std::atan(gradient) * 180 / std::numbers::pi;
40 double cost = 0;
41 if (base > 0 && slope <= settings.maxSlopeDegrees)
42 cost = base * (1 + double(settings.slopeCost) * gradient);
43 if (!isRepresentable(cost)) return invalid("terrain.traversalCosts: cost overflow");
44 candidate[size_t(z) * heights.getWidth() + x] = float(cost);
45 }
46 }
47 return publish(target, std::move(candidate));
48}
49
50Result<int> smoothTerrainMask(Heightmap& target, const Heightmap& input, float verticality, float blurRadius) {
51 if (!validRaster(target) || !validRaster(input) || target.getWidth() != input.getWidth() ||
52 target.getHeight() != input.getHeight() || !std::isfinite(verticality) || std::abs(verticality) > 1 ||
53 !std::isfinite(blurRadius) || blurRadius < 0)
54 return invalid("terrain.smoothMask: matching finite rasters, verticality [-1,1] and radius >= 0 required");
55 Heightmap candidate = input;
56 Heightmap fullMask(input.getWidth(), input.getHeight());
57 std::fill(fullMask.data().begin(), fullMask.data().end(), 1.0F);
59 settings.radius = blurRadius;
60 settings.verticality = verticality;
61 settings.strength = 1;
62 auto result = applyTerrainSmooth(candidate, fullMask, settings);
63 if (!result.ok()) return result;
64 return publish(target, std::move(candidate.data()));
65}
66
68 int contextWidth, int contextHeight, const TerrainSampleGrid& h) {
69 auto positive = [](double v) { return std::isfinite(v) && v > 0; };
70 if (contextWidth <= 0 || contextHeight <= 0 || h.width <= 0 || h.height <= 0 || !positive(w.spacingX) ||
71 !positive(w.spacingZ) || !positive(h.spacingX) || !positive(h.spacingZ) || !positive(w.width) ||
72 !positive(w.depth) || !std::isfinite(target.strength))
73 return invalid("terrain.paintContext: positive dimensions, spacing, footprint and finite strength required");
74 for (double v : {w.originX, w.originZ, w.centerX, w.centerZ, w.rotation, h.originX, h.originZ})
75 if (!std::isfinite(v)) return invalid("terrain.paintContext: finite world coordinates required");
76 const double spanX = contextWidth * w.spacingX, spanZ = contextHeight * w.spacingZ;
77 const double heightSpanX = h.width * h.spacingX, heightSpanZ = h.height * h.spacingZ;
78 if (!std::isfinite(spanX) || !std::isfinite(spanZ) || !std::isfinite(heightSpanX) || !std::isfinite(heightSpanZ))
79 return invalid("terrain.paintContext: world spans exceed finite double range");
80 const double c = std::cos(w.rotation), s = std::sin(w.rotation);
81 const double bx = (w.originX - w.centerX) - 0.5 * w.spacingX, bz = (w.originZ - w.centerZ) - 0.5 * w.spacingZ;
82 const double values[] = {spanX / heightSpanX,
83 0,
84 0,
85 spanZ / heightSpanZ,
86 ((w.originX - h.originX) - 0.5 * w.spacingX + 0.5 * h.spacingX) / heightSpanX,
87 ((w.originZ - h.originZ) - 0.5 * w.spacingZ + 0.5 * h.spacingZ) / heightSpanZ,
88 c * spanX / w.width,
89 s * spanZ / w.width,
90 -s * spanX / w.depth,
91 c * spanZ / w.depth,
92 0.5 + (c * bx + s * bz) / w.width,
93 0.5 + (-s * bx + c * bz) / w.depth};
94 if (!std::all_of(std::begin(values), std::end(values), [](double v) { return isRepresentable(v); }))
95 return invalid("terrain.paintContext: UV coefficients exceed finite float range");
97 float* fields[] = {&candidate.heightXX, &candidate.heightXZ, &candidate.heightZX,
98 &candidate.heightZZ, &candidate.heightOffsetX, &candidate.heightOffsetZ,
99 &candidate.brushXX, &candidate.brushXZ, &candidate.brushZX,
100 &candidate.brushZZ, &candidate.brushOffsetX, &candidate.brushOffsetZ};
101 int changed = 0;
102 for (size_t i = 0; i < std::size(values); ++i) {
103 changed += *fields[i] != float(values[i]);
104 *fields[i] = float(values[i]);
105 }
106 target = candidate;
108}
109
110
113 TerrainMaskBlend mode) {
114 if (!validRaster(target) || !validRaster(input) || !validRaster(heights) || !validRaster(curve) ||
115 target.getWidth() != input.getWidth() || target.getHeight() != input.getHeight() || curve.getHeight() != 1 ||
116 !std::isfinite(s.featureSize) || s.featureSize <= 0 || double(s.featureSize) > UINT32_MAX ||
117 !std::isfinite(s.concavity) || mode < TerrainMaskBlend::Multiply || mode > TerrainMaskBlend::Subtract)
118 return invalid("terrain.concavity: finite compatible rasters and valid feature controls required");
119 const double factor = double(heights.getWidth()) / input.getWidth();
120 if ((input.getHeight() - 1) * factor > UINT32_MAX)
121 return invalid("terrain.concavity: mapped coordinates exceed uint32");
122 const uint32_t width = heights.getWidth(), height = heights.getHeight(), offset = uint32_t(s.featureSize);
123 auto sample = [&](uint32_t x, uint32_t z) -> double {
124 return x < width && z < height ? heights.height(int(x), int(z)) : 0;
125 };
126 auto gradient = [&](uint32_t x, uint32_t z) {
127 const uint32_t r = x - offset, l = std::min(width, uint32_t(x + offset));
128 const uint32_t u = z - offset, d = std::min(height, uint32_t(z + offset));
129 const double dx =
130 (sample(r, u) + 2 * sample(r, z) + sample(r, d) - sample(l, u) - 2 * sample(l, z) - sample(l, d)) / 8;
131 const double dz =
132 (sample(l, d) + 2 * sample(x, d) + sample(r, d) - sample(l, u) - 2 * sample(x, u) - sample(r, u)) / 8;
133 const double length = std::hypot(dx, dz);
134 return length == 0 ? std::array<double, 2>{0, 0} : std::array<double, 2>{dx / length, dz / length};
135 };
136 std::vector<float> output(target.data().size());
137 for (int z = 0; z < input.getHeight(); ++z)
138 for (int x = 0; x < input.getWidth(); ++x) {
139 const uint32_t hx = uint32_t(x * factor), hz = uint32_t(z * factor);
140 const uint32_t r = hx - offset, l = std::min(width, uint32_t(hx + offset));
141 const uint32_t u = hz - offset, d = std::min(height, uint32_t(hz + offset));
142 const auto ru = gradient(r, u), rc = gradient(r, hz), rd = gradient(r, d);
143 const auto lu = gradient(l, u), lc = gradient(l, hz), ld = gradient(l, d);
144 const auto cd = gradient(hx, d), cu = gradient(hx, u);
145 const double dx = (ru[0] + 2 * rc[0] + rd[0] - lu[0] - 2 * lc[0] - ld[0]) / 8;
146 const double dz = (ld[1] + 2 * cd[1] + rd[1] - lu[1] - 2 * cu[1] - ru[1]) / 8;
147 const uint32_t border = std::min({uint32_t(width - hx), hx, uint32_t(height - hz), hz});
148 double fade = std::clamp((double(border) - 2 * s.featureSize) / (2 * s.featureSize), 0.0, 1.0);
149 fade = fade * fade * (3 - 2 * fade);
150 const double value =
151 std::clamp(2 * fade * std::clamp(double(s.concavity) * (dx + dz) / 2, 0.0, 1.0), 0.0, 1.0);
152 const double filter = curve.height(int(value * (curve.getWidth() - 1)), 0);
153 const size_t i = size_t(z) * input.getWidth() + x;
154 const double old = input.data()[i];
155 double result = old;
156 switch (mode) {
157 case TerrainMaskBlend::Multiply: result = old * filter; break;
158 case TerrainMaskBlend::Maximum: result = std::max(old, filter); break;
159 case TerrainMaskBlend::Minimum: result = std::min(old, filter); break;
160 case TerrainMaskBlend::Add: result = old + filter; break;
161 case TerrainMaskBlend::Subtract: result = old - filter; break;
162 }
163 if (!isRepresentable(result)) return invalid("terrain.concavity: result exceeds finite float range");
164 output[i] = float(result);
165 }
166 return publish(target, std::move(output));
167}
168
169// Radial blur design attribution from the reference shader:
170// MIT License, Copyright (c) 2018 @XorDev
171// Permission is hereby granted, free of charge, to any person obtaining a copy
172// of this software and associated documentation files (the "Software"), to deal
173// in the Software without restriction, including without limitation the rights
174// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
175// copies of the Software, and to permit persons to whom the Software is
176// furnished to do so, subject to the following conditions:
177// The above copyright notice and this permission notice shall be included in all
178// copies or substantial portions of the Software.
179// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
180// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
181// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
182// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
183// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
184// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
187 TerrainMaskBlend mode) {
188 if (!validRaster(target) || !validRaster(input) || !validRaster(heights) || !validRaster(curve) ||
189 curve.getHeight() != 1 || target.getWidth() != input.getWidth() || target.getHeight() != input.getHeight() ||
190 !std::isfinite(s.radius) || s.radius < 0 || !std::isfinite(s.worldUnits) || !std::isfinite(s.intensity) ||
191 s.intensity <= 0 || s.steps <= 0 || s.directions <= 0 ||
192 s.steps > (std::numeric_limits<int>::max() - 1) / s.directions || mode < TerrainMaskBlend::Multiply ||
194 return invalid("terrain.curvature: finite compatible rasters, curve and valid radial controls required");
195 std::vector<float> output(target.data().size());
196 for (int z = 0; z < target.getHeight(); ++z)
197 for (int x = 0; x < target.getWidth(); ++x) {
198 const double u = (x + 0.5) / target.getWidth(), v = (z + 0.5) / target.getHeight();
199 const double origin = textureSample(heights, u, v);
200 double sum = origin;
201 for (int direction = 0; direction < s.directions; ++direction) {
202 const double angle = 2 * std::numbers::pi * direction / s.directions;
203 for (int step = 1; step <= s.steps; ++step) {
204 const double radius = double(s.radius) * step / s.steps;
205 sum += textureSample(heights, u + std::cos(angle) * radius, v + std::sin(angle) * radius);
206 }
207 }
208 const double base = (origin - sum / (double(s.steps) * s.directions + 1)) * s.worldUnits;
209 if (base < 0 && std::floor(s.intensity) != s.intensity)
210 return invalid("terrain.curvature: negative base with fractional intensity has no real result");
211 const double powered = std::pow(base, double(s.intensity));
212 if (std::isnan(powered)) return invalid("terrain.curvature: undefined power result");
213 const double filter = curveSample(curve, std::clamp(std::abs(powered), 0.0, 1.0));
214 const size_t i = size_t(z) * target.getWidth() + x;
215 const double previous = input.data()[i];
216 double result = previous;
217 switch (mode) {
219 case TerrainMaskBlend::Maximum: result = std::max(previous, filter); break;
223 }
224 if (!isRepresentable(result)) return invalid("terrain.curvature: result exceeds finite float range");
225 output[i] = float(result);
226 }
227 return publish(target, std::move(output));
228}
229
231 const Heightmap& brush, const TerrainBrushBlendSettings& spatial,
232 const Heightmap& curve, TerrainStrengthMode mode, float strength,
233 bool userInvert) {
234 Heightmap candidate = target;
235 auto blended = blendTerrainBrush(candidate, oldHeights, erosion, brush, spatial);
236 if (!blended.ok()) return blended;
237 auto filtered = applyTerrainStrength(candidate, candidate, curve, mode, strength, !userInvert);
238 if (!filtered.ok()) return filtered;
239 return publish(target, std::move(candidate.data()));
240}
242 const double radius = std::abs(double(distance));
244 target.getWidth() != source.getWidth() || target.getHeight() != source.getHeight() ||
245 !std::isfinite(distance) || 2 * radius * source.getWidth() > std::numeric_limits<int>::max())
246 return invalid(
247 "terrain.growShrink: matching finite rasters, one-row curve and indexable finite radius required");
248 const int width = source.getWidth(), height = source.getHeight();
249 const long long last = static_cast<long long>(std::floor(2 * radius * width));
250 std::vector<float> output(target.data().size());
251 for (int z = 0; z < height; ++z)
252 for (int x = 0; x < width; ++x) {
253 const double u = (x + 0.5) / width, v = (z + 0.5) / height;
254 double value = source.height(x, z);
255 if (radius > 0) {
256 // Skip definitely out-of-bounds indices, retaining one boundary candidate for rounding.
257 const auto firstX = std::max(0LL, static_cast<long long>(std::floor((radius - u) * width)) - 1);
258 const auto lastX = std::min(last, static_cast<long long>(std::ceil((radius + 1 - u) * width)) + 1);
259 const auto firstZ = std::max(0LL, static_cast<long long>(std::floor((radius - v) * width)) - 1);
260 const auto lastZ = std::min(last, static_cast<long long>(std::ceil((radius + 1 - v) * width)) + 1);
261 for (auto ix = firstX; ix <= lastX; ++ix)
262 for (auto iz = firstZ; iz <= lastZ; ++iz) {
263 const double dx = -radius + double(ix) / width, dz = -radius + double(iz) / width;
264 if (u + dx < 0 || u + dx > 1 || v + dz < 0 || v + dz > 1) continue;
265 double weight = std::clamp(std::hypot(dx, dz) / std::hypot(radius, radius), 0.0, 1.0);
266 weight = weight * weight * (3 - 2 * weight);
267 const double candidate = std::lerp(textureSample(source, u + dx, v + dz), value, weight);
268 value = distance > 0 ? std::max(value, candidate) : std::min(value, candidate);
269 }
270 }
271 const double transformed = curveSample(curve, value);
272 if (!isRepresentable(transformed)) return invalid("terrain.growShrink: result exceeds finite float range");
273 output[size_t(z) * width + x] = float(transformed);
274 }
275 return publish(target, std::move(output));
276}
278 TerrainStrengthMode mode, float strength, bool invert) {
280 target.getWidth() != source.getWidth() || target.getHeight() != source.getHeight() ||
281 !std::isfinite(strength) || strength < 0 || strength > 1 || mode < TerrainStrengthMode::Replace ||
283 return invalid(
284 "terrain.strength: matching finite rasters, one-row curve, valid mode and unit strength required");
285 std::vector<float> output(target.data().size());
286 for (size_t i = 0; i < output.size(); ++i) {
287 const double old = source.data()[i];
288 double value = curveSample(curve, old);
289 if (invert) value = 1 - value;
290 switch (mode) {
292 case TerrainStrengthMode::Maximum: value = std::max(old, value); break;
293 case TerrainStrengthMode::Minimum: value = std::min(old, value); break;
294 case TerrainStrengthMode::Add: value = old + value; break;
295 case TerrainStrengthMode::Subtract: value = old - value; break;
296 }
297 value = std::lerp(old, value, double(strength));
298 if (!isRepresentable(value)) return invalid("terrain.strength: output exceeds finite float range");
299 output[i] = float(value);
300 }
301 return publish(target, std::move(output));
302}
303Result<int> blendTerrainBrush(Heightmap& target, const Heightmap& oldHeights, const Heightmap& newHeights,
304 const Heightmap& brush, const TerrainBrushBlendSettings& s) {
305 const float coefficients[] = {s.heightXX, s.heightXZ, s.heightZX, s.heightZZ, s.heightOffsetX,
306 s.heightOffsetZ, s.brushXX, s.brushXZ, s.brushZX, s.brushZZ,
307 s.brushOffsetX, s.brushOffsetZ, s.strength};
308 if (!validRaster(target) || !validRaster(oldHeights) || !validRaster(newHeights) || !validRaster(brush) ||
309 !std::all_of(std::begin(coefficients), std::end(coefficients), [](float v) { return std::isfinite(v); }))
310 return invalid("terrain.brush: finite rasters and transform coefficients required");
311 std::vector<float> output(target.data().size());
312 for (int z = 0; z < target.getHeight(); ++z)
313 for (int x = 0; x < target.getWidth(); ++x) {
314 const double u = (x + 0.5) / target.getWidth(), v = (z + 0.5) / target.getHeight();
315 const double hu = s.heightXX * u + s.heightXZ * v + s.heightOffsetX,
316 hv = s.heightZX * u + s.heightZZ * v + s.heightOffsetZ;
317 const double bu = s.brushXX * u + s.brushXZ * v + s.brushOffsetX,
318 bv = s.brushZX * u + s.brushZZ * v + s.brushOffsetZ;
319 double result = textureSample(oldHeights, hu, hv);
320 if (bu >= 0 && bu <= 1 && bv >= 0 && bv <= 1)
321 result = std::lerp(result, textureSample(newHeights, hu, hv),
322 double(s.strength) * textureSample(brush, bu, bv));
323 if (!isRepresentable(result)) return invalid("terrain.brush: result exceeds finite float range");
324 output[size_t(z) * target.getWidth() + x] = float(result);
325 }
326 return publish(target, std::move(output));
327}
328namespace {
329bool sameShape(const Heightmap& a, const Heightmap& b) {
330 return validRaster(a) && validRaster(b) && a.getWidth() == b.getWidth() && a.getHeight() == b.getHeight();
331}
332bool validCurve(const Heightmap& curve) { return validRaster(curve) && curve.getHeight() == 1; }
333double smooth(double value) {
334 value = std::clamp(value, 0.0, 1.0);
335 return value * value * (3 - 2 * value);
336}
337double wrap(double value) {
338 // Match the source shader's boundary convention: zero/negative integers become 1.
339 return value > 0 ? std::fmod(value, 1.0) : 1.0 + std::fmod(value, 1.0);
340}
341} // namespace
342
344 if (!sameShape(target, source) || !validCurve(curve))
345 return invalid("terrain.mask.transform: matching finite rasters and a one-row curve required");
346 std::vector<float> result(target.data().size());
347 for (size_t i = 0; i < result.size(); ++i) result[i] = float(curveSample(curve, source.data()[i]));
348 return publish(target, std::move(result));
349}
350
352 const Heightmap& filterCurve, const Heightmap& strengthCurve) {
353 if (!sameShape(target, source) || !validCurve(filterCurve) || !validCurve(strengthCurve) ||
354 !std::isfinite(minimum) || !std::isfinite(maximum) || minimum >= maximum)
355 return invalid(
356 "terrain.mask.range: matching finite rasters, one-row curves and increasing finite range required");
357 std::vector<float> result(target.data().size());
358 for (size_t i = 0; i < result.size(); ++i) {
359 const double t = smooth((double(source.data()[i]) - minimum) / (double(maximum) - minimum));
360 result[i] = float(curveSample(strengthCurve, curveSample(filterCurve, t)));
361 }
362 return publish(target, std::move(result));
363}
364
366 float heightScale) {
367 if (!sameShape(target, heights) || !std::isfinite(spacingX) || !std::isfinite(spacingZ) ||
368 !std::isfinite(heightScale) || spacingX <= 0 || spacingZ <= 0)
369 return invalid(
370 "terrain.mask.slope: matching finite rasters, positive spacing and finite height scale required");
371 std::vector<float> result(target.data().size());
372 for (int y = 0; y < heights.getHeight(); ++y) {
373 for (int x = 0; x < heights.getWidth(); ++x) {
374 const int left = std::max(0, x - 1), right = std::min(x + 1, heights.getWidth() - 1);
375 const int top = std::max(0, y - 1), bottom = std::min(y + 1, heights.getHeight() - 1);
376 double dx = 0, dz = 0;
377 if (right > left)
378 dx = (double(heights.height(right, y)) - heights.height(left, y)) * heightScale /
379 (double(right - left) * spacingX);
380 if (bottom > top)
381 dz = (double(heights.height(x, bottom)) - heights.height(x, top)) * heightScale /
382 (double(bottom - top) * spacingZ);
383 result[size_t(y) * heights.getWidth() + x] = float(1 - 1 / std::hypot(1.0, dx, dz));
384 }
385 }
386 return publish(target, std::move(result));
387}
388
390 const Heightmap& filterCurve, const Heightmap& strengthCurve) {
391 if (!validRaster(target) || !validCurve(filterCurve) || !validCurve(strengthCurve) ||
392 s.axis < TerrainDistanceAxis::Circle || s.axis > TerrainDistanceAxis::RoundedSquare || s.scaleX == 0 ||
393 s.scaleZ == 0 || s.roundness <= 0)
394 return invalid("terrain.mask.distance: valid raster, curves, axis, scales and roundness required");
395 for (float value : {s.offsetX, s.offsetZ, s.scaleX, s.scaleZ, s.rotation, s.roundness})
396 if (!std::isfinite(value)) return invalid("terrain.mask.distance: finite settings required");
397 const double c = std::cos(double(s.rotation)), sn = std::sin(double(s.rotation));
398 std::vector<float> result(target.data().size());
399 for (int y = 0; y < target.getHeight(); ++y) {
400 for (int x = 0; x < target.getWidth(); ++x) {
401 const double px = ((x + 0.5) / target.getWidth() - 0.5 - s.offsetX) / s.scaleX;
402 const double pz = ((y + 0.5) / target.getHeight() - 0.5 - s.offsetZ) / s.scaleZ;
403 double u = c * px + sn * pz + 0.5, v = -sn * px + c * pz + 0.5;
404 if (s.tiling) {
405 u = wrap(u);
406 v = wrap(v);
407 }
408 double parameter = 0, filtered = 0;
409 if (s.axis != TerrainDistanceAxis::RoundedSquare || (u >= 0 && u <= 1 && v >= 0 && v <= 1)) {
410 switch (s.axis) {
411 case TerrainDistanceAxis::Circle: parameter = smooth(2 * std::hypot(u - 0.5, v - 0.5)); break;
412 case TerrainDistanceAxis::X: parameter = u; break;
413 case TerrainDistanceAxis::Z: parameter = v; break;
415 parameter = 1 - 2 * std::pow(u * (1 - v) * v * (1 - u), double(s.roundness));
416 break;
417 }
418 filtered = curveSample(filterCurve, parameter);
419 }
420 result[size_t(y) * target.getWidth() + x] = float(curveSample(strengthCurve, filtered));
421 }
422 }
423 return publish(target, std::move(result));
424}
425} // namespace eve::procgen
double z
double y
double x
LogicalId target
float w
Definition AnimClip.cpp:738
std::string output
eve::action::ActionSpatialBinding spatial
const std::string & s
bool changed
eve::resource::CostSpec cost
std::vector< std::string > fields
Definition ECS.cpp:42
EvpackChunkInput input
Definition Evpack.cpp:170
float strength
float maximum[3]
float minimum[3]
float u
Definition Grass.cpp:233
double r
bool border
float v
HexVec3 left
HexVec3 right
std::int32_t c
int h
std::vector< Colorf > px
std::uint32_t height
std::uint32_t width
float length
size_t offset
Poco::JSON::Object::Ptr result
MeleePoint3 b
Definition MeleeHit.cpp:41
double radius
Definition MeleeHit.cpp:42
MeleePoint3 a
Definition MeleeHit.cpp:40
float distance
OceanWakeSettings settings
glm::dvec3 origin
glm::dvec3 dx
glm::dvec3 dz
std::shared_ptr< const OceanSprayFrame > previous
std::set< std::string > values
Object::Ptr value
float d
float t
std::string parameter
RoadLaneDirection direction
std::string filter
std::string_view source
Heightmap curve
double spacingZ
double spacingX
float step
Definition TreeMesh.cpp:451
double weight
float heightScale
float bottom
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
In-memory terrain heightmap: a dense float grid (row-major, index = y * width + x) materialized from ...
Definition Heightmap.h:21
int getHeight() const
Returns the height.
Definition Heightmap.cpp:17
const std::vector< float > & data() const
Data.
Definition Heightmap.h:48
float height(int x, int y) const
Height.
Definition Heightmap.cpp:28
int getWidth() const
Returns the width.
Definition Heightmap.cpp:16
SQInteger top
Definition Snapshot.cpp:115
double textureSample(const Heightmap &map, double u, double v)
Texture sample.
double curveSample(const Heightmap &curve, double value)
Curve sample.
double sample(const Heightmap &map, double u, double v)
Sample.
Result< int > publish(Heightmap &target, std::vector< float > candidate)
Publish.
bool validRaster(const Heightmap &map)
Valid raster.
Result< int > invalid(std::string message)
Invalid.
bool isRepresentable(double value)
True when representable.
TerrainStrengthMode
StrengthTransform pass order; source pass 0 named Multiply actually replaces with the curve value.
Result< int > generateTerrainDistanceMask(Heightmap &target, const TerrainDistanceMaskSettings &s, const Heightmap &filterCurve, const Heightmap &strengthCurve)
Generate a transformed distance mask using circle, X, Z or rounded-square coordinates.
Result< int > transformTerrainMask(Heightmap &target, const Heightmap &source, const Heightmap &curve)
Transform scalar input through a clamped bilinear one-row curve texture.
Result< int > generateTerrainRangeMask(Heightmap &target, const Heightmap &source, float minimum, float maximum, const Heightmap &filterCurve, const Heightmap &strengthCurve)
Generate height/range fitness with smoothstep followed by filter and strength curves.
Result< int > generateTerrainCurvatureMask(Heightmap &target, const Heightmap &input, const Heightmap &heights, const Heightmap &curve, const TerrainCurvatureSettings &s, TerrainMaskBlend mode)
Radially blur heights, derive source curvature, transform its curve and combine with an input mask.
Result< int > configureTerrainBrushWorld(TerrainBrushBlendSettings &target, const TerrainStampSettings &w, int contextWidth, int contextHeight, const TerrainSampleGrid &h)
Configure paint-context UV matrices from world sample centers and a rotated stamp footprint.
Result< int > generateTerrainTraversalCosts(Heightmap &target, const Heightmap &heights, const Heightmap &baseCosts, const TerrainTraversalSettings &settings)
Bake a separate terrain cost raster for one actor policy.
Result< int > blendTerrainBrush(Heightmap &target, const Heightmap &oldHeights, const Heightmap &newHeights, const Heightmap &brush, const TerrainBrushBlendSettings &s)
Blend an erosion scalar output with old heights through transformed brush UVs.
TerrainMaskBlend
Ordered scalar-mask arithmetic; intermediate values are not clamped.
Definition TerrainStamp.h:9
Result< int > smoothTerrainMask(Heightmap &target, const Heightmap &input, float verticality, float blurRadius)
Apply Pcg's two-pass Smooth ImageMask operation to a scalar mask.
Result< int > applyTerrainSmooth(Heightmap &target, const Heightmap &mask, const TerrainSmoothSettings &settings)
Apply Pcg's horizontal then vertical seven-pair weighted smooth passes.
Result< int > applyTerrainStrength(Heightmap &target, const Heightmap &source, const Heightmap &curve, TerrainStrengthMode mode, float strength, bool invert)
Apply the reference strength curve, inversion, mode and final interpolation.
Result< int > deriveTerrainSlope(Heightmap &target, const Heightmap &heights, float spacingX, float spacingZ, float heightScale)
Derive the shader's slope metric 1-normal.y from world-scaled height gradients.
Result< int > generateTerrainErosionMask(Heightmap &target, const Heightmap &oldHeights, const Heightmap &erosion, const Heightmap &brush, const TerrainBrushBlendSettings &spatial, const Heightmap &curve, TerrainStrengthMode mode, float strength, bool userInvert)
Compose spatial erosion-output blending and the source's inverted strength filter atomically.
Result< int > generateTerrainConcavityMask(Heightmap &target, const Heightmap &input, const Heightmap &heights, const Heightmap &curve, const TerrainConcavitySettings &s, TerrainMaskBlend mode)
Generate source normalized-gradient concavity with border attenuation and indexed curve lookup.
Result< int > growShrinkTerrainMask(Heightmap &target, const Heightmap &source, const Heightmap &curve, float distance)
Ordered radial Grow/Shrink followed by the reference strength curve.
Paint-context affine UV mappings, evaluated at destination pixel centers.
Concavity source controls; featureSize is in height texels, concavity is signed.
Definition TerrainMask.h:39
Radial curvature controls; radius is UV distance, worldUnits scales signed height-minus-blur.
Definition TerrainMask.h:65
Value-only UV transform; distances are relative to the target raster, rotation in radians.
World X/Z positions of height sample centers, with positive spacing and dimensions.
Two-pass smoothing controls; radius in texels, verticality in [-1,1], strength in [0,...
Value configuration for a rectangular stamp in world X/Z coordinates.
Actor traversal policy in world metres; degrees from horizontal.
Definition TerrainMask.h:8