Real-time GLSL to SPIR-V translator. Powered by Glslang and Khronos' SPIR-V Tools.
Compiled into JavaScript via Emscripten.
To add Glslang.js to your web application, include it with:
<script src="glslang.min.js"></script>
or install it with the Bower command:
bower install glslangjs
// Input: GLSL source code and shader type
var type = glslang.EShLangFragment;
var source = `
#version 150
out vec4 finalColor;
void main() {
finalColor = vec4(1.0, 1.0, 1.0, 1.0);
}`;
// Initialize Glslang
glslang.initialize();
// Compile shader
var shader = new glslang.Shader(type, source);
// Output: SPIR-V binary and disassembly
var binary = shader.data();
var disassembly = shader.disasm();
// Delete shader
shader.delete();
// Finalize Glslang
glslang.finalize();
To build the Glslang.js library, clone the master branch of this repository, and do the following:
-
Initialize the Glslang and SPIR-V Tools submodules:
git submodule update --init
. -
Install the development and client dependencies with:
npm install
andbower install
. -
Install the lastest Python 2.x (64-bit), CMake and the Emscripten SDK. Follow the respective instructions and make sure all environment variables are configured correctly. Under Windows MinGW (specifically mingw32-make) is required.
-
Finally, build the source with:
grunt build
.