Page 1 of 1

Logarithmic functions and shell scripting

Posted: 22.10.2006, 22:07
by LoneHiker
I had the idea of writing a shell script that would reduce a texture to the nearest power of two before tiling it into virtual textures. But it would require a logarithmic function (and a floor and exponent function). I have very little experience with shell scripting and I'm unsure these functions are possible. Does anyone know? I'm using Cygwin, btw.

Lone

Re: Logarithmic functions and shell scripting

Posted: 22.10.2006, 22:17
by t00fri
LoneHiker wrote:I had the idea of writing a shell script that would reduce a texture to the nearest power of two before tiling it into virtual textures. But it would require a logarithmic function (and a floor and exponent function). I have very little experience with shell scripting and I'm unsure these functions are possible. Does anyone know? I'm using Cygwin, btw.

Lone


Certainly. With zsh there is the mathfunc module that you just have to load like so in your shell scrip:

zmodload zsh/mathfunc

I used that quite a bit when coding the latitude dependent optimization of the tile resolution.


Bye Fridger

Posted: 22.10.2006, 22:34
by t00fri
I actually have a number of scripts that do relvant things for the present discussions of dxt5nm, tile optimization etc.

But I don't have a bit of spare time for explaining, after just returning from Lisbon/Portugal...and getting ready for the next trip.

E.g. this texdxt5nm script, using convert and nvdxt

Code: Select all

#! /usr/bin/zsh
if [ $# -lt 2 -o "$1" = "--help" ]; then
   echo
     echo 'Usage: texdxt5nm [--help | <level> <tile format>]'
     echo
     echo
     echo The shell script \'texdxt5nm\' is a tool for Celestia \> 1.3.0
     echo that maps the RGB layers of normalmap VT tiles such as to make
     echo them compatible with Chris Laurels DXT5nm scheme: 'G -> A, R -> GB'.
     echo This matches NVIDIAs DXT5nm format apart from an additional 'R <-> G' flip.
     echo The flip is motivated by having 6 bit for G storage and only 5 bits
     echo for R,B storage, each.
     echo
     echo The script requires the standard square tiles tx_i_j
     echo in a specified format, \<tile format\> = png, tga, jpg,....
     echo
     echo Note that NO mipmaps are generated, since these are useless in a
     echo tile setup with varying resolution levels
     echo
     echo Besides Linux/Unix, the script also runs in a current Cygwin \
       installation
     echo under Windows, \( http://www.cygwin.com \). The zsh is needed!
     echo
     echo The script assumes that a recent version \(\>= 6.1.8\) of the ImageMagick package
     echo \( http://www.ImageMagick.org \) is installed \
        \(either under Unix/Linux or Windows\).
     echo The utility \'convert\' of that package is used.
     echo
     echo Author: Dr. Fridger Schrempp, fridger.schrempp@desy.de
     echo Version: 1.00, 09/04/06
     echo 
else
   zmodload zsh/mathfunc
   level=$1
   tileformat=$2
   (( p2 = 2**level ))
   echo
   echo "Level = " $level
   echo "Image format of tiles:" $tileformat
   echo "Number of tiles =" $(( 2 * p2 * p2 ))
    echo "----------------------------------------"   

   mkdir dxt5nm
   cd dxt5nm

   j=0
   while (( j  <=  p2 - 1 )); do
       i=0
       while (( i  <= 2 * p2 - 1 )); do
          convert ../tx_"$i"_"$j".$tileformat -channel A  -fx G -channel GB -fx R tx_"$i"_"$j".png      
          #texconvert -d 5 -n tx_"$i"_"$j".png  tx_"$i"_"$j".dds >/dev/null
           nvdxt -quality_highest -file tx_"$i"_"$j".png  -nomipmaps -32 dxt5
           (( i++ ))
       done
       (( j++ ))
        echo "Tiles done:" $(( j * 2 * p2 ))
    done
fi


That script still referred to Chris previous map. But an adaptation to the new standard is utterly trivial.

Bye Fridger

Re: Logarithmic functions and shell scripting

Posted: 22.10.2006, 22:50
by LoneHiker
t00fri wrote:With zsh there is the mathfunc module that you just have to load like so in your shell scrip:

zmodload zsh/mathfunc


Thanks for pointing me in the right direction, Fridger. I'll look for more information on this.

BTW, I added two new arguments to virtualtex to work with the eight BMNG monthly tiles. Now all one needs to do is input the column and row of a particular tile and the script will do the rest. The column and row information is included at the end of each BMNG tile file name. For example:

world.200407.3x21600x21600.A1.png = a 1
world.topo.200401.3x21600.21600.D2.png = d 2

Of course I'm sure your latest tools do this and much more. :wink: But it was a good exercise for learning how to write shell scripts and it will come in handy.

Lone