A thin wrapper around glsl-optimizer for an easier JavaScript-focused API. Also includes a command-line tool for quick optimizing.
This tool is in heavy work in progress. Ultimately it would be great to integrate as a transform/through stream for glslify.
Usage
Install it globally, like so: (the native build may take a little while)
npm install optimize-shader -g
Command-line usage:
Usage: optimize-shader shader.glsl -v|-f [-t es20 -d MAX_LIGHTS:3]
Options:
-v vertex shader
-f fragment shader
-t, --target the target: gl, es20, es30 [default: "gl"]
-d, --defines define in KEY:value form, or a path to *.json file to include
Pass the shader, flag whether it's vertex or fragment, and additional options. You can specify target GLSL language and a list of pre-processor #define
statements to inject before optimizing.
# output to file
optimize-shader PointLight.frag -f > build/PointLight.opt.frag
# specify defines like so:
optimize-shader PointLight.frag -f -t es20 -d MAX_LIGHTS:10 -d USE_GAMMA -d customDefines.json
API
If you want to use the API directly:
var optimizer = ; var result = ; console; //boolean, whether it compiled successfullyconsole; //from glsl_optimizer, which isn't always reliableconsole; //the optimized output shader
License
MIT, see LICENSE.md for details.