Atvaark / FtexTool

Fox Engine Texture (.ftex) to DDS converter
MIT License
30 stars 9 forks source link

FilterLUTs cannot properly convert from .dds to .ftex #8

Closed folly-ah-duh closed 7 years ago

folly-ah-duh commented 7 years ago

I'm running into an issue where the FtexTool isn't properly converting a .dds back into an .ftex format. I'm attempting to edit a FilterLUT, which appears to convert perfectly from .ftex to .dds. Upon conversion from .dds to .ftex, the generated .1.ftexs is significantly smaller in size and fails to properly convert back to the .dds format.

this is an example of a FilterLUT found in TPP's game files: TFGreenFinal_FILTERLUT

I'm not really sure what's going on. The FilterLUT doesn't seem to be DXT1 or DXT5, perhaps that's the cause?

Atvaark commented 7 years ago

It appears to be a 16x16x16px volume texture in in A8R8G8B8. Looks like FtexTool only reads the 1st depth layer from the DDS file when it creates the ftexs file.

folly-ah-duh commented 7 years ago

I see, that explains it.

Is there an easy fix to this, or am I SOL?

folly-ah-duh commented 7 years ago

I think I fixed it. Depth needs to be accounted for when calculating image size.

public static int CalculateImageSize(DdsPixelFormat pixelFormat, int width, int height, int depth)

        {
            if (pixelFormat.RgbBitCount > 0)
                return (int)((long)width * height * depth * pixelFormat.RgbBitCount / 8);
            if (pixelFormat.Equals(DdsPfDxt1()))
                return width * height * depth / 2;
            if (pixelFormat.Equals(DdsPfDxt3()))
                return width * height * depth;
            if (pixelFormat.Equals(DdsPfDxt5()))
                return width * height * depth;
            throw new ArgumentException("Could not calculate the image size of the current pixel format.");
        }
Atvaark commented 7 years ago

Since I don't have any files to test the changes on you'll have to test the release 0.3.3.

folly-ah-duh commented 7 years ago

Everything seems to be working, including A8R8G8B8. Logically, the update shouldn't have broken anything, so I think the prerelease is good to go.