npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

shaderify

v0.2.0

Published

Browser module and browserify plugin for compiling webgl shaders

Downloads

7

Readme

shaderify

Browser module, webpack loader, and browserify plug-in for compiling WebGL shaders.

Usage

Server side (webpack):

	module: {
		loaders: [
			{ test: /\.shader$/, loader: "shaderify" },
		]
	}

Server side (browserify):

var browserify = require('browserify-middleware');
var shaderify = require('shaderify');
var express = require('express');
var app = express();

app.use('/example.js', browserify('./example.js', { transform: shaderify() }));
//...

Client Side:

var gl = ...;
gl.bindBuffer(...);

// Create the shader
var flat = require('./flat.shader')(gl);

// Initialize the shader
flat.use();
flat.color = new Float32Array([1, 0, 1, 1]);
flat.project = new Float32Array([1, 0, 0, 0,  0, 1, 0, 0,  0, 0, 1, 0,  0, 0, 0, 1]);
flat.position.enable();
flat.position.pointer(2, gl.FLOAT, false, 8, 0);

// Draw the array
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);

Check out the example folder for a complete working implementation.

Example

webpack example

browserify example

Server Side API

On the server shaderify is a browserify transform plug-in for compiling shader programs into your browserify bundles.

It will also work as a webpack loader. It works just like the browserify plug-in. Set up the loader in your webpack.config.js:

	module: {
		loaders: [
			{ test: /\.shader$/, loader: "shaderify" },
		]
	}

or specify the loader inline

var flat = require('shaderify!./flat.shader')(gl);

.shader file

Browserify expects each require directive to specify a single file, but WebGL shaders are made up of a vertex and a fragment shader program. To specify both components of the shader program you create a JSON file with this format:

{
  vertex: 'myshader.vert'
  fragment: 'myshader.frag'
}

Each member can be a string containing the path to a file to load. If the string contains the character '{' it is interpreted directly as a shader program. An array of lines may be specified, in which case they are .join('\n')'ed to make the program.

When a .shader file is require'd in a browserify or webpack module it is converted into a function taking a WebGL context returning a ShaderProgram.

Client Side API

ShaderProgram

A wrapper around a WebGL shader program with accessors for the shader uniforms and attributes. The interface was inspired by shayda.

new shaderify.ShaderProgram(program, gl)

Create a new wrapper from a linked WebGL program and a context. Accessors for the uniforms and attributes of the shader are automatically created.

Uniforms

The ShaderProgram constructor will create setters and getters for each uniform in the program. If the shader program contains a declaration uniform lowp vec4 color, then you set the value with shader.color = new Float32Array([1, 0, 0, 1]); or with shader.setColor(1, 0, 0, 1).

Attributes

Each attribute in the shader program will create an attribute object. A shader program containing attribute vec4 position would create these methods:

shader.position.enable();
shader.position.disable();
shader.position.pointer(size, type, normalize, stride, offset);

Compiling

The shaderify server side plug-in will usually take care of this for you, but if you have vertex and fragment shader as strings they can be compiled to a ShaderProgram directly.

var program = shaderify.compile(gl, vert_src, frag_src);

License

MIT