Skip to main content

Overview

The Binary serializer encodes each DMX channel value as 8 separate binary bits, allowing for extremely high channel density. Each bit is represented as a 4×4 pixel block, making this one of the most space-efficient serialization methods.

Class: Binary

Namespace: Global
Implements: IDMXSerializer

Configuration Constants

blockSize
const int
default:"4"
Size in pixels of each bit block (4×4 pixels)
blocksPerCol
const int
default:"52"
Number of bit blocks per column. Since each channel uses 8 blocks, this allows for approximately 6.5 channels per column.

How It Works

Bit Encoding

Each DMX channel value (0-255) is split into 8 individual bits:
Channel Value: 170 (0b10101010)

Bit 0: 0 → Black block
Bit 1: 1 → White block  
Bit 2: 0 → Black block
Bit 3: 1 → White block
Bit 4: 0 → Black block
Bit 5: 1 → White block
Bit 6: 0 → Black block
Bit 7: 1 → White block
Each bit is encoded as:
  • 0 → RGB(0, 0, 0) - Black
  • 1 → RGB(255, 255, 255) - White

Spatial Layout

Bits are arranged vertically in columns:
[Ch0 Bit0] [Ch6 Bit0] [Ch13 Bit0]
[Ch0 Bit1] [Ch6 Bit1] [Ch13 Bit1]
[Ch0 Bit2] [Ch6 Bit2] [Ch13 Bit2]
[Ch0 Bit3] [Ch6 Bit3] [Ch13 Bit3]
[Ch0 Bit4] [Ch6 Bit4] [Ch13 Bit4]
[Ch0 Bit5] [Ch6 Bit5] [Ch13 Bit5]
[Ch0 Bit6] [Ch6 Bit6] [Ch13 Bit6]
[Ch0 Bit7] [Ch6 Bit7] [Ch13 Bit7]
[Ch1 Bit0] [Ch7 Bit0] ...

Methods

SerializeChannel

Encodes a DMX channel value as 8 binary bit blocks.
public void SerializeChannel(ref Color32[] pixels, byte channelValue, 
    int channel, int textureWidth, int textureHeight)
pixels
ref Color32[]
required
The pixel array to write the encoded bits to
channelValue
byte
required
The DMX channel value (0-255) to encode
channel
int
required
The DMX channel number
textureWidth
int
required
Width of the output texture
textureHeight
int
required
Height of the output texture
Process:
  1. Converts the channel value to a BitArray
  2. For each of the 8 bits:
    • Calculates the position based on (channel * 8) + bitIndex
    • Creates a 4×4 color block (white for 1, black for 0)
    • Writes the block to the pixel array
  3. Skips any blocks that would exceed texture bounds

DeserializeChannel

Decodes a DMX channel value from 8 binary bit blocks.
public void DeserializeChannel(Texture2D tex, ref byte channelValue, 
    int channel, int textureWidth, int textureHeight)
tex
Texture2D
required
The input texture to read from
channelValue
ref byte
required
Output parameter that receives the decoded value
channel
int
required
The DMX channel number to decode
textureWidth
int
required
Width of the input texture
textureHeight
int
required
Height of the input texture
Process:
  1. Creates an 8-bit BitArray
  2. For each bit position:
    • Calculates the block position
    • Reads the center pixel of the block (offset +1, +1)
    • Determines bit value based on red channel threshold (> 0.5 = 1)
  3. Converts the BitArray back to a byte value

Usage Example

// Create binary serializer
var binary = new Binary();

// Initialize pixel array
int textureWidth = 256;
int textureHeight = 256;
Color32[] pixels = new Color32[textureWidth * textureHeight];

// Encode channel 0 with value 128
binary.SerializeChannel(ref pixels, 128, 0, textureWidth, textureHeight);

// Channel 0, Value 128 (0b10000000) produces:
// Bit 0-6: Black blocks
// Bit 7: White block

// Decode from texture
Texture2D inputTexture = GetCapturedTexture();
byte decodedValue = 0;
binary.DeserializeChannel(inputTexture, ref decodedValue, 0, 
    textureWidth, textureHeight);

Debug.Log($"Decoded value: {decodedValue}"); // Should output 128

Channel Capacity

For a given texture size, the Binary serializer can encode:
// Calculate maximum channels
int maxBitsPerColumn = blocksPerCol; // 52 bits
int maxChannelsPerColumn = maxBitsPerColumn / 8; // 6.5 channels
int columns = textureWidth / blockSize;
int totalChannels = (maxChannelsPerColumn * columns);

// Example: 256×256 texture
// Columns: 256 / 4 = 64
// Channels: 6.5 × 64 = 416 channels

Capacity by Resolution

ResolutionChannels
128×128104
256×256416
512×5121,664
1024×10246,656
1920×10803,120

Advantages

High Density

8× more efficient than block-based encoding methods

Simple Decoding

Easy threshold-based bit detection

Small Blocks

4×4 pixel blocks minimize texture usage

Clear Visual

Binary pattern is easily recognizable

Limitations

No Error Correction: This serializer does not include any error detection or correction. For applications requiring data integrity, consider using Binary Stage Flight instead.
  • Compression Artifacts: Video compression may corrupt individual bits
  • Noise Sensitivity: Single-pixel errors can cause incorrect values
  • No Redundancy: Each bit is represented only once

Best Practices

1. Video Quality

Use high bitrate, lossless or near-lossless compression:
// Recommended video settings
Bitrate: >= 20 Mbps
Compression: H.264 High Profile, CRF 15 or lower
Color Space: RGB (not YUV)
Chroma Subsampling: 4:4:4

2. Threshold Testing

The default threshold is 0.5, but you may need to adjust based on your video pipeline:
// Test different thresholds
float threshold = 0.5f;
bool bitValue = TextureReader.GetColor(tex, x, y).r > threshold;

3. Bounds Checking

Always verify that your channel count fits within the texture:
int maxChannels = (textureWidth / blockSize) * (textureHeight / blockSize) / 8;
if (channelCount > maxChannels)
{
    Debug.LogError($"Too many channels! Maximum: {maxChannels}");
}

Comparison with Other Serializers

FeatureBinaryVRSLBinary Stage Flight
Block Size4×416×164×4
Error DetectionNoneNoneCRC-4
Channels (256×256)416169~195
Compression ToleranceLowHighMedium
Decoding ComplexitySimpleSimpleMedium

Performance

  • Encoding: ~0.02ms per channel (tested on Unity 2019.4)
  • Decoding: ~0.03ms per channel
  • Memory: Minimal overhead, uses BitArray

Troubleshooting

  • Check video compression settings - use minimal compression
  • Verify color space is RGB, not YUV
  • Ensure no chroma subsampling (use 4:4:4)
  • Test with threshold adjustment
  • Verify channel count doesn’t exceed capacity
  • Check texture dimensions are correct
  • Ensure textureWidth/textureHeight match actual texture
  • Binary format is sensitive to single-bit errors
  • Consider using Binary Stage Flight for CRC error detection
  • Increase video bitrate
  • Use error-tolerant video transport

Build docs developers (and LLMs) love