Compare commits

...
Sign in to create a new pull request.

3 commits

Author SHA1 Message Date
Chad Engler
9d9b36329c Merge branch 'master' into palette-swap-filter 2014-02-10 11:59:34 -08:00
Chad Engler
f7f35f2060 Merge branch 'dev' into palette-swap-filter 2014-02-10 11:59:23 -08:00
Chad Engler
43806c63f2 Add Palette filter 2014-01-27 20:04:53 -08:00
2 changed files with 59 additions and 0 deletions

View file

@ -80,6 +80,7 @@ module.exports = function(grunt) {
'<%= dirs.src %>/filters/DotScreenFilter.js',
'<%= dirs.src %>/filters/CrossHatchFilter.js',
'<%= dirs.src %>/filters/RGBSplitFilter.js',
'<%= dirs.src %>/filters/PaletteFilter.js',
'<%= dirs.src %>/Outro.js'
],
banner = [

View file

@ -0,0 +1,58 @@
/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
PIXI.PaletteFilter = function(paletteTexture, paletteWidth)
{
PIXI.AbstractFilter.call(this);
this.passes = [this];
// set the uniforms
this.uniforms = {
palette: { type: 'sampler2D', value: paletteTexture },
width: { type: '1f', value: paletteWidth },
widthInv: { type: '1f', value: 1 / paletteWidth }
};
this.fragmentSrc = [
'precision mediump float;',
'varying vec2 vTextureCoord;',
'varying vec4 vColor;',
'uniform sampler2D uSampler;',
'uniform sampler2D palette;',
'uniform float width;',
'uniform float widthInv;',
'void main() {',
' float index = texture2D(uSampler, vTextureCoord).r * 255.0;', //Red holds index into palette
' vec2 coord = vec2(', //convert index into coords in palette texture
' mod(index, width) * widthInv,',
' (index / width) * widthInv',
' );',
' gl_FragColor = texture2D(palette, coord);', //Read color from palette and output
'}'
];
};
PIXI.PaletteFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
PIXI.PaletteFilter.prototype.constructor = PIXI.PaletteFilter;
Object.defineProperty(PIXI.PaletteFilter.prototype, 'palette', {
get: function() {
return this.uniforms.palette.value;
},
set: function(value) {
this.uniforms.palette.value = value;
}
});
Object.defineProperty(PIXI.PaletteFilter.prototype, 'width', {
get: function() {
return this.uniforms.width.value;
},
set: function(value) {
this.uniforms.width.value = value;
this.uniforms.widthInv.value = 1 / value;
}
});