载入中...
搜索中...
未找到
CaveRoughness.cpp
浏览该文件的文档.
2
3#include <algorithm>
4#include <cmath>
5
6namespace eve::procgen {
7namespace {
8
9uint32_t mixHash(uint32_t value) {
10 value ^= value >> 16u;
11 value *= 0x7feb352du;
12 value ^= value >> 15u;
13 value *= 0x846ca68bu;
14 value ^= value >> 16u;
15 return value;
16}
17
18float smooth(float value) { return value * value * (3.f - 2.f * value); }
19
20float cornerNoise(int x, int y, int z, uint32_t seed) {
21 uint32_t value = seed;
22 value ^= mixHash(uint32_t(x) + 0x9e3779b9u);
23 value ^= mixHash(uint32_t(y) + 0x85ebca6bu);
24 value ^= mixHash(uint32_t(z) + 0xc2b2ae35u);
25 return float(mixHash(value) & 0x00ffffffu) / float(0x007fffffu) - 1.f;
26}
27
28float valueNoise(float x, float y, float z, uint32_t seed) {
29 const int x0 = int(std::floor(x));
30 const int y0 = int(std::floor(y));
31 const int z0 = int(std::floor(z));
32 const float tx = smooth(x - float(x0));
33 const float ty = smooth(y - float(y0));
34 const float tz = smooth(z - float(z0));
35 auto lerp = [](float a, float b, float t) { return a + (b - a) * t; };
36 const float x00 = lerp(cornerNoise(x0, y0, z0, seed), cornerNoise(x0 + 1, y0, z0, seed), tx);
37 const float x10 = lerp(cornerNoise(x0, y0 + 1, z0, seed), cornerNoise(x0 + 1, y0 + 1, z0, seed), tx);
38 const float x01 = lerp(cornerNoise(x0, y0, z0 + 1, seed), cornerNoise(x0 + 1, y0, z0 + 1, seed), tx);
39 const float x11 = lerp(cornerNoise(x0, y0 + 1, z0 + 1, seed), cornerNoise(x0 + 1, y0 + 1, z0 + 1, seed), tx);
40 return lerp(lerp(x00, x10, ty), lerp(x01, x11, ty), tz);
41}
42
43} // namespace
44
46 // Frequency bands remain below the default voxel Nyquist limit. Vertical frequencies
47 // are lower because bedding makes carbonate relief statistically anisotropic.
48 const float macro = valueNoise(input.x * 3.7f, input.y * 2.1f, input.z * 3.7f, input.seed ^ 0x21f0aaadu);
49 const float meso = valueNoise(input.x * 8.3f, input.y * 4.8f, input.z * 8.3f, input.seed ^ 0x91e10da5u);
50 const float fine = valueNoise(input.x * 16.7f, input.y * 9.5f, input.z * 16.7f, input.seed ^ 0xd1b54a35u);
51 const float relief = std::clamp((macro * 0.72f + meso * 0.24f + fine * 0.08f) / 1.04f, -1.f, 1.f);
52 return {relief, macro, meso, fine};
53}
54
55} // namespace eve::procgen
double value
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
EvpackChunkInput input
Definition Evpack.cpp:170
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
std::uint32_t seed
Definition PointSet.cpp:807
float t
constexpr HexVec3 lerp(HexVec3 a, HexVec3 b, float t) noexcept
Linear interpolation between two positions.
Definition HexMetrics.h:51
CaveRoughnessSample sampleCaveWallRoughness(const CaveRoughnessInput &input)
Sample a three-band, spatially correlated cave-wall relief field.
Inputs for deterministic, band-limited cave-wall roughness.
Multi-scale wall relief and its separated spatial-frequency bands.