webgl-to-opengl
Convert GLSL from WebGL to OpenGL
Last updated a year ago by kazmer .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install webgl-to-opengl 
SYNC missed versions from official npm registry.

glsl-100-to-300

unstable

Transpile GLSL source tokens from version "100" (WebGL1) to "300 es" (WebGL2).

Example

Source:

var transpile = require('glsl-100-to-300')
var tokenize = require('glsl-tokenizer')
var stringify = require('glsl-token-string')

var tokens = transpile.fragment(tokenize(inputShader))
console.log(stringify(tokens))

Input fragment shader:

#version 100
#extension GL_OES_standard_derivatives : enable
varying vec2 vUv;
uniform sampler2D iChannel0;

void main() {
  float sample = 1.0;
  vec4 fragColor = vec4(sample);
  gl_FragColor = texture2D(iChannel0, vUv);
}

The resulting WebGL2 shader.

#version 300 es
out vec4 fragColor_1;
in vec2 vUv;
uniform sampler2D iChannel0;

void main() {
  float sample_0 = 1.0;
  vec4 fragColor = vec4(sample_0);
  fragColor_1 = texture(iChannel0, vUv);
}

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

NPM

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.

Current Tags

  • 0.0.17                                ...           latest (a year ago)

17 Versions

  • 0.0.17                                ...           a year ago
  • 0.0.16                                ...           2 years ago
  • 0.0.15                                ...           2 years ago
  • 0.0.14                                ...           2 years ago
  • 0.0.13                                ...           2 years ago
  • 0.0.12                                ...           2 years ago
  • 0.0.11                                ...           2 years ago
  • 0.0.10                                ...           2 years ago
  • 0.0.9                                ...           2 years ago
  • 0.0.8                                ...           2 years ago
  • 0.0.7                                ...           2 years ago
  • 0.0.6                                ...           2 years ago
  • 0.0.5                                ...           2 years ago
  • 0.0.4                                ...           3 years ago
  • 0.0.3                                ...           3 years ago
  • 0.0.2                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 20
Dependencies (2)
Dev Dependencies (2)

Copyright 2014 - 2017 © taobao.org |