effects/seriously.invert.js (40 lines of code) (raw):
/* global define, require */
(function (root, factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['seriously'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS
factory(require('seriously'));
} else {
if (!root.Seriously) {
root.Seriously = { plugin: function (name, opt) { this[name] = opt; } };
}
factory(root.Seriously);
}
}(this, function (Seriously) {
'use strict';
Seriously.plugin('invert', {
commonShader: true,
shader: function (inputs, shaderSource) {
shaderSource.fragment = [
'precision mediump float;',
'varying vec2 vTexCoord;',
'uniform sampler2D source;',
'void main(void) {',
' gl_FragColor = texture2D(source, vTexCoord);',
' gl_FragColor = vec4(1.0 - gl_FragColor.rgb, gl_FragColor.a);',
'}'
].join('\n');
return shaderSource;
},
inPlace: true,
inputs: {
source: {
type: 'image',
uniform: 'source',
shaderDirty: false
}
},
title: 'Invert',
description: 'Invert image color'
});
}));