glsl-100-to-300
Transpile GLSL source tokens from version "100"
(WebGL1) to "300 es"
(WebGL2).
Example
Source:
var transpile = var tokenize = var stringify = var tokens = transpileconsole
Input fragment shader:
#version 100#extension GL_OES_standard_derivatives : enablevarying vec2 vUv;uniform sampler2D iChannel0; void
The resulting WebGL2 shader.
#version 300 esout vec4 fragColor_1;in vec2 vUv;uniform sampler2D iChannel0; void
sample
is a reserved word in 300es so it must be renamed, and GL_OES_standard_derivatives
has been promoted to core so the extension pragma should be removed.
Usage
Operates on GLSL tokens, but ignoring column
, position
and line
.
transpile.vertex(tokens)
Transpiles the tokens
array from a vertex shader and modifies them in place, to allow the code to run in a WebGL2 context.
In this case, varying
will be converted to out
.
Returns the tokens
array.
transpile.fragment(tokens)
Same as above, but handles fragment shaders, where varying
will be converted to in
.
Limitations
If any of your attributes conflict with a new builtin function or keyword like texture
or sample
, this method will throw an error.
License
MIT, see LICENSE.md for details.