DaemonEngine / crunch

Advanced DXTc texture compression and transcoding library and tool, upgraded with Unity improvements, added features, extended system and hardware support, deeply tested.
https://github.com/DaemonEngine/crunch
Other
16 stars 6 forks source link

Add `-noNormalDetection` to avoid normal map detection #30

Closed illwieckz closed 1 year ago

illwieckz commented 1 year ago

Add -noNormalDetection to avoid normal map detection

Crunch has an algorithm to try to detect normal maps, probably to pick higher quality compressors.

It prevents the compressor to wrongly detect a normal map and select formats like DXT5_AGBR when DXT1 is good enough.

It does not only avoid to produce files in less supported swizzled formats, it also allows to pick smaller formats, sometime saving half of the produced file size.

illwieckz commented 1 year ago

with Metro's rust06e

$ crunch -quality 255 -file /tmp/rust06e.tga -out /tmp/rust06e-dxt5.crn
Apparent type: Normal map, Flags: R G B Non-Flipped 
Input texture: 128x128, Levels: 1, Faces: 1, Format: R8G8B8
Input pixels: 16384, Input file size: 49196, Input bits/pixel: 24.021
Output texture: 128x128, Levels: 8, Faces: 1, Format: DXT5_AGBR
Output pixels: 21845, Output file size: 9364, Output bits/pixel: 3.429
$ crunch -quality 255 -noNormalDetection -file /tmp/rust06e.tga -out /tmp/rust06e-dxt5.crn
Apparent type: 2D map, Flags: R G B Non-Flipped 
Input texture: 128x128, Levels: 1, Faces: 1, Format: R8G8B8
Input pixels: 16384, Input file size: 49196, Input bits/pixel: 24.021
Output texture: 128x128, Levels: 8, Faces: 1, Format: DXT1
Output pixels: 21845, Output file size: 3532, Output bits/pixel: 1.293

With Metro's m77-blanc

$ crunch -quality 255 /tmp/m77-blanc.tga -out /tmp/m77-blanc.crn
Apparent type: Normal map, Flags: R G B Non-Flipped 
Input texture: 32x32, Levels: 1, Faces: 1, Format: R8G8B8
Input pixels: 1024, Input file size: 3116, Input bits/pixel: 24.344
Output texture: 32x32, Levels: 6, Faces: 1, Format: DXT5_AGBR
Output pixels: 1365, Output file size: 771, Output bits/pixel: 4.519
$ crunch -quality 255 -NoNormalDetection /tmp/m77-blanc.tga -out /tmp/m77-blanc.crn
Apparent type: 2D map, Flags: R G B Non-Flipped 
Input texture: 32x32, Levels: 1, Faces: 1, Format: R8G8B8
Input pixels: 1024, Input file size: 3116, Input bits/pixel: 24.344
Output texture: 32x32, Levels: 6, Faces: 1, Format: DXT1
Output pixels: 1365, Output file size: 356, Output bits/pixel: 2.086

Comparison

Image Format before Format after Size before size after
rust06e DXT5_AGBR DXT1 9364 3532
m77-blanc DXT5_AGBR DXT1 771 356
illwieckz commented 1 year ago

It looks like crunch only produces DXT5_AGBR files with normal maps, not non-normal maps.

We already use -DXn format for normal maps, so anytime we don't use -DXn we can set -noNormalDetection because we already know the files are not normal maps, and then we never run code that may pick the specific swizzled AGBR format, formats we never need.