]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/fft-normalmap-to-heightmap-soft.sh
Add AppData file
[xonotic/xonotic.git] / misc / tools / fft-normalmap-to-heightmap-soft.sh
1 #!/bin/sh
2
3 i=$1
4 o=$2
5 f=$3
6 sca=$4
7 ofs=$5
8
9 s=`"${0%-soft.sh}" "$i" "$o" "$f"`
10 echo >&2 "$s"
11
12 # we want to map so that:
13 #   sca
14 #   med/avg -> ofs
15
16 realscale=`echo "$s" | grep ^Scale: | cut -d ' ' -f 2`
17 realmedian=`echo "$s" | grep ^Scaled-Med: | cut -d ' ' -f 2`
18
19 # we have to undo realscale, and apply sca instead
20 # assume we had an input range of 0 .. 1
21 # then this tool will scale by 2, stretching it to 1..255
22 # so, scale 2 means a 254/255 scale from DP's view!
23 extrascale=`echo "$sca / ($realscale * (127.0 / 255.0))" | bc -l`
24
25 # we want to make $realmedian + $ofs neutral
26 # note: ofs is in pre-scale units
27 extraoffset=`echo "($realmedian + $ofs / $realscale)" | bc -l`
28
29 # note: this tool maps  -1 to 1 neutral, and +1 to 255 neutral
30 #       darkplaces maps  1 to 0 neutral, and  0 to 255 neutral
31 #
32 # p_t(-1) = 1
33 # p_t(+1) = 255
34 #   -> p_t(x) = 128 + 127 * x
35 # p_d(1) = 0
36 # p_d(0) = 255
37 #   -> p_d(x) = 255 * (1 - x)
38 #   -> p_d^-1(x) = 1 - x / 255
39 #
40 # we need p_d^-1(p_t(x)) = 1 - (128 + 127 * x) / 255
41 #
42 extraoffset="match8 "`echo "128 + 127 * $extraoffset" | bc -l`
43
44 echo "  dpoffsetmapping - $extrascale $extraoffset"