VTF (Valve Texture Format): Difference between revisions
(→Storage capabilities: this makes more sense ?) |
(moved from texture page; makes more sense here) |
||
Line 5: | Line 5: | ||
VTF files can be compiled from [[TGA]] images using the Source SDK Tool [[Vtex]], or a [[Valve_Texture_Format#Utilities|third-party VTF utility]]. VTFs and VMTs are stored in subfolders of the <code>game_dir/materials</code> directory. | VTF files can be compiled from [[TGA]] images using the Source SDK Tool [[Vtex]], or a [[Valve_Texture_Format#Utilities|third-party VTF utility]]. VTFs and VMTs are stored in subfolders of the <code>game_dir/materials</code> directory. | ||
To be valid, all textures must have dimensions that are powers of two (see the note about mipmaps under [[Valve Texture Format#Storage capabilities|Storage capabilities]] below): | |||
1 | |||
2 | |||
4 | |||
8 | |||
16 | |||
32 | |||
64 | |||
128 | |||
256 | |||
512 | |||
1024 | |||
2048 | |||
4096 | |||
== Storage capabilities == | == Storage capabilities == |
Revision as of 17:06, 27 April 2008
The Valve Texture Format (VTF) is the proprietary texture format used by the Source engine.
VTF files are just one layer in the Material System. VTFs ("Textures") can only be applied to Geometry via a VMT ("Material") File. VMTs can assign several VTFs to the same surface, and specify which Shader and Shader Parameters to use when rendering the textures.
VTF files can be compiled from TGA images using the Source SDK Tool Vtex, or a third-party VTF utility. VTFs and VMTs are stored in subfolders of the game_dir/materials
directory.
To be valid, all textures must have dimensions that are powers of two (see the note about mipmaps under Storage capabilities below):
1 2 4 8 16 32 64 128 256 512 1024 2048 4096
Storage capabilities
The VTF image format can store either a Texture, an Environment Map, or a Volumetric Texture; and each of these may have multiple frames.
- An Environment Map may be a six faced cubemap or a (deprecated) single faced spheremap (v7.1 and up).
- For each frame and face, the VTF file contains both the basic original source-image data (pixel map) and a series of mipmaps used for rendering the texture over varying distances. Because each successive mipmap is exactly 1/2 the dimension (height and width) of the previous one, the source-image dimensions must be powers of 2. Although the source-image may be rectangular, square mipmaps are stored more efficiently in the VTF.
- VTF file data may also include several keyvalues:
- the start frame for an animated VTF,
- the bumpmap scale for the VTF,
- the reflectivity vector of the VTF,
- and a low resolution copy of the VTF (for color sampling by the engine).
Image data formats
The VTF image format can store image data in a variety of formats. Some formats were meant for the engine, some only as an interim format for conversions. The uncompressed formats are not lossy and the compressed (DXT) formats are.
Image data format table
Format | Red Bits | Green Bits | Blue Bits | Alpha Bits | Total Bits | Compressed | Supported | Comment |
A8 | 0 | 0 | 0 | 8 | 8 | False | True | |
ABGR8888 | 8 | 8 | 8 | 8 | 32 | False | True | |
ARGB8888 | 8 | 8 | 8 | 8 | 32 | False | True | |
BGR565 | 5 | 6 | 5 | 0 | 16 | False | True | |
BGR888 | 8 | 8 | 8 | 0 | 24 | False | True | |
BGR888_BLUESCREEN | 8 | 8 | 8 | 0 | 24 | False | True | |
BGRA4444 | 4 | 4 | 4 | 4 | 16 | False | True | |
BGRA5551 | 5 | 5 | 5 | 1 | 16 | False | True | |
BGRA8888 | 8 | 8 | 8 | 8 | 32 | False | True | |
BGRX5551 | 5 | 5 | 5 | 0 | 16 | False | True | |
BGRX8888 | 8 | 8 | 8 | 0 | 32 | False | True | |
DXT1 | N/A | N/A | N/A | 0 | 4 | True | True | |
DXT1_ONEBITALPHA | N/A | N/A | N/A | 1 | 4 | True | True | |
DXT3 | N/A | N/A | N/A | 4 | 8 | True | True | Uninterpolated Alpha |
DXT5 | N/A | N/A | N/A | 4 | 8 | True | True | Interpolated Alpha |
I8 | N/A | N/A | N/A | N/A | 8 | False | True | Luminance (Grayscale) |
IA88 | N/A | N/A | N/A | 8 | 16 | False | True | Luminance (Grayscale) |
P8 | N/A | N/A | N/A | N/A | 8 | False | False | Paletted |
RGB565 | 5 | 6 | 5 | 0 | 16 | False | True | |
RGB888 | 8 | 8 | 8 | 0 | 24 | False | True | |
RGB888_BLUESCREEN | 8 | 8 | 8 | 0 | 24 | False | True | |
RGBA16161616 | 16 | 16 | 16 | 16 | 64 | False | True | HDR Format |
RGBA16161616F | 16 | 16 | 16 | 16 | 64 | False | True | Floating Point HDR Format |
RGBA8888 | 8 | 8 | 8 | 8 | 32 | False | True | |
UV88 | N/A | N/A | N/A | N/A | 16 | False | True | |
UVLX8888 | N/A | N/A | N/A | N/A | 32 | False | True | |
UVWQ8888 | N/A | N/A | N/A | N/A | 32 | False | True |
Choosing an image format
Though the VTF image format provides support for a wide range of image data formats, there are only a handful of image data formats you are likely to use. These formats and their criteria are described below:
- BGR888: use this format for textures with no alpha channel and very fine gradients (i.e. normal maps or light halos).
- BGRA8888: use this format for textures with an alpha channel and very fine gradients (i.e. normal maps or light halos).
- DXT1: use this format for typical textures with no alpha channel.
- DXT3: use this format for typical textures with an alpha channel with sharp gradients.
- DXT5: use this format for typical textures with an alpha channel with smooth gradients.
- I8: use this format for black and white textures with no alpha channel and very fine gradients (i.e. light halos).
- IA88: use this format for black and white textures with an alpha channel and very fine gradients (i.e. smoke or light halos).
- RGBA16161616F: use this format for HDR textures.
- UV88: use this format for DuDv maps.
Image flags
A VTF file can contain the following flags:
Flag | Value | Comment |
Point Sampling | 0x0001 | Low quality texture filtering. |
Trilinear Sampling | 0x0002 | Medium quality texture filtering. |
Clamp S | 0x0004 | Clamp S coordinates. |
Clamp T | 0x0008 | Clamp T coordinates. |
Anisotropic Sampling | 0x0010 | High quality texture filtering. |
Hint DXT5 | 0x0020 | Used in skyboxes. Makes sure edges are seamless. |
No Compress | 0x0040 | No DXT compression used. |
NORMAL | 0x0080 | Texture is a normal map. |
No Mipmaps | 0x0100 | Render largest mipmap only. |
No LOD | 0x0200 | Use largest mipmap set, even on old hardware. |
Min Mipmap | 0x0400 | |
Procedural | 0x0800 | Texture is an procedural texture (code can modify it). |
One Bit Alpha | 0x1000 | One bit alpha channel used. |
Eight Bit Alpha | 0x2000 | Eight bit alpha channel used. |
Environment Map | 0x4000 | Texture is an environment map. |
Render Target | 0x8000 | Texture is a render target. |
Depth Render Target | 0x10000 | Texture is a depth render target. |
No Debug Override | 0x20000 | |
Single Copy | 0x40000 | |
One Over Mipmap Level In Alpha | 0x80000 | Fill the alpha channel with 1/Mipmap Level. (Internal to VTEX?) |
Premultiply Color By One Over Mipmap Level | 0x100000 | (Internal to VTEX?) |
Normal To DuDv | 0x200000 | Texture is a DuDv map. (Internal to VTEX?) |
Alpha Test Mipmap Generation | 0x400000 | (Internal to VTEX?) |
No Depth Buffer | 0x800000 | |
Nice Filtered | 0x1000000 | Use NICE filtering to generate mipmaps. (Internal to VTEX?) |
Clamp U | 0x2000000 | Clamp U coordinates (for volumetric textures). |
File format
The VTF image format is described as follows.
VTF layout
VTF Header VTF Low Resolution Image Data For Each Mipmap (Smallest to Largest) For Each Frame (First to Last) For Each Face (First to Last) For Each Z Slice (Min to Max; Varies with Mipmap) VTF High Resolution Image Data
VTF enumerations
enum { IMAGE_FORMAT_NONE = -1, IMAGE_FORMAT_RGBA8888 = 0, IMAGE_FORMAT_ABGR8888, IMAGE_FORMAT_RGB888, IMAGE_FORMAT_BGR888, IMAGE_FORMAT_RGB565, IMAGE_FORMAT_I8, IMAGE_FORMAT_IA88, IMAGE_FORMAT_P8, IMAGE_FORMAT_A8, IMAGE_FORMAT_RGB888_BLUESCREEN, IMAGE_FORMAT_BGR888_BLUESCREEN, IMAGE_FORMAT_ARGB8888, IMAGE_FORMAT_BGRA8888, IMAGE_FORMAT_DXT1, IMAGE_FORMAT_DXT3, IMAGE_FORMAT_DXT5, IMAGE_FORMAT_BGRX8888, IMAGE_FORMAT_BGR565, IMAGE_FORMAT_BGRX5551, IMAGE_FORMAT_BGRA4444, IMAGE_FORMAT_DXT1_ONEBITALPHA, IMAGE_FORMAT_BGRA5551, IMAGE_FORMAT_UV88, IMAGE_FORMAT_UVWQ8888, IMAGE_FORMAT_RGBA16161616F, IMAGE_FORMAT_RGBA16161616, IMAGE_FORMAT_UVLX8888 };
enum { TEXTUREFLAGS_POINTSAMPLE = 0x00000001, TEXTUREFLAGS_TRILINEAR = 0x00000002, TEXTUREFLAGS_CLAMPS = 0x00000004, TEXTUREFLAGS_CLAMPT = 0x00000008, TEXTUREFLAGS_ANISOTROPIC = 0x00000010, TEXTUREFLAGS_HINT_DXT5 = 0x00000020, TEXTUREFLAGS_NOCOMPRESS = 0x00000040, TEXTUREFLAGS_NORMAL = 0x00000080, TEXTUREFLAGS_NOMIP = 0x00000100, TEXTUREFLAGS_NOLOD = 0x00000200, TEXTUREFLAGS_MINMIP = 0x00000400, TEXTUREFLAGS_PROCEDURAL = 0x00000800, TEXTUREFLAGS_ONEBITALPHA = 0x00001000, TEXTUREFLAGS_EIGHTBITALPHA = 0x00002000, TEXTUREFLAGS_ENVMAP = 0x00004000, TEXTUREFLAGS_RENDERTARGET = 0x00008000, TEXTUREFLAGS_DEPTHRENDERTARGET = 0x00010000, TEXTUREFLAGS_NODEBUGOVERRIDE = 0x00020000, TEXTUREFLAGS_SINGLECOPY = 0x00040000, TEXTUREFLAGS_ONEOVERMIPLEVELINALPHA = 0x00080000, TEXTUREFLAGS_PREMULTCOLORBYONEOVERMIPLEVEL = 0x00100000, TEXTUREFLAGS_NORMALTODUDV = 0x00200000, TEXTUREFLAGS_ALPHATESTMIPGENERATION = 0x00400000, TEXTUREFLAGS_NODEPTHBUFFER = 0x00800000, TEXTUREFLAGS_NICEFILTERED = 0x01000000, TEXTUREFLAGS_CLAMPU = 0x02000000 };
VTF header
typedef struct tagVTFHEADER { char signature[4]; // File signature ("VTF\0"). unsigned int version[2]; // version[0].version[1] (currently 7.2). unsigned int headerSize; // Size of the header struct (16 byte aligned; currently 80 bytes). unsigned short width; // Width of the largest mipmap in pixels. Must be a power of 2. unsigned short height; // Height of the largest mipmap in pixels. Must be a power of 2. unsigned int flags; // VTF flags. unsigned short frames; // Number of frames, if animated (1 for no animation). unsigned short firstFrame; // First frame in animation (0 based). unsigned char padding0[4]; // reflectivity padding (16 byte alignment). float reflectivity[3]; // reflectivity vector. unsigned char padding1[4]; // reflectivity padding (8 byte packing). float bumpmapScale; // Bumpmap scale. unsigned int highResImageFormat; // High resolution image format. unsigned char mipmapCount; // Number of mipmaps. unsigned int lowResImageFormat; // Low resolution image format (always DXT1). unsigned char lowResImageWidth; // Low resolution image width. unsigned char lowResImageHeight; // Low resolution image height. unsigned short depth; // Depth of the largest mipmap in pixels. // Must be a power of 2. Can be 0 or 1 for a 2D texture (v7.2 only). } VTFHEADER;
VTF lo-res image data
Tightly packed low resolution image data in the format described in the header. The low resolution image data is always stored in the DXT1 compressed image format. Its dimensions are that of the largest mipmap with a width or height that does not exceed 16 pixels. i.e. for a 256x256 pixel VTF: 16x16, for a 256x64 pixel VTF: 16x4, for a 1x32 pixel VTF: 1x16, for a 4x4 pixel VTF: 4x4.
VTF hi-res image data
Tightly packed interleaved high resolution image data in the format described in the header. Common image formats include DXT1, DXT5, BGR888, BGRA8888 and UV88. All dimensions must be a power of two.
Version history
v7.4
- Released October 10th, 2007 as part of The Orange Box.
- Bitwise equivalent to v7.3.
- Addresses issues related to how gamma-correction is performed on textures for TV-output on XBOX 360 combined with hunting down OS Paged Pool Memory.
v7.3
- Added an extensible resource orientated structure.
- Added CRC, Texture LOD Control and Sheet resources, along with backwards compatible Image and Low Resolution Image resources.
- Added several vendor specific depth-stencil formats (for internal engine use), along with normal map formats and linear uncompressed formats.
- Released September 18th, 2007 as part of the Team Fortress 2 beta.
v7.2
- Added volumetric texture support.
- Released September 23rd, 2005 as a Steam engine update.
v7.1
- Added spheremap support to environment maps. (This was intended for DirectX 6 support which was later cut.)
v7.0
- Initial release. (Internal release only, however, some v7.0 textures made it to the published title.)
Implementation
An example Steam independent implementation of the VTF image file format can be found in the LGPL C/C++ library VTFLib.
Utilities
- 3DSMax VTF plugin
- 3D Studio Max 6/7/8 VTF Plug-in.
- IrfanView
- General purpose image viewer with optional VTF support (see PlugIns section).
- Leadwerks Image Viewer
- General purpose image viewer with VTF support.
- Paint.NET Plug-in
- Paint.NET VTF Plug-in.
- Photoshop Plug-in
- Photoshop 6 (and up) VTF Plug-in.
- Shell Extension
- Windows XP/2000 VTF shell extension.
- VTFTool
- Windows based VTEX and VTF2TGA replacement.
- VTFCmd
- VTF and VMT command line editing tool (VTEX clone).
- VTFEdit
- VTF and VMT viewer and editing GUI.
- VTF Explorer
- VTF and VMT viewer\explorer GUI. Easy and extensible VMT creation. Can browse GCF files.
- studiocompiler
- includes VTF and VMT compile & decompile GUI.