]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/normalmap.sh
fix generated alpha channel
[xonotic/xonotic.git] / misc / tools / normalmap.sh
1 #!/bin/sh
2
3 # usage: ./bump2norm.sh foo_bump.tga foo_norm.tga
4 # NOTE: unfortunately requires X-server (otherwise file-tga-save won't work... no joke)
5 # also, alpha channel value 0 is avoided as gimp doesn't save it properly
6
7 in=$1
8 out=$2
9
10 # env variables you can set:
11 # filter:
12 #   Filter type (0 = 4 sample, 1 = sobel 3x3, 2 = sobel 5x5, 3 = prewitt 3x3, 4 = prewitt 5x5, 5-8 = 3x3,5x5,7x7,9x9)
13 # minz:
14 #   Minimun Z (0 to 1)
15 # scale:
16 #   Scale (>0)
17 # heightsource:
18 #   Height source (0 = average RGB, 1 = alpha channel)
19 # conv:
20 #   Conversion (0 = none, 1 = Biased RGB, 2 = Red, 3 = Green, 4 = Blue, 5 = Max RGB, 6 = Min RGB, 7 = Colorspace)
21 : ${filter:=0}
22 : ${minz:=0}
23 : ${scale:=1}
24 : ${heightsource:=0}
25 : ${conv:=0}
26
27 gimp -i -b - <<EOF
28
29 (let*(
30                 (img (car (gimp-file-load RUN-NONINTERACTIVE "$in" "$in")))
31                 (drawable (car (gimp-image-active-drawable img)))
32                 (layer (car (gimp-image-get-active-layer img)))
33                 (mycurve (cons-array 256 'byte))
34                 (i 1)
35         )
36         (gimp-layer-add-alpha layer)
37         (plug-in-normalmap RUN-NONINTERACTIVE img drawable $filter $minz $scale 1 $heightsource 1 $conv 0 0 1 0 1 layer)
38         (aset mycurve 0 1)
39         (while (< i 256) (aset mycurve i i) (set! i (+ i 1)))
40         (gimp-curves-explicit drawable HISTOGRAM-ALPHA 256 mycurve)
41         (file-tga-save RUN-NONINTERACTIVE img drawable "$out" "$out" 1 1)
42         (gimp-quit 0)
43 )
44
45 EOF