]> git.rm.cloudns.org Git - xonotic/xonotic.git/commitdiff
Add support for the "crunch" texture compression tool.
authorRudolf Polzer <divVerent@gmail.com>
Thu, 18 Mar 2021 12:19:31 +0000 (05:19 -0700)
committerRudolf Polzer <divVerent@gmail.com>
Thu, 18 Mar 2021 12:19:31 +0000 (05:19 -0700)
misc/tools/cached-converter.sh
misc/tools/compress-texture

index 9fbdf240eb3594fbd3b243fa9a1edf93606bdbdf..ec976351921dcd0329a86710e2ea5a8f379a1f80 100755 (executable)
@@ -396,25 +396,31 @@ for F in "$@"; do
                        ;;
        esac
 
-       # configure S2TC
+       # Specific hacks for normalmaps.
        case "$f" in
                ./maps/*/lm_[0-9][0-9][0-9][13579]) # deluxemap
                        export S2TC_COLORDIST_MODE=NORMALMAP
                        export S2TC_RANDOM_COLORS=256
                        export S2TC_REFINE_COLORS=LOOP
                        export S2TC_DITHER_MODE=NONE
+                       # Engine ignores alpha channel on these, so we can use the DXT1 black encoding.
+                       export CRUNCH_TEXTYPEFLAGS='-gamma 1.0 -renormalize -rtopmip -uniformMetrics -usetransparentindicesforblack'
                        ;;
                *_norm)
                        export S2TC_COLORDIST_MODE=NORMALMAP
                        export S2TC_RANDOM_COLORS=256
                        export S2TC_REFINE_COLORS=LOOP
                        export S2TC_DITHER_MODE=NONE
+                       # Alpha channel here means height.
+                       export CRUNCH_TEXTYPEFLAGS='-gamma 1.0 -renormalize -rtopmip -uniformMetrics'
                        ;;
                *)
                        export S2TC_COLORDIST_MODE=SRGB_MIXED
                        export S2TC_RANDOM_COLORS=64
                        export S2TC_REFINE_COLORS=LOOP
                        export S2TC_DITHER_MODE=FLOYDSTEINBERG
+                       # Color channel-like images - consider as sRGB.
+                       export CRUNCH_TEXTYPEFLAGS='-gamma 2.2'
                        ;;
        esac
 
index 9e3b58e5e26719f9d25a33644ba43f58c198cf88..418d8e5c40afa401ff93d9e42771008fd7708dd9 100755 (executable)
@@ -17,8 +17,8 @@ f=
 
 fourcchack=
 case "$tool" in
-       compressonator-dxtc)
-               # we still have to preprocess the image to premultiply alpha, as it seems
+       compressonator-dxtc|crunch)
+               # We still have to preprocess the image to premultiply alpha, as it seems
                case "$format" in
                        dxt2)
                                fourcchack=DXT2
@@ -30,7 +30,8 @@ case "$tool" in
                                ;;
                esac
                ;;
-       *)
+       compressonator-atic|nvcompress|s2tc)
+               # These tools don't support DXT2/4 at all.
                case "$format" in
                        dxt2)
                                fourcchack=DXT2
@@ -42,6 +43,9 @@ case "$tool" in
                                ;;
                esac
                ;;
+       *)
+               echo >&2 "Please figure out the DXT2/DXT4 story for $tool."
+               ;;
 esac
 
 if [ -n "$fourcchack" ]; then
@@ -93,6 +97,16 @@ case "$tool" in
                esac
                s2tc_compress $f "$@" -i "$src" -o "$dst"
                ;;
+       crunch)
+               case "$format" in
+                       dxt1) f="-DXT1" ;;
+                       dxt2) f="-DXT2" ;;
+                       dxt3) f="-DXT3" ;;
+                       dxt4) f="-DXT4" ;;
+                       dxt5) f="-DXT5" ;;
+               esac
+               crunch $f "$@" -noprogress -nostats -quality 255 -mipMode Generate -dxtQuality uber $CRUNCH_TEXTYPEFLAGS -file "$src" -out "$dst"
+               ;;
 esac
 
 if [ -n "$fourcchack" ]; then