1
$\begingroup$

I'm in the dead-end of some things done wrong before they were given to me.

Basically, I have many, many DDS textures here stored in the X8R8G8B8 pixel format. However, the X channel is actually holding alpha information and thus the whole texture should've been stored as A8R8G8B8.

When importing such a DDS file into Blender, it correctly ignores the X channel like every sane tool should do, but I want it to load it as the A channel.

Is there any way to customize the image loading step and configure how Blender maps the channels? I cannot tell the people who converted those buggy DDS textures to fix them, sadly.

Right now, I simply use:

texture.image = bpy.data.images.load("bugged.dds")

Can this "load" be configured? Or do I have to write the whole DDS support myself again to make Blender the victim which has to fix these pixel format shenanigans? (I'd probably change the DDS header to give the X channel a meaning then. The alpha bit mask is not set and the flags do not include alpha support.)

$\endgroup$
1
$\begingroup$

So far, I modify the header of the DDS texture file (according to how it is documented officially), as I didn't find another way. It's still a kinda hackish solution for me, but it's also a hackish problem I have.

with BinaryWriter(open(image_file_name, "r+b")) as writer:
    writer.seek(0x68) # DDS_HEADER->DDS_PIXELFORMAT->dwABitMask
    writer.write_uint32(0xFF000000) # Mask of the alpha data.

(BinaryWriter is a custom class. Simply pack an unsigned integer at position 0x68 which masks the alpha bits.)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.