← All tools

glslify

Popularity 65 Updated Development & Build

A node.js-style module system for GLSL!

npmauto-collected

Installation

npm
npm install -g glslify

Install with npm.

glslify [![stability][0]][1]

A node.js-style module system for GLSL!

This module contains:

  • glslify's command-line interface (CLI)
  • glslify node/electron interface
  • browserify transform

It forms one of the core components of the stack.gl ecosystem, allowing you to install GLSL modules from npm and use them in your shaders. This makes it trivial to piece together different effects and techniques from the community, including but certainly not limited to fog, noise, film grain, raymarching helpers, easing functions and lighting models.

A full list can be found on the stack.gl packages list under the "Shader Components" category.

Because glslify just outputs a single shader file as a string, it's easy to use it with any WebGL framework of your choosing, provided they accept custom shaders. Integration is planned for three.js and pex, with more on the way! Open an issue here if you'd like to discuss integrating glslify with your platform of choice.

If you're interested in playing around with glslify, you should check out glslb.in: it's a fragment shader sandbox similar to Shadertoy and GLSL Sandbox with built in support for glslify.

Example

var glsl = require('glslify')
console.log(glsl(`
  #pragma glslify: noise = require('glsl-noise/simplex/3d')

  precision mediump float;
  varying vec3 vpos;
  void main () {
    gl_FragColor = vec4(noise(vpos*25.0),1);
  }
`))

Module API

var glsl = require('glslify')

var src = glsl\shader source...\

Compile a shader inline using glsl as a tagged template string function.

var src = glsl(file, opts)

var src = glsl(shaderSource, opts)

Compile a shader using an inline shader string or a file name.

These are convencience methods provided that call glsl.compile() or glsl.file() accordingly. These methods are also provided for backwards compatibility with the previous < 6 interface.