frak-slang
v0.3.6
Published
Lightweight GLSL preprocessor for FRAK Engine
Downloads
23
Readme
frak-slang
Lightweight GLSL preprocessor for FRAK Engine.
Features
- Declare uniforms/attributes/varyings only once
- #include
- Have both vertex and fragment shader entry points in the same file
- Transpile into standard GLSL vertex and fragment shader
- Unused variables and functions are culled
- Extract shader parameters
- Command line tool for integrating into build scripts
Limitations
- Preprocessor directives inside functions are not evaluated
- Unused variables and functions inside preprocessor directives are not culled
- Comments on the same line as #include directives are not handled
Install
npm install frak-slang
Usage (as library)
var FRAKSlang = require('frak-slang');
FRAKSlang.compile(glslSource, {
// handle included files
include: function(includedFile, parentFile, done) {
/* ... */
done(includedFileData, includedFilePath);
},
sourceURI: 'main/glsl/file/location'
}, function(compiled) {
// compiled = {
// vertex: 'vertex program code here',
// fragment: 'fragment program code here'
// }
});
Usage (as command line tool)
frak-slang -o <output_filename> -t <glsl|json> <file.glsl>
- The default value for --type (-t) is GLSL
- If the type is GLSL the output will result in two files: output_filename.vert and output_filename.frag