]> git.xonotic.org Git - xonotic/xonotic.git/blobdiff - misc/tools/normalmap.sh
fix generated alpha channel
[xonotic/xonotic.git] / misc / tools / normalmap.sh
index 08905b7952a68bba386fd2327eec975d3dfed892..49b32200c8e4099ac4560178c1f2891e0cc04f5e 100755 (executable)
@@ -2,6 +2,7 @@
 
 # usage: ./bump2norm.sh foo_bump.tga foo_norm.tga
 # NOTE: unfortunately requires X-server (otherwise file-tga-save won't work... no joke)
+# also, alpha channel value 0 is avoided as gimp doesn't save it properly
 
 in=$1
 out=$2
@@ -13,11 +14,14 @@ out=$2
 #   Minimun Z (0 to 1)
 # scale:
 #   Scale (>0)
+# heightsource:
+#   Height source (0 = average RGB, 1 = alpha channel)
 # conv:
 #   Conversion (0 = none, 1 = Biased RGB, 2 = Red, 3 = Green, 4 = Blue, 5 = Max RGB, 6 = Min RGB, 7 = Colorspace)
 : ${filter:=0}
 : ${minz:=0}
 : ${scale:=1}
+: ${heightsource:=0}
 : ${conv:=0}
 
 gimp -i -b - <<EOF
@@ -26,9 +30,14 @@ gimp -i -b - <<EOF
                (img (car (gimp-file-load RUN-NONINTERACTIVE "$in" "$in")))
                (drawable (car (gimp-image-active-drawable img)))
                (layer (car (gimp-image-get-active-layer img)))
+               (mycurve (cons-array 256 'byte))
+               (i 1)
        )
        (gimp-layer-add-alpha layer)
-       (plug-in-normalmap RUN-NONINTERACTIVE img drawable $filter $minz $scale 1 0 1 $conv 0 0 1 0 1 layer)
+       (plug-in-normalmap RUN-NONINTERACTIVE img drawable $filter $minz $scale 1 $heightsource 1 $conv 0 0 1 0 1 layer)
+       (aset mycurve 0 1)
+       (while (< i 256) (aset mycurve i i) (set! i (+ i 1)))
+       (gimp-curves-explicit drawable HISTOGRAM-ALPHA 256 mycurve)
        (file-tga-save RUN-NONINTERACTIVE img drawable "$out" "$out" 1 1)
        (gimp-quit 0)
 )