11 trap 'status=false' USR1
22 echo "$1" | sed 's/\.\(tga\|jpg\|png\)$//'
30 identify -verbose -depth 8 -alpha set -alpha extract "$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`
65 [ -f "$1" ] || return 1
66 eval `getstats_e "$1"`
72 # $3 = shader | map | animmap | editorimage | sky
77 [ -f "../$2.tga" ] || \
78 [ -f "../$2.jpg" ] || \
79 [ -f "../$2.png" ]; then
82 if [ "$3" = "shader" ]; then
85 echo "(EE) shader $1 uses non-existing texture $2"; seterror
88 textures_used="$textures_used$LF$2"
90 if [ x"$3" = x"map" ]; then
92 if [ -n "$AUDIT_ALPHACHANNELS" ] && [ x"$offsetmapping_match8" != x"firststagedone" ]; then
93 if [ -f "../${2}_norm.tga" ] || [ -f "../${2}_norm.png" ] || [ -f "../${2}_norm.jpg" ]; then
94 case "$offsetmapping_match8" in
95 '') # no dpoffsetmapping keyword
96 getstats "../${2}_norm.tga" || getstats "../${2}_norm.png" || getstats "../${2}_norm.jpg"
97 if [ "$min" -eq "$max" ]; then
98 echo "(WW) shader $1 uses broken normalmap ${2}_norm.tga (add dpoffsetmapping none)"
100 echo "(EE) shader $1 uses ${2}_norm.tga but lacks median (add dpoffsetmapping - 1 match8 $median)"; seterror
103 none) # offsetmapping turned off explicitly
105 default) # offsetmapping keyword without bias
106 getstats "../${2}_norm.tga"
107 if [ "$min" -eq "$max" ]; then
108 echo "(WW) shader $1 uses broken normalmap ${2}_norm.tga, maybe use dpoffsetmapping none?"
110 echo "(EE) shader $1 uses ${2}_norm.tga but lacks median (add to dpoffsetmapping: match8 $median)"; seterror
113 *) # offsetmapping keyword with bias
117 if [ -n "$offsetmapping_match8" ]; then
118 echo "(WW) shader $1 specifies offsetmapping, but texture $2 does not have a normalmap"
124 if [ -n "$allowed_prefixes" ]; then
126 for p in $allowed_prefixes; do
136 for p in $forbidden_prefixes; do
144 echo "(EE) shader $1 is not allowed in this shader file (allowed: $allowed_prefixes, forbidden: $forbidden_prefixes)"; seterror
148 ## RULE: skyboxes must lie in env/
154 echo "(EE) texture $2 of shader $1 is out of place, $3 textures must be in env/"; seterror
158 ## RULE: non-skyboxes must not lie in env/
162 echo "(EE) texture $2 of shader $1 is out of place, $3 textures must not be in env/"; seterror
170 # verify shader -> texture name
172 ## RULE: textures/FOOx/BAR-BAZ must use textures/FOOx/*/*, recommended textures/FOOx/BAR/BAZ
176 suf="`echo "$suf" | sed 's,-,/,g'`"
181 echo "(EE) texture $2 of shader $1 is out of place, recommended file name is $pre/$suf"; seterror
185 ## RULE: textures/FOOx/BAR must use textures/FOOx/*/*, recommended textures/FOOx/base/BAR
193 echo "(EE) texture $2 of shader $1 is out of place, recommended file name is $pre/base/$suf"; seterror
197 ## RULE: textures/map_FOO[_/]* must use textures/map_FOO[_/]*
203 "$pre"/map_$map[/_]*)
206 # protect one map's textures from the evil of other maps :P
207 echo "(EE) texture $2 of shader $1 is out of place, recommended file name is $pre/map_$map/*"; seterror
210 # using outside stuff is permitted
214 ## RULE: textures/common/FOO must use textures/common/FOO or textures/common/*/*
222 echo "(EE) texture $2 of shader $1 is out of place, recommended file name is $1 or textures/common/*/*"; seterror
226 ## RULE: textures/FOO/* must use textures/FOO/*, for FOO in decals, liquids_water, liquids_slime, liquids_lava
227 textures/decals/*|textures/liquids_*/*|textures/effects_*/*|textures/screens/*|textures/logos/*)
228 pre=`echo "$1" | cut -d / -f 1-2`
231 # I _suppose_ this is fine, as tZork committed this pack
234 echo "(EE) texture $2 of shader $1 is out of place, recommended file name is $1"; seterror
238 ## 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
240 sky=${1#textures/skies/}
243 textures/skies/$sky|textures/skies/$sky[_]*)
244 # typical place for preview image
247 # typical place for skybox
250 echo "(EE) texture $2 of shader $1 is out of place, recommended file name is $1"; seterror
254 ## RULE: models/* must use models/*
260 echo "(EE) texture $2 of shader $1 is out of place, recommended file name is $1 or models/*"; seterror
265 echo "(EE) no shader name pattern for $1"; seterror
277 while read L A1 Aother; do
278 case "`echo "$L" | tr A-Z a-z`" in
280 ss_blendfunc=`echo $A1 $Aother | tr A-Z a-z`
283 ss_alphafunc=`echo $A1 | tr A-Z a-z`
286 ss_alphagen=`echo $A1 | tr A-Z a-z`
293 use_texture "$parsing_shader" "`normalize "$A1"`" map
294 ss_map="`normalize "$A1"`"
295 offsetmapping_match8=firststagedone
301 use_texture "$parsing_shader" "`normalize "$X"`" animmap
304 ss_map="`normalize "$X"`"
309 echo "(EE) brace nesting error in $parsing_shader"; seterror
319 if [ -n "$AUDIT_ALPHACHANNELS" ] && [ -n "$ss_map" ]; then
320 getstats "../$ss_map.tga" || getstats "../$ss_map.png" || getstats "../$ss_map.jpg"
321 case "$ss_blendfunc" in
323 # texture must have alpha
324 if [ x"$ss_alphagen" = x"none" -a $min -eq 255 ]; then
325 echo "(EE) $parsing_shader uses alpha-less texture $ss_map with blendfunc $ss_blendfunc and alphagen $ss_alphagen"; seterror
329 # texture must not have alpha (engine bug)
330 if [ x"$ss_alphagen" != x"none" -o $min -lt 255 ]; then
331 echo "(EE) $parsing_shader uses alpha-using texture $ss_map with blendfunc $ss_blendfunc and alphagen $ss_alphagen"; seterror
335 case "$ss_alphafunc" in
337 # texture must have alpha
338 if [ x"$ss_alphagen" = x"none" -a $min -eq 255 ]; then
339 echo "(EE) $parsing_shader uses alpha-less texture $ss_map with alphafunc $ss_alphafunc and alphagen $ss_alphagen"; seterror
343 # texture should not have alpha (no bug if not)
344 case "$ss_alphagen" in
346 if [ $min -lt 255 ]; then
347 echo "(WW) $parsing_shader uses alpha-using texture $ss_map with blendfunc $ss_blendfunc and alphafunc $ss_alphafunc and alphagen $ss_alphagen"
351 # alphagen is set, but blendfunc has no use for it
352 echo "(EE) $parsing_shader uses alpha-using texture $ss_map with blendfunc $ss_blendfunc and alphafunc $ss_alphafunc and alphagen $ss_alphagen"; seterror
364 use_texture "$parsing_shader" "$parsing_shader" shader
365 offsetmapping_match8=
366 while read L A1 Aother; do
367 case "`echo "$L" | tr A-Z a-z`" in
370 if [ x"$A1" = x"none" ]; then
371 offsetmapping_match8=none
372 elif [ x"$A1" = x"off" ]; then
373 offsetmapping_match8=none
374 elif [ x"$A1" = x"disabled" ]; then
375 offsetmapping_match8=none
376 elif [ x"$2" = x"match8" ]; then
377 offsetmapping_match8=`echo "($3 + 0.5) / 1" | bc`
378 elif [ x"$2" = x"match16" ]; then
379 offsetmapping_match8=`echo "($3 / 257 + 0.5) / 1" | bc`
380 elif [ x"$2" = x"match" ]; then
381 offsetmapping_match8=`echo "($3 * 255 + 0.5) / 1" | bc`
382 elif [ x"$2" = x"bias" ]; then
383 offsetmapping_match8=`echo "((1 - $3) * 255 + 0.5) / 1" | bc`
385 offsetmapping_match8=default
389 use_texture "$parsing_shader" "`normalize "$A1"`" editorimage
392 use_texture "$parsing_shader" "${A1}_lf" sky
393 use_texture "$parsing_shader" "${A1}_rt" sky
394 use_texture "$parsing_shader" "${A1}_up" sky
395 use_texture "$parsing_shader" "${A1}_dn" sky
396 use_texture "$parsing_shader" "${A1}_ft" sky
397 use_texture "$parsing_shader" "${A1}_bk" sky
414 ## RULE: map_FOO.shader may define tetxures/map_FOO_* and textures/map_FOO/*
416 allowed_prefixes="textures/map_`echo "$1" | cut -d _ -f 2`_ textures/map_`echo "$1" | cut -d _ -f 2`/"
419 ## RULE: skies_FOO.shader may define tetxures/skies/FOO and textures/skies/FOO_*
421 allowed_prefixes="textures/skies/`echo "$1" | cut -d _ -f 2`: textures/skies/`echo "$1" | cut -d _ -f 2`_"
424 ## RULE: model_*.shader may define models/*
426 allowed_prefixes="models/"
429 ## RULE: any other FOO.shader may define textures/FOO/*
431 allowed_prefixes="textures/$1/"
432 forbidden_prefixes="textures/skies/ textures/map_ models/"
438 parsing_shader="`normalize "$L"`"
439 if [ x"$L" != x"$parsing_shader" ]; then
440 echo "(WW) normalized shader name $L to $parsing_shader"
454 sed 's,//.*,,g; s,\r, ,g; s,\t, ,g; s, *, ,g; s, $,,; s,^ ,,; /^$/ d'
457 t=`mktemp || echo ".temp"`
458 for X in *.shader; do
459 strip_comments < "$X" > "$t"
460 parse_shaderfile "${X%.shader}" < "$t"
464 textures_avail=`( cd ..; find textures/ -type f -not -name '*.sh' -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`
465 textures_used=`echo "${textures_used#$LF}" | sort -u`
467 echo "$textures_used$LF$textures_used$LF$textures_avail" | sort | uniq -u | while IFS= read -r L; do
474 echo "(EE) texture $L is not referenced by any shader"; seterror