Saving UTexture2D to the PF_R8G8 pixel format

Creating and writing to UTexture2D in the PF_R8G8 pixel format at runtime works well (for direct color lookup onto 256 x 256 textures, R = UV.x, G = UV.y). But I can’t get to save them without them losing their format.

texture->GetPlatformData()->PixelFormat = EPixelFormat::PF_R8G8;

texture->GetPlatformData()->Mips[0]->BulkData.Lock(LOCK_READ_WRITE);

void* data_ptr = texture->GetPlatformData()->Mips[0]->BulkData.Realloc(sizeof(uint16) * source._num);

memcpy(data_ptr, source, sizeof(uint16) * source_num);

texture->GetPlatformData()->Mips[0].BulkData.Unlock();
texture->UpdateResource();

This works fine. But at some point I have to write the following so the texture is saved across sessions :

texture->Source.Init(height, height, 1, 1, ETextureSourceFormat::TSF_BGRA8, (uint8*)source);

Problem is that there is no PF_R8G8 or seemingly compatible 16 bit format in the ETextureSourceFormat enum.

Any workaround?

It’s been nearly six months and a few dozen crashes dedicated to this later, I still didn’t find a way to save a R8G8 texture asset.

Saving it with the R16F compression settings and changing the pixel format programmatically on startup works in the Editor, but fails in builds because changing cooked static textures’ pixel format simply isn’t enabled.

I’m surprised to have found few posts even mentioning the existence of R8G8 or two channels formats in general given how useful they are to me. Bitmaps with values within 2^16, 2D distance fields, or even pairs of terrain indices used with a side blending weight linear grayscale texture. It’s just a waste to have to use four channels when you only need two, especially with very large textures.