Compression (Source 1)

From Valve Developer Community
Revision as of 19:11, 17 May 2023 by SirYodaJedi (talk | contribs) (→‎Audio Compression: write out section)
Jump to navigation Jump to search

Describe importance of compression here

Texture Compression

Textures are one of the biggest potential sources of file size bloat. Additionally, higher quality textures can result in increased VRAM usage, which will increase a game or mod's minimum GPU requirements.

  • Most textures should use DXT1 or DXT5 (depending on if they have an alpha channel). While older DXTn compressors introduced a green tint to textures, the modern compressors used in VTFEdit Reloaded and Vtex2 can reliably compress to these formats without noticeable color shift.
  • If an opaque texture is low-res enough that DXT1 compression artefacts are problematic, consider using 16-bit BGR565 instead of 24-bit BGR888. The quality difference may
  • Formats with more than 8 bits per channel should be reserved for HDR skyboxes and cubemaps only; nobody is going to be able to tell a 48-bit normal map apart from a 24-bit one!

The Strata Source Strata Source, notably used by Portal 2: Community Edition and Momentum Mod, supports some additional texture formats and features:

  • BC7 is much higher quality than DXT1 or DXT5, while maintaining the same GPU footprint as DXT5. This means it can be used where other engine branches would require a BGR565 or BGRA8888 texture.
  • ATI1N is a compressed greyscale format which is half the size of I8. While this is the same size as DXT1, it only has a single greyscale channel, making it superior for greyscale textures like decals using the DecalModulate shader, or specular masks for materials without a normal map.
    Confirm:Make sure the DecalModulate shader actually supports greyscale textures.
  • VTF 7.6 supports deflate compression. While this does not reduce GPU footprint, it can greatly reduce filesize on the user's storage device.

Audio Compression

Audio is another major source of file size bloat.

  • The most obvious way to reduce audio file size is to use lossy audio compression, with MP3 being the most common. This works well for non-looping music or incidental sounds in a soundscape. This introduces latency, however, and it can't be used for certain Source Engine features that are built with WAV files in mind, such as looping sounds and lip synching.
Tip.pngTip:When making your own game or single-player mod, it is possible to add support for other similar lossy formats, such as Ogg Vorbis or Opus, and bypass some of the limitations of the default MP3 implementation.
  • WAV files don't need to be uncompressed. Source Engine also supports 4-bit Microsoft ADPCM, which can be used for almost anything that uncompressed 16-bit PCM-encoded WAVs can be used for. They can be looped in their entirety, and can be used for lip-synched dialogue. They are natively supported by sound hardware, making them less CPU-demanding than MP3 files.
    They have some disadvantages, though, mostly related to looping. The format requires fixed sample counts, meaning that shorter looped sound effects will have a noticeable "pop" when looping (this isn't usually noticeable for longer music tracks). The starting loop cue will also sometimes be ignored, making the format unsuitable for music that doesn't loop the entire file. Therefore, ADPCM is best suited for dialogue, non-looping sound effects, and some looping music.
    • If ADPCM and MP3 are unsuitable for a given sound, but you are absolutely desperate to reduce the sound's file size, it is also possible to use an 8-bit WAV instead of 16-bit. This will cut file size in half, but will also raise the noise floor to a noticeable level, resulting in an effect similar to tape hiss, which may be undesirable and obnoxious.
  • Regardless of the chosen format, reducing the sample rate of a sound effect will result in lower potential file sizes (see the MP3 and WAV pages for examples). This will result in a reduction in quality, but for certain applications such as music on a multiplayer map and explosions, the drop in sample rate from 44100 Hz to 22050 Hz may be an acceptable compromise in exchange for a lower file size.

Map Compression

In some engine branches, such as Source 2013 Multiplayer Source 2013 Multiplayer, BSP files can be losslessly compressed using a BSPZIP command. There is usually no disadvantage to doing this, although some caveats are listed on the BSPZIP page.

Dedicated Server FastDL Compression

Source supports FastDL downloads to be compressed using BZip2 (BZ2). The files will be decompressed by the user client after downloading. It is recommended to compress most loose files that are larger than a couple kilobytes (VTF, WAV, MDL, etc). BSP files should be compressed with BZ2 if not already compressed with BSPZIP. MP3 files are already heavily compressed and do not substantially reduce in size from BZ2 compression; BZ2 compression of MP3s or BSPZIP-compressed BSPs may unnecessarily increase user client load times with negligible bandwidth savings.

File System Compression

User-side; last resort

  • NTFS compression
  • BTRFS compression