-
-
Notifications
You must be signed in to change notification settings - Fork 8
Materials
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.
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:
- https://developer.valvesoftware.com/wiki/Material --VMT/VTF Information
- https://github.com/HaodongMo/ARC-9-Standard-Weapons/tree/main/tools --Source of the python script
- https://github.com/NeilJed/VTFLib --Source of VTFLib