Skip to main content

Codec shaders

A TSMP codec shader converts between payload bytes and visible frame pixels. The default Luma4 codec is available as a reference path, but custom codecs can use their own materials and shader passes.

Encode side

An encode shader or material usually receives:

InputPurpose
Payload byte texture or buffer textureSource bytes arranged by the encoder.
Header pixelsHeader area already prepared by the core encoder.
Codec option bytesSmall codec-specific settings.
Block sizePixel block dimensions for symbol output.
Payload sizeNumber of valid bytes to draw.

The encode result must leave the header readable and place payload symbols at the layout reported by the codec.

Decode side

A decode shader or material usually receives:

InputPurpose
Source TSMP frameCaptured texture from camera, OBS, Spout, or another path.
Header metadataPayload size, block size, sample size, and codec option bytes.
Payload layoutStart row/block and block count.
Byte output textureTexture that stores recovered bytes for readback.

The decoder reads only the payload byte count from the header. Unused pixels should not affect the result.

For decode shaders that output recovered bytes to an RGBA byte texture, see the TSMPDecodeByteOutput.cginc scripting API.

Shader include paths

Package shaders should use package-stable include paths. Relative include paths that depend on a scene folder are fragile when the package is moved between project and package locations.

Prefer includes that still work when the package is installed as a VPM package.

Precision rules

  • Keep header sampling exact.
  • Avoid filtering on payload symbols.
  • Use point sampling for byte recovery.
  • Clear or overwrite every output pixel used by the current payload.
  • Leave unused output pixels deterministic when possible to avoid visible stale blocks.

Material properties

Custom codecs should document their shader properties. Common properties include:

PropertyMeaning
_MainTexSource frame or payload texture.
_PayloadByteTextureIntermediate byte texture.
_PayloadSizeValid payload byte count.
_BlockSizeCodec block size.
_SampleSizeDecode sample size.
_CodecOptionBytesCodec-specific option vector.

Use stable property names so editor setup and runtime code can assign values without special cases.

Validation

Before shipping a codec shader:

  • Encode and decode a deterministic byte sequence.
  • Test non-full payload sizes.
  • Switch codecs and confirm no stale blocks remain.
  • Test with capture scaling disabled.
  • Test with the same render texture size users will ship.