13 trap 'status=false' USR1
27 $nowarn || echo "(WW) $*"
38 identify -verbose -depth 8 -alpha set -alpha extract "$1" | {
40 while read -r L V R; do
44 pix=$(( (${V%%x*} * ${V#*x}) / 2 ))
53 pix=$(( $pix - ${L%:} ))
54 if [ $pix -le 0 ]; then
55 median=`echo "$V $R" | cut -d , -f 1 | tr -cd 0-9`
73 [ -f "$1" ] || return 1
74 eval `getstats_e "$1"`
80 # $3 = shader | map | animmap | editorimage | sky
85 [ -f "../$2.tga" ] || \
86 [ -f "../$2.jpg" ] || \
87 [ -f "../$2.png" ]; then
90 if [ "$3" = "shader" ]; then
93 err "$1 uses non-existing texture $2"
96 textures_used="$textures_used$LF$2"
98 if [ x"$3" = x"map" ]; then
100 if [ -n "$AUDIT_ALPHACHANNELS" ] && [ x"$offsetmapping_match8" != x"firststagedone" ]; then
101 if [ -f "../${2}_norm.tga" ] || [ -f "../${2}_norm.png" ] || [ -f "../${2}_norm.jpg" ]; then
102 case "$offsetmapping_match8" in
103 '') # no dpoffsetmapping keyword
104 getstats "../${2}_norm.tga" || getstats "../${2}_norm.png" || getstats "../${2}_norm.jpg"
105 if [ "$min" -eq "$max" ]; then
106 warn "$1 uses broken normalmap ${2}_norm.tga (add dpoffsetmapping none)"
108 err "$1 uses ${2}_norm.tga but lacks median (add dpoffsetmapping - 1 match8 $median)"
111 none) # offsetmapping turned off explicitly
113 default) # offsetmapping keyword without bias
114 getstats "../${2}_norm.tga"
115 if [ "$min" -eq "$max" ]; then
116 warn "$1 uses broken normalmap ${2}_norm.tga, maybe use dpoffsetmapping none?"
118 err "$1 uses ${2}_norm.tga but lacks median (add to dpoffsetmapping: match8 $median)"
121 *) # offsetmapping keyword with bias
125 if [ -n "$offsetmapping_match8" ]; then
126 warn "$1 specifies offsetmapping, but texture $2 does not have a normalmap"
132 if [ -n "$allowed_prefixes" ]; then
134 for p in $allowed_prefixes; do
144 for p in $forbidden_prefixes; do
152 err "$1 is not allowed in this shader file (allowed: $allowed_prefixes, forbidden: $forbidden_prefixes)"
156 ## RULE: skyboxes must lie in env/
162 err "texture $2 of shader $1 is out of place, $3 textures must be in env/"
166 ## RULE: non-skyboxes must not lie in env/
170 err "texture $2 of shader $1 is out of place, $3 textures must not be in env/"
178 # verify shader -> texture name
180 ## RULE: textures/FOOx/BAR-BAZ must use textures/FOOx/*/*, recommended textures/FOOx/BAR/BAZ
184 suf="`echo "$suf" | sed 's,-,/,g'`"
189 err "texture $2 of shader $1 is out of place, recommended file name is $pre/$suf"
193 ## RULE: textures/FOOx/BAR must use textures/FOOx/*/*, recommended textures/FOOx/base/BAR
201 err "texture $2 of shader $1 is out of place, recommended file name is $pre/base/$suf"
205 ## RULE: textures/map_FOO[_/]* must use textures/map_FOO[_/]*
206 textures/map_*/*|models/map_*/*)
211 textures/map_$map[/_]*)
213 models/map_$map[/_]*)
215 textures/map_*|models/map_*)
216 # protect one map's textures from the evil of other maps :P
217 err "texture $2 of shader $1 is out of place, recommended file name is $pre/map_$map/*"
220 # using outside stuff is permitted
224 ## RULE: textures/common/FOO must use textures/common/FOO or textures/common/*/*
232 err "texture $2 of shader $1 is out of place, recommended file name is $1 or textures/common/*/*"
236 ## RULE: textures/FOO/* must use textures/FOO/*, for FOO in decals, liquids_water, liquids_slime, liquids_lava, alphamod
237 textures/decals/*|textures/liquids_*/*|textures/effects_*/*|textures/screens/*|textures/logos/*|textures/alphamod/*)
238 pre=`echo "$1" | cut -d / -f 1-2`
241 # I _suppose_ this is fine, as tZork committed this pack
244 err "texture $2 of shader $1 is out of place, recommended file name is $1"
248 ## 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
250 sky=${1#textures/skies/}
253 textures/skies/$sky|textures/skies/$sky[_]*)
254 # typical place for preview image
257 # typical place for skybox
260 err "texture $2 of shader $1 is out of place, recommended file name is $1"
264 ## RULE: models/* must use models/*
270 err "texture $2 of shader $1 is out of place, recommended file name is $1 or models/*"
275 err "no shader name pattern for $1"
281 parse_shaderstage_pre()
289 parse_shaderstage_line()
294 case "`echo "$L" | tr A-Z a-z`" in
296 ss_blendfunc=`echo $A1 $Aother | tr A-Z a-z`
299 ss_alphafunc=`echo $A1 | tr A-Z a-z`
302 ss_alphagen=`echo $A1 | tr A-Z a-z`
309 use_texture "$parsing_shader" "`shader_normalize "$A1"`" map
310 ss_map="`shader_normalize "$A1"`"
311 offsetmapping_match8=firststagedone
317 use_texture "$parsing_shader" "`shader_normalize "$X"`" animmap
320 ss_map="`shader_normalize "$X"`"
325 err "brace nesting error in $parsing_shader"
335 parse_shaderstage_post()
337 if [ -n "$ss_map" ]; then
338 if [ -z "$maintexture" ]; then
340 mainblendfunc=$ss_blendfunc
341 mainalphafunc=$ss_alphafunc
342 mainalphagen=$ss_alphagen
343 elif [ x"$ss_alphagen" = x"vertex" ] && ! $textureblending; then
344 case "$mainblendfunc:$mainalphafunc:$ss_blendfunc:$ss_alphafunc" in
345 # TODO check against dp
346 none:none:"gl_src_alpha gl_one_minus_src_alpha":none) textureblending=true ;;
347 none:none:filter:none) textureblending=true ;;
348 none:none:none:g*) textureblending=true ;;
349 "gl_one gl_zero":none:filter:none) textureblending=true ;;
350 "gl_one gl_zero":none:none:g*) textureblending=true ;;
352 err "$parsing_shader uses texture blending, but that requires first stage to have no blendfunc/alphatest, and requires second stage to be blendfunc filter"
356 err "$parsing_shader, a multistage shader without alphagen vertex, or using more than 2 stages, is not supported by DarkPlaces"
363 use_texture "$parsing_shader" "$parsing_shader" shader
364 offsetmapping_match8=
365 textureblending=false
375 case "`echo "$L" | tr A-Z a-z`" in
381 if [ x"$A1" = x"none" ]; then
382 offsetmapping_match8=none
383 elif [ x"$A1" = x"off" ]; then
384 offsetmapping_match8=none
385 elif [ x"$A1" = x"disabled" ]; then
386 offsetmapping_match8=none
387 elif [ x"$2" = x"match8" ]; then
388 offsetmapping_match8=`echo "($3 + 0.5) / 1" | bc`
389 elif [ x"$2" = x"match16" ]; then
390 offsetmapping_match8=`echo "($3 / 257 + 0.5) / 1" | bc`
391 elif [ x"$2" = x"match" ]; then
392 offsetmapping_match8=`echo "($3 * 255 + 0.5) / 1" | bc`
393 elif [ x"$2" = x"bias" ]; then
394 offsetmapping_match8=`echo "((1 - $3) * 255 + 0.5) / 1" | bc`
396 offsetmapping_match8=default
400 use_texture "$parsing_shader" "`shader_normalize "$A1"`" editorimage
403 use_texture "$parsing_shader" "${A1}_lf" sky
404 use_texture "$parsing_shader" "${A1}_rt" sky
405 use_texture "$parsing_shader" "${A1}_up" sky
406 use_texture "$parsing_shader" "${A1}_dn" sky
407 use_texture "$parsing_shader" "${A1}_ft" sky
408 use_texture "$parsing_shader" "${A1}_bk" sky
417 if [ -n "$AUDIT_ALPHACHANNELS" ] && [ -n "$maintexture" ] && ! $textureblending; then
418 getstats "../$maintexture.tga" || getstats "../$maintexture.png" || getstats "../$maintexture.jpg"
419 case "$mainblendfunc" in
421 # texture must have alpha
422 if [ x"$mainalphagen" = x"none" -a $min -eq 255 ]; then
423 err "$parsing_shader uses alpha-less texture $maintexture with blendfunc $mainblendfunc and alphagen $mainalphagen"
427 # texture must not have alpha (engine bug)
428 if [ x"$mainalphagen" != x"none" -o $min -lt 255 ]; then
429 err "$parsing_shader uses alpha-using texture $maintexture with blendfunc $mainblendfunc and alphagen $mainalphagen"
433 case "$mainalphafunc" in
435 # texture must have alpha
436 if [ x"$mainalphagen" = x"none" -a $min -eq 255 ]; then
437 err "$parsing_shader uses alpha-less texture $maintexture with alphafunc $mainalphafunc and alphagen $mainalphagen"
441 # texture should not have alpha (no bug if not)
442 case "$mainalphagen" in
444 if [ $min -lt 255 ]; then
445 warn "$parsing_shader uses alpha-using texture $maintexture with blendfunc $mainblendfunc and alphafunc $mainalphafunc and alphagen $mainalphagen"
449 # alphagen is set, but blendfunc has no use for it
450 err "$parsing_shader uses alpha-using texture $maintexture with blendfunc $mainblendfunc and alphafunc $mainalphafunc and alphagen $mainalphagen"
460 parse_shaderfile_pre()
462 s="${parsing_shaderfile%.shader}"
464 ## RULE: map_FOO.shader may define tetxures/map_FOO_* and textures/map_FOO/*
466 allowed_prefixes="textures/map_`echo "$s" | cut -d _ -f 2`_ textures/map_`echo "$s" | cut -d _ -f 2`/ models/map_`echo "$s" | cut -d _ -f 2`_ models/map_`echo "$s" | cut -d _ -f 2`/"
469 ## RULE: skies_FOO.shader may define tetxures/skies/FOO and textures/skies/FOO_*
471 allowed_prefixes="textures/skies/`echo "$s" | cut -d _ -f 2`: textures/skies/`echo "$s" | cut -d _ -f 2`_"
474 ## RULE: model_*.shader may define models/*
476 allowed_prefixes="models/"
477 forbidden_prefixes="models/map_"
479 ## RULE: any other FOO.shader may define textures/FOO/*
481 allowed_prefixes="textures/$s/"
482 forbidden_prefixes="textures/skies/ textures/map_ models/"
487 parse_shaders *.shader
489 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 shader_normalize "$T"; done | sort -u`
490 textures_used=`echo "${textures_used#$LF}" | sort -u`
492 echo "$textures_used$LF$textures_used$LF$textures_avail" | sort | uniq -u | while IFS= read -r L; do
501 err "texture $L is not referenced by any shader"