11 trap 'status=false' USR1
22 echo "$1" | sed 's/\.\(tga\|jpg\|png\)$//'
30 identify -verbose -alpha extract -depth 8 "$1" | {
32 while read -r L V R; do
36 pix=$(( (${V%%x*} * ${V#*x}) / 2 ))
45 pix=$(( $pix - ${L%:} ))
46 if [ $pix -le 0 ]; then
47 median=`echo "$V $R" | cut -d , -f 1 | tr -cd 0-9`
60 eval `getstats_e "$1"`
66 # $3 = shader | map | animmap | editorimage | sky
71 [ -f "../$2.tga" ] || \
72 [ -f "../$2.jpg" ] || \
73 [ -f "../$2.png" ]; then
76 if [ "$3" = "shader" ]; then
79 echo "(EE) shader $1 uses non-existing texture $2"; seterror
82 textures_used="$textures_used$LF$2"
84 if [ x"$3" = x"map" ]; then
86 if [ -n "$AUDIT_OFFSETMAPPING" ]; then
87 if [ -f "../${2}_norm.tga" ]; then
88 case "$offsetmapping_match8" in
89 '') # no dpoffsetmapping keyword
90 getstats "../${2}_norm.tga"
91 if [ "$min" -eq "$max" ]; then
92 echo "(EE) shader $1 uses broken normalmap ${2}_norm.tga (add dpoffsetmapping none)"; seterror
94 echo "(EE) shader $1 uses ${2}_norm.tga but lacks median (add dpoffsetmapping - 1 match8 $median)"; seterror
97 none) # offsetmapping turned off explicitly
99 default) # offsetmapping keyword without bias
100 getstats "../${2}_norm.tga"
101 if [ "$min" -eq "$max" ]; then
102 echo "(EE) shader $1 uses broken normalmap ${2}_norm.tga, maybe use dpoffsetmapping none?"; seterror
104 echo "(EE) shader $1 uses ${2}_norm.tga but lacks median (add to dpoffsetmapping: match8 $median)"; seterror
107 *) # offsetmapping keyword with bias
111 if [ -n "$offsetmapping_match8" ]; then
112 echo "(EE) shader $1 specifies offsetmapping, but texture $2 does not have a normalmap"
118 if [ -n "$allowed_prefixes" ]; then
120 for p in $allowed_prefixes; do
130 for p in $forbidden_prefixes; do
138 echo "(EE) shader $1 is not allowed in this shader file (allowed: $allowed_prefixes, forbidden: $forbidden_prefixes)"; seterror
142 ## RULE: skyboxes must lie in env/
148 echo "(EE) texture $2 of shader $1 is out of place, $3 textures must be in env/"; seterror
152 ## RULE: non-skyboxes must not lie in env/
156 echo "(EE) texture $2 of shader $1 is out of place, $3 textures must not be in env/"; seterror
164 # verify shader -> texture name
166 ## RULE: textures/FOOx/BAR-BAZ must use textures/FOOx/*/*, recommended textures/FOOx/BAR/BAZ
170 suf="`echo "$suf" | sed 's,-,/,g'`"
175 echo "(EE) texture $2 of shader $1 is out of place, recommended file name is $pre/$suf"; seterror
179 ## RULE: textures/FOOx/BAR must use textures/FOOx/*/*, recommended textures/FOOx/base/BAR
187 echo "(EE) texture $2 of shader $1 is out of place, recommended file name is $pre/base/$suf"; seterror
191 ## RULE: textures/map_FOO[_/]* must use textures/map_FOO[_/]*
197 "$pre"/map_$map[/_]*)
200 # protect one map's textures from the evil of other maps :P
201 echo "(EE) texture $2 of shader $1 is out of place, recommended file name is $pre/map_$map/*"; seterror
204 # using outside stuff is permitted
208 ## RULE: textures/common/FOO must use textures/common/FOO or textures/common/*/*
216 echo "(EE) texture $2 of shader $1 is out of place, recommended file name is $1 or textures/common/*/*"; seterror
220 ## RULE: textures/FOO/* must use textures/FOO/*, for FOO in decals, liquids_water, liquids_slime, liquids_lava
221 textures/decals/*|textures/liquids_*/*|textures/effects_*/*|textures/screens/*|textures/logos/*)
222 pre=`echo "$1" | cut -d / -f 1-2`
225 # I _suppose_ this is fine, as tZork committed this pack
228 echo "(EE) texture $2 of shader $1 is out of place, recommended file name is $1"; seterror
232 ## RULE: textures/skies/FOO or textures/skies/FOO_BAR must use textures/skies/FOO respective textures/skies/FOO_BAR as preview image, and env/FOO[_/]* as skybox
234 sky=${1#textures/skies/}
237 textures/skies/$sky|textures/skies/$sky[_]*)
238 # typical place for preview image
241 # typical place for skybox
244 echo "(EE) texture $2 of shader $1 is out of place, recommended file name is $1"; seterror
248 ## RULE: models/* must use models/*
254 echo "(EE) texture $2 of shader $1 is out of place, recommended file name is $1 or models/*"; seterror
259 echo "(EE) no shader name pattern for $1"; seterror
267 while read L A1 Aother; do
268 case "`echo "$L" | tr A-Z a-z`" in
274 use_texture "$parsing_shader" "`normalize "$A1"`" map
280 use_texture "$parsing_shader" "`normalize "$X"`" animmap
284 echo "(EE) brace nesting error in $parsing_shader"; seterror
297 use_texture "$parsing_shader" "$parsing_shader" shader
298 offsetmapping_match8=
299 while read L A1 Aother; do
300 case "`echo "$L" | tr A-Z a-z`" in
303 if [ x"$A1" = x"none" ]; then
304 offsetmapping_match8=none
305 elif [ x"$A1" = x"off" ]; then
306 offsetmapping_match8=none
307 elif [ x"$A1" = x"disabled" ]; then
308 offsetmapping_match8=none
309 elif [ x"$2" = x"match8" ]; then
310 offsetmapping_match8=`echo "($3 + 0.5) / 1" | bc`
311 elif [ x"$2" = x"match16" ]; then
312 offsetmapping_match8=`echo "($3 / 257 + 0.5) / 1" | bc`
313 elif [ x"$2" = x"match" ]; then
314 offsetmapping_match8=`echo "($3 * 255 + 0.5) / 1" | bc`
315 elif [ x"$2" = x"bias" ]; then
316 offsetmapping_match8=`echo "((1 - $3) * 255 + 0.5) / 1" | bc`
318 offsetmapping_match8=default
322 use_texture "$parsing_shader" "`normalize "$A1"`" editorimage
325 use_texture "$parsing_shader" "${A1}_lf" sky
326 use_texture "$parsing_shader" "${A1}_rt" sky
327 use_texture "$parsing_shader" "${A1}_up" sky
328 use_texture "$parsing_shader" "${A1}_dn" sky
329 use_texture "$parsing_shader" "${A1}_ft" sky
330 use_texture "$parsing_shader" "${A1}_bk" sky
347 ## RULE: map_FOO.shader may define tetxures/map_FOO_* and textures/map_FOO/*
349 allowed_prefixes="textures/map_`echo "$1" | cut -d _ -f 2`_ textures/map_`echo "$1" | cut -d _ -f 2`/"
352 ## RULE: skies_FOO.shader may define tetxures/skies/FOO and textures/skies/FOO_*
354 allowed_prefixes="textures/skies/`echo "$1" | cut -d _ -f 2`: textures/skies/`echo "$1" | cut -d _ -f 2`_"
357 ## RULE: model_*.shader may define models/*
359 allowed_prefixes="models/"
362 ## RULE: any other FOO.shader may define textures/FOO/*
364 allowed_prefixes="textures/$1/"
365 forbidden_prefixes="textures/skies/ textures/map_ models/"
371 parsing_shader="`normalize "$L"`"
372 if [ x"$L" != x"$parsing_shader" ]; then
373 echo "(WW) normalized shader name $L to $parsing_shader"
387 sed 's,//.*,,g; s,\r, ,g; s,\t, ,g; s, *, ,g; s, $,,; s,^ ,,; /^$/ d'
390 t=`mktemp || echo ".temp"`
391 for X in *.shader; do
392 strip_comments < "$X" > "$t"
393 parse_shaderfile "${X%.shader}" < "$t"
397 textures_avail=`( cd ..; find textures/ -type f -not -name '*_norm.*' -not -name '*_glow.*' -not -name '*_gloss.*' -not -name '*_reflect.*' -not -name '*.xcf' ) | while IFS= read -r T; do normalize "$T"; done | sort -u`
398 textures_used=`echo "${textures_used#$LF}" | sort -u`
400 echo "$textures_used$LF$textures_used$LF$textures_avail" | sort | uniq -u | while IFS= read -r L; do
407 echo "(EE) texture $L is not referenced by any shader"; seterror