New shader bundler script

This commit is contained in:
Richard Davey 2020-10-01 16:15:00 +01:00
parent bf17d061f7
commit 8c3226dc91
3 changed files with 101 additions and 0 deletions

View file

@ -43,6 +43,7 @@
"lintfix": "eslint --config .eslintrc.json \"src/**/*.js\" --fix",
"sloc": "node-sloc \"./src\" --include-extensions \"js\"",
"bundleshaders": "node scripts/bundle-shaders.js",
"bundle3dshaders": "node scripts/bundle-layer3d-shaders.js",
"build-tsgen": "cd scripts/tsgen && tsc",
"tsgen": "cd scripts/tsgen && jsdoc -c jsdoc-tsd.conf.json",
"test-ts": "cd scripts/tsgen/test && tsc --build tsconfig.json > output.txt",

View file

@ -0,0 +1,46 @@
let fs = require('fs-extra');
let srcdir = './src/layer3d/shaders/chunks/glsl/';
let destdir = './src/layer3d/shaders/chunks/';
let files = fs.readdirSync(srcdir);
files.forEach(function (file) {
let shaderSource = fs.readFileSync(srcdir + file, 'utf8');
let shaderFilename = file.substr(0, file.lastIndexOf('.')) + '.js';
let outputSource = 'module.exports = [\n';
let lines = shaderSource.split('\n');
for (var i = 0; i < lines.length; i++)
{
let line = lines[i].trimRight();
if (i < lines.length - 1)
{
outputSource = outputSource.concat(" '" + line + "',\n");
}
else
{
outputSource = outputSource.concat(" '" + line + "'\n");
}
}
outputSource = outputSource.concat('].join(\'\\n\');\n');
fs.writeFile(destdir + shaderFilename, outputSource, function (error) {
if (error)
{
throw error;
}
else
{
console.log('Saved', shaderFilename);
}
});
});

View file

@ -0,0 +1,54 @@
var ShaderChunk = require('../ShaderChunk');
var Basic = {
frag: [
ShaderChunk.commonFrag,
ShaderChunk.uvParsFrag,
ShaderChunk.colorParsFrag,
ShaderChunk.diffuseMapParsFrag,
ShaderChunk.alphamapParsFrag,
ShaderChunk.envMapParsFrag,
ShaderChunk.aoMapParsFrag,
ShaderChunk.fogParsFrag,
ShaderChunk.main,
ShaderChunk.beginFrag,
ShaderChunk.colorFrag,
ShaderChunk.diffuseMapFrag,
ShaderChunk.alphamapFrag,
ShaderChunk.alphaTestFrag,
ShaderChunk.envMapFrag,
ShaderChunk.endFrag,
ShaderChunk.encodingsFrag,
ShaderChunk.premultipliedAlphaFrag,
ShaderChunk.fogFrag
],
vert: [
ShaderChunk.commonVert,
ShaderChunk.uvParsVert,
ShaderChunk.colorParsVert,
ShaderChunk.envMapParsVert,
ShaderChunk.morphtargetParsVert,
ShaderChunk.skinningParsVert,
ShaderChunk.main,
ShaderChunk.beginVert,
ShaderChunk.morphtargetVert,
ShaderChunk.skinningVert,
ShaderChunk.pvmVert,
ShaderChunk.uvVert,
ShaderChunk.colorVert,
ShaderChunk.envMapVert
]
};
module.exports = Basic;