Vixen
02b45cc4
csharp
public static class TerrainHeightmapPng

Sixteen-bit greyscale PNG, which is what every terrain generator writes and what Vixen.Core.Imaging deliberately does not read.

Read the guide page for this →

Remarks

[docs/plan/31 § T3]'s owed import and export. Raw .r16 has been wired since T1 and is lossless, but it carries no header — so a person importing one has to know its size and its endianness, and getting either wrong produces a terrain that looks like static. A PNG says both.

⚠ Here rather than in Vixen.Core.Imaging, and the split is the bit depth. That library's decoder reads eight bits a channel, which is the right answer for a texture and the wrong one for a heightfield: a terrain quantised to 256 heights is a faint terrace on every slope, and it gets attributed to the generator rather than to the import. This reads sixteen and refuses everything else rather than narrowing it.

⚠ Greyscale only, and a colour PNG is refused rather than averaged. There is no defensible way to turn three channels into one height — a luminance weighting is a photographic convention and a heightfield is not a photograph — and averaging silently would make a terrain that is subtly wrong everywhere.

⚠ Every filter type is decoded and only one is encoded. A file this writes is one we control; a file it reads came from World Machine, Gaea or Photoshop, and each picks filters per row. Refusing a filter would refuse most real files.

⚠ PNG is big-endian and always has been. Sixteen-bit samples are stored high byte first whatever the machine is, which is the one place a heightmap import cannot be asked about endianness — and the one place a raw .r16 always must be.

Fields and properties (1)

  • public const int BytesPerSample

    How many bytes one sample is.

Methods (3)

  • public static TerrainHeightmapImage Decode(ReadOnlySpan<byte> data)

    Reads a sixteen-bit greyscale PNG.

  • public static byte[] Encode(Terrain terrain)

    Writes a terrain's composited heights as a sixteen-bit greyscale PNG.

  • public static byte[] Encode(int width, int height, ReadOnlySpan<ushort> samples)

    Writes samples as a sixteen-bit greyscale PNG.

Used by (3)

  • TerrainHeightmapPngTestsVixen.Terrain.Tests
  • HeightmapImporterVixen.Editor.Assets
  • TerrainAssetImporterTestsVixen.Editor.Assets.Tests