mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-09 02:23:52 +00:00
feat(editor): add --gen-texture-noise-color two-color noise blends
Same value-noise function as --gen-texture-noise but interpolated between two RGB endpoints rather than emitted as grayscale. Useful for terrain detail (grass+dirt mottle), magic fog, marble veining, or any "natural variation" pass that shouldn't be desaturated. Args: <out.png> <colorAHex> <colorBHex> [seed] [W H] Defaults: seed 1, 256x256. 11th procedural texture pattern (joining solid, BW checker, color checker, grid, vertical/horizontal/radial gradients, grayscale noise, stripes, dots, rings).
This commit is contained in:
parent
f4fd009a0c
commit
41d50c824a
1 changed files with 127 additions and 1 deletions
|
|
@ -531,6 +531,8 @@ static void printUsage(const char* argv0) {
|
|||
std::printf(" Synthesize a linear gradient PNG (default vertical, 256x256)\n");
|
||||
std::printf(" --gen-texture-noise <out.png> [seed] [W H]\n");
|
||||
std::printf(" Synthesize a smooth value-noise PNG (deterministic from seed; default 256x256)\n");
|
||||
std::printf(" --gen-texture-noise-color <out.png> <colorAHex> <colorBHex> [seed] [W H]\n");
|
||||
std::printf(" Same noise pattern but blended between two colors instead of grayscale\n");
|
||||
std::printf(" --gen-texture-radial <out.png> <centerHex> <edgeHex> [W H]\n");
|
||||
std::printf(" Synthesize a radial gradient PNG (center→edge, smooth distance-based blend)\n");
|
||||
std::printf(" --gen-texture-stripes <out.png> <colorAHex> <colorBHex> [stripePx] [diagonal|horizontal|vertical] [W H]\n");
|
||||
|
|
@ -1052,7 +1054,7 @@ int main(int argc, char* argv[]) {
|
|||
"--gen-mesh-from-heightmap", "--export-mesh-heightmap",
|
||||
"--displace-mesh",
|
||||
"--scale-mesh", "--translate-mesh", "--strip-mesh",
|
||||
"--gen-texture-noise", "--rotate-mesh",
|
||||
"--gen-texture-noise", "--gen-texture-noise-color", "--rotate-mesh",
|
||||
"--center-mesh", "--flip-mesh-normals", "--mirror-mesh",
|
||||
"--smooth-mesh-normals",
|
||||
"--merge-meshes",
|
||||
|
|
@ -17496,6 +17498,130 @@ int main(int argc, char* argv[]) {
|
|||
std::printf(" seed : %u\n", seed);
|
||||
std::printf(" type : smooth value noise (16x16 bilinear lattice)\n");
|
||||
return 0;
|
||||
} else if (std::strcmp(argv[i], "--gen-texture-noise-color") == 0 && i + 3 < argc) {
|
||||
// Two-color noise blend: same value-noise function as
|
||||
// --gen-texture-noise but interpolated between two RGB
|
||||
// endpoints rather than emitted as grayscale. Useful
|
||||
// for terrain detail (grass+dirt mottle), magic fog,
|
||||
// marble veining, or any "natural variation" pass that
|
||||
// shouldn't be desaturated.
|
||||
std::string outPath = argv[++i];
|
||||
std::string aHex = argv[++i];
|
||||
std::string bHex = argv[++i];
|
||||
uint32_t seed = 1;
|
||||
int W = 256, H = 256;
|
||||
if (i + 1 < argc && argv[i + 1][0] != '-') {
|
||||
try { seed = static_cast<uint32_t>(std::stoul(argv[++i])); }
|
||||
catch (...) {}
|
||||
}
|
||||
if (i + 1 < argc && argv[i + 1][0] != '-') {
|
||||
try { W = std::stoi(argv[++i]); } catch (...) {}
|
||||
}
|
||||
if (i + 1 < argc && argv[i + 1][0] != '-') {
|
||||
try { H = std::stoi(argv[++i]); } catch (...) {}
|
||||
}
|
||||
if (W < 1 || H < 1 || W > 8192 || H > 8192) {
|
||||
std::fprintf(stderr,
|
||||
"gen-texture-noise-color: invalid size %dx%d\n", W, H);
|
||||
return 1;
|
||||
}
|
||||
auto parseHex = [](std::string hex,
|
||||
uint8_t& r, uint8_t& g, uint8_t& b) -> bool {
|
||||
std::transform(hex.begin(), hex.end(), hex.begin(),
|
||||
[](unsigned char c) { return std::tolower(c); });
|
||||
if (!hex.empty() && hex[0] == '#') hex.erase(0, 1);
|
||||
auto fromHexC = [](char c) -> int {
|
||||
if (c >= '0' && c <= '9') return c - '0';
|
||||
if (c >= 'a' && c <= 'f') return 10 + c - 'a';
|
||||
return -1;
|
||||
};
|
||||
int v[6];
|
||||
if (hex.size() == 6) {
|
||||
for (int k = 0; k < 6; ++k) {
|
||||
v[k] = fromHexC(hex[k]);
|
||||
if (v[k] < 0) return false;
|
||||
}
|
||||
r = static_cast<uint8_t>((v[0] << 4) | v[1]);
|
||||
g = static_cast<uint8_t>((v[2] << 4) | v[3]);
|
||||
b = static_cast<uint8_t>((v[4] << 4) | v[5]);
|
||||
return true;
|
||||
}
|
||||
if (hex.size() == 3) {
|
||||
for (int k = 0; k < 3; ++k) {
|
||||
v[k] = fromHexC(hex[k]);
|
||||
if (v[k] < 0) return false;
|
||||
}
|
||||
r = static_cast<uint8_t>((v[0] << 4) | v[0]);
|
||||
g = static_cast<uint8_t>((v[1] << 4) | v[1]);
|
||||
b = static_cast<uint8_t>((v[2] << 4) | v[2]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
uint8_t ra, ga, ba, rb, gb, bb;
|
||||
if (!parseHex(aHex, ra, ga, ba)) {
|
||||
std::fprintf(stderr,
|
||||
"gen-texture-noise-color: '%s' is not a valid hex color\n",
|
||||
aHex.c_str());
|
||||
return 1;
|
||||
}
|
||||
if (!parseHex(bHex, rb, gb, bb)) {
|
||||
std::fprintf(stderr,
|
||||
"gen-texture-noise-color: '%s' is not a valid hex color\n",
|
||||
bHex.c_str());
|
||||
return 1;
|
||||
}
|
||||
// Same noise pipeline as --gen-texture-noise.
|
||||
const int latticeSize = 17;
|
||||
std::vector<float> lattice(latticeSize * latticeSize);
|
||||
uint32_t state = seed ? seed : 1u;
|
||||
auto next = [&]() -> float {
|
||||
state = state * 1664525u + 1013904223u;
|
||||
return (state >> 8) / float(1 << 24);
|
||||
};
|
||||
for (auto& v : lattice) v = next();
|
||||
std::vector<uint8_t> pixels(static_cast<size_t>(W) * H * 3, 0);
|
||||
for (int y = 0; y < H; ++y) {
|
||||
float fy = static_cast<float>(y) / H * (latticeSize - 1);
|
||||
int yi = static_cast<int>(fy);
|
||||
if (yi >= latticeSize - 1) yi = latticeSize - 2;
|
||||
float fty = fy - yi;
|
||||
float ty = fty * fty * (3.0f - 2.0f * fty);
|
||||
for (int x = 0; x < W; ++x) {
|
||||
float fx = static_cast<float>(x) / W * (latticeSize - 1);
|
||||
int xi = static_cast<int>(fx);
|
||||
if (xi >= latticeSize - 1) xi = latticeSize - 2;
|
||||
float ftx = fx - xi;
|
||||
float tx = ftx * ftx * (3.0f - 2.0f * ftx);
|
||||
float a = lattice[yi * latticeSize + xi];
|
||||
float b = lattice[yi * latticeSize + xi + 1];
|
||||
float c = lattice[(yi + 1) * latticeSize + xi];
|
||||
float d = lattice[(yi + 1) * latticeSize + xi + 1];
|
||||
float ab = a + (b - a) * tx;
|
||||
float cd = c + (d - c) * tx;
|
||||
float v = ab + (cd - ab) * ty;
|
||||
auto lerp = [](uint8_t lo, uint8_t hi, float t) {
|
||||
return static_cast<uint8_t>(lo + (hi - lo) * t + 0.5f);
|
||||
};
|
||||
size_t i2 = (static_cast<size_t>(y) * W + x) * 3;
|
||||
pixels[i2 + 0] = lerp(ra, rb, v);
|
||||
pixels[i2 + 1] = lerp(ga, gb, v);
|
||||
pixels[i2 + 2] = lerp(ba, bb, v);
|
||||
}
|
||||
}
|
||||
if (!stbi_write_png(outPath.c_str(), W, H, 3,
|
||||
pixels.data(), W * 3)) {
|
||||
std::fprintf(stderr,
|
||||
"gen-texture-noise-color: stbi_write_png failed for %s\n",
|
||||
outPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("Wrote %s\n", outPath.c_str());
|
||||
std::printf(" size : %dx%d\n", W, H);
|
||||
std::printf(" seed : %u\n", seed);
|
||||
std::printf(" from : %s\n", aHex.c_str());
|
||||
std::printf(" to : %s\n", bHex.c_str());
|
||||
return 0;
|
||||
} else if (std::strcmp(argv[i], "--gen-texture-radial") == 0 && i + 3 < argc) {
|
||||
// Radial gradient: centerHex at the image center fading
|
||||
// smoothly to edgeHex at the corner. Useful for spell
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue