Home

Awesome

babel-plugin-glslify

A babel transform for glslify.

Example

This module works the same as the browserify transform in glslify, except that it is compatible with babel. It also supports ES6 syntax and some more advanced features like tagged strings. For example, you can write something like this,

import glsl from "glslify";

const myFragShader = glsl`
#pragma glslify: noise = require(glsl-noise/simplex/2d)

void main () {
  float brightness = noise(gl_FragCoord.xy);
  gl_FragColor = vec4(vec3(brightness), 1.);
}
`;

Configuration

To install this module, you need to install glslify as well:

npm i -S glslify babel-plugin-glslify

Then you need to configure babel to run the transform. For example, if you were using browserify with babelify to run babel you would add the following to your package.json to run glslify:

// ... in your package.json
"browserify": {
  "transform": [[
    "babelify", {
      "presets": ["es2015"],
      "plugins": ["glslify"]
    }
  ]]
}

License

(c) 2016 MIT License