islaApocalypse-v2/Tools/Scripts/GrayscaleRenderer.cs
beezm fdf52f61ee Phase 1 review: raw grayscale, the wide gradient as hero, fixed batch naming
Presentation only. No generation file is touched — Topography, TerrainNoise,
IslandFalloff, Pass1Result, TerrainGenConfig and GenerationScale are all unchanged.

Batch naming, fixed in code. The prefix is the AUTHORING TASK number, not a running
counter: 04_review means "the batch task 04 authored", not "the fifth batch". It had
already drifted — tasks 02 and 03 produced 00_smoke through 05_trophy_10240 across
two tasks, so no folder name said which task made what. Now the task number is an
explicit argument to ToolingPaths.BatchRoot(taskNumber, descriptor), which composes
the prefix itself and REFUSES a descriptor that carries its own. All three tools
take it as ISLA_TASK. Verified: ISLA_BATCH=05_foo is refused with a stated reason
and exit 2, and creates no folder.

Also fixed: an exception out of _Ready does not stop Godot — it logs and the process
sits there with no main loop, so a misconfigured run HUNG rather than failing. A
hang looks like slow work, which is worse than a crash. The batch tools now catch,
print what was refused, and exit non-zero.

Grayscale mode: normalize a field to its own [min,max]. This is the one place
per-image normalization is correct — everywhere else anchors are fixed so images
compare, but here the point is to see one field at full contrast. The range is
printed and indexed so a shade reads back to a height. You cannot judge noise
through a palette: a ramp bends the distribution, a hillshade adds shape the data
does not have.

The wide Costa-Rica palette, and the reframing the developer asked for: the pretty
map is the WIDE GRADIENT RENDERED FLAT, and relief is no longer the hero. On raw
pass-1 noise a hillshade has nothing coherent to shade, so it renders fine fractal
bumpiness as fuzz that actively hides the elevation the colour is showing. Strong
hillshade is retained as diagnostic_relief and labelled a dev view — its bumpiness
is exaggerated slope, not extra terrain. Subtle relief is kept for comparison, with
the honest note that it still fuzzes until Phase 2 carves coherent landforms.

Legend: a colour bar with ticks drawn from the palette's own ramp, so it cannot
drift from the map beside it. Ticks are RELATIVE height and the image says NOT
METRES — the conversion is Phase 2's, and labelling it "m" would invent a fact in
the artefact a reader most trusts. Text comes from a 5x7 bitmap font written for
this, specifically so a legend does not drag in the SubViewport capture path.
2026-08-19 22:55:53 -04:00

51 lines
2 KiB
C#

using Godot;
namespace IslaApocalypse.Tools
{
/// <summary>
/// A plain grayscale render: normalize a float field to its own [min, max] and map to
/// [black, white]. No colour, no hillshade, no interpretation.
///
/// ═══ WHY THIS EXISTS ═══
///
/// Because you cannot judge noise through a palette. A hypsometric ramp and a hillshade are both
/// opinionated transforms — one bends the value distribution onto chosen stops, the other adds
/// shape the data does not contain. Both are the right thing for a map and the wrong thing for
/// asking "is the noise itself good?". This mode answers that question and no other.
///
/// ⚠ THIS IS THE ONE PLACE PER-IMAGE NORMALIZATION IS CORRECT. Everywhere else the palette
/// anchors are fixed so images can be compared. Here the point is to see the full structure of
/// ONE field at full contrast, so it is normalized to its own range — and the range used is
/// printed and written into the INDEX, so a shade reads back to a height.
/// </summary>
public static class GrayscaleRenderer
{
/// <summary>Render to grayscale. Returns the (min, max) used for the normalization.</summary>
public static (float min, float max) SavePng(float[,] field, int mapSize, string absolutePath)
{
float min = float.MaxValue, max = float.MinValue;
for (int x = 0; x < mapSize; x++)
for (int y = 0; y < mapSize; y++)
{
float v = field[x, y];
if (v < min) min = v;
if (v > max) max = v;
}
float span = max - min;
float inv = span > 1e-9f ? 1f / span : 0f;
var img = Image.CreateEmpty(mapSize, mapSize, false, Image.Format.Rgb8);
for (int x = 0; x < mapSize; x++)
for (int y = 0; y < mapSize; y++)
{
float g = (field[x, y] - min) * inv;
img.SetPixel(x, y, new Color(g, g, g));
}
Error err = img.SavePng(absolutePath);
if (err != Error.Ok) GD.PrintErr($"[GrayscaleRenderer] SavePng failed ({err}) for {absolutePath}");
return (min, max);
}
}
}