11 trap 'status=false' USR1
25 $nowarn || echo "(WW) $*"
33 echo "$1" | sed 's/\.\(tga\|jpg\|png\)$//'
41 identify -verbose -depth 8 -alpha set -alpha extract "$1" | {
43 while read -r L V R; do
47 pix=$(( (${V%%x*} * ${V#*x}) / 2 ))
56 pix=$(( $pix - ${L%:} ))
57 if [ $pix -le 0 ]; then
58 median=`echo "$V $R" | cut -d , -f 1 | tr -cd 0-9`
76 [ -f "$1" ] || return 1
77 eval `getstats_e "$1"`
83 # $3 = shader | map | animmap | editorimage | sky
88 [ -f "../$2.tga" ] || \
89 [ -f "../$2.jpg" ] || \
90 [ -f "../$2.png" ]; then
93 if [ "$3" = "shader" ]; then
96 err "$1 uses non-existing texture $2"
99 textures_used="$textures_used$LF$2"
101 if [ x"$3" = x"map" ]; then
103 if [ -n "$AUDIT_ALPHACHANNELS" ] && [ x"$offsetmapping_match8" != x"firststagedone" ]; then
104 if [ -f "../${2}_norm.tga" ] || [ -f "../${2}_norm.png" ] || [ -f "../${2}_norm.jpg" ]; then
105 case "$offsetmapping_match8" in
106 '') # no dpoffsetmapping keyword
107 getstats "../${2}_norm.tga" || getstats "../${2}_norm.png" || getstats "../${2}_norm.jpg"
108 if [ "$min" -eq "$max" ]; then
109 warn "$1 uses broken normalmap ${2}_norm.tga (add dpoffsetmapping none)"
111 err "$1 uses ${2}_norm.tga but lacks median (add dpoffsetmapping - 1 match8 $median)"
114 none) # offsetmapping turned off explicitly
116 default) # offsetmapping keyword without bias
117 getstats "../${2}_norm.tga"
118 if [ "$min" -eq "$max" ]; then
119 warn "$1 uses broken normalmap ${2}_norm.tga, maybe use dpoffsetmapping none?"
121 err "$1 uses ${2}_norm.tga but lacks median (add to dpoffsetmapping: match8 $median)"
124 *) # offsetmapping keyword with bias
128 if [ -n "$offsetmapping_match8" ]; then
129 warn "$1 specifies offsetmapping, but texture $2 does not have a normalmap"
135 if [ -n "$allowed_prefixes" ]; then
137 for p in $allowed_prefixes; do
147 for p in $forbidden_prefixes; do
155 err "$1 is not allowed in this shader file (allowed: $allowed_prefixes, forbidden: $forbidden_prefixes)"
159 ## RULE: skyboxes must lie in env/
165 err "texture $2 of shader $1 is out of place, $3 textures must be in env/"
169 ## RULE: non-skyboxes must not lie in env/
173 err "texture $2 of shader $1 is out of place, $3 textures must not be in env/"
181 # verify shader -> texture name
183 ## RULE: textures/FOOx/BAR-BAZ must use textures/FOOx/*/*, recommended textures/FOOx/BAR/BAZ
187 suf="`echo "$suf" | sed 's,-,/,g'`"
192 err "texture $2 of shader $1 is out of place, recommended file name is $pre/$suf"
196 ## RULE: textures/FOOx/BAR must use textures/FOOx/*/*, recommended textures/FOOx/base/BAR
204 err "texture $2 of shader $1 is out of place, recommended file name is $pre/base/$suf"
208 ## RULE: textures/map_FOO[_/]* must use textures/map_FOO[_/]*
214 "$pre"/map_$map[/_]*)
217 # protect one map's textures from the evil of other maps :P
218 err "texture $2 of shader $1 is out of place, recommended file name is $pre/map_$map/*"
221 # using outside stuff is permitted
225 ## RULE: textures/common/FOO must use textures/common/FOO or textures/common/*/*
233 err "texture $2 of shader $1 is out of place, recommended file name is $1 or textures/common/*/*"
237 ## RULE: textures/FOO/* must use textures/FOO/*, for FOO in decals, liquids_water, liquids_slime, liquids_lava, alphamod
238 textures/decals/*|textures/liquids_*/*|textures/effects_*/*|textures/screens/*|textures/logos/*|textures/alphamod/*)
239 pre=`echo "$1" | cut -d / -f 1-2`
242 # I _suppose_ this is fine, as tZork committed this pack
245 err "texture $2 of shader $1 is out of place, recommended file name is $1"
249 ## 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
251 sky=${1#textures/skies/}
254 textures/skies/$sky|textures/skies/$sky[_]*)
255 # typical place for preview image
258 # typical place for skybox
261 err "texture $2 of shader $1 is out of place, recommended file name is $1"
265 ## RULE: models/* must use models/*
271 err "texture $2 of shader $1 is out of place, recommended file name is $1 or models/*"
276 err "no shader name pattern for $1"
288 while read L A1 Aother; do
289 case "`echo "$L" | tr A-Z a-z`" in
291 ss_blendfunc=`echo $A1 $Aother | tr A-Z a-z`
294 ss_alphafunc=`echo $A1 | tr A-Z a-z`
297 ss_alphagen=`echo $A1 | tr A-Z a-z`
304 use_texture "$parsing_shader" "`normalize "$A1"`" map
305 ss_map="`normalize "$A1"`"
306 offsetmapping_match8=firststagedone
312 use_texture "$parsing_shader" "`normalize "$X"`" animmap
315 ss_map="`normalize "$X"`"
320 err "brace nesting error in $parsing_shader"
330 if [ -n "$ss_map" ]; then
331 if [ -z "$maintexture" ]; then
333 mainblendfunc=$ss_blendfunc
334 mainalphafunc=$ss_alphafunc
335 mainalphagen=$ss_alphagen
336 elif [ x"$ss_alphagen" = x"vertex" ] && ! $textureblending; then
337 case "$mainblendfunc:$mainalphafunc:$ss_blendfunc:$ss_alphafunc" in
338 none:none:"gl_src_alpha gl_one_minus_src_alpha":none) textureblending=true ;;
339 none:none:filter:none) textureblending=true ;;
340 none:none:none:g*) textureblending=true ;;
341 "gl_one gl_zero":none:filter:none) textureblending=true ;;
342 "gl_one gl_zero":none:none:g*) textureblending=true ;;
344 err "texture blending requires first stage to have no blendfunc/alphatest, and requires second stage to be blendfunc filter"
348 err "multistage shader without alphagen vertex, or using more than 2 stages, is not supported by DarkPlaces"
355 use_texture "$parsing_shader" "$parsing_shader" shader
356 offsetmapping_match8=
357 textureblending=false
360 while read L A1 Aother; do
361 case "`echo "$L" | tr A-Z a-z`" in
367 if [ x"$A1" = x"none" ]; then
368 offsetmapping_match8=none
369 elif [ x"$A1" = x"off" ]; then
370 offsetmapping_match8=none
371 elif [ x"$A1" = x"disabled" ]; then
372 offsetmapping_match8=none
373 elif [ x"$2" = x"match8" ]; then
374 offsetmapping_match8=`echo "($3 + 0.5) / 1" | bc`
375 elif [ x"$2" = x"match16" ]; then
376 offsetmapping_match8=`echo "($3 / 257 + 0.5) / 1" | bc`
377 elif [ x"$2" = x"match" ]; then
378 offsetmapping_match8=`echo "($3 * 255 + 0.5) / 1" | bc`
379 elif [ x"$2" = x"bias" ]; then
380 offsetmapping_match8=`echo "((1 - $3) * 255 + 0.5) / 1" | bc`
382 offsetmapping_match8=default
386 use_texture "$parsing_shader" "`normalize "$A1"`" editorimage
389 use_texture "$parsing_shader" "${A1}_lf" sky
390 use_texture "$parsing_shader" "${A1}_rt" sky
391 use_texture "$parsing_shader" "${A1}_up" sky
392 use_texture "$parsing_shader" "${A1}_dn" sky
393 use_texture "$parsing_shader" "${A1}_ft" sky
394 use_texture "$parsing_shader" "${A1}_bk" sky
406 if [ -n "$AUDIT_ALPHACHANNELS" ] && [ -n "$maintexture" ] && ! $textureblending; then
407 getstats "../$maintexture.tga" || getstats "../$maintexture.png" || getstats "../$maintexture.jpg"
408 case "$mainblendfunc" in
410 # texture must have alpha
411 if [ x"$mainalphagen" = x"none" -a $min -eq 255 ]; then
412 err "$parsing_shader uses alpha-less texture $maintexture with blendfunc $mainblendfunc and alphagen $mainalphagen"
416 # texture must not have alpha (engine bug)
417 if [ x"$mainalphagen" != x"none" -o $min -lt 255 ]; then
418 err "$parsing_shader uses alpha-using texture $maintexture with blendfunc $mainblendfunc and alphagen $mainalphagen"
422 case "$mainalphafunc" in
424 # texture must have alpha
425 if [ x"$mainalphagen" = x"none" -a $min -eq 255 ]; then
426 err "$parsing_shader uses alpha-less texture $maintexture with alphafunc $mainalphafunc and alphagen $mainalphagen"
430 # texture should not have alpha (no bug if not)
431 case "$mainalphagen" in
433 if [ $min -lt 255 ]; then
434 warn "$parsing_shader uses alpha-using texture $maintexture with blendfunc $mainblendfunc and alphafunc $mainalphafunc and alphagen $mainalphagen"
438 # alphagen is set, but blendfunc has no use for it
439 err "$parsing_shader uses alpha-using texture $maintexture with blendfunc $mainblendfunc and alphafunc $mainalphafunc and alphagen $mainalphagen"
452 ## RULE: map_FOO.shader may define tetxures/map_FOO_* and textures/map_FOO/*
454 allowed_prefixes="textures/map_`echo "$1" | cut -d _ -f 2`_ textures/map_`echo "$1" | cut -d _ -f 2`/"
457 ## RULE: skies_FOO.shader may define tetxures/skies/FOO and textures/skies/FOO_*
459 allowed_prefixes="textures/skies/`echo "$1" | cut -d _ -f 2`: textures/skies/`echo "$1" | cut -d _ -f 2`_"
462 ## RULE: model_*.shader may define models/*
464 allowed_prefixes="models/"
467 ## RULE: any other FOO.shader may define textures/FOO/*
469 allowed_prefixes="textures/$1/"
470 forbidden_prefixes="textures/skies/ textures/map_ models/"
476 parsing_shader="`normalize "$L"`"
477 if [ x"$L" != x"$parsing_shader" ]; then
478 warn "normalized shader name $L to $parsing_shader"
492 sed 's,//.*,,g; s,\r, ,g; s,\t, ,g; s, *, ,g; s, $,,; s,^ ,,; /^$/ d'
495 t=`mktemp || echo ".temp"`
496 for X in *.shader; do
497 strip_comments < "$X" > "$t"
498 parse_shaderfile "${X%.shader}" < "$t"
502 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`
503 textures_used=`echo "${textures_used#$LF}" | sort -u`
505 echo "$textures_used$LF$textures_used$LF$textures_avail" | sort | uniq -u | while IFS= read -r L; do
512 err "texture $L is not referenced by any shader"