Transforms GLSL shader source code into optimized JavaScript, converting vectors and matrices to arrays, expanding swizzles, and applying expression optimizations. The latest version (2.0.21) ships as an ESM package with optional CommonJS support. It works both as a programmatic API and as a stream transform, integrating with glsl-parser and glsl-tokenizer. Key differentiators include runtime variable replacement for uniforms/attributes/varyings, built-in stdlib for environment compatibility, debug facilities (print/show), and support for GLSL ES 100 and 300. Alternatives like glsl.js or raw string manipulation lack its AST-level optimization and streaming pipeline. The package is a fork of the original stackgl/glsl-transpiler with ongoing maintenance.
npm install glsl-transpiler-fork-for-gmNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to transpile a basic vertex shader to JavaScript with uniforms/attributes as object properties.
Use Node.js >=12 or enable ESM compatibility.
Update import to include .js extension.
Call GLSL(options) directly without new.
Pass texture data as ndarray or provide width and height fields.
Pass an object like { normalize: false } instead of false.Use version '100' or '300 es'.
Set "type": "module" in package.json or use .mjs extension for import.
Remove new: const compile = GLSL(options);
Use '100' or '300 es' instead.
Ensure callbacks return a string that resolves to a valid JS expression.