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[_/]*
209 textures/map_*/*|models/map_*/*)
214 textures/map_$map[/_]*)
216 models/map_$map[/_]*)
218 textures/map_*|models/map_*)
219 # protect one map's textures from the evil of other maps :P
220 err "texture $2 of shader $1 is out of place, recommended file name is $pre/map_$map/*"
223 # using outside stuff is permitted
227 ## RULE: textures/common/FOO must use textures/common/FOO or textures/common/*/*
235 err "texture $2 of shader $1 is out of place, recommended file name is $1 or textures/common/*/*"
239 ## RULE: textures/FOO/* must use textures/FOO/*, for FOO in decals, liquids_water, liquids_slime, liquids_lava, alphamod
240 textures/decals/*|textures/liquids_*/*|textures/effects_*/*|textures/screens/*|textures/logos/*|textures/alphamod/*)
241 pre=`echo "$1" | cut -d / -f 1-2`
244 # I _suppose_ this is fine, as tZork committed this pack
247 err "texture $2 of shader $1 is out of place, recommended file name is $1"
251 ## 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
253 sky=${1#textures/skies/}
256 textures/skies/$sky|textures/skies/$sky[_]*)
257 # typical place for preview image
260 # typical place for skybox
263 err "texture $2 of shader $1 is out of place, recommended file name is $1"
267 ## RULE: models/* must use models/*
273 err "texture $2 of shader $1 is out of place, recommended file name is $1 or models/*"
278 err "no shader name pattern for $1"
290 while read L A1 Aother; do
291 case "`echo "$L" | tr A-Z a-z`" in
293 ss_blendfunc=`echo $A1 $Aother | tr A-Z a-z`
296 ss_alphafunc=`echo $A1 | tr A-Z a-z`
299 ss_alphagen=`echo $A1 | tr A-Z a-z`
306 use_texture "$parsing_shader" "`normalize "$A1"`" map
307 ss_map="`normalize "$A1"`"
308 offsetmapping_match8=firststagedone
314 use_texture "$parsing_shader" "`normalize "$X"`" animmap
317 ss_map="`normalize "$X"`"
322 err "brace nesting error in $parsing_shader"
332 if [ -n "$ss_map" ]; then
333 if [ -z "$maintexture" ]; then
335 mainblendfunc=$ss_blendfunc
336 mainalphafunc=$ss_alphafunc
337 mainalphagen=$ss_alphagen
338 elif [ x"$ss_alphagen" = x"vertex" ] && ! $textureblending; then
339 case "$mainblendfunc:$mainalphafunc:$ss_blendfunc:$ss_alphafunc" in
340 none:none:"gl_src_alpha gl_one_minus_src_alpha":none) textureblending=true ;;
341 none:none:filter:none) textureblending=true ;;
342 none:none:none:g*) textureblending=true ;;
343 "gl_one gl_zero":none:filter:none) textureblending=true ;;
344 "gl_one gl_zero":none:none:g*) textureblending=true ;;
346 err "texture blending requires first stage to have no blendfunc/alphatest, and requires second stage to be blendfunc filter"
350 err "multistage shader without alphagen vertex, or using more than 2 stages, is not supported by DarkPlaces"
357 use_texture "$parsing_shader" "$parsing_shader" shader
358 offsetmapping_match8=
359 textureblending=false
362 while read L A1 Aother; do
363 case "`echo "$L" | tr A-Z a-z`" in
369 if [ x"$A1" = x"none" ]; then
370 offsetmapping_match8=none
371 elif [ x"$A1" = x"off" ]; then
372 offsetmapping_match8=none
373 elif [ x"$A1" = x"disabled" ]; then
374 offsetmapping_match8=none
375 elif [ x"$2" = x"match8" ]; then
376 offsetmapping_match8=`echo "($3 + 0.5) / 1" | bc`
377 elif [ x"$2" = x"match16" ]; then
378 offsetmapping_match8=`echo "($3 / 257 + 0.5) / 1" | bc`
379 elif [ x"$2" = x"match" ]; then
380 offsetmapping_match8=`echo "($3 * 255 + 0.5) / 1" | bc`
381 elif [ x"$2" = x"bias" ]; then
382 offsetmapping_match8=`echo "((1 - $3) * 255 + 0.5) / 1" | bc`
384 offsetmapping_match8=default
388 use_texture "$parsing_shader" "`normalize "$A1"`" editorimage
391 use_texture "$parsing_shader" "${A1}_lf" sky
392 use_texture "$parsing_shader" "${A1}_rt" sky
393 use_texture "$parsing_shader" "${A1}_up" sky
394 use_texture "$parsing_shader" "${A1}_dn" sky
395 use_texture "$parsing_shader" "${A1}_ft" sky
396 use_texture "$parsing_shader" "${A1}_bk" sky
408 if [ -n "$AUDIT_ALPHACHANNELS" ] && [ -n "$maintexture" ] && ! $textureblending; then
409 getstats "../$maintexture.tga" || getstats "../$maintexture.png" || getstats "../$maintexture.jpg"
410 case "$mainblendfunc" in
412 # texture must have alpha
413 if [ x"$mainalphagen" = x"none" -a $min -eq 255 ]; then
414 err "$parsing_shader uses alpha-less texture $maintexture with blendfunc $mainblendfunc and alphagen $mainalphagen"
418 # texture must not have alpha (engine bug)
419 if [ x"$mainalphagen" != x"none" -o $min -lt 255 ]; then
420 err "$parsing_shader uses alpha-using texture $maintexture with blendfunc $mainblendfunc and alphagen $mainalphagen"
424 case "$mainalphafunc" in
426 # texture must have alpha
427 if [ x"$mainalphagen" = x"none" -a $min -eq 255 ]; then
428 err "$parsing_shader uses alpha-less texture $maintexture with alphafunc $mainalphafunc and alphagen $mainalphagen"
432 # texture should not have alpha (no bug if not)
433 case "$mainalphagen" in
435 if [ $min -lt 255 ]; then
436 warn "$parsing_shader uses alpha-using texture $maintexture with blendfunc $mainblendfunc and alphafunc $mainalphafunc and alphagen $mainalphagen"
440 # alphagen is set, but blendfunc has no use for it
441 err "$parsing_shader uses alpha-using texture $maintexture with blendfunc $mainblendfunc and alphafunc $mainalphafunc and alphagen $mainalphagen"
454 ## RULE: map_FOO.shader may define tetxures/map_FOO_* and textures/map_FOO/*
456 allowed_prefixes="textures/map_`echo "$1" | cut -d _ -f 2`_ textures/map_`echo "$1" | cut -d _ -f 2`/ models/map_`echo "$1" | cut -d _ -f 2`_ models/map_`echo "$1" | cut -d _ -f 2`/"
459 ## RULE: skies_FOO.shader may define tetxures/skies/FOO and textures/skies/FOO_*
461 allowed_prefixes="textures/skies/`echo "$1" | cut -d _ -f 2`: textures/skies/`echo "$1" | cut -d _ -f 2`_"
464 ## RULE: model_*.shader may define models/*
466 allowed_prefixes="models/"
467 forbidden_prefixes="models/map_"
469 ## RULE: any other FOO.shader may define textures/FOO/*
471 allowed_prefixes="textures/$1/"
472 forbidden_prefixes="textures/skies/ textures/map_ models/"
478 parsing_shader="`normalize "$L"`"
479 if [ x"$L" != x"$parsing_shader" ]; then
480 warn "normalized shader name $L to $parsing_shader"
494 sed 's,//.*,,g; s,\r, ,g; s,\t, ,g; s, *, ,g; s, $,,; s,^ ,,; /^$/ d'
497 t=`mktemp || echo ".temp"`
498 for X in *.shader; do
499 strip_comments < "$X" > "$t"
500 parse_shaderfile "${X%.shader}" < "$t"
504 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' -not -name '*.txt' ) | while IFS= read -r T; do normalize "$T"; done | sort -u`
505 textures_used=`echo "${textures_used#$LF}" | sort -u`
507 echo "$textures_used$LF$textures_used$LF$textures_avail" | sort | uniq -u | while IFS= read -r L; do
516 err "texture $L is not referenced by any shader"