VTFX file format
For help, see the VDC Editing Help and Wikipedia cleanup process. Also, remember to check for any notes left by the tagger at this article's talk page.
VTFX is a file format used by Valve to store textures on the Xbox 360 and PS3. It has a modified header from normal VTF files. VTFX files can be identified by them beginning with "VTFX" instead of "VTF".
Conversion to VTF or another usable format is difficult due to the header and content being Big-Endian. The header is always Big-Endian but the contained resources vary between platforms. Some files have their resources compressed using LZMA.
Contents
Tools
- vtfx_reader (Supports header reading and image resource output for X360 and PS3 files. Supports both compress and non compressed resources)
Resource Decoding
Resource data may be compressed using LZMA. Compressed resources can be identified as they start with "LZMA". Decompression with other tools may require the header to be reconstructed.
Image resources need their data to be converted to the platform endianness before decoding is attempted, and this conversion differs depending on the encoding used (DXT data requires each block to be endian corrected). However files created for the PS3 may not require Big to Little endian conversion.
VTFX header
typedef struct tagVTFXHEADER
{
char fileTypeString[4]; // VTFX.
int version[2]; // version[0].version[1].
int headerSize;
unsigned int flags;
unsigned short width; // actual width of data in file.
unsigned short height; // actual height of data in file.
unsigned short depth; // actual depth of data in file.
unsigned short numFrames;
unsigned short preloadDataSize; // exact size of preload data (may extend into image!).
unsigned char mipSkipCount; // used to resconstruct mapping dimensions.
unsigned char numResources;
Vector reflectivity; // Resides on 16 byte boundary!.
float bumpScale;
ImageFormat imageFormat;
unsigned char lowResImageSample[4];
unsigned int compressedSize;
// *** followed by *** ResourceEntryInfo resources[0];
} VTFXHEADER;
#define VTF_X360_MAJOR_VERSION 0x0360
#define VTF_X360_MINOR_VERSION 8
ResourceEntryInfo Info
VTF_LEGACY_RSRC_LOW_RES_IMAGE = MK_VTF_RSRC_ID( 0x01, 0, 0 ), // Low-res image data
VTF_LEGACY_RSRC_IMAGE = MK_VTF_RSRC_ID( 0x30, 0, 0 ), // Image data
VTF_RSRC_SHEET = MK_VTF_RSRC_ID( 0x10, 0, 0 ), // Sheet data
RSRCF_HAS_NO_DATA_CHUNK = MK_VTF_RSRCF( 0x02 ), // Resource doesn't have a corresponding data chunk
RSRCF_MASK = MK_VTF_RSRCF( 0xFF ) // Mask for all the flags
#define VTF_RSRC_TEXTURE_CRC ( MK_VTF_RSRC_ID( 'C','R','C' ) ) //CRC Checksum?
#define VTF_RSRC_TEXTURE_SETTINGS_EX ( MK_VTF_RSRC_ID( 'T','S','0' ) ) //TextureSettingsEx_t
#define VTF_RSRC_TEXTURE_LOD_SETTINGS ( MK_VTF_RSRC_ID( 'L','O','D' ) ) //TextureLODControlSettings_t
struct ResourceEntryInfo
{
union
{
unsigned int eType; // Use MK_VTF_??? macros to be endian compliant with the type
unsigned char chTypeBytes[4];
};
unsigned int resData; // Resource data or offset from the beginning of the file
};
ImageFormat
These are additional image formats available to be used in vtfx files, the pre existing formats defined in ImageFormat are still usable.
enum ImageFormat
{
//...
IMAGE_FORMAT_X360_DST16, //39
IMAGE_FORMAT_X360_DST24,
IMAGE_FORMAT_X360_DST24F,
// supporting these specific formats as non-tiled for procedural cpu access
IMAGE_FORMAT_LINEAR_BGRX8888,
IMAGE_FORMAT_LINEAR_RGBA8888,
IMAGE_FORMAT_LINEAR_ABGR8888,
IMAGE_FORMAT_LINEAR_ARGB8888,
IMAGE_FORMAT_LINEAR_BGRA8888,
IMAGE_FORMAT_LINEAR_RGB888,
IMAGE_FORMAT_LINEAR_BGR888,
IMAGE_FORMAT_LINEAR_BGRX5551,
IMAGE_FORMAT_LINEAR_I8,
IMAGE_FORMAT_LINEAR_RGBA16161616,
IMAGE_FORMAT_LE_BGRX8888,
IMAGE_FORMAT_LE_BGRA8888,
}
LZMA Resource Header
Header format if a resource is LZMA compressed. Refer to the SDK source for how the properties array is decoded during decompression.
#if !defined( _X360 )
#define LZMA_ID (('A'<<24)|('M'<<16)|('Z'<<8)|('L'))
#else
#define LZMA_ID (('L'<<24)|('Z'<<16)|('M'<<8)|('A'))
#endif
#pragma pack(1)
struct lzma_header_t
{
unsigned int id; //Note: Can be treated as a char*[4], which contains LZMA_ID
unsigned int actualSize; // always little endian
unsigned int lzmaSize; // always little endian
unsigned char properties[5];
};
#pragma pack()