X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=misc%2Ftools%2Ffft-normalmap-to-heightmap-soft.sh;h=708d44484b14b6c14a049f705d0da46a7d082e4c;hb=462b9c845dafb878244fa6b022ea083f35ad8ae4;hp=618bf9ef3fc574499083b6e0a8b190110126549d;hpb=c3c600a6d3a3e375c8fa98f1614e63212df51f1c;p=xonotic%2Fxonotic.git diff --git a/misc/tools/fft-normalmap-to-heightmap-soft.sh b/misc/tools/fft-normalmap-to-heightmap-soft.sh index 618bf9ef..708d4448 100755 --- a/misc/tools/fft-normalmap-to-heightmap-soft.sh +++ b/misc/tools/fft-normalmap-to-heightmap-soft.sh @@ -17,10 +17,28 @@ realscale=`echo "$s" | grep ^Scale: | cut -d ' ' -f 2` realmedian=`echo "$s" | grep ^Scaled-Med: | cut -d ' ' -f 2` # we have to undo realscale, and apply sca instead -extrascale=`echo "$sca / $realscale" | bc -l` +# assume we had an input range of 0 .. 1 +# then this tool will scale by 2, stretching it to 1..255 +# so, scale 2 means a 254/255 scale from DP's view! +extrascale=`echo "$sca / ($realscale * (127.0 / 255.0))" | bc -l` # we want to make $realmedian + $ofs neutral - -extraoffset=`echo "127.5 - 127.5 * ($realmedian + $ofs)" | bc -l` - -echo "dpoffsetmapping - $extrascale $extraoffset" +# note: ofs is in pre-scale units +extraoffset=`echo "($realmedian + $ofs / $realscale)" | bc -l` + +# note: this tool maps -1 to 1 neutral, and +1 to 255 neutral +# darkplaces maps 1 to 0 neutral, and 0 to 255 neutral +# +# p_t(-1) = 1 +# p_t(+1) = 255 +# -> p_t(x) = 128 + 127 * x +# p_d(1) = 0 +# p_d(0) = 255 +# -> p_d(x) = 255 * (1 - x) +# -> p_d^-1(x) = 1 - x / 255 +# +# we need p_d^-1(p_t(x)) = 1 - (128 + 127 * x) / 255 +# +extraoffset="match8 "`echo "128 + 127 * $extraoffset" | bc -l` + +echo " dpoffsetmapping - $extrascale $extraoffset"