-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_shaders.sh
executable file
·48 lines (41 loc) · 1.02 KB
/
process_shaders.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh
##
## Bash scrip to conver .fs / .vs files into .ts string
##
STR_OUT_FILE="shader_source.ts"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null 2>&1 && pwd )"
GLSL_DIR="$DIR/src/render_engine/shader/glsl"
GLSL_FILES=($( cd $GLSL_DIR && ls *.vs *.fs))
OUTPUT="$GLSL_DIR/$STR_OUT_FILE"
# extract name from name.fs/.vs
extracted_name=''
extract_str_name() {
while IFS='.' read -ra name
do
extracted_name="${name[0]}_${name[1]}"
return;
done <<< "$1"
echo "Couldnt extract string name from $file_name"
exit -1;
}
main() {
# remove old shader_source.ts
if [ -e $OUTPUT ]; then
rm $OUTPUT 2> /dev/null
fi
# print message
echo "// DO NOT EDIT MANUALLY: Auto generated by process_shaders.sh" >> $OUTPUT
# loop through all the files
for i in ${GLSL_FILES[@]}
do
glsl_file="$GLSL_DIR/$i"
extract_str_name $i
printf "export const $extracted_name=\`" >> $OUTPUT
while IFS='' read -ra line || [[ -n "$line" ]]
do
printf "$line\n" >> $OUTPUT
done < "$glsl_file"
printf "\`\n" >> $OUTPUT
done
}
main