]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/shadescript/shade.sh
better usage message
[xonotic/xonotic.git] / misc / tools / shadescript / shade.sh
1 #!/bin/sh
2
3 case "$#" in
4         2)
5                 ;;
6         *)
7                 echo "Usage: from xonotic-maps.pk3dir directory, copy and edit shader.template, then"
8                 echo "  $0 texturepackname myshader.template"
9                 exit 1
10                 ;;
11 esac
12
13 LF="
14 "
15
16 exec 3>"scripts/$1.shader"
17 template=`cat "$2"`
18
19 find "textures/$1" -type f -path "textures/*/*/*.*" -not -name '*_norm.*' -not -name '*_glow.*' -not -name '*_gloss.*' -not -name '*_reflect.*' -not -name '*.xcf' | while IFS= read -r F; do
20         F=${F%.*}
21
22         noLightmap=false
23         isLiquid=false
24         isTransparent=false
25         bounceScale=1.00
26         shaderString="$template"
27         shaderHead=
28         shaderTail=
29         shaderQUI=
30         shaderDiffuse=
31         diffuseExtra=
32
33         case "$F" in
34                 *decal*)
35                         noLightmap=true
36                         ;;
37         esac
38
39         # material type
40         case "$F" in
41                 *water*)
42                         noLightmap=true
43                         isLiquid=true
44                         shaderHead="$shaderHead surfaceparm trans\n     surfaceparm water\n     qer_trans 20\n"
45                         ;;
46                 *slime*)
47                         noLightmap=true
48                         isLiquid=true
49                         shaderHead="$shaderHead surfaceparm trans\n     surfaceparm slime\n     qer_trans 20\n"
50                         ;;
51                 *lava*)
52                         noLightmap=true
53                         isLiquid=true
54                         shaderHead="$shaderHead surfaceparm trans\n     surfaceparm lava\n      qer_trans 20\n"
55                         ;;
56                 *glass*)
57                         noLightmap=true
58                         shaderHead="$shaderHead surfaceparm trans\n"
59                         diffuseExtra="$diffuseExtra             blendfunc add\n"
60                         ;;
61                 *metal*)
62                         bounceScale=`echo "$bounceScale + 0.25" | bc -l`
63                         shaderHead="$shaderHead         surfaceparm metalsteps\n"
64                         ;;
65         esac
66
67         # what is it used for
68         case "$F" in
69                 *grate*)
70                         bounceScale=`echo "$bounceScale + 0.25" | bc -l`
71                         shaderHead="$shaderHead surfaceparm trans\n"
72                         diffuseExtra="$diffuseExtra             blendfunc blend\n"
73                         ;;
74         esac
75
76         # further properties
77         case "$F" in
78                 *shiny*)
79                         bounceScale=`echo "$bounceScale + 0.25" | bc -l`
80                         ;;
81         esac
82         case "$F" in
83                 *dirt*|*terrain*|*old*)
84                         bounceScale=`echo "$bounceScale - 0.25" | bc -l`
85                         shaderHead="$shaderHead surfaceparm dust\n"
86                         ;;
87         esac
88
89         shaderDiffuse="$F"
90         if [ -f "$F""_gloss.tga" ] || [ -f "$F""_gloss.jpg" ] || [ -f "$F""_gloss.png" ]; then
91                 bounceScale=`echo "$bounceScale - 0.25" | bc -l`
92         fi
93
94         if [ -f "$F""_qei.tga" ] || [ -f "$F""_qei.jpg" ] || [ -f "$F""_qei.png" ]; then
95                 shaderQUI="$F""_qei"
96         else
97                 shaderQUI="$F"
98         fi
99
100         if ! $noLightmap; then
101                 shaderTail="    {\n             map \$lightmap\n                rgbGen identity\n               tcGen lightmap\n                blendfunc filter\n      }"
102         fi
103         case "$bounceScale" in
104                 1|1.0|1.00)
105                         ;;
106                 *)
107                         shaderHead="$shaderHead q3map_bouncescale $bounceScale\n"
108                         ;;
109         esac
110
111         shaderName="`echo "$F" | cut -d / -f 1-2`/`echo "$F" | cut -d / -f 3`-`echo "$F" | cut -d / -f 4`"
112         echo "$shaderString$LF$LF" | sed -e "
113                 s,%shader_name%,$shaderName,g;
114                 s,%qei_name%,$shaderQUI,g;
115                 s,%shader_head%,$shaderHead,g;
116                 s,%diffuse_map%,$shaderDiffuse,g;
117                 s,%diffuse_map_extra%,$diffuseExtra,g;
118                 s,%shader_tail%,$shaderTail,g;
119         " >&3
120 done