Skip to content

Instantly share code, notes, and snippets.

@amadeus
Created November 26, 2014 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amadeus/536ddf5a8d53ca692b2e to your computer and use it in GitHub Desktop.
Save amadeus/536ddf5a8d53ca692b2e to your computer and use it in GitHub Desktop.
/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
/**
* This inverts your Display Objects colors.
*
* @class InvertFilter
* @extends AbstractFilter
* @constructor
*/
PIXI.InvertFilter = function()
{
PIXI.AbstractFilter.call( this );
this.passes = [this];
// set the uniforms
this.uniforms = {
invert: {type: '1f', value: 1}
};
this.fragmentSrc = [
'precision mediump float;',
'varying vec2 vTextureCoord;',
'varying vec4 vColor;',
'uniform float invert;',
'uniform sampler2D uSampler;',
'void main(void) {',
' gl_FragColor = texture2D(uSampler, vTextureCoord);',
' gl_FragColor.rgb = mix( (vec3(1)-gl_FragColor.rgb) * gl_FragColor.a, gl_FragColor.rgb, 1.0 - invert);',
//' gl_FragColor.rgb = gl_FragColor.rgb * gl_FragColor.a;',
// ' gl_FragColor = gl_FragColor * vColor;',
'}'
];
};
PIXI.InvertFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
PIXI.InvertFilter.prototype.constructor = PIXI.InvertFilter;
/**
* The strength of the invert. 1 will fully invert the colors, 0 will make the object its normal color
* @property invert
* @type Number
*/
Object.defineProperty(PIXI.InvertFilter.prototype, 'invert', {
get: function() {
return this.uniforms.invert.value;
},
set: function(value) {
this.uniforms.invert.value = value;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment