From 706c820f8adb20594cb5886ab042eb4cfcd9712e Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 9 May 2026 14:26:57 -0700 Subject: [PATCH] feat(editor): add --gen-texture-moon disc with phase shadow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 82nd procedural texture: solid filled circle of moonHex on bg, with an optional crescent shadow created by subtracting a second bg-colored disc offset by `phase` pixels along +X. Phase reads as the lunar-cycle moment: • phase = 0 — full moon • 0 < phase < moonR — gibbous (waning right) • phase = moonR — half moon • phase > moonR — crescent (thinner as phase grows) Useful for night-sky overlays, banner moons (heraldry of night-themed orders), shrine medallion centers, druid / priest emblem inserts, lunar-festival decoration, vampire- zone backdrops. The simplest centered-disc texture in the catalogue — pairs naturally with --gen-texture-stars for a complete night-sky composite. --- tools/editor/cli_arg_required.cpp | 2 +- tools/editor/cli_gen_texture.cpp | 62 +++++++++++++++++++++++++++++++ tools/editor/cli_help.cpp | 2 + 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index ecfaf176..30988466 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -125,7 +125,7 @@ const char* const kArgRequired[] = { "--gen-texture-dewdrops", "--gen-texture-pinwheel", "--gen-texture-scratched-metal", "--gen-texture-crackle", "--gen-texture-star", "--gen-texture-halftone", - "--gen-texture-bayer", + "--gen-texture-bayer", "--gen-texture-moon", "--validate-glb", "--info-glb", "--info-glb-tree", "--info-glb-bytes", "--validate-jsondbc", "--check-glb-bounds", "--validate-stl", "--validate-png", "--validate-blp", diff --git a/tools/editor/cli_gen_texture.cpp b/tools/editor/cli_gen_texture.cpp index 7e33b9c4..f9e2f567 100644 --- a/tools/editor/cli_gen_texture.cpp +++ b/tools/editor/cli_gen_texture.cpp @@ -3500,6 +3500,67 @@ int handleKnit(int& i, int argc, char** argv) { return 0; } +int handleMoon(int& i, int argc, char** argv) { + // Moon disc: solid filled circle of color moonHex on a bg. + // Optional crescent: subtract a second disc of color bgHex + // offset by `phase` pixels along +X. With phase=0 the result + // is a full moon; with phase = moonR the result is roughly a + // half-moon; phase > moonR gives a thin crescent. + std::string outPath = argv[++i]; + std::string bgHex = argv[++i]; + std::string moonHex = argv[++i]; + int moonR = 80; + int phase = 0; // 0 = full moon + int W = 256, H = 256; + parseOptInt(i, argc, argv, moonR); + parseOptInt(i, argc, argv, phase); + parseOptInt(i, argc, argv, W); + parseOptInt(i, argc, argv, H); + if (W < 1 || H < 1 || W > 8192 || H > 8192 || + moonR < 4 || moonR > 4096 || + phase < 0 || phase > 2 * moonR) { + std::fprintf(stderr, + "gen-texture-moon: invalid dims (W/H 1..8192, " + "moonR 4..4096, phase 0..2*moonR)\n"); + return 1; + } + uint8_t br_, bg_, bb_, mr, mg, mb_; + if (!parseHexOrError(bgHex, br_, bg_, bb_, "gen-texture-moon")) return 1; + if (!parseHexOrError(moonHex, mr, mg, mb_, + "gen-texture-moon")) return 1; + std::vector pixels(static_cast(W) * H * 3, 0); + const float cx = W * 0.5f; + const float cy = H * 0.5f; + const float shadowCX = cx + phase; // shadow disc offset + const float moonR2 = static_cast(moonR) * moonR; + for (int y = 0; y < H; ++y) { + for (int x = 0; x < W; ++x) { + float dx = x - cx; + float dy = y - cy; + bool inMoon = (dx * dx + dy * dy) <= moonR2; + float sdx = x - shadowCX; + bool inShadow = phase > 0 && + (sdx * sdx + dy * dy) <= moonR2; + uint8_t r, g, b; + if (inMoon && !inShadow) { + r = mr; g = mg; b = mb_; + } else { + r = br_; g = bg_; b = bb_; + } + setPixelRGB(pixels, W, x, y, r, g, b); + } + } + if (!savePngOrError(outPath, W, H, pixels, "gen-texture-moon")) return 1; + printPngWrote(outPath, W, H); + std::printf(" bg/moon : %s / %s\n", bgHex.c_str(), moonHex.c_str()); + std::printf(" disc : R=%d, phase=%d (%s)\n", + moonR, phase, + phase == 0 ? "full" : + (phase < moonR ? "gibbous" : + (phase == moonR ? "half" : "crescent"))); + return 0; +} + int handleBayer(int& i, int argc, char** argv) { // Classic 4x4 ordered-dither Bayer matrix tiled across the // image. Each pixel's color comes from interpolating bg → fg @@ -5971,6 +6032,7 @@ constexpr TextureEntry kTextureTable[] = { {"--gen-texture-star", 3, handleStar}, {"--gen-texture-halftone", 3, handleHalftone}, {"--gen-texture-bayer", 3, handleBayer}, + {"--gen-texture-moon", 3, handleMoon}, }; } // namespace diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index a848c55e..7e5203e6 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -197,6 +197,8 @@ void printUsage(const char* argv0) { std::printf(" Halftone: grid of dots whose radii grow with a v/h/r gradient (comic / newspaper print look)\n"); std::printf(" --gen-texture-bayer [cellSize] [W H]\n"); std::printf(" Bayer: 4x4 ordered-dither matrix tiled (retro / 8-bit / monochrome-CRT effects)\n"); + std::printf(" --gen-texture-moon [moonR] [phase] [W H]\n"); + std::printf(" Moon disc with optional crescent shadow (phase 0=full, =moonR=half, >moonR=crescent)\n"); std::printf(" --add-texture-to-zone [renameTo]\n"); std::printf(" Copy an existing PNG into (optionally renaming it on the way in)\n"); std::printf(" --gen-mesh [size]\n");