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 🙏

© 2024 – Pkg Stats / Ryan Hefner

browserify-shader

v0.1.2

Published

Super simple WebGL shader loader plugin for browserify

Downloads

20

Readme

browserify-shader Build Status

super simple browserify transform for loading webgl shaders

Installation:

npm install browserify-shader --save NPM

Usage:

Simply use require() to load your shader files:

var vs = require('./vertex.c');
var fs = require('./fragment.c');

WebGL API example:

var vs = require('./vertex.c');
var fs = require('./fragment.c');

var shader = gl.createShader(gl.VERTEX_SHADER)
gl.shaderSource(shader, vs()); 
gl.compileShader(shader);
gl.attachShader(yourWebGLProg, shader);

THREE.js example:

var vs = require('./vertex.c');
var fs = require('./fragment.c');

var myMaterial = new THREE.ShaderMaterial({
        uniforms: uniforms,
        attributes: attributes,
        vertexShader: vs(),
        fragmentShader: fs(),
        transparent: true,
        side: THREE.BackSide
    });

Parameterised shaders:

You can add compile-time parameters in your shaders. Simply add {{foo}}-style parameters, eg.:

attribute vec3 pos;
void main() {
  gl_Position = vec4(pos, {{zoom}});
}

Then in your code:

var vs = require('./vertex.c');
...
gl.shaderSource(shader, vs({
    zoom: "2.0"
  })); 

For runtime parameters, use uniform-s in the shader.

Extensions

browserify-shader recognises the following extensions by default:

[
    "c"
  , "glsl"
  , "vert"
  , "frag"
  , "vs"
  , "fs"
  , "gs"
  , "vsh"
  , "fsh"
  , "gsh"
  , "vshader"
  , "fshader"
  , "gshader"
];

You can add/delete/modify this list using:

require("browserify-shader").extensions = ["vertexshader", "fragmentshader", "c"]

How to run

Options

The following options will work if you want to customize your transform:

  • parameterize: Boolean
    • enables parameterised shaders, Note: if disabled, modules will be required/imported as strings instead of functions.
  • module: String
    • configures module type incase your using an es6 transpiler with browserify, possibilities are "es6"/"es2015" and "common" (default).

CLI:

run browserify with the transform option:

browserify -t browserify-shader entry-point.js
browserify -t [browserify-shader --parameterize=true] entry-point.js

Node/grunt:

When compiling using Javascript code custom extensions can be set:

var browserify = require("browserify");
var browserifyShader = require("browserify-shader")

browserify("./index.js");
  .transform(browserifyShader, {
     module: "es6"
  });
  .bundle()
  .pipe(fs.createWriteStream("./bundle.js"));

Gulp + Watchify

var gulp = require('gulp')
var source = require('vinyl-source-stream')

gulp.task('watch', function() {
  var bundler = watchify('./src/index.js');
  bundler.transform('browserify-shader') 

  bundler.on('update', rebundle)

  function rebundle () {
    return bundler.bundle()
      .pipe(source('bundle.js'))
      .pipe(gulp.dest('./dist'))
  }

  return rebundle()
})