Skip to content

Materials

Redox edited this page Sep 28, 2024 · 6 revisions

Texture compression

The majority of file size in addons comes from materials, these consist of a .vmt and a .vtf. Vmt's take up neglectable space as they're just text, so we'll be looking only at .vtf files.

Downsizing materials

A lot of the file size from materials comes from their size.
Example: a 2048x2048 image has 4.194.304 pixels, compared to 512x512 having 262.144 pixels. This is a 94% difference!

Many addons use sizes like 2048x2048 or 1024x1024 without it really being necessary, thus unnecessary increasing the file size.
For this we can use material-compressor this is a tool which uses python and VTFLib to resize VTF files to lower resolution ones and compress them. Out of this directory we'll use resize-and-compress.py
Simply set the PATH_TO_DIR to the folder of your addons materials and select the CLAMP_SIZE to whatever you want the max allowed resolution to be, i recommend 512 but viewmodels might need more.

There's also resize_and_compress_singlefile.py to compress a single texture, very useful if you have a texture thats just a single color or for something that isn't important. And there's resize_png.py which helps with reducing the size of png's, i personally use this for animated vtf's. I convert them to pngs then resize the pngs and rebuild it as a animated vtf.

All the above tools have been converted over to use the new CLI

Sources used:

Clone this wiki locally