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 "$ss_map" ]; then
320 if [ -z "$maintexture" ]; then
322 mainblendfunc=$ss_blendfunc
323 mainalphafunc=$ss_alphafunc
324 mainalphagen=$ss_alphagen
325 elif [ x"$ss_alphagen" = x"vertex" ] && ! $textureblending; then
326 case "$mainblendfunc:$mainalphafunc:$ss_blendfunc:$ss_alphafunc" in
327 none:none:"gl_src_alpha gl_one_minus_src_alpha":none) textureblending=true ;;
328 none:none:filter:none) textureblending=true ;;
329 none:none:none:g*) textureblending=true ;;
330 "gl_one gl_zero":none:filter:none) textureblending=true ;;
331 "gl_one gl_zero":none:none:g*) textureblending=true ;;
333 echo "(EE) texture blending requires first stage to have no blendfunc/alphatest, and requires second stage to be blendfunc filter"; seterror
337 echo "(EE) multistage shader without alphagen vertex, or using more than 2 stages, is not supported by DarkPlaces"; seterror
344 use_texture "$parsing_shader" "$parsing_shader" shader
345 offsetmapping_match8=
346 textureblending=false
348 while read L A1 Aother; do
349 case "`echo "$L" | tr A-Z a-z`" in
352 if [ x"$A1" = x"none" ]; then
353 offsetmapping_match8=none
354 elif [ x"$A1" = x"off" ]; then
355 offsetmapping_match8=none
356 elif [ x"$A1" = x"disabled" ]; then
357 offsetmapping_match8=none
358 elif [ x"$2" = x"match8" ]; then
359 offsetmapping_match8=`echo "($3 + 0.5) / 1" | bc`
360 elif [ x"$2" = x"match16" ]; then
361 offsetmapping_match8=`echo "($3 / 257 + 0.5) / 1" | bc`
362 elif [ x"$2" = x"match" ]; then
363 offsetmapping_match8=`echo "($3 * 255 + 0.5) / 1" | bc`
364 elif [ x"$2" = x"bias" ]; then
365 offsetmapping_match8=`echo "((1 - $3) * 255 + 0.5) / 1" | bc`
367 offsetmapping_match8=default
371 use_texture "$parsing_shader" "`normalize "$A1"`" editorimage
374 use_texture "$parsing_shader" "${A1}_lf" sky
375 use_texture "$parsing_shader" "${A1}_rt" sky
376 use_texture "$parsing_shader" "${A1}_up" sky
377 use_texture "$parsing_shader" "${A1}_dn" sky
378 use_texture "$parsing_shader" "${A1}_ft" sky
379 use_texture "$parsing_shader" "${A1}_bk" sky
391 if [ -n "$AUDIT_ALPHACHANNELS" ] && [ -n "$maintexture" ] && ! $textureblending; then
392 getstats "../$maintexture.tga" || getstats "../$maintexture.png" || getstats "../$maintexture.jpg"
393 case "$mainblendfunc" in
395 # texture must have alpha
396 if [ x"$mainalphagen" = x"none" -a $min -eq 255 ]; then
397 echo "(EE) $parsing_shader uses alpha-less texture $maintexture with blendfunc $mainblendfunc and alphagen $mainalphagen"; seterror
401 # texture must not have alpha (engine bug)
402 if [ x"$mainalphagen" != x"none" -o $min -lt 255 ]; then
403 echo "(EE) $parsing_shader uses alpha-using texture $maintexture with blendfunc $mainblendfunc and alphagen $mainalphagen"; seterror
407 case "$mainalphafunc" in
409 # texture must have alpha
410 if [ x"$mainalphagen" = x"none" -a $min -eq 255 ]; then
411 echo "(EE) $parsing_shader uses alpha-less texture $maintexture with alphafunc $mainalphafunc and alphagen $mainalphagen"; seterror
415 # texture should not have alpha (no bug if not)
416 case "$mainalphagen" in
418 if [ $min -lt 255 ]; then
419 echo "(WW) $parsing_shader uses alpha-using texture $maintexture with blendfunc $mainblendfunc and alphafunc $mainalphafunc and alphagen $mainalphagen"
423 # alphagen is set, but blendfunc has no use for it
424 echo "(EE) $parsing_shader uses alpha-using texture $maintexture with blendfunc $mainblendfunc and alphafunc $mainalphafunc and alphagen $mainalphagen"; seterror
437 ## RULE: map_FOO.shader may define tetxures/map_FOO_* and textures/map_FOO/*
439 allowed_prefixes="textures/map_`echo "$1" | cut -d _ -f 2`_ textures/map_`echo "$1" | cut -d _ -f 2`/"
442 ## RULE: skies_FOO.shader may define tetxures/skies/FOO and textures/skies/FOO_*
444 allowed_prefixes="textures/skies/`echo "$1" | cut -d _ -f 2`: textures/skies/`echo "$1" | cut -d _ -f 2`_"
447 ## RULE: model_*.shader may define models/*
449 allowed_prefixes="models/"
452 ## RULE: any other FOO.shader may define textures/FOO/*
454 allowed_prefixes="textures/$1/"
455 forbidden_prefixes="textures/skies/ textures/map_ models/"
461 parsing_shader="`normalize "$L"`"
462 if [ x"$L" != x"$parsing_shader" ]; then
463 echo "(WW) normalized shader name $L to $parsing_shader"
477 sed 's,//.*,,g; s,\r, ,g; s,\t, ,g; s, *, ,g; s, $,,; s,^ ,,; /^$/ d'
480 t=`mktemp || echo ".temp"`
481 for X in *.shader; do
482 strip_comments < "$X" > "$t"
483 parse_shaderfile "${X%.shader}" < "$t"
487 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`
488 textures_used=`echo "${textures_used#$LF}" | sort -u`
490 echo "$textures_used$LF$textures_used$LF$textures_avail" | sort | uniq -u | while IFS= read -r L; do
497 echo "(EE) texture $L is not referenced by any shader"; seterror