1#!/bin/sh 2 3case "$#" in 4 2) 5 ;; 6 *) 7 echo "Usage: from xonotic-maps.pk3dir directory, copy and edit shader.template, then" 8 echo " $0 texturepackname myshader.template" 9 exit 1 10 ;; 11esac 12 13LF=" 14" 15 16exec 3>"scripts/$1.shader" 17template=`cat "$2"` 18 19find "textures/$1" -type f -path "textures/*/*/*.*" -not -name '*_norm.*' -not -name '*_glow.*' -not -name '*_gloss.*' -not -name '*_reflect.*' -not -name '*.xcf' | while IFS= read -r F; do 20 F=${F%.*} 21 22 noLightmap=false 23 isLiquid=false 24 isTransparent=false 25 bounceScale=1.00 26 shaderString="$template" 27 shaderHead= 28 shaderTail= 29 shaderQUI= 30 shaderDiffuse= 31 diffuseExtra= 32 33 case "$F" in 34 *decal*) 35 noLightmap=true 36 ;; 37 esac 38 39 # material type 40 case "$F" in 41 *water*) 42 noLightmap=true 43 isLiquid=true 44 shaderHead="$shaderHead surfaceparm trans$LF surfaceparm water$LF qer_trans 20$LF" 45 ;; 46 *slime*) 47 noLightmap=true 48 isLiquid=true 49 shaderHead="$shaderHead surfaceparm trans$LF surfaceparm slime$LF qer_trans 20$LF" 50 ;; 51 *lava*) 52 noLightmap=true 53 isLiquid=true 54 shaderHead="$shaderHead surfaceparm trans$LF surfaceparm lava$LF qer_trans 20$LF" 55 ;; 56 *glass*) 57 noLightmap=true 58 shaderHead="$shaderHead surfaceparm trans$LF" 59 diffuseExtra="$diffuseExtra blendfunc add$LF" 60 ;; 61 *metal*) 62 bounceScale=`echo "$bounceScale + 0.25" | bc -l` 63 shaderHead="$shaderHead surfaceparm metalsteps$LF" 64 ;; 65 esac 66 67 # what is it used for 68 case "$F" in 69 *grate*) 70 bounceScale=`echo "$bounceScale + 0.25" | bc -l` 71 shaderHead="$shaderHead surfaceparm trans$LF" 72 diffuseExtra="$diffuseExtra blendfunc blend$LF" 73 ;; 74 esac 75 76 # further properties 77 case "$F" in 78 *shiny*) 79 bounceScale=`echo "$bounceScale + 0.25" | bc -l` 80 ;; 81 esac 82 case "$F" in 83 *dirt*|*terrain*|*old*) 84 bounceScale=`echo "$bounceScale - 0.25" | bc -l` 85 shaderHead="$shaderHead surfaceparm dust$LF" 86 ;; 87 esac 88 89 shaderDiffuse="$F" 90 if [ -f "$F""_gloss.tga" ] || [ -f "$F""_gloss.jpg" ] || [ -f "$F""_gloss.png" ]; then 91 bounceScale=`echo "$bounceScale + 0.25" | bc -l` 92 fi 93 94 if [ -f "$F""_qei.tga" ] || [ -f "$F""_qei.jpg" ] || [ -f "$F""_qei.png" ]; then 95 shaderQUI="$F""_qei" 96 else 97 shaderQUI="$F" 98 fi 99 100 if ! $noLightmap; then 101 shaderTail=" {$LF map \$lightmap$LF rgbGen identity$LF tcGen lightmap$LF blendfunc filter$LF }" 102 fi 103 case "$bounceScale" in 104 1|1.0|1.00) 105 ;; 106 *) 107 shaderHead="$shaderHead q3map_bouncescale $bounceScale$LF" 108 ;; 109 esac 110 111 shaderName="`echo "$F" | cut -d / -f 1-2`/`echo "$F" | cut -d / -f 3`-`echo "$F" | cut -d / -f 4`" 112 echo "$shaderString$LF$LF" | sed -e " 113 s,%shader_name%,$shaderName,g; 114 s,%qei_name%,$shaderQUI,g; 115 s,%shader_head%,$shaderHead,g; 116 s,%diffuse_map%,$shaderDiffuse,g; 117 s,%diffuse_map_extra%,$diffuseExtra,g; 118 s,%shader_tail%,$shaderTail,g; 119 " >&3 120done 121