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

phaser-glsl-loader

v0.0.5

Published

A shader loader for webpack that allows you to keep your glsl files external when working in phaser.

Downloads

10

Readme

#Phaser GLSL Loader

Build Status

Coverage Status

Code Climate

David-Dm

This is a simple GLSL loader that is meant to work with Phaser and Webpack.

##The Problem:

Lets say you're working in phaser, and you see a really cool looking fragment shader you want to use.

Some cool shader

So you go to the phaser examples, and they show you to integrate your code just like this:

var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { create: create, update: update });

var filter;
var sprite;

function create() {

    //  From http://glslsandbox.com/e#20450.0

    var fragmentSrc = [
        "precision mediump float;",
        "uniform vec2      resolution;",
        "uniform float     time;",

        "float size = 0.002;",

        "void main( void ) {",
            "vec2 view = ( gl_FragCoord.xy - resolution / 2.0 ) / ( resolution.y / 2.0);",
            "float time = time + length(view)*8.;",
            "vec4 color = vec4(0);",
            "vec2 center = vec2(0);",
            "float rotationVelocity = 2.0;",
            "for( int j = 0; j < 20; j++ ) {",
                "for( int i = 0; i < 20; i++ ) {",
                    "float amplitude = ( cos( time / 10.0 ) + sin(  time /5.0 ) ) / 2.0;",
                    "float angle =   sin( float(j) * time) * rotationVelocity + 2.0 * 3.14 * float(i) / 20.0;",
                    "center.x = cos( 7.0 * float(j) / 20.0 * 2.0 * 3.14 ) + sin( time / 4.0);",
                    "center.y = sin( 3.0 * float(j) / 20.0 * 2.0 *  3.14 )+ cos( time / 8.0);",
                    "vec2 light = center + amplitude * vec2( cos( angle ), sin( angle ));",
                    "//size = sin( time ) * 0.005;",
                    "float l = size / length( view - light );",
                    "vec4 c = vec4( l / 20.0, l, l, 1.0 ) / 5.0;",
                    "color += c;",
                "}",
            "}",
            "gl_FragColor = color;",
        "}"
    ];

    filter = new Phaser.Filter(game, null, fragmentSrc);
    filter.setResolution(800, 600);

    sprite = game.add.sprite();
    sprite.width = 800;
    sprite.height = 600;

    sprite.filters = [ filter ];

}

function update() {
    filter.update();
}

Man, what mess! Wouldnt it be awesome if you could just put the shader into a seperate file and load it that way?

var fragmentSrc = require('../shaders/cubething.frag'),

You could cut all that code out into a simple require statement! That is what this loader is for.

The Solution

First, you need to add the loader to your list of loaders, most likely in your webpack.config.js file.

Something like this:

var path = require('path');
var glFragmentLoader = path.join(__dirname, '/node_modules/phaser-glsl-loader');

module.exports = {
  module: {
    loaders: [
      {
        test: /\.frag$/i,
        loader: 'gl-fragment-loader'
      }
    ]
  },
  resolveLoader: {
    alias: {
      'gl-fragment-loader': glFragmentLoader,
    }
  }
};

Then you'll be able to reference external files, instead of basically including a large array of strings!