diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b16c170 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +root = true + +[*.{js,json}] +indent_style = tab +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1fe1b00 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +node_modules/ diff --git a/effects/seriously.accumulator.js b/effects/seriously.accumulator.js deleted file mode 100644 index 13d36d9..0000000 --- a/effects/seriously.accumulator.js +++ /dev/null @@ -1,434 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - /* - Adapted from blend mode shader by Romain Dura - http://mouaif.wordpress.com/2009/01/05/photoshop-math-with-glsl-shaders/ - */ - - function vectorBlendFormula(formula, base, blend) { - function replace(channel) { - var r = { - base: (base || 'base') + '.' + channel, - blend: (blend || 'blend') + '.' + channel - }; - return function (match) { - return r[match] || match; - }; - } - - return 'vec3(' + - formula.replace(/blend|base/g, replace('r')) + ', ' + - formula.replace(/blend|base/g, replace('g')) + ', ' + - formula.replace(/blend|base/g, replace('b')) + - ')'; - } - - var blendModes = { - normal: 'blend', - lighten: 'max(blend, base)', - darken: 'min(blend, base)', - multiply: '(base * blend)', - average: '(base + blend / TWO)', - add: 'min(base + blend, ONE)', - subtract: 'max(base - blend, ZERO)', - divide: 'base / blend', - difference: 'abs(base - blend)', - negation: '(ONE - abs(ONE - base - blend))', - exclusion: '(base + blend - TWO * base * blend)', - screen: '(ONE - ((ONE - base) * (ONE - blend)))', - lineardodge: 'min(base + blend, ONE)', - phoenix: '(min(base, blend) - max(base, blend) + ONE)', - linearburn: 'max(base + blend - ONE, ZERO)', //same as subtract? - - hue: 'BlendHue(base, blend)', - saturation: 'BlendSaturation(base, blend)', - color: 'BlendColor(base, blend)', - luminosity: 'BlendLuminosity(base, blend)', - darkercolor: 'BlendDarkerColor(base, blend)', - lightercolor: 'BlendLighterColor(base, blend)', - - overlay: vectorBlendFormula('base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend))'), - softlight: vectorBlendFormula('blend < 0.5 ? (2.0 * base * blend + base * base * (1.0 - 2.0 * blend)) : (sqrt(base) * (2.0 * blend - 1.0) + 2.0 * base * (1.0 - blend))'), - hardlight: vectorBlendFormula('base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend))', 'blend', 'base'), - colordodge: vectorBlendFormula('blend == 1.0 ? blend : min(base / (1.0 - blend), 1.0)'), - colorburn: vectorBlendFormula('blend == 0.0 ? blend : max((1.0 - ((1.0 - base) / blend)), 0.0)'), - linearlight: vectorBlendFormula('BlendLinearLightf(base, blend)'), - vividlight: vectorBlendFormula('BlendVividLightf(base, blend)'), - pinlight: vectorBlendFormula('BlendPinLightf(base, blend)'), - hardmix: vectorBlendFormula('BlendHardMixf(base, blend)'), - reflect: vectorBlendFormula('BlendReflectf(base, blend)'), - glow: vectorBlendFormula('BlendReflectf(blend, base)') - }, - - /* - All blend modes other than "normal" effectively act as adjustment layers, - so the alpha channel of the resulting image is just a copy of the "bottom" - or "destination" layer. The "top" or "source" alpha is only used to dampen - the color effect. - */ - mixAlpha = { - normal: true - }; - - Seriously.plugin('accumulator', function () { - var drawOpts = { - clear: false - }, - frameBuffers, - fbIndex = 0, - me = this, - width = this.width, - height = this.height; - - function clear() { - var gl = me.gl, - width = me.width, - height = me.height, - color = me.inputs.startColor; - - if (gl && width && height) { - gl.viewport(0, 0, width, height); - gl.clearColor.apply(gl, color); - - gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffers[0].frameBuffer); - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - - gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffers[1].frameBuffer); - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - } - } - - return { - initialize: function (initialize, gl) { - initialize(); - frameBuffers = [ - this.frameBuffer, - new Seriously.util.FrameBuffer(gl, this.width, this.height) - ]; - clear(); - }, - shader: function (inputs, shaderSource) { - var mode = inputs.blendMode || 'normal'; - mode = mode.toLowerCase(); - - shaderSource.fragment = [ - '#define SHADER_NAME seriously.accumulator.' + mode, - 'precision mediump float;', - - 'const vec3 ZERO = vec3(0.0);', - 'const vec3 ONE = vec3(1.0);', - 'const vec3 HALF = vec3(0.5);', - 'const vec3 TWO = vec3(2.0);', - - '#define BlendAddf(base, blend) min(base + blend, 1.0)', - '#define BlendLinearDodgef(base, blend) BlendAddf(base, blend)', - '#define BlendLinearBurnf(base, blend) max(base + blend - 1.0, 0.0)', - '#define BlendLightenf(base, blend) max(blend, base)', - '#define BlendDarkenf(base, blend) min(blend, base)', - '#define BlendLinearLightf(base, blend) (blend < 0.5 ? BlendLinearBurnf(base, (2.0 * blend)) : BlendLinearDodgef(base, (2.0 * (blend - 0.5))))', - '#define BlendScreenf(base, blend) (1.0 - ((1.0 - base) * (1.0 - blend)))', - '#define BlendOverlayf(base, blend) (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)))', - '#define BlendSoftLightf(base, blend) ((blend < 0.5) ? (2.0 * base * blend + base * base * (1.0 - 2.0 * blend)) : (sqrt(base) * (2.0 * blend - 1.0) + 2.0 * base * (1.0 - blend)))', - '#define BlendColorDodgef(base, blend) ((blend == 1.0) ? blend : min(base / (1.0 - blend), 1.0))', - '#define BlendColorBurnf(base, blend) ((blend == 0.0) ? blend : max((1.0 - ((1.0 - base) / blend)), 0.0))', - '#define BlendVividLightf(base, blend) ((blend < 0.5) ? BlendColorBurnf(base, (2.0 * blend)) : BlendColorDodgef(base, (2.0 * (blend - 0.5))))', - '#define BlendPinLightf(base, blend) ((blend < 0.5) ? BlendDarkenf(base, (2.0 * blend)) : BlendLightenf(base, (2.0 *(blend - 0.5))))', - '#define BlendHardMixf(base, blend) ((BlendVividLightf(base, blend) < 0.5) ? 0.0 : 1.0)', - '#define BlendReflectf(base, blend) ((blend == 1.0) ? blend : min(base * base / (1.0 - blend), 1.0))', - - /* - Linear Light is another contrast-increasing mode - If the blend color is darker than midgray, Linear Light darkens the image - by decreasing the brightness. If the blend color is lighter than midgray, - the result is a brighter image due to increased brightness. - */ - - /* - RGB/HSL conversion functions needed for Color, Saturation, Hue, Luminosity, etc. - */ - - 'vec3 RGBToHSL(vec3 color) {', - ' vec3 hsl;', // init to 0 to avoid warnings ? (and reverse if + remove first part) - - ' float fmin = min(min(color.r, color.g), color.b);', //Min. value of RGB - ' float fmax = max(max(color.r, color.g), color.b);', //Max. value of RGB - ' float delta = fmax - fmin;', //Delta RGB value - - ' hsl.z = (fmax + fmin) / 2.0;', // Luminance - - ' if (delta == 0.0) {', //This is a gray, no chroma... - ' hsl.x = 0.0;', // Hue - ' hsl.y = 0.0;', // Saturation - ' } else {', //Chromatic data... - ' if (hsl.z < 0.5)', - ' hsl.y = delta / (fmax + fmin);', // Saturation - ' else', - ' hsl.y = delta / (2.0 - fmax - fmin);', // Saturation - - ' float deltaR = (((fmax - color.r) / 6.0) + (delta / 2.0)) / delta;', - ' float deltaG = (((fmax - color.g) / 6.0) + (delta / 2.0)) / delta;', - ' float deltaB = (((fmax - color.b) / 6.0) + (delta / 2.0)) / delta;', - - ' if (color.r == fmax )', - ' hsl.x = deltaB - deltaG;', // Hue - ' else if (color.g == fmax)', - ' hsl.x = (1.0 / 3.0) + deltaR - deltaB;', // Hue - ' else if (color.b == fmax)', - ' hsl.x = (2.0 / 3.0) + deltaG - deltaR;', // Hue - - ' if (hsl.x < 0.0)', - ' hsl.x += 1.0;', // Hue - ' else if (hsl.x > 1.0)', - ' hsl.x -= 1.0;', // Hue - ' }', - - ' return hsl;', - '}', - - 'float HueToRGB(float f1, float f2, float hue) {', - ' if (hue < 0.0)', - ' hue += 1.0;', - ' else if (hue > 1.0)', - ' hue -= 1.0;', - ' float res;', - ' if ((6.0 * hue) < 1.0)', - ' res = f1 + (f2 - f1) * 6.0 * hue;', - ' else if ((2.0 * hue) < 1.0)', - ' res = f2;', - ' else if ((3.0 * hue) < 2.0)', - ' res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0;', - ' else', - ' res = f1;', - ' return res;', - '}', - - 'vec3 HSLToRGB(vec3 hsl) {', - ' vec3 rgb;', - - ' if (hsl.y == 0.0)', - ' rgb = vec3(hsl.z);', // Luminance - ' else {', - ' float f2;', - - ' if (hsl.z < 0.5)', - ' f2 = hsl.z * (1.0 + hsl.y);', - ' else', - ' f2 = (hsl.z + hsl.y) - (hsl.y * hsl.z);', - - ' float f1 = 2.0 * hsl.z - f2;', - - ' rgb.r = HueToRGB(f1, f2, hsl.x + (1.0/3.0));', - ' rgb.g = HueToRGB(f1, f2, hsl.x);', - ' rgb.b= HueToRGB(f1, f2, hsl.x - (1.0/3.0));', - ' }', - - ' return rgb;', - '}', - - // Hue Blend mode creates the result color by combining the luminance and saturation of the base color with the hue of the blend color. - 'vec3 BlendHue(vec3 base, vec3 blend) {', - ' vec3 baseHSL = RGBToHSL(base);', - ' return HSLToRGB(vec3(RGBToHSL(blend).r, baseHSL.g, baseHSL.b));', - '}', - - // Saturation Blend mode creates the result color by combining the luminance and hue of the base color with the saturation of the blend color. - 'vec3 BlendSaturation(vec3 base, vec3 blend) {', - ' vec3 baseHSL = RGBToHSL(base);', - ' return HSLToRGB(vec3(baseHSL.r, RGBToHSL(blend).g, baseHSL.b));', - '}', - - // Color Mode keeps the brightness of the base color and applies both the hue and saturation of the blend color. - 'vec3 BlendColor(vec3 base, vec3 blend) {', - ' vec3 blendHSL = RGBToHSL(blend);', - ' return HSLToRGB(vec3(blendHSL.r, blendHSL.g, RGBToHSL(base).b));', - '}', - - // Luminosity Blend mode creates the result color by combining the hue and saturation of the base color with the luminance of the blend color. - 'vec3 BlendLuminosity(vec3 base, vec3 blend) {', - ' vec3 baseHSL = RGBToHSL(base);', - ' return HSLToRGB(vec3(baseHSL.r, baseHSL.g, RGBToHSL(blend).b));', - '}', - - // Compares the total of all channel values for the blend and base color and displays the higher value color. - 'vec3 BlendLighterColor(vec3 base, vec3 blend) {', - ' float baseTotal = base.r + base.g + base.b;', - ' float blendTotal = blend.r + blend.g + blend.b;', - ' return blendTotal > baseTotal ? blend : base;', - '}', - - // Compares the total of all channel values for the blend and base color and displays the lower value color. - 'vec3 BlendDarkerColor(vec3 base, vec3 blend) {', - ' float baseTotal = base.r + base.g + base.b;', - ' float blendTotal = blend.r + blend.g + blend.b;', - ' return blendTotal < baseTotal ? blend : base;', - '}', - - '#define BlendFunction(base, blend) ' + blendModes[mode], - (mixAlpha[mode] ? '#define MIX_ALPHA' : ''), - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform sampler2D previous;', - - 'uniform float opacity;', - 'uniform float blendGamma;', - - 'vec3 BlendOpacity(vec4 base, vec4 blend, float opacity) {', - //apply blend, then mix by (opacity * blend.a) - ' vec3 blendedColor = BlendFunction(base.rgb, blend.rgb);', - ' return mix(base.rgb, blendedColor, opacity * blend.a);', - '}', - - 'vec4 linear(vec4 color, vec3 gamma) {', - ' return vec4(pow(color.rgb, gamma), color.a);', - '}', - - 'void main(void) {', - ' vec3 exp = vec3(blendGamma);', - ' vec4 topPixel = linear(texture2D(source, vTexCoord), exp);', - ' vec4 bottomPixel = texture2D(previous, vTexCoord);', - - ' if (topPixel.a == 0.0) {', - ' gl_FragColor = bottomPixel;', - ' } else {', - ' float alpha;', - '#ifdef MIX_ALPHA', - ' alpha = topPixel.a * opacity;', - ' alpha = alpha + bottomPixel.a * (1.0 - alpha);', - '#else', - ' alpha = bottomPixel.a;', - '#endif', - ' bottomPixel = linear(bottomPixel, exp);', - ' gl_FragColor = vec4(pow(BlendOpacity(bottomPixel, topPixel, opacity), 1.0 / exp), alpha);', - ' }', - '}' - ].join('\n'); - - return shaderSource; - }, - resize: function () { - if (frameBuffers && (this.width !== width || this.height !== height)) { - width = this.width; - height = this.height; - frameBuffers[0].resize(width, height); - frameBuffers[1].resize(width, height); - clear(); - } - }, - draw: function (shader, model, uniforms, frameBuffer, draw) { - var fb; - - // ping-pong textures - this.uniforms.previous = this.frameBuffer.texture; - fbIndex = (fbIndex + 1) % 2; - fb = frameBuffers[fbIndex]; - this.frameBuffer = fb; - this.texture = fb.texture; - - if (this.inputs.clear) { - clear(); - draw(this.baseShader, model, uniforms, fb.frameBuffer, null); - return; - } - - draw(shader, model, uniforms, fb.frameBuffer, null, drawOpts); - }, - destroy: function () { - if (frameBuffers) { - frameBuffers[0].destroy(); - frameBuffers[1].destroy(); - frameBuffers.length = 0; - } - } - }; - }, { - inPlace: false, - title: 'Accumulator', - description: 'Draw on top of previous frame', - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - clear: { - type: 'boolean', - defaultValue: false - }, - startColor: { - type: 'color', - defaultValue: [0, 0, 0, 0] - }, - opacity: { - type: 'number', - uniform: 'opacity', - defaultValue: 1, - min: 0, - max: 1 - }, - blendGamma: { - type: 'number', - uniform: 'blendGamma', - defaultValue: 2.2, - min: 0, - max: 4 - }, - blendMode: { - type: 'enum', - shaderDirty: true, - defaultValue: 'normal', - options: [ - ['normal', 'Normal'], - ['lighten', 'Lighten'], - ['darken', 'Darken'], - ['multiply', 'Multiply'], - ['average', 'Average'], - ['add', 'Add'], - ['subtract', 'Subtract'], - ['divide', 'Divide'], - ['difference', 'Difference'], - ['negation', 'Negation'], - ['exclusion', 'Exclusion'], - ['screen', 'Screen'], - ['overlay', 'Overlay'], - ['softlight', 'Soft Light'], - ['hardlight', 'Hard Light'], - ['colordodge', 'Color Dodge'], - ['colorburn', 'Color Burn'], - ['lineardodge', 'Linear Dodge'], - ['linearburn', 'Linear Burn'], - ['linearlight', 'Linear Light'], - ['vividlight', 'Vivid Light'], - ['pinlight', 'Pin Light'], - ['hardmix', 'Hard Mix'], - ['reflect', 'Reflect'], - ['glow', 'Glow'], - ['phoenix', 'Phoenix'], - ['hue', 'Hue'], - ['saturation', 'Saturation'], - ['color', 'color'], - ['luminosity', 'Luminosity'], - ['darkercolor', 'Darker Color'], - ['lightercolor', 'Lighter Color'] - ] - } - } - }); -})); diff --git a/effects/seriously.ascii.js b/effects/seriously.ascii.js deleted file mode 100644 index 7fee535..0000000 --- a/effects/seriously.ascii.js +++ /dev/null @@ -1,186 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - /* - todo: consider an alternative algorithm: - http://tllabs.io/asciistreetview/ - http://sol.gfxile.net/textfx/index.html - */ - - var identity, letters; - - letters = document.createElement('img'); - letters.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAvAAAAAICAYAAACf+MsnAAAFY0lEQVR4Xu2Z644bOwyDN+//0NsOigEMQdRHyU6CFDnA+bHVWNaFojiTx8/Pz+/f/4/89/v7z9Xj8Tjib3XyTN9usFcMz8gt3h9zXf/O6nD/W1V7Vb9uXad+nHucZ9xenX7OqTHdSfmRXfmPsSn8xPMrllcfCkdVfHSe7Ned0/yp7jv2GPfqK+MCByc0zzvxKi5RPq8cuvE4+JrwpFM7N78K2yu+qb9kd3qV+ZjUx5n/+xnXP81ctW/UHQ5P3Gd360vxKf+n8dGpxXTeKu6h2ansFT6pvo5G2/FP99NsUf9d/xleInfetcj629m9cf9WOV5K+78R8ERGRLYO8VQiecd/1vwKEJV46JBJRzhRfXftVL/MTgM48UmL0l2OSmzs9kctAJfE4/1KkNFzbj8cjFHsJ/u460vhnPDfqddujJ27poLCWWBuHt0YKr/ki+yOKJnk5Z7pPLfLf4TZif+qvi7XuDWg+HbtNEe79ds9H7m1m2/3+YzLK5Hc9e/gYxdfNP+ZfdV9lT3usWn+9310/qiAdxa1O5gTEqVhoLudxVwVNPrvCqDp/ZX4d0Uk1Y7sbgyU4zooCk8nB3i9Y61V5wWpIjDlP+ZJsxPvmLxEOD2sntk5Pz1LBOb0L+sPfQGs6ksYpt7QAiHuUwtkgl+F3Qyf2YxTX53+Vdjfjc8VYIq7KT+abzof7ervZ8fX8d/Jyc3PmTcnRrrPEbyVTnD8T+Y38pH624mfNIr6muzO95S/sh1Gvog/XmW/a6N+scww43zgqLjcOX9cwFeESQK3Gpx32QggTlwk8Ei8OXfE4VMLeCLQiLBjfJM7VA069XefnZBGJz7Vr24dK3GwEoqLD7p/1+4IMWdRdxaMK9CmP4E62F7nm8S7s4B3BMCkBzQPVQ0IM06+2WLvzlDlI+NfF4d0ljiHuF/Zb/4m/4ojTgnA6f0qfiWA135P5l/NoFv/7txm+5ZyyOw0e1R/skd8ZKKwwnjXf9xLrkBV+2x3Pib9Vz3JOMaNL/KZ+oCkXhDUTLxEwLsC41OfI5DEYe9+mXfr0l2mJH5ISHTOUw2U8IjD5LyVUtxEmrvi4V5ejvijWNWicBbOyfsrYejkMMXmdIFEAZH19ASWnNyrPlBdKH+yU3y0gGjGKf4Mv51ft9zzKk83vul5qr9r7+CT9gHx2zvs0/yofpGX1AuC4svqhYJeJJydNZk/urcSxet91dfiUy94HX6oBHCHi5+F38svCeg1h+zZ6nyF5VUzVC8Q0X9LwE/IkMjmpJ3i27XvxuqQ0c4dp/JTfnb9T847AoNIW/nokIYrYKvnJvln/siPwtD0XAeTU+x0luEugWdLNeY4ecl260vxK8Efl3OnZi4uaZZIMBFeJ/hw6xrFvppvV1Q559d8MwwR50cskIBQ2KhE3y7/ZeddAUjxOr3diZ/8U3+I953z7uzR7Lj4rvjl9HxXvaHaOflSfSkf93y24xx94PpX89I5H2t9+fwK+KVzNOwdIeM+e905+ZqqRIj7pYHiU3FNFnBnkO+41EKige3cpX7GunwoARfjIwKrxNhEJFLfMrsbI+G/smfkojAa60vxPcNeCZCqhjSra6ydBaAWSFzaqnb01c4VEdVCWWPM7svstKDWuKrZpwUb7dVsOzPcxUeGdYdfdgV8Vr+Mv1R8Tn/iHcSNWR8jjjv9URzama9qbp0XlBP4y2Jw6u/E577AZTVz/BM/OfySzSjl79o73FRxaFdfuPG5/XE58PbXEvAT8UBn1HKuSIB8ThYwiZfJnd8z768Aib/3R/iN4J0VeMXcVwvynbl/735OBV6BKTfyT+e/T4/f7dP3uW8F3Aqs/PIHbWXeeeKjnSsAAAAASUVORK5CYII='; - identity = new Float32Array([ - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 - ]); - - Seriously.plugin('ascii', function () { - var baseShader, - scaledBuffer, - lettersTexture, - gl, - width, - height, - scaledWidth, - scaledHeight, - unif = {}, - me = this; - - function resize() { - //set up scaledBuffer if (width or height have changed) - height = me.height; - width = me.width; - scaledWidth = Math.ceil(width / 8); - scaledHeight = Math.ceil(height / 8); - - unif.resolution = me.uniforms.resolution; - unif.transform = identity; - - if (scaledBuffer) { - scaledBuffer.resize(scaledWidth, scaledHeight); - } - } - - return { - initialize: function (parent) { - function setLetters() { - gl.bindTexture(gl.TEXTURE_2D, lettersTexture); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, letters); - gl.bindTexture(gl.TEXTURE_2D, null); - } - - var me = this; - - parent(); - this.texture = this.frameBuffer.texture; - - gl = this.gl; - - lettersTexture = gl.createTexture(); - if (letters.naturalWidth) { - setLetters(); - } else { - letters.addEventListener('load', function () { - setLetters(); - me.setDirty(); - }); - } - - unif.letters = lettersTexture; - - //when the output scales up, don't smooth it out - gl.bindTexture(gl.TEXTURE_2D, this.texture || this.frameBuffer && this.frameBuffer.texture); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); - gl.bindTexture(gl.TEXTURE_2D, null); - - resize(); - - scaledBuffer = new Seriously.util.FrameBuffer(gl, scaledWidth, scaledHeight); - - //so it stays blocky - gl.bindTexture(gl.TEXTURE_2D, scaledBuffer.texture); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); - - this.uniforms.transform = identity; - - baseShader = this.baseShader; - }, - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform sampler2D letters;', - 'uniform vec4 background;', - 'uniform vec2 resolution;', - - 'const vec3 lumcoeff = vec3(0.2125, 0.7154, 0.0721);', - 'const vec2 fontSize = vec2(8.0, 8.0);', - - 'vec4 lookup(float ascii) {', - ' vec2 pos = mod(vTexCoord * resolution, fontSize) / vec2(752.0, fontSize.x) + vec2(ascii, 0.0);', - ' return texture2D(letters, pos);', - '}', - - 'void main(void) {', - ' vec4 sample = texture2D(source, vTexCoord);', - ' vec4 clamped = vec4(floor(sample.rgb * 8.0) / 8.0, sample.a);', - - ' float luma = dot(sample.rgb,lumcoeff);', - ' float char = floor(luma * 94.0) / 94.0;', - - ' gl_FragColor = mix(background, clamped, lookup(char).r);', - '}' - ].join('\n'); - - return shaderSource; - }, - resize: resize, - draw: function (shader, model, uniforms, frameBuffer, draw) { - draw(baseShader, model, uniforms, scaledBuffer.frameBuffer, false, { - width: scaledWidth, - height: scaledHeight, - blend: false - }); - - unif.source = scaledBuffer.texture; - unif.background = uniforms.background; - - draw(shader, model, unif, frameBuffer); - }, - destroy: function () { - if (scaledBuffer) { - scaledBuffer.destroy(); - } - if (gl && lettersTexture) { - gl.deleteTexture(lettersTexture); - } - } - }; - }, - { - inPlace: false, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - }, - background: { - type: 'color', - uniform: 'background', - defaultValue: [0, 0, 0, 1] - } - }, - description: 'Display image as ascii text in 8-bit color.', - title: 'Ascii Text' - }); -})); diff --git a/effects/seriously.bleach-bypass.js b/effects/seriously.bleach-bypass.js deleted file mode 100644 index 0c48380..0000000 --- a/effects/seriously.bleach-bypass.js +++ /dev/null @@ -1,90 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - /* - Shader code: - * Copyright vade - Anton Marini - * Creative Commons, Attribution - Non Commercial - Share Alike 3.0 - - http://v002.info/?page_id=34 - - Modified to keep alpha channel constant - */ - - Seriously.plugin('bleach-bypass', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - - 'uniform float amount;', - - //constants - 'const vec4 one = vec4(1.0);', - 'const vec4 two = vec4(2.0);', - 'const vec4 lumcoeff = vec4(0.2125,0.7154,0.0721,0.0);', - - 'vec4 overlay(vec4 myInput, vec4 previousmix, vec4 amount) {', - ' float luminance = dot(previousmix,lumcoeff);', - ' float mixamount = clamp((luminance - 0.45) * 10.0, 0.0, 1.0);', - - ' vec4 branch1 = two * previousmix * myInput;', - ' vec4 branch2 = one - (two * (one - previousmix) * (one - myInput));', - - ' vec4 result = mix(branch1, branch2, vec4(mixamount) );', - - ' return mix(previousmix, result, amount);', - '}', - - 'void main (void) {', - ' vec4 pixel = texture2D(source, vTexCoord);', - ' vec4 luma = vec4(vec3(dot(pixel,lumcoeff)), pixel.a);', - ' gl_FragColor = overlay(luma, pixel, vec4(amount));', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - }, - amount: { - type: 'number', - uniform: 'amount', - defaultValue: 1, - min: 0, - max: 1 - } - }, - title: 'Bleach Bypass', - categories: ['film'], - description: [ - 'Bleach Bypass film treatment', - 'http://en.wikipedia.org/wiki/Bleach_bypass', - 'see: "Saving Private Ryan", "Minority Report"' - ].join('\n') - }); -})); diff --git a/effects/seriously.blend.js b/effects/seriously.blend.js deleted file mode 100644 index 24fc9ac..0000000 --- a/effects/seriously.blend.js +++ /dev/null @@ -1,627 +0,0 @@ -/* global define, require, exports, Float32Array */ -(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); - } -}(window, function (Seriously) { - 'use strict'; - - /* - todo: if transforms are used, do multiple passes and enable depth testing? - todo: for now, only supporting float blend modes. Add complex ones - todo: apply proper credit and license - - Adapted from blend mode shader by Romain Dura - http://mouaif.wordpress.com/2009/01/05/photoshop-math-with-glsl-shaders/ - */ - - function vectorBlendFormula(formula, base, blend) { - function replace(channel) { - var r = { - base: (base || 'base') + '.' + channel, - blend: (blend || 'blend') + '.' + channel - }; - return function (match) { - return r[match] || match; - }; - } - - return 'vec3(' + - formula.replace(/blend|base/g, replace('r')) + ', ' + - formula.replace(/blend|base/g, replace('g')) + ', ' + - formula.replace(/blend|base/g, replace('b')) + - ')'; - } - - var blendModes = { - normal: 'blend', - lighten: 'max(blend, base)', - darken: 'min(blend, base)', - multiply: '(base * blend)', - average: '(base + blend / TWO)', - add: 'min(base + blend, ONE)', - subtract: 'max(base - blend, ZERO)', - divide: 'base / blend', - difference: 'abs(base - blend)', - negation: '(ONE - abs(ONE - base - blend))', - exclusion: '(base + blend - TWO * base * blend)', - screen: '(ONE - ((ONE - base) * (ONE - blend)))', - lineardodge: 'min(base + blend, ONE)', - phoenix: '(min(base, blend) - max(base, blend) + ONE)', - linearburn: 'max(base + blend - ONE, ZERO)', - - hue: 'BlendHue(base, blend)', - saturation: 'BlendSaturation(base, blend)', - color: 'BlendColor(base, blend)', - luminosity: 'BlendLuminosity(base, blend)', - darkercolor: 'BlendDarkerColor(base, blend)', - lightercolor: 'BlendLighterColor(base, blend)', - - overlay: vectorBlendFormula('base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend))'), - softlight: vectorBlendFormula('blend < 0.5 ? (2.0 * base * blend + base * base * (1.0 - 2.0 * blend)) : (sqrt(base) * (2.0 * blend - 1.0) + 2.0 * base * (1.0 - blend))'), - hardlight: vectorBlendFormula('base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend))', 'blend', 'base'), - colordodge: vectorBlendFormula('blend == 1.0 ? blend : min(base / (1.0 - blend), 1.0)'), - colorburn: vectorBlendFormula('blend == 0.0 ? blend : max((1.0 - ((1.0 - base) / blend)), 0.0)'), - linearlight: vectorBlendFormula('BlendLinearLightf(base, blend)'), - vividlight: vectorBlendFormula('BlendVividLightf(base, blend)'), - pinlight: vectorBlendFormula('BlendPinLightf(base, blend)'), - hardmix: vectorBlendFormula('BlendHardMixf(base, blend)'), - reflect: vectorBlendFormula('BlendReflectf(base, blend)'), - glow: vectorBlendFormula('BlendReflectf(blend, base)') - }, - nativeBlendModes = { - //native blend modes removed for now, because they don't work with linear blending - // normal: ['FUNC_ADD', 'SRC_ALPHA', 'ONE_MINUS_SRC_ALPHA', 'SRC_ALPHA', 'DST_ALPHA'] - //todo: add, multiply, screen - }, - identity = new Float32Array([ - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 - ]); - - Seriously.plugin('blend', function () { - var topUniforms, - bottomUniforms, - topOpts = { - clear: false - }, - inputs, - gl; - - function updateDrawFunction() { - var nativeMode = inputs && nativeBlendModes[inputs.mode]; - if (nativeMode && gl) { - topOpts.blendEquation = gl[nativeMode[0]]; - topOpts.srcRGB = gl[nativeMode[1]]; - topOpts.dstRGB = gl[nativeMode[2]]; - topOpts.srcAlpha = gl[nativeMode[3]]; - topOpts.dstAlpha = gl[nativeMode[4]]; - } - } - - // custom resize method - this.resize = function () { - var width, - height, - mode = this.inputs.sizeMode, - node, - fn, - i, - bottom = this.inputs.bottom, - top = this.inputs.top; - - if (mode === 'bottom' || mode === 'top') { - node = this.inputs[mode]; - if (node) { - width = node.width; - height = node.height; - } else { - width = 1; - height = 1; - } - } else { - if (bottom) { - if (top) { - fn = (mode === 'union' ? Math.max : Math.min); - width = fn(bottom.width, top.width); - height = fn(bottom.height, top.height); - } else { - width = bottom.width; - height = bottom.height; - } - } else if (top) { - width = top.width; - height = top.height; - } else { - width = 1; - height = 1; - } - } - - if (this.width !== width || this.height !== height) { - this.width = width; - this.height = height; - - this.uniforms.resolution[0] = width; - this.uniforms.resolution[1] = height; - - if (this.frameBuffer) { - this.frameBuffer.resize(width, height); - } - - this.emit('resize'); - this.setDirty(); - } - - this.uniforms.resBottom[0] = bottom && bottom.width || 1; - this.uniforms.resBottom[1] = bottom && bottom.height || 1; - this.uniforms.resTop[0] = top && top.width || 1; - this.uniforms.resTop[1] = top && top.height || 1; - - if (topUniforms) { - if (bottom) { - bottomUniforms.resolution[0] = bottom.width; - bottomUniforms.resolution[1] = bottom.height; - } - if (top) { - topUniforms.resolution[0] = top.width; - topUniforms.resolution[1] = top.height; - } - } - - for (i = 0; i < this.targets.length; i++) { - this.targets[i].resize(); - } - }; - - this.uniforms.resTop = [1, 1]; - this.uniforms.resBottom = [1, 1]; - - return { - initialize: function (initialize) { - inputs = this.inputs; - initialize(); - gl = this.gl; - updateDrawFunction(); - }, - shader: function (inputs, shaderSource) { - var mode = inputs.mode || 'normal', - node; - mode = mode.toLowerCase(); - - if (nativeBlendModes[mode]) { - //todo: move this to an 'update' event for 'mode' input - if (!topUniforms) { - node = this.inputs.top; - topUniforms = { - resolution: [ - node && node.width || 1, - node && node.height || 1 - ], - targetRes: this.uniforms.resolution, - source: node, - transform: node && node.cumulativeMatrix || identity, - opacity: this.inputs.opacity - }; - - node = this.inputs.bottom; - bottomUniforms = { - resolution: [ - node && node.width || 1, - node && node.height || 1 - ], - targetRes: this.uniforms.resolution, - source: node, - transform: node && node.cumulativeMatrix || identity, - opacity: 1 - }; - } - - shaderSource.vertex = [ - '#define SHADER_NAME seriously.blend.' + mode, - 'precision mediump float;', - - 'attribute vec4 position;', - 'attribute vec2 texCoord;', - - 'uniform vec2 resolution;', - 'uniform vec2 targetRes;', - 'uniform mat4 transform;', - - 'varying vec2 vTexCoord;', - - 'void main(void) {', - // first convert to screen space - ' vec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);', - ' screenPosition = transform * screenPosition;', - - // convert back to OpenGL coords - ' gl_Position.xy = screenPosition.xy * 2.0 / resolution;', - ' gl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);', - ' gl_Position.xy *= resolution / targetRes;', - ' gl_Position.w = screenPosition.w;', - ' vTexCoord = texCoord;', - '}\n' - ].join('\n'); - - shaderSource.fragment = [ - '#define SHADER_NAME seriously.blend.' + mode, - 'precision mediump float;', - 'varying vec2 vTexCoord;', - 'uniform sampler2D source;', - 'uniform float opacity;', - 'void main(void) {', - ' gl_FragColor = texture2D(source, vTexCoord);', - ' gl_FragColor.a *= opacity;', - '}' - ].join('\n'); - - return shaderSource; - } - - topUniforms = null; - bottomUniforms = null; - - //todo: need separate texture coords for different size top/bottom images - shaderSource.vertex = [ - '#define SHADER_NAME seriously.blend.' + mode, - 'precision mediump float;', - - 'attribute vec4 position;', - 'attribute vec2 texCoord;', - - 'uniform vec2 resolution;', - 'uniform vec2 resBottom;', - 'uniform vec2 resTop;', - - 'varying vec2 texCoordBottom;', - 'varying vec2 texCoordTop;', - - 'const vec2 HALF = vec2(0.5);', - - 'void main(void) {', - //we don't need to do a transform in this shader, since this effect is not "inPlace" - ' gl_Position = position;', - - ' vec2 adjusted = (texCoord - HALF) * resolution;', - - ' texCoordBottom = adjusted / resBottom + HALF;', - ' texCoordTop = adjusted / resTop + HALF;', - '}' - ].join('\n'); - - shaderSource.fragment = [ - '#define SHADER_NAME seriously.blend.' + mode, - 'precision mediump float;', - - 'const vec3 ZERO = vec3(0.0);', - 'const vec3 ONE = vec3(1.0);', - 'const vec3 HALF = vec3(0.5);', - 'const vec3 TWO = vec3(2.0);', - - /* - Linear Light is another contrast-increasing mode - If the blend color is darker than midgray, Linear Light darkens the image - by decreasing the brightness. If the blend color is lighter than midgray, - the result is a brighter image due to increased brightness. - */ - - '#define BlendAddf(base, blend) min(base + blend, 1.0)', - '#define BlendLinearDodgef(base, blend) BlendAddf(base, blend)', - '#define BlendLinearBurnf(base, blend) max(base + blend - 1.0, 0.0)', - '#define BlendLightenf(base, blend) max(blend, base)', - '#define BlendDarkenf(base, blend) min(blend, base)', - '#define BlendLinearLightf(base, blend) (blend < 0.5 ? BlendLinearBurnf(base, (2.0 * blend)) : BlendLinearDodgef(base, (2.0 * (blend - 0.5))))', - '#define BlendScreenf(base, blend) (1.0 - ((1.0 - base) * (1.0 - blend)))', - '#define BlendOverlayf(base, blend) (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)))', - '#define BlendSoftLightf(base, blend) ((blend < 0.5) ? (2.0 * base * blend + base * base * (1.0 - 2.0 * blend)) : (sqrt(base) * (2.0 * blend - 1.0) + 2.0 * base * (1.0 - blend)))', - '#define BlendColorDodgef(base, blend) ((blend == 1.0) ? blend : min(base / (1.0 - blend), 1.0))', - '#define BlendColorBurnf(base, blend) ((blend == 0.0) ? blend : max((1.0 - ((1.0 - base) / blend)), 0.0))', - '#define BlendVividLightf(base, blend) ((blend < 0.5) ? BlendColorBurnf(base, (2.0 * blend)) : BlendColorDodgef(base, (2.0 * (blend - 0.5))))', - '#define BlendPinLightf(base, blend) ((blend < 0.5) ? BlendDarkenf(base, (2.0 * blend)) : BlendLightenf(base, (2.0 *(blend - 0.5))))', - '#define BlendHardMixf(base, blend) ((BlendVividLightf(base, blend) < 0.5) ? 0.0 : 1.0)', - '#define BlendReflectf(base, blend) ((blend == 1.0) ? blend : min(base * base / (1.0 - blend), 1.0))', - - /* - RGB/HSL conversion functions needed for Color, Saturation, Hue, Luminosity, etc. - */ - - 'vec3 RGBToHSL(vec3 color) {', - ' vec3 hsl;', // init to 0 to avoid warnings ? (and reverse if + remove first part) - - ' float fmin = min(min(color.r, color.g), color.b);', //Min. value of RGB - ' float fmax = max(max(color.r, color.g), color.b);', //Max. value of RGB - ' float delta = fmax - fmin;', //Delta RGB value - - ' hsl.z = (fmax + fmin) / 2.0;', // Luminance - - ' if (delta == 0.0) {', //This is a gray, no chroma... - ' hsl.x = 0.0;', // Hue - ' hsl.y = 0.0;', // Saturation - ' } else {', //Chromatic data... - ' if (hsl.z < 0.5)', - ' hsl.y = delta / (fmax + fmin);', // Saturation - ' else', - ' hsl.y = delta / (2.0 - fmax - fmin);', // Saturation - - ' float deltaR = (((fmax - color.r) / 6.0) + (delta / 2.0)) / delta;', - ' float deltaG = (((fmax - color.g) / 6.0) + (delta / 2.0)) / delta;', - ' float deltaB = (((fmax - color.b) / 6.0) + (delta / 2.0)) / delta;', - - ' if (color.r == fmax )', - ' hsl.x = deltaB - deltaG;', // Hue - ' else if (color.g == fmax)', - ' hsl.x = (1.0 / 3.0) + deltaR - deltaB;', // Hue - ' else if (color.b == fmax)', - ' hsl.x = (2.0 / 3.0) + deltaG - deltaR;', // Hue - - ' if (hsl.x < 0.0)', - ' hsl.x += 1.0;', // Hue - ' else if (hsl.x > 1.0)', - ' hsl.x -= 1.0;', // Hue - ' }', - - ' return hsl;', - '}', - - 'float HueToRGB(float f1, float f2, float hue) {', - ' if (hue < 0.0)', - ' hue += 1.0;', - ' else if (hue > 1.0)', - ' hue -= 1.0;', - ' float res;', - ' if ((6.0 * hue) < 1.0)', - ' res = f1 + (f2 - f1) * 6.0 * hue;', - ' else if ((2.0 * hue) < 1.0)', - ' res = f2;', - ' else if ((3.0 * hue) < 2.0)', - ' res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0;', - ' else', - ' res = f1;', - ' return res;', - '}', - - 'vec3 HSLToRGB(vec3 hsl) {', - ' vec3 rgb;', - - ' if (hsl.y == 0.0)', - ' rgb = vec3(hsl.z);', // Luminance - ' else {', - ' float f2;', - - ' if (hsl.z < 0.5)', - ' f2 = hsl.z * (1.0 + hsl.y);', - ' else', - ' f2 = (hsl.z + hsl.y) - (hsl.y * hsl.z);', - - ' float f1 = 2.0 * hsl.z - f2;', - - ' rgb.r = HueToRGB(f1, f2, hsl.x + (1.0/3.0));', - ' rgb.g = HueToRGB(f1, f2, hsl.x);', - ' rgb.b= HueToRGB(f1, f2, hsl.x - (1.0/3.0));', - ' }', - - ' return rgb;', - '}', - - // Hue Blend mode creates the result color by combining the luminance and saturation of the base color with the hue of the blend color. - 'vec3 BlendHue(vec3 base, vec3 blend) {', - ' vec3 baseHSL = RGBToHSL(base);', - ' return HSLToRGB(vec3(RGBToHSL(blend).r, baseHSL.g, baseHSL.b));', - '}', - - // Saturation Blend mode creates the result color by combining the luminance and hue of the base color with the saturation of the blend color. - 'vec3 BlendSaturation(vec3 base, vec3 blend) {', - ' vec3 baseHSL = RGBToHSL(base);', - ' return HSLToRGB(vec3(baseHSL.r, RGBToHSL(blend).g, baseHSL.b));', - '}', - - // Color Mode keeps the brightness of the base color and applies both the hue and saturation of the blend color. - 'vec3 BlendColor(vec3 base, vec3 blend) {', - ' vec3 blendHSL = RGBToHSL(blend);', - ' return HSLToRGB(vec3(blendHSL.r, blendHSL.g, RGBToHSL(base).b));', - '}', - - // Luminosity Blend mode creates the result color by combining the hue and saturation of the base color with the luminance of the blend color. - 'vec3 BlendLuminosity(vec3 base, vec3 blend) {', - ' vec3 baseHSL = RGBToHSL(base);', - ' return HSLToRGB(vec3(baseHSL.r, baseHSL.g, RGBToHSL(blend).b));', - '}', - - // Compares the total of all channel values for the blend and base color and displays the higher value color. - 'vec3 BlendLighterColor(vec3 base, vec3 blend) {', - ' float baseTotal = base.r + base.g + base.b;', - ' float blendTotal = blend.r + blend.g + blend.b;', - ' return blendTotal > baseTotal ? blend : base;', - '}', - - // Compares the total of all channel values for the blend and base color and displays the lower value color. - 'vec3 BlendDarkerColor(vec3 base, vec3 blend) {', - ' float baseTotal = base.r + base.g + base.b;', - ' float blendTotal = blend.r + blend.g + blend.b;', - ' return blendTotal < baseTotal ? blend : base;', - '}', - - '#define BlendFunction(base, blend) ' + blendModes[mode], - - 'varying vec2 texCoordBottom;', - 'varying vec2 texCoordTop;', - - 'uniform sampler2D top;', - 'uniform sampler2D bottom;', - 'uniform float opacity;', - 'uniform float blendGamma;', - - 'vec3 BlendOpacity(vec4 base, vec4 blend, float opacity) {', - //apply blend, then mix by (opacity * blend.a) - ' vec3 blendedColor = BlendFunction(base.rgb, blend.rgb);', - ' return mix(base.rgb, blendedColor, opacity * blend.a);', - '}', - - 'vec4 linear(vec4 color, vec3 gamma) {', - ' return vec4(pow(color.rgb, gamma), color.a);', - '}', - - 'void main(void) {', - ' vec3 exp = vec3(blendGamma);', - ' vec4 topPixel = linear(texture2D(top, texCoordTop), exp);', - ' vec4 bottomPixel = texture2D(bottom, texCoordBottom);', - - ' if (topPixel.a == 0.0) {', - ' gl_FragColor = bottomPixel;', - ' } else {', - ' bottomPixel = linear(bottomPixel, exp);', - ' gl_FragColor = vec4(pow(BlendOpacity(bottomPixel, topPixel, opacity), 1.0 / exp), bottomPixel.a);', - ' }', - '}' - ].join('\n'); - - return shaderSource; - }, - draw: function (shader, model, uniforms, frameBuffer, draw) { - if (nativeBlendModes[this.inputs.mode]) { - if (this.inputs.bottom) { - draw(shader, model, bottomUniforms, frameBuffer); - } else { - //just clear - gl.viewport(0, 0, this.width, this.height); - gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer); - gl.clearColor(0.0, 0.0, 0.0, 0.0); - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - } - - if (this.inputs.top && this.inputs.opacity) { - draw(shader, model, topUniforms, frameBuffer, null, topOpts); - } - } else { - draw(shader, model, uniforms, frameBuffer); - } - }, - requires: function (sourceName) { - if (!this.inputs.opacity && sourceName === 'top') { - return false; - } - return true; - }, - inputs: { - top: { - type: 'image', - uniform: 'top', - update: function () { - if (topUniforms) { - topUniforms.source = this.inputs.top; - topUniforms.transform = this.inputs.top.cumulativeMatrix || identity; - } - this.resize(); - } - }, - bottom: { - type: 'image', - uniform: 'bottom', - update: function () { - if (bottomUniforms) { - bottomUniforms.source = this.inputs.bottom; - bottomUniforms.transform = this.inputs.bottom.cumulativeMatrix || identity; - } - this.resize(); - } - }, - opacity: { - type: 'number', - uniform: 'opacity', - defaultValue: 1, - min: 0, - max: 1, - updateSources: true, - update: function (opacity) { - if (topUniforms) { - topUniforms.opacity = opacity; - } - } - }, - blendGamma: { - type: 'number', - uniform: 'blendGamma', - defaultValue: 2.2, - min: 0, - max: 4 - }, - sizeMode: { - type: 'enum', - defaultValue: 'bottom', - options: [ - 'bottom', - 'top', - 'union', - 'intersection' - ], - update: function () { - this.resize(); - } - }, - mode: { - type: 'enum', - shaderDirty: true, - defaultValue: 'normal', - options: [ - ['normal', 'Normal'], - ['lighten', 'Lighten'], - ['darken', 'Darken'], - ['multiply', 'Multiply'], - ['average', 'Average'], - ['add', 'Add'], - ['subtract', 'Subtract'], - ['divide', 'Divide'], - ['difference', 'Difference'], - ['negation', 'Negation'], - ['exclusion', 'Exclusion'], - ['screen', 'Screen'], - ['overlay', 'Overlay'], - ['softlight', 'Soft Light'], - ['hardlight', 'Hard Light'], - ['colordodge', 'Color Dodge'], - ['colorburn', 'Color Burn'], - ['lineardodge', 'Linear Dodge'], - ['linearburn', 'Linear Burn'], - ['linearlight', 'Linear Light'], - ['vividlight', 'Vivid Light'], - ['pinlight', 'Pin Light'], - ['hardmix', 'Hard Mix'], - ['reflect', 'Reflect'], - ['glow', 'Glow'], - ['phoenix', 'Phoenix'], - ['hue', 'Hue'], - ['saturation', 'Saturation'], - ['color', 'color'], - ['luminosity', 'Luminosity'], - ['darkercolor', 'Darker Color'], - ['lightercolor', 'Lighter Color'] - ], - update: function () { - updateDrawFunction(); - } - } - } - }; - }, - { - inPlace: function () { - return !!nativeBlendModes[this.inputs.mode]; - }, - description: 'Blend two layers', - title: 'Blend' - }); -})); diff --git a/effects/seriously.blur.js b/effects/seriously.blur.js deleted file mode 100644 index efe9993..0000000 --- a/effects/seriously.blur.js +++ /dev/null @@ -1,260 +0,0 @@ -/* global define, require */ -/* -Blur - -Adapted from v002 by Anton Marini and Tom Butterworth -* Copyright vade - Anton Marini -* Creative Commons, Attribution - Non Commercial - Share Alike 3.0 - -http://v002.info/plugins/v002-blurs/ -*/ -(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); - } -}(window, function (Seriously) { - 'use strict'; - - var passes = [0.2, 0.3, 0.5, 0.8, 1], - finalPass = passes.length - 1, - horizontal = [1, 0], - vertical = [0, 1], - identity = new Float32Array([ - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 - ]); - - Seriously.plugin('blur', function (options) { - var fbHorizontal, - fbVertical, - baseShader, - loopUniforms = { - amount: 0, - blendGamma: 2, - inputScale: 1, - resolution: [this.width, this.height], - transform: identity, - direction: null - }; - - return { - initialize: function (parent) { - var gl; - - parent(); - - gl = this.gl; - - if (!gl) { - return; - } - - baseShader = this.baseShader; - - fbHorizontal = new Seriously.util.FrameBuffer(gl, this.width, this.height); - fbVertical = new Seriously.util.FrameBuffer(gl, this.width, this.height); - }, - commonShader: true, - shader: function (inputs, shaderSource) { - var gl = this.gl; - - shaderSource.vertex = [ - 'precision mediump float;', - - 'attribute vec4 position;', - 'attribute vec2 texCoord;', - - 'uniform vec2 resolution;', - 'uniform mat4 transform;', - - 'uniform vec2 direction;', - 'uniform float amount;', - 'uniform float inputScale;', - - 'const vec2 zero = vec2(0.0);', - - 'varying vec2 vTexCoord;', - 'varying vec4 vTexCoords[4];', - - 'void main(void) {', - // first convert to screen space - ' vec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);', - ' screenPosition = transform * screenPosition;', - - // convert back to OpenGL coords - ' gl_Position = screenPosition;', - ' gl_Position.xy = screenPosition.xy * 2.0 / resolution;', - ' gl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);', - ' vTexCoord = texCoord;', - - ' vec2 one = vec2(1.0) * inputScale;', - ' if (inputScale < 1.0) {', - ' one -= 1.0 / resolution;', - ' }', - - ' vTexCoord = max(zero, min(one, texCoord.st * inputScale));', - ' vec2 amount = direction * (inputScale * amount * 5.0 / resolution);', - - ' for (int i = 0; i < 4; i++) {', - ' float s = pow(3.0, float(i));', - ' vTexCoords[i].xy = max(zero, min(one, vTexCoord + amount * s));', - ' vTexCoords[i].zw = max(zero, min(one, vTexCoord - amount * s));', - ' }', - '}' - ].join('\n'); - shaderSource.fragment = [ - 'precision mediump float;\n', - - 'uniform sampler2D source;', - 'uniform float blendGamma;', - - 'varying vec2 vTexCoord;', - 'varying vec4 vTexCoords[4];', - - 'vec3 exp;', - - 'vec4 sample(sampler2D sampler, vec2 coord) {', - ' vec4 pixel = texture2D(sampler, coord);', - ' pixel.rgb = pow(pixel.rgb, exp);', - ' return pixel;', - '}', - - 'void main(void) {', - - ' exp = vec3(blendGamma);', - - ' gl_FragColor = sample(source, vTexCoord) / 9.0;', - - ' for (int i = 0; i < 4; i++) {', - ' gl_FragColor += sample(source, vTexCoords[i].xy) / 9.0;', - ' gl_FragColor += sample(source, vTexCoords[i].zw) / 9.0;', - ' }', - - ' gl_FragColor.rgb = pow(gl_FragColor.rgb, 1.0 / exp);', - - '}', - ].join('\n'); - - return shaderSource; - }, - draw: function (shader, model, uniforms, frameBuffer, parent) { - var i, - pass, - amount, - width, - height, - opts = { - width: 0, - height: 0, - blend: false - }, - previousPass = 1; - - amount = this.inputs.amount; - if (!amount) { - uniforms.source = this.inputs.source.texture; - parent(baseShader, model, uniforms, frameBuffer); - return; - } - - if (amount <= 0.01) { - //horizontal pass - uniforms.inputScale = 1; - uniforms.direction = horizontal; - uniforms.source = this.inputs.source.texture; - parent(shader, model, uniforms, fbHorizontal.frameBuffer); - - //vertical pass - uniforms.direction = vertical; - uniforms.source = fbHorizontal.texture; - parent(shader, model, uniforms, frameBuffer); - return; - } - - loopUniforms.amount = amount; - loopUniforms.blendGamma = uniforms.blendGamma; - loopUniforms.source = this.inputs.source.texture; - - for (i = 0; i < passes.length; i++) { - pass = Math.min(1, passes[i] / amount); - width = Math.floor(pass * this.width); - height = Math.floor(pass * this.height); - - loopUniforms.resolution[0] = width; - loopUniforms.resolution[1] = height; - loopUniforms.inputScale = previousPass; - previousPass = pass; - - opts.width = width; - opts.height = height; - - //horizontal pass - loopUniforms.direction = horizontal; - parent(shader, model, loopUniforms, fbHorizontal.frameBuffer, null, opts); - - //vertical pass - loopUniforms.inputScale = pass; - loopUniforms.source = fbHorizontal.texture; - loopUniforms.direction = vertical; - parent(shader, model, loopUniforms, i === finalPass ? frameBuffer : fbVertical.frameBuffer, null, opts); - - loopUniforms.source = fbVertical.texture; - } - }, - resize: function () { - loopUniforms.resolution[0] = this.width; - loopUniforms.resolution[1] = this.height; - if (fbHorizontal) { - fbHorizontal.resize(this.width, this.height); - fbVertical.resize(this.width, this.height); - } - }, - destroy: function () { - if (fbHorizontal) { - fbHorizontal.destroy(); - fbVertical.destroy(); - fbHorizontal = null; - fbVertical = null; - } - - loopUniforms = null; - } - }; - }, - { - inputs: { - source: { - type: 'image', - shaderDirty: false - }, - amount: { - type: 'number', - uniform: 'amount', - defaultValue: 0.2, - min: 0, - max: 1 - }, - blendGamma: { - type: 'number', - uniform: 'blendGamma', - defaultValue: 2.2, - min: 0, - max: 4 - } - }, - title: 'Gaussian Blur' - }); -})); diff --git a/effects/seriously.brightness-contrast.js b/effects/seriously.brightness-contrast.js deleted file mode 100644 index 400cf36..0000000 --- a/effects/seriously.brightness-contrast.js +++ /dev/null @@ -1,72 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('brightness-contrast', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform float brightness;', - 'uniform float saturation;', - 'uniform float contrast;', - - 'const vec3 half3 = vec3(0.5);', - - 'void main(void) {', - ' vec4 pixel = texture2D(source, vTexCoord);', - - //adjust brightness - ' vec3 color = pixel.rgb * brightness;', - - //adjust contrast - ' color = (color - half3) * contrast + half3;', - - //keep alpha the same - ' gl_FragColor = vec4(color, pixel.a);', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - brightness: { - type: 'number', - uniform: 'brightness', - defaultValue: 1, - min: 0 - }, - contrast: { - type: 'number', - uniform: 'contrast', - defaultValue: 1, - min: 0 - } - }, - title: 'Brightness/Contrast', - description: 'Multiply brightness and contrast values. Works the same as CSS filters.' - }); -})); diff --git a/effects/seriously.channels.js b/effects/seriously.channels.js deleted file mode 100644 index ca9d52f..0000000 --- a/effects/seriously.channels.js +++ /dev/null @@ -1,375 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - var channelOptions = [ - 'Red', - 'Green', - 'Blue', - 'Alpha' - ], - channelLookup = { - r: 0, - g: 1, - b: 2, - a: 3, - x: 0, - y: 1, - z: 2, - w: 3 - }; - - Seriously.plugin('channels', function () { - var sources = [], - shaders = [], - matrices = [], - me = this; - - function validateChannel(value, input, name) { - var val; - if (typeof value === 'string') { - val = value.charAt(0).toLowerCase(); - val = channelLookup[val]; - if (val === undefined) { - val = -1; - } - if (val < 0) { - val = parseFloat(value); - } - } else { - val = value; - } - - if (val === 0 || val === 1 || val === 2 || val === 3) { - return val; - } - - return me.inputs[name]; - } - - function updateChannels() { - var inputs = me.inputs, - i, j, - source, - matrix; - - for (i = 0; i < sources.length; i++) { - source = sources[i]; - matrix = matrices[i]; - if (!matrix) { - matrix = matrices[i] = []; - me.uniforms['channels' + i] = matrix; - } - - for (j = 0; j < 16; j++) { - matrix[j] = 0; - } - - matrix[inputs.red] = (inputs.redSource === source) ? 1 : 0; - matrix[4 + inputs.green] = (inputs.greenSource === source) ? 1 : 0; - matrix[8 + inputs.blue] = (inputs.blueSource === source) ? 1 : 0; - matrix[12 + inputs.alpha] = (inputs.alphaSource === source) ? 1 : 0; - } - } - - function updateSources() { - var inputs = me.inputs; - - function validateSource(name) { - var s, j; - s = inputs[name]; - if (!s) { - s = me.sources[name] = inputs[name] = inputs.source; - } - - j = sources.indexOf(s); - if (j < 0) { - j = sources.length; - sources.push(s); - me.uniforms['source' + j] = s; - } - } - sources.length = 0; - - validateSource('redSource'); - validateSource('greenSource'); - validateSource('blueSource'); - validateSource('alphaSource'); - - me.resize(); - - updateChannels(); - } - - // custom resize method - this.resize = function () { - var width, - height, - mode = this.inputs.sizeMode, - i, - resolution, - source; - - if (!sources.length) { - width = 1; - height = 1; - } else if (sources.length === 1) { - source = sources[0]; - width = source.width; - height = source.height; - } else if (mode === 'union') { - width = 0; - height = 0; - for (i = 0; i < sources.length; i++) { - source = sources[0]; - width = Math.max(width, source.width); - height = Math.max(height, source.height); - } - } else if (mode === 'intersection') { - width = Infinity; - height = Infinity; - for (i = 0; i < sources.length; i++) { - source = sources[0]; - width = Math.min(width, source.width); - height = Math.min(height, source.height); - } - } else { - source = me.inputs[mode + 'Source']; - if (source) { - width = source.width; - height = source.height; - } else { - width = 1; - height = 1; - } - } - - for (i = 0; i < sources.length; i++) { - source = sources[i]; - resolution = me.uniforms['resolution' + i]; - if (resolution) { - resolution[0] = source.width; - resolution[1] = source.height; - } else { - me.uniforms['resolution' + i] = [source.width, source.height]; - } - } - - if (this.width !== width || this.height !== height) { - this.width = width; - this.height = height; - - this.uniforms.resolution[0] = width; - this.uniforms.resolution[1] = height; - - if (this.frameBuffer) { - this.frameBuffer.resize(width, height); - } - - this.emit('resize'); - this.setDirty(); - } - - for (i = 0; i < this.targets.length; i++) { - this.targets[i].resize(); - } - }; - - return { - shader: function () { - var i, - frag, - vert, - shader, - uniforms = '', - samples = '', - varyings = '', - position = ''; - - /* - We'll restore this and the draw function below if we ever figure out a way to - add/& multiple renders without screwing up the brightness - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - 'uniform mat4 channels;', - 'uniform sampler2D source;', - //'uniform sampler2D previous;', - 'void main(void) {', - ' vec4 pixel;', - ' if (any(lessThan(vTexCoord, vec2(0.0))) || any(greaterThanEqual(vTexCoord, vec2(1.0)))) {', - ' pixel = vec4(0.0);', - ' } else {', - ' pixel = texture2D(source, vTexCoord) * channels;', - //' if (gl_FragColor.a == 0.0) gl_FragColor.a = 1.0;', - ' }', - ' gl_FragColor = pixel;', - '}' - ].join('\n'); - - return shaderSource; - */ - if (shaders[sources.length]) { - return shaders[sources.length]; - } - - for (i = 0; i < sources.length; i++) { - varyings += 'varying vec2 vTexCoord' + i + ';\n'; - - uniforms += 'uniform sampler2D source' + i + ';\n' + - 'uniform mat4 channels' + i + ';\n' + - 'uniform vec2 resolution' + i + ';\n\n'; - - position += ' vTexCoord' + i + ' = (position.xy * resolution / resolution' + i + ') * 0.5 + 0.5;\n'; - - samples += ' if (all(greaterThanEqual(vTexCoord' + i + ', vec2(0.0))) && all(lessThan(vTexCoord' + i + ', vec2(1.0)))) {\n' + - ' gl_FragColor += texture2D(source' + i + ', vTexCoord' + i + ') * channels' + i + ';\n }\n'; - } - - vert = [ - 'precision mediump float;', - - 'attribute vec4 position;', - 'attribute vec2 texCoord;', - - 'uniform vec2 resolution;', - uniforms, - - varyings, - - 'void main(void) {', - position, - ' gl_Position = position;', - '}\n' - ].join('\n'); - - frag = [ - 'precision mediump float;', - - varyings, - uniforms, - - 'void main(void) {', - ' gl_FragColor = vec4(0.0);', - samples, - '}' - ].join('\n'); - - shader = new Seriously.util.ShaderProgram(this.gl, - vert, - frag); - - shaders[sources.length] = shader; - return shader; - }, - /* - draw: function (shader, model, uniforms, frameBuffer, draw) { - var i, - source; - - options.clear = true; - for (i = 0; i < sources.length; i++) { - //for (i = sources.length - 1; i >= 0; i--) { - uniforms.channels = matrices[i]; - source = sources[i]; - uniforms.source = sources[i]; - //uniforms.resolution[] - - draw(shader, model, uniforms, frameBuffer, null, options); - options.clear = false; - } - }, - */ - inputs: { - sizeMode: { - type: 'enum', - defaultValue: 'red', - options: [ - 'red', - 'green', - 'blue', - 'alpha', - 'union', - 'intersection' - ], - update: function () { - this.resize(); - } - }, - source: { - type: 'image', - update: updateSources, - shaderDirty: true - }, - redSource: { - type: 'image', - update: updateSources, - shaderDirty: true - }, - greenSource: { - type: 'image', - update: updateSources, - shaderDirty: true - }, - blueSource: { - type: 'image', - update: updateSources, - shaderDirty: true - }, - alphaSource: { - type: 'image', - update: updateSources, - shaderDirty: true - }, - red: { - type: 'enum', - options: channelOptions, - validate: validateChannel, - update: updateChannels, - defaultValue: 0 - }, - green: { - type: 'enum', - options: channelOptions, - validate: validateChannel, - update: updateChannels, - defaultValue: 1 - }, - blue: { - type: 'enum', - options: channelOptions, - validate: validateChannel, - update: updateChannels, - defaultValue: 2 - }, - alpha: { - type: 'enum', - options: channelOptions, - validate: validateChannel, - update: updateChannels, - defaultValue: 3 - } - } - }; - }, - { - inPlace: false, - title: 'Channel Mapping' - }); -})); diff --git a/effects/seriously.checkerboard.js b/effects/seriously.checkerboard.js deleted file mode 100644 index b94fbaf..0000000 --- a/effects/seriously.checkerboard.js +++ /dev/null @@ -1,132 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('checkerboard', function () { - var me = this; - - function resize() { - me.resize(); - } - - return { - initialize: function (initialize) { - initialize(); - resize(); - }, - shader: function (inputs, shaderSource) { - shaderSource.vertex = [ - 'precision mediump float;', - - 'attribute vec4 position;', - 'attribute vec2 texCoord;', - - 'uniform vec2 resolution;', - 'uniform mat4 transform;', - - 'uniform vec2 size;', - 'uniform vec2 anchor;', - - 'vec2 pixelCoord;', //based in center - 'varying vec2 vGridCoord;', //based in center - - 'void main(void) {', - // first convert to screen space - ' vec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);', - ' screenPosition = transform * screenPosition;', - - // convert back to OpenGL coords - ' gl_Position.xy = screenPosition.xy * 2.0 / resolution;', - ' gl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);', - ' gl_Position.w = screenPosition.w;', - - ' pixelCoord = resolution * (texCoord - 0.5) / 2.0;', - ' vGridCoord = (pixelCoord - anchor) / size;', - '}\n' - ].join('\n'); - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - 'varying vec2 vPixelCoord;', - 'varying vec2 vGridCoord;', - - 'uniform vec2 resolution;', - 'uniform vec2 anchor;', - 'uniform vec2 size;', - 'uniform vec4 color1;', - 'uniform vec4 color2;', - - - 'void main(void) {', - ' vec2 modGridCoord = floor(mod(vGridCoord, 2.0));', - ' if (modGridCoord.x == modGridCoord.y) {', - ' gl_FragColor = color1;', - ' } else {', - ' gl_FragColor = color2;', - ' }', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - anchor: { - type: 'vector', - uniform: 'anchor', - dimensions: 2, - defaultValue: [0, 0] - }, - size: { - type: 'vector', - uniform: 'size', - dimensions: 2, - defaultValue: [4, 4] - }, - color1: { - type: 'color', - uniform: 'color1', - defaultValue: [1, 1, 1, 1] - }, - color2: { - type: 'color', - uniform: 'color2', - defaultValue: [187 / 255, 187 / 255, 187 / 255, 1] - }, - width: { - type: 'number', - min: 0, - step: 1, - update: resize, - defaultValue: 640 - }, - height: { - type: 'number', - min: 0, - step: 1, - update: resize, - defaultValue: 360 - } - }, - }; - }, { - commonShader: true, - title: 'Checkerboard', - categories: ['generator'] - }); -})); diff --git a/effects/seriously.chroma.js b/effects/seriously.chroma.js deleted file mode 100644 index d944624..0000000 --- a/effects/seriously.chroma.js +++ /dev/null @@ -1,178 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - /* - experimental chroma key algorithm - todo: try allowing some color despill on opaque pixels - todo: add different modes? - */ - - Seriously.plugin('chroma', { - shader: function (inputs, shaderSource) { - shaderSource.vertex = [ - 'precision mediump float;', - - 'attribute vec4 position;', - 'attribute vec2 texCoord;', - - 'uniform vec2 resolution;', - 'uniform mat4 transform;', - - 'varying vec2 vTexCoord;', - - 'uniform vec4 screen;', - 'uniform float balance;', - 'varying float screenSat;', - 'varying vec3 screenPrimary;', - - 'void main(void) {', - ' float fmin = min(min(screen.r, screen.g), screen.b);', //Min. value of RGB - ' float fmax = max(max(screen.r, screen.g), screen.b);', //Max. value of RGB - ' float secondaryComponents;', - - ' screenPrimary = step(fmax, screen.rgb);', - ' secondaryComponents = dot(1.0 - screenPrimary, screen.rgb);', - ' screenSat = fmax - mix(secondaryComponents - fmin, secondaryComponents / 2.0, balance);', - - // first convert to screen space - ' vec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);', - ' screenPosition = transform * screenPosition;', - - // convert back to OpenGL coords - ' gl_Position = screenPosition;', - ' gl_Position.xy = screenPosition.xy * 2.0 / resolution;', - ' gl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);', - ' vTexCoord = texCoord;', - '}' - ].join('\n'); - shaderSource.fragment = [ - this.inputs.mask ? '#define MASK' : '', - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform vec4 screen;', - 'uniform float screenWeight;', - 'uniform float balance;', - 'uniform float clipBlack;', - 'uniform float clipWhite;', - 'uniform bool mask;', - - 'varying float screenSat;', - 'varying vec3 screenPrimary;', - - 'void main(void) {', - ' float pixelSat, secondaryComponents;', - ' vec4 sourcePixel = texture2D(source, vTexCoord);', - - ' float fmin = min(min(sourcePixel.r, sourcePixel.g), sourcePixel.b);', //Min. value of RGB - ' float fmax = max(max(sourcePixel.r, sourcePixel.g), sourcePixel.b);', //Max. value of RGB - // luminance = fmax - - ' vec3 pixelPrimary = step(fmax, sourcePixel.rgb);', - - ' secondaryComponents = dot(1.0 - pixelPrimary, sourcePixel.rgb);', - ' pixelSat = fmax - mix(secondaryComponents - fmin, secondaryComponents / 2.0, balance);', // Saturation - - // solid pixel if primary color component is not the same as the screen color - ' float diffPrimary = dot(abs(pixelPrimary - screenPrimary), vec3(1.0));', - ' float solid = step(1.0, step(pixelSat, 0.1) + step(fmax, 0.1) + diffPrimary);', - - /* - Semi-transparent pixel if the primary component matches but if saturation is less - than that of screen color. Otherwise totally transparent - */ - ' float alpha = max(0.0, 1.0 - pixelSat / screenSat);', - ' alpha = smoothstep(clipBlack, clipWhite, alpha);', - ' vec4 semiTransparentPixel = vec4((sourcePixel.rgb - (1.0 - alpha) * screen.rgb * screenWeight) / max(0.00001, alpha), alpha);', - - ' vec4 pixel = mix(semiTransparentPixel, sourcePixel, solid);', - - /* - Old branching code - ' if (pixelSat < 0.1 || fmax < 0.1 || any(notEqual(pixelPrimary, screenPrimary))) {', - ' pixel = sourcePixel;', - - ' } else if (pixelSat < screenSat) {', - ' float alpha = max(0.0, 1.0 - pixelSat / screenSat);', - ' alpha = smoothstep(clipBlack, clipWhite, alpha);', - ' pixel = vec4((sourcePixel.rgb - (1.0 - alpha) * screen.rgb * screenWeight) / alpha, alpha);', - ' }', - //*/ - - - '#ifdef MASK', - ' gl_FragColor = vec4(vec3(pixel.a), 1.0);', - '#else', - ' gl_FragColor = pixel;', - '#endif', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - screen: { - type: 'color', - uniform: 'screen', - defaultValue: [66 / 255, 195 / 255, 31 / 255, 1] - }, - weight: { - type: 'number', - uniform: 'screenWeight', - defaultValue: 1, - min: 0 - }, - balance: { - type: 'number', - uniform: 'balance', - defaultValue: 1, - min: 0, - max: 1 - }, - clipBlack: { - type: 'number', - uniform: 'clipBlack', - defaultValue: 0, - min: 0, - max: 1 - }, - clipWhite: { - type: 'number', - uniform: 'clipWhite', - defaultValue: 1, - min: 0, - max: 1 - }, - mask: { - type: 'boolean', - defaultValue: false, - uniform: 'mask', - shaderDirty: true - } - }, - title: 'Chroma Key', - description: '' - }); -})); diff --git a/effects/seriously.color-select.js b/effects/seriously.color-select.js deleted file mode 100644 index 627513c..0000000 --- a/effects/seriously.color-select.js +++ /dev/null @@ -1,264 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('color-select', { - shader: function(inputs, shaderSource, utilities) { - shaderSource.vertex = [ - 'precision mediump float;', - - 'attribute vec4 position;', - 'attribute vec2 texCoord;', - - 'uniform vec2 resolution;', - 'uniform mat4 transform;', - - 'uniform float hueMin;', - 'uniform float hueMax;', - 'uniform float hueMinFalloff;', - 'uniform float hueMaxFalloff;', - 'uniform float saturationMin;', - 'uniform float saturationMax;', - 'uniform float saturationMinFalloff;', - 'uniform float saturationMaxFalloff;', - 'uniform float lightnessMin;', - 'uniform float lightnessMax;', - 'uniform float lightnessMinFalloff;', - 'uniform float lightnessMaxFalloff;', - - 'varying vec2 vTexCoord;', - 'varying vec4 adjustedHueRange;', - 'varying vec4 saturationRange;', - 'varying vec4 lightnessRange;', - - 'void main(void) {', - // first convert to screen space - ' vec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);', - ' screenPosition = transform * screenPosition;', - - // convert back to OpenGL coords - ' gl_Position.xy = screenPosition.xy * 2.0 / resolution;', - ' gl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);', - ' gl_Position.w = screenPosition.w;', - ' vTexCoord = texCoord;', - - ' float hueOffset = hueMin - hueMinFalloff;', - ' adjustedHueRange = mod(vec4(' + - 'hueOffset, ' + - 'hueMin - hueOffset, ' + - 'hueMax - hueOffset, ' + - 'hueMax + hueMaxFalloff - hueOffset' + - '), 360.0);', - ' if (hueMin != hueMax) {', - ' if (adjustedHueRange.z == 0.0) {', - ' adjustedHueRange.z = 360.0;', - ' adjustedHueRange.w += 360.0;', - ' } else if (adjustedHueRange.w == 0.0) {', - ' adjustedHueRange.w += 360.0;', - ' }', - ' }', - ' saturationRange = vec4(' + - 'saturationMin - saturationMinFalloff, ' + - 'saturationMin, ' + - 'saturationMax, ' + - 'saturationMax + saturationMaxFalloff ' + - ');', - - ' lightnessRange = vec4(' + - 'lightnessMin - lightnessMinFalloff, ' + - 'lightnessMin, ' + - 'lightnessMax, ' + - 'lightnessMax + lightnessMaxFalloff ' + - ');', - '}' - ].join('\n'); - - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform bool mask;', - - 'varying vec4 adjustedHueRange;', - 'varying vec4 saturationRange;', - 'varying vec4 lightnessRange;', - - 'vec3 calcHSL(vec3 c) {', - ' float minColor = min(c.r, min(c.g, c.b));', - ' float maxColor = max(c.r, max(c.g, c.b));', - ' float delta = maxColor - minColor;', - ' vec3 hsl = vec3(0.0, 0.0, (maxColor + minColor) / 2.0);', - ' if (delta > 0.0) {', - ' if (hsl.z < 0.5) {', - ' hsl.y = delta / (maxColor + minColor);', - ' } else {', - ' hsl.y = delta / (2.0 - maxColor - minColor);', - ' }', - ' if (c.r == maxColor) {', - ' hsl.x = (c.g - c.b) / delta;', - ' } else if (c.g == maxColor) {', - ' hsl.x = 2.0 + (c.b - c.r) / delta;', - ' } else {', - ' hsl.x = 4.0 + (c.r - c.g) / delta;', - ' }', - ' hsl.x = hsl.x * 360.0 / 6.0;', - ' if (hsl.x < 0.0) {', - ' hsl.x += 360.0;', - ' } else {', - ' hsl.x = mod(hsl.x, 360.0);', - ' }', - ' }', - ' return hsl;', - '}', - - 'void main(void) {', - ' vec4 color = texture2D(source, vTexCoord);', - ' vec3 hsl = calcHSL(color.rgb);', - ' float adjustedHue = mod(hsl.x - adjustedHueRange.x, 360.0);', - - // calculate hue mask - ' float maskValue;', - ' if (adjustedHue < adjustedHueRange.y) {', - ' maskValue = smoothstep(0.0, adjustedHueRange.y, adjustedHue);', - ' } else if (adjustedHue < adjustedHueRange.z) {', - ' maskValue = 1.0;', - ' } else {', - ' maskValue = 1.0 - smoothstep(adjustedHueRange.z, adjustedHueRange.w, adjustedHue);', - ' }', - - // calculate saturation maskValue - ' if (maskValue > 0.0) {', - ' if (hsl.y < saturationRange.y) {', - ' maskValue = min(maskValue, smoothstep(saturationRange.x, saturationRange.y, hsl.y));', - ' } else {', - ' maskValue = min(maskValue, 1.0 - smoothstep(saturationRange.z, saturationRange.w, hsl.y));', - ' }', - ' }', - - // calculate lightness maskValue - ' if (maskValue > 0.0) {', - ' if (hsl.z < lightnessRange.y) {', - ' maskValue = min(maskValue, smoothstep(lightnessRange.x, lightnessRange.z, hsl.y));', - ' } else {', - ' maskValue = min(maskValue, 1.0 - smoothstep(lightnessRange.z, lightnessRange.w, hsl.z));', - ' }', - ' }', - - ' if (mask) {', - ' gl_FragColor = vec4(maskValue, maskValue, maskValue, 1.0);', - ' } else {', - ' color.a = min(color.a, maskValue);', - ' gl_FragColor = color;', - ' }', - '}' - ].join('\n'); - - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - hueMin: { - type: 'number', - uniform: 'hueMin', - defaultValue: 0 - }, - hueMax: { - type: 'number', - uniform: 'hueMax', - defaultValue: 360 - }, - hueMinFalloff: { - type: 'number', - uniform: 'hueMinFalloff', - defaultValue: 0, - min: 0 - }, - hueMaxFalloff: { - type: 'number', - uniform: 'hueMaxFalloff', - defaultValue: 0, - min: 0 - }, - saturationMin: { - type: 'number', - uniform: 'saturationMin', - defaultValue: 0, - min: 0, - max: 1 - }, - saturationMax: { - type: 'number', - uniform: 'saturationMax', - defaultValue: 1, - min: 0, - max: 1 - }, - saturationMinFalloff: { - type: 'number', - uniform: 'saturationMinFalloff', - defaultValue: 0, - min: 0 - }, - saturationMaxFalloff: { - type: 'number', - uniform: 'saturationMaxFalloff', - defaultValue: 0, - min: 0 - }, - lightnessMin: { - type: 'number', - uniform: 'lightnessMin', - defaultValue: 0, - min: 0, - max: 1 - }, - lightnessMax: { - type: 'number', - uniform: 'lightnessMax', - defaultValue: 1, - min: 0, - max: 1 - }, - lightnessMinFalloff: { - type: 'number', - uniform: 'lightnessMinFalloff', - defaultValue: 0, - min: 0 - }, - lightnessMaxFalloff: { - type: 'number', - uniform: 'lightnessMaxFalloff', - defaultValue: 0, - min: 0 - }, - mask: { - type: 'boolean', - defaultValue: false, - uniform: 'mask' - } - }, - title: 'Color Select', - description: 'Create a mask by hue, saturation and lightness range.' - }); -})); diff --git a/effects/seriously.color.js b/effects/seriously.color.js deleted file mode 100644 index 6fb9ab5..0000000 --- a/effects/seriously.color.js +++ /dev/null @@ -1,145 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('color', function () { - var me = this, - drawOpts = { - width: 1, - height: 1 - }, - colorDirty = true; - - function resize() { - me.resize(); - } - - /* - Similar to the EffectNode prototype resize method, but does not resize the FrameBuffer - */ - this.resize = function () { - var width, - height, - i, - target; - - if (this.inputs && this.inputs.width) { - width = this.inputs.width; - height = this.inputs.height || width; - } else if (this.inputs && this.inputs.height) { - width = height = this.inputs.height; - } else { - width = 1; - height = 1; - } - - width = Math.floor(width); - height = Math.floor(height); - - if (this.width !== width || this.height !== height) { - this.width = width; - this.height = height; - - this.emit('resize'); - this.setDirty(); - } - - for (i = 0; i < this.targets.length; i++) { - target = this.targets[i]; - target.resize(); - if (target.setTransformDirty) { - target.setTransformDirty(); - } - } - }; - - return { - initialize: function (initialize) { - /* - No reason to use anything bigger than 1x1, since it's a single color. - This should make look-ups on this texture very fast - */ - this.frameBuffer = new Seriously.util.FrameBuffer(this.gl, 1, 1); - resize(); - colorDirty = true; - }, - commonShader: true, - shader: function(inputs, shaderSource) { - shaderSource.vertex = [ - 'precision mediump float;', - - 'attribute vec4 position;', - - 'void main(void) {', - ' gl_Position = position;', - '}\n' - ].join('\n'); - shaderSource.fragment = [ - 'precision mediump float;\n', - - 'uniform vec4 color;', - - 'void main(void) {', - ' gl_FragColor = color;', - '}' - ].join('\n'); - return shaderSource; - }, - draw: function (shader, model, uniforms, frameBuffer, draw) { - /* - Node will be dirty if size changes, but we only need to redraw if - the color changes...not that it matters much, since we're only drawing - a single pixel. - */ - if (colorDirty) { - draw(shader, model, uniforms, frameBuffer, null, drawOpts); - colorDirty = false; - } - }, - inPlace: true, - inputs: { - color: { - type: 'color', - uniform: 'color', - defaultValue: [0, 0, 0, 1], - update: function () { - colorDirty = true; - } - }, - width: { - type: 'number', - min: 0, - step: 1, - update: resize, - defaultValue: 640 - }, - height: { - type: 'number', - min: 0, - step: 1, - update: resize, - defaultValue: 360 - } - }, - }; - }, { - title: 'Color', - description: 'Generate color', - categories: ['generator'] - }); -})); diff --git a/effects/seriously.colorcomplements.js b/effects/seriously.colorcomplements.js deleted file mode 100644 index a9a2ce5..0000000 --- a/effects/seriously.colorcomplements.js +++ /dev/null @@ -1,129 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('colorcomplements', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform vec4 guideColor;', - 'uniform float correlation;', - 'uniform float amount;', - 'uniform float concentration;', - - 'float hueLerp(float h1, float h2, float v) {', - ' float d = abs(h1 - h2);', - ' if (d <= 0.5) {', - ' return mix(h1, h2, v);', - ' } else if (h1 < h2) {', - ' return fract(mix((h1 + 1.0), h2, v));', - ' } else {', - ' return fract(mix(h1, (h2 + 1.0), v));', - ' }', - '}', - - //conversion functions borrowed from http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl - 'vec3 rgbToHsv(vec3 c) {', - ' vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);', - ' vec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);', - ' vec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);', - - ' float d = q.x - min(q.w, q.y);', - ' float e = 1.0e-10;', - ' return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);', - '}', - - 'vec3 hsvToRgb(vec3 c) {', - ' vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);', - ' vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);', - ' return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);', - '}', - - 'vec3 hsvComplement(vec3 hsv) {', - ' vec3 compl = hsv;', - ' compl.x = mod(compl.x - 0.5, 1.0);', - ' return compl;', - '}', - - 'void main(void) {', - ' vec4 pixel = texture2D(source, vTexCoord);', - ' vec3 hsv = rgbToHsv(pixel.rgb);', - ' vec3 hsvPole1 = rgbToHsv(guideColor.rgb);', - ' vec3 hsvPole2 = hsvPole1;', - ' hsvPole2 = hsvComplement(hsvPole1);', - ' float dist1 = abs(hsv.x - hsvPole1.x);', - ' dist1 = dist1 > 0.5 ? 1.0 - dist1 : dist1;', - ' float dist2 = abs(hsv.x - hsvPole2.x);', - ' dist2 = dist2 > 0.5 ? 1.0 - dist2 : dist2;', - - ' float descent = smoothstep(0.0, correlation, hsv.y);', - ' vec3 outputHsv = hsv;', - ' vec3 pole = dist1 < dist2 ? hsvPole1 : hsvPole2;', - ' float dist = min(dist1, dist2);', - ' float c = descent * amount * (1.0 - pow((dist * 2.0), 1.0 / concentration));', - ' outputHsv.x = hueLerp(hsv.x, pole.x, c);', - ' outputHsv.y = mix(hsv.y, pole.y, c);', - - ' gl_FragColor = vec4(hsvToRgb(outputHsv), pixel.a);', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - amount: { - type: 'number', - uniform: 'amount', - min: 0, - max: 1, - defaultValue: 0.8 - }, - concentration: { - type: 'number', - uniform: 'concentration', - min: 0.1, - max: 4, - defaultValue: 2 - }, - correlation: { - type: 'number', - uniform: 'correlation', - min: 0, - max: 1, - defaultValue: 0.5 - }, - guideColor: { - type: 'color', - uniform: 'guideColor', - defaultValue: [1, 0.5, 0, 1] - } - }, - title: 'Color Complements', - categories: ['color'], - description: 'http://theabyssgazes.blogspot.com/2010/03/teal-and-orange-hollywood-please-stop.html' - }); -})); diff --git a/effects/seriously.colorcube.js b/effects/seriously.colorcube.js deleted file mode 100644 index 1fe8a0b..0000000 --- a/effects/seriously.colorcube.js +++ /dev/null @@ -1,71 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - // based on tutorial by to Gregg Tavares - // http://www.youtube.com/watch?v=rfQ8rKGTVlg&t=24m30s - // todo: find a way to not invert every single texture - - Seriously.plugin('colorcube', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'uniform sampler2D source;', - 'uniform sampler2D colorCube;', - 'varying vec2 vTexCoord;', - - 'vec3 sampleAs3DTexture(sampler2D tex, vec3 coord, float size) {', - ' float sliceSize = 1.0 / size;', // space of 1 slice - ' float slicePixelSize = sliceSize / size;', // space of 1 pixel - ' float sliceInnerSize = slicePixelSize * (size - 1.0);', // space of size pixels - ' float zSlice0 = min(floor(coord.z * size), size - 1.0);', - ' float zSlice1 = min(zSlice0 + 1.0, size - 1.0);', - ' float xOffset = slicePixelSize * 0.5 + coord.x * sliceInnerSize;', - ' float s0 = xOffset + (zSlice0 * sliceSize);', - ' float s1 = xOffset + (zSlice1 * sliceSize);', - ' vec3 slice0Color = texture2D(tex, vec2(s0, 1.0 - coord.y)).rgb;', - ' vec3 slice1Color = texture2D(tex, vec2(s1, 1.0 - coord.y)).rgb;', - ' float zOffset = mod(coord.z * size, 1.0);', - ' return mix(slice0Color, slice1Color, zOffset);', - '}', - - 'void main(void) {', - ' vec4 originalColor = texture2D(source, vTexCoord);', - ' vec3 color = sampleAs3DTexture(colorCube, originalColor.rgb, 8.0);', - ' gl_FragColor = vec4(color, originalColor.a);', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - cube: { - type: 'image', - uniform: 'colorCube' - } - }, - title: 'Color Cube', - description: '' - }); -})); diff --git a/effects/seriously.crop.js b/effects/seriously.crop.js deleted file mode 100755 index d8cdb68..0000000 --- a/effects/seriously.crop.js +++ /dev/null @@ -1,158 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('crop', function () { - var me = this; - - // custom resize method - function resize() { - var width = 1, - height = 1, - source = me.inputs.source, - target, - i; - - if (me.source) { - width = me.source.width; - height = me.source.height; - } else if (me.sources && me.sources.source) { - width = me.sources.source.width; - height = me.sources.source.height; - } - - width = width - me.inputs.left - me.inputs.right; - height = height - me.inputs.top - me.inputs.bottom; - - width = Math.max(1, Math.floor(width)); - height = Math.max(1, Math.floor(height)); - - - if (me.width !== width || me.height !== height) { - me.width = width; - me.height = height; - - me.uniforms.resolution[0] = width; - me.uniforms.resolution[1] = height; - - if (me.frameBuffer) { - me.frameBuffer.resize(me.width, me.height); - } - - me.emit('resize'); - me.setDirty(); - } - - for (i = 0; i < me.targets.length; i++) { - target = me.targets[i]; - target.resize(); - if (target.setTransformDirty) { - target.setTransformDirty(); - } - } - } - - me.resize = resize; - - return { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.vertex = [ - 'precision mediump float;', - - 'attribute vec4 position;', - 'attribute vec2 texCoord;', - - 'uniform vec2 resolution;', - 'uniform mat4 transform;', - - 'uniform float top;', - 'uniform float left;', - 'uniform float bottom;', - 'uniform float right;', - - 'varying vec2 vTexCoord;', - - 'const vec2 ZERO = vec2(0.0);', - 'const vec2 ONE = vec2(1.0);', - - 'void main(void) {', - // first convert to screen space - ' vec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);', - ' screenPosition = transform * screenPosition;', - - // convert back to OpenGL coords - ' gl_Position.xy = screenPosition.xy * 2.0 / resolution;', - ' gl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);', - ' gl_Position.w = screenPosition.w;', - - ' vec2 dim = resolution + vec2(right + left, bottom + top);', - ' vec2 scale = dim / resolution;', - ' vec2 offset = vec2(left, bottom) / resolution;', - - ' vTexCoord = max(ZERO, (texCoord + offset) / scale);', - '}\n' - ].join('\n'); - return shaderSource; - }, - inputs: { - source: { - type: 'image', - uniform: 'source', - update: resize - }, - top: { - type: 'number', - uniform: 'top', - min: 0, - step: 1, - update: resize, - defaultValue: 0 - }, - left: { - type: 'number', - uniform: 'left', - min: 0, - step: 1, - update: resize, - defaultValue: 0 - }, - bottom: { - type: 'number', - uniform: 'bottom', - min: 0, - step: 1, - update: resize, - defaultValue: 0 - }, - right: { - type: 'number', - uniform: 'right', - min: 0, - step: 1, - update: resize, - defaultValue: 0 - } - } - }; - }, - { - inPlace: true, - title: 'Crop' - }); -})); diff --git a/effects/seriously.daltonize.js b/effects/seriously.daltonize.js deleted file mode 100644 index 76f0365..0000000 --- a/effects/seriously.daltonize.js +++ /dev/null @@ -1,171 +0,0 @@ -/* 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 { - var Seriously = root.Seriously; - if (!Seriously) { - Seriously = { plugin: function (name, opt) { this[name] = opt; } }; - } - factory(Seriously); - } -}(window, function (Seriously) { - 'use strict'; - -//todo: add Simulate mode http://mudcu.be/labs/Color/Vision/Javascript/Color.Vision.Simulate.js - -/* -* Daltonization algorithm from: -* Digital Video Colourmaps for Checking the Legibility of Displays by Dichromats -* http://vision.psychol.cam.ac.uk/jdmollon/papers/colourmaps.pdf -* -* JavaScript implementation: -* http://mudcu.be/labs/Color/Vision/Javascript/Color.Vision.Daltonize.js -* -* Copyright (c) 2013 David Lewis, British Broadcasting Corporation -* (http://www.bbc.co.uk) -* -* MIT Licence: -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: - -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. - -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* - */ - Seriously.plugin('daltonize', { - commonShader: true, - shader: function (inputs, shaderSource) { - //Vertex shader - shaderSource.vertex = [ - 'precision mediump float;', - - 'attribute vec3 position;', - 'attribute vec2 texCoord;', - - 'uniform mat4 transform;', - - 'varying vec2 vTexCoord;', - - 'void main(void) {', - ' gl_Position = transform * vec4(position, 1.0);', - ' vTexCoord = vec2(texCoord.s, texCoord.t);', - '}' - ].join('\n'); - //Fragment shader - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform float cbtype;', - - 'void main(void) {', - ' vec4 color = texture2D(source, vTexCoord);', - - //No change, skip the rest - ' if (cbtype == 0.0) {', - ' gl_FragColor = color;', - ' return;', - ' }', - - // RGB to LMS matrix conversion - ' const mat3 RGBLMS = mat3( ' + - ' 17.8824, 43.5161, 4.11935,' + - ' 3.45565, 27.1554, 3.86714,' + - ' 0.0299566, 0.184309, 1.46709' + - ' );', - ' vec3 LMS = color.rgb * RGBLMS;', - - ' vec3 lms = vec3(0.0,0.0,0.0);', - //Protanope - ' if (cbtype < 0.33) {', - ' lms = vec3( ' + - ' (2.02344 * LMS.g) + (-2.52581 * LMS.b),' + - ' LMS.g,' + - ' LMS.b' + - ' );', - ' }', - //Deuteranope - ' if (cbtype > 0.33 && cbtype < 0.66) {', - ' lms = vec3( ' + - ' LMS.r,' + - ' (0.494207 * LMS.r) + (1.24827 * LMS.b),' + - ' LMS.b' + - ' );', - ' }', - //Tritanope - ' if (cbtype > 0.66) {', - ' lms = vec3( ' + - ' LMS.r,' + - ' LMS.g,' + - ' (-0.395913 * LMS.r) + (0.801109 * LMS.g)' + - ' );', - ' }', - - // LMS to RGB matrix operation - ' const mat3 LMSRGB = mat3( ' + - ' 0.0809444479, -0.130504409, 0.116721066,' + - ' -0.0102485335, 0.0540193266, -0.113614708,' + - ' -0.000365296938, -0.00412161469, 0.693511405' + - ' );', - - ' vec3 RGB = lms * LMSRGB;', - - // Colour shift - // values may go over 1.0 but will get automatically clamped on output - ' RGB.rgb = color.rgb - RGB.rgb;', - ' RGB.g = 0.7*RGB.r + RGB.g;', - ' RGB.b = 0.7*RGB.r + RGB.b;', - ' color.rgb = color.rgb + RGB.rgb;', - - //Output - ' gl_FragColor = color;', - - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - type: { - title: 'Type', - type: 'enum', - uniform: 'cbtype', - defaultValue: '0.2', - options: [ - ['0.0', 'Off'], - ['0.2', 'Protanope'], - ['0.6', 'Deuteranope'], - ['0.8', 'Tritanope'] - ] - } - }, - title: 'Daltonize', - description: 'Add contrast to colours to assist CVD (colour-blind) users.' - }); -})); \ No newline at end of file diff --git a/effects/seriously.directionblur.js b/effects/seriously.directionblur.js deleted file mode 100644 index e734705..0000000 --- a/effects/seriously.directionblur.js +++ /dev/null @@ -1,260 +0,0 @@ -/* global define, require */ -/* -Directional Motion Blur - -Adapted from v002 by Anton Marini and Tom Butterworth -* Copyright vade - Anton Marini -* Creative Commons, Attribution - Non Commercial - Share Alike 3.0 - -http://v002.info/plugins/v002-blurs/ -*/ -(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); - } -}(window, function (Seriously) { - 'use strict'; - - var passes = [0.2, 0.3, 0.5, 0.8], - identity = new Float32Array([ - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 - ]); - - Seriously.plugin('directionblur', function (options) { - var fbs, - baseShader, - loopUniforms = { - amount: 0, - blendGamma: 2, - angle: 0, - inputScale: 1, - resolution: [this.width, this.height], - transform: identity, - projection: new Float32Array([ - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 - ]) - }; - - return { - initialize: function (parent) { - var gl; - - parent(); - - gl = this.gl; - - if (!gl) { - return; - } - - fbs = [ - new Seriously.util.FrameBuffer(gl, this.width, this.height), - new Seriously.util.FrameBuffer(gl, this.width, this.height) - ]; - }, - commonShader: true, - shader: function (inputs, shaderSource) { - var gl = this.gl; - - baseShader = this.baseShader; - - shaderSource.vertex = [ - 'precision mediump float;', - - 'attribute vec4 position;', - 'attribute vec2 texCoord;', - - 'uniform vec2 resolution;', - 'uniform mat4 projection;', - 'uniform mat4 transform;', - - 'uniform float angle;', - 'uniform float amount;', - 'uniform float inputScale;', - - 'const vec2 zero = vec2(0.0);', - - 'varying vec2 vTexCoord;', - 'varying vec4 vTexCoords[4];', - - 'void main(void) {', - // first convert to screen space - ' vec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);', - ' screenPosition = transform * screenPosition;', - - // convert back to OpenGL coords - ' gl_Position = screenPosition;', - ' gl_Position.xy = screenPosition.xy * 2.0 / resolution;', - ' gl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);', - ' vTexCoord = texCoord;', - - ' vec2 one = vec2(1.0) * inputScale;', - ' if (inputScale < 1.0) {', - ' one -= 1.0 / resolution;', - ' }', - ' vTexCoord = max(zero, min(one, texCoord.st * inputScale));', - ' vec2 amount = vec2(cos(angle), sin(angle)) * amount * 5.0 / resolution;', - - ' for (int i = 0; i < 4; i++) {', - ' float s = pow(3.0, float(i));', - ' vTexCoords[i].xy = max(zero, min(one, vTexCoord + amount * s));', - ' vTexCoords[i].zw = max(zero, min(one, vTexCoord - amount * s));', - ' }', - '}' - ].join('\n'); - shaderSource.fragment = [ - 'precision mediump float;\n', - - 'uniform sampler2D source;', - 'uniform float angle;', - 'uniform float amount;', - 'uniform float blendGamma;', - - 'varying vec2 vTexCoord;', - 'varying vec4 vTexCoords[4];', - - 'vec3 exp;', - - 'vec4 sample(sampler2D sampler, vec2 coord) {', - ' vec4 pixel = texture2D(sampler, coord);', - ' pixel.rgb = pow(pixel.rgb, exp);', - ' return pixel;', - '}', - - 'void main(void) {', - - ' exp = vec3(blendGamma);', - - ' gl_FragColor = sample(source, vTexCoord) / 9.0;', - - ' for (int i = 0; i < 4; i++) {', - ' gl_FragColor += sample(source, vTexCoords[i].xy) / 9.0;', - ' gl_FragColor += sample(source, vTexCoords[i].zw) / 9.0;', - ' }', - - ' gl_FragColor.rgb = pow(gl_FragColor.rgb, 1.0 / exp);', - - '}' - ].join('\n'); - - return shaderSource; - }, - draw: function (shader, model, uniforms, frameBuffer, parent) { - var i, - fb, - pass, - amount, - width, - height, - opts = { - width: 0, - height: 0, - blend: false - }, - previousPass = 1; - - amount = this.inputs.amount; - if (!amount) { - parent(baseShader, model, uniforms, frameBuffer); - return; - } - - if (amount <= 0.01) { - parent(shader, model, uniforms, frameBuffer); - return; - } - - loopUniforms.amount = amount; - loopUniforms.angle = this.inputs.angle; - loopUniforms.projection[0] = this.height / this.width; - - for (i = 0; i < passes.length; i++) { - pass = Math.min(1, passes[i] / amount); - width = Math.floor(pass * this.width); - height = Math.floor(pass * this.height); - - loopUniforms.source = fb ? fb.texture : this.inputs.source.texture; - - fb = fbs[i % 2]; - loopUniforms.inputScale = previousPass;//pass; - previousPass = pass; - opts.width = width; - opts.height = height; - - parent(shader, model, loopUniforms, fb.frameBuffer, null, opts); - } - - loopUniforms.source = fb.texture; - loopUniforms.inputScale = previousPass; - parent(shader, model, loopUniforms, frameBuffer); - }, - resize: function () { - loopUniforms.resolution[0] = this.width; - loopUniforms.resolution[1] = this.height; - if (fbs) { - fbs[0].resize(this.width, this.height); - fbs[1].resize(this.width, this.height); - } - }, - destroy: function () { - if (fbs) { - fbs[0].destroy(); - fbs[1].destroy(); - fbs = null; - } - - if (baseShader) { - baseShader.destroy(); - } - - loopUniforms = null; - } - }; - }, - { - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - }, - amount: { - type: 'number', - uniform: 'amount', - defaultValue: 0.4, - min: 0, - max: 1 - }, - angle: { - type: 'number', - uniform: 'angle', - defaultValue: 0 - }, - blendGamma: { - type: 'number', - uniform: 'blendGamma', - defaultValue: 2.2, - min: 0, - max: 4 - } - }, - title: 'Directional Motion Blur' - }); -})); diff --git a/effects/seriously.displacement.js b/effects/seriously.displacement.js deleted file mode 100644 index ff87f0c..0000000 --- a/effects/seriously.displacement.js +++ /dev/null @@ -1,195 +0,0 @@ -/* global define, require */ -(function (root, factory) { - 'use strict'; - - if (typeof exports === 'object') { - // Node/CommonJS - factory(require('seriously')); - } else if (typeof define === 'function' && define.amd) { - // AMD. Register as an anonymous module. - define(['seriously'], factory); - } else { - if (!root.Seriously) { - root.Seriously = { plugin: function (name, opt) { this[name] = opt; } }; - } - factory(root.Seriously); - } -}(window, function (Seriously) { - 'use strict'; - - var fillModes = { - wrap: 'pos = mod(pos, 1.0);', - clamp: 'pos = min(max(pos, 0.0), 1.0);', - ignore: 'pos = texCoordSource;', - color: 'gl_FragColor = color;\n\treturn;' - }, - channelVectors = { - none: [0, 0, 0, 0], - red: [1, 0, 0, 0], - green: [0, 1, 0, 0], - blue: [0, 0, 1, 0], - alpha: [0, 0, 0, 1], - luma: [0.2125, 0.7154, 0.0721, 0], - lightness: [1 / 3, 1 / 3, 1 / 3, 0] - }; - - Seriously.plugin('displacement', function () { - this.uniforms.resMap = [1, 1]; - this.uniforms.resSource = [1, 1]; - this.uniforms.xVector = channelVectors.red; - this.uniforms.yVector = channelVectors.green; - - return { - shader: function (inputs, shaderSource) { - var fillMode = fillModes[inputs.fillMode]; - - shaderSource.vertex = [ - 'precision mediump float;', - - 'attribute vec4 position;', - 'attribute vec2 texCoord;', - - 'uniform vec2 resolution;', - 'uniform vec2 resSource;', - 'uniform vec2 resMap;', - - 'varying vec2 texCoordSource;', - 'varying vec2 texCoordMap;', - - 'const vec2 HALF = vec2(0.5);', - - 'void main(void) {', - //we don't need to do a transform in this shader, since this effect is not "inPlace" - ' gl_Position = position;', - - ' vec2 adjusted = (texCoord - HALF) * resolution;', - - ' texCoordSource = adjusted / resSource + HALF;', - ' texCoordMap = adjusted / resMap + HALF;', - '}' - ].join('\n'); - - shaderSource.fragment = [ - 'precision mediump float;\n', - - 'varying vec2 texCoordSource;', - 'varying vec2 texCoordMap;', - - 'uniform sampler2D source;', - 'uniform sampler2D map;', - - 'uniform float amount;', - 'uniform float offset;', - 'uniform vec2 mapScale;', - 'uniform vec4 color;', - 'uniform vec4 xVector;', - 'uniform vec4 yVector;', - - 'void main(void) {', - ' vec4 mapPixel = texture2D(map, texCoordMap);', - ' vec2 mapVector = vec2(dot(mapPixel, xVector), dot(mapPixel, yVector));', - ' vec2 pos = texCoordSource + (mapVector.xy - offset) * mapScale * amount;', - - ' if (pos.x < 0.0 || pos.x > 1.0 || pos.y < 0.0 || pos.y > 1.0) {', - ' ' + fillMode, - ' }', - - ' gl_FragColor = texture2D(source, pos);', - '}' - ].join('\n'); - - return shaderSource; - }, - requires: function (sourceName) { - if (!this.inputs.mapScale && sourceName === 'map') { - return false; - } - return true; - }, - resize: function () { - var source = this.inputs.source, - map = this.inputs.map; - - if (source) { - this.uniforms.resSource[0] = source.width; - this.uniforms.resSource[1] = source.height; - } else { - this.uniforms.resSource[0] = 1; - this.uniforms.resSource[1] = 1; - } - - if (map) { - this.uniforms.resMap[0] = map.width; - this.uniforms.resMap[1] = map.height; - } else { - this.uniforms.resMap[0] = 1; - this.uniforms.resMap[1] = 1; - } - } - }; - }, - { - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - map: { - type: 'image', - uniform: 'map' - }, - xChannel: { - type: 'enum', - defaultValue: 'red', - options: [ - 'red', 'green', 'blue', 'alpha', 'luma', 'lightness', 'none' - ], - update: function (val) { - this.uniforms.xVector = channelVectors[val]; - } - }, - yChannel: { - type: 'enum', - defaultValue: 'green', - options: [ - 'red', 'green', 'blue', 'alpha', 'luma', 'lightness', 'none' - ], - update: function (val) { - this.uniforms.yVector = channelVectors[val]; - } - }, - fillMode: { - type: 'enum', - shaderDirty: true, - defaultValue: 'color', - options: [ - 'color', 'wrap', 'clamp', 'ignore' - ] - }, - color: { - type: 'color', - uniform: 'color', - defaultValue: [0, 0, 0, 0] - }, - offset: { - type: 'number', - uniform: 'offset', - defaultValue: 0.5 - }, - mapScale: { - type: 'vector', - dimensions: 2, - uniform: 'mapScale', - defaultValue: [1, 1], - updateSources: true - }, - amount: { - type: 'number', - uniform: 'amount', - defaultValue: 1 - } - }, - title: 'Displacement Map', - description: '' - }); -})); diff --git a/effects/seriously.dither.js b/effects/seriously.dither.js deleted file mode 100644 index 57cb814..0000000 --- a/effects/seriously.dither.js +++ /dev/null @@ -1,98 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - /* - Shader code: - Adapted from a blog post by Martin Upitis - http://devlog-martinsh.blogspot.com.es/2011/03/glsl-dithering.html - */ - - Seriously.plugin('dither', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - '#define mod4(a) (a >= 4 ? a - 4 : a)', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform vec2 resolution;', - - 'const mat4 dither = mat4(' + - '1.0, 33.0, 9.0, 41.0,' + - '49.0, 17.0, 57.0, 25.0,' + - '13.0, 45.0, 5.0, 37.0,' + - '61.0, 29.0, 53.0, 21.0' + - ');', - - 'float find_closest(int x, int y, float c0) {', - ' float limit = 0.0;', - ' int x4 = mod4(x);', - ' int y4 = mod4(y);', - //annoying hack since GLSL ES doesn't support variable array index - ' for (int i = 0; i < 4; i++) {', - ' if (i == x4) {', - ' for (int j = 0; j < 4; j++) {', - ' if (j == y4) {', - ' limit = dither[i][j];', - ' break;', - ' }', - ' }', - ' }', - ' }', - ' if (x < 4) {', - ' if (y >= 4) {', - ' limit += 3.0;', - ' }', - ' } else {', - ' if (y >= 4) {', - ' limit += 1.0;', - ' } else {', - ' limit += 2.0;', - ' }', - ' }', - ' limit /= 65.0;', - ' return c0 < limit ? 0.0 : 1.0;', - '}', - - 'void main (void) {', - ' vec4 pixel = texture2D(source, vTexCoord);', - ' vec2 coord = vTexCoord * resolution;', - ' int x = int(mod(coord.x, 8.0));', - ' int y = int(mod(coord.y, 8.0));', - ' pixel.r = find_closest(x, y, pixel.r);', - ' pixel.g = find_closest(x, y, pixel.g);', - ' pixel.b = find_closest(x, y, pixel.b);', - ' gl_FragColor = pixel;', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: false, - inputs: { - source: { - type: 'image', - uniform: 'source' - } - }, - title: 'Dither' - }); -})); diff --git a/effects/seriously.edge.js b/effects/seriously.edge.js deleted file mode 100644 index 2f822da..0000000 --- a/effects/seriously.edge.js +++ /dev/null @@ -1,170 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - // Adapted from http://rastergrid.com/blog/2011/01/frei-chen-edge-detector/ - var sqrt = Math.sqrt, - i, j, - flatMatrices = [], - matrices, - freiChenMatrixConstants, - sobelMatrixConstants; - - //initialize shader matrix arrays - function multiplyArray(factor, a) { - var i; - for (i = 0; i < a.length; i++) { - a[i] *= factor; - } - return a; - } - - matrices = [ - multiplyArray(1.0 / (2.0 * sqrt(2.0)), [ 1.0, sqrt(2.0), 1.0, 0.0, 0.0, 0.0, -1.0, -sqrt(2.0), -1.0 ]), - multiplyArray(1.0 / (2.0 * sqrt(2.0)), [1.0, 0.0, -1.0, sqrt(2.0), 0.0, -sqrt(2.0), 1.0, 0.0, -1.0]), - multiplyArray(1.0 / (2.0 * sqrt(2.0)), [0.0, -1.0, sqrt(2.0), 1.0, 0.0, -1.0, -sqrt(2.0), 1.0, 0.0]), - multiplyArray(1.0 / (2.0 * sqrt(2.0)), [sqrt(2.0), -1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 1.0, -sqrt(2.0)]), - multiplyArray(1.0 / 2.0, [0.0, 1.0, 0.0, -1.0, 0.0, -1.0, 0.0, 1.0, 0.0]), - multiplyArray(1.0 / 2.0, [-1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.0]), - multiplyArray(1.0 / 6.0, [1.0, -2.0, 1.0, -2.0, 4.0, -2.0, 1.0, -2.0, 1.0]), - multiplyArray(1.0 / 6.0, [-2.0, 1.0, -2.0, 1.0, 4.0, 1.0, -2.0, 1.0, -2.0]), - multiplyArray(1.0 / 3.0, [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]) - ]; - - for (i = 0; i < matrices.length; i++) { - for (j = 0; j < matrices[i].length; j++) { - flatMatrices.push(matrices[i][j]); - } - } - - freiChenMatrixConstants = new Float32Array(flatMatrices); - - sobelMatrixConstants = new Float32Array([ - 1.0, 2.0, 1.0, 0.0, 0.0, 0.0, -1.0, -2.0, -1.0, - 1.0, 0.0, -1.0, 2.0, 0.0, -2.0, 1.0, 0.0, -1.0 - ]); - - Seriously.plugin('edge', { - initialize: function (initialize) { - initialize(); - - this.uniforms.pixelWidth = 1 / this.width; - this.uniforms.pixelHeight = 1 / this.height; - - if (this.inputs.mode === 'sobel') { - this.uniforms.G = sobelMatrixConstants; - } else { - this.uniforms.G = freiChenMatrixConstants; - } - }, - shader: function (inputs, shaderSource) { - var defines; - - if (inputs.mode === 'sobel') { - defines = '#define N_MATRICES 2\n' + - '#define SOBEL\n'; - } else { - //frei-chen - defines = '#define N_MATRICES 9\n'; - } - - shaderSource.fragment = [ - defines, - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform float pixelWidth;', - 'uniform float pixelHeight;', - 'uniform mat3 G[9];', - - 'void main(void) {', - ' mat3 I;', - ' float dp3, cnv[9];', - ' vec3 tc;', - - // fetch the 3x3 neighbourhood and use the RGB vector's length as intensity value - ' float fi = 0.0, fj = 0.0;', - ' for (int i = 0; i < 3; i++) {', - ' fj = 0.0;', - ' for (int j = 0; j < 3; j++) {', - ' I[i][j] = length( ' + - 'texture2D(source, ' + - 'vTexCoord + vec2((fi - 1.0) * pixelWidth, (fj - 1.0) * pixelHeight)' + - ').rgb );', - ' fj += 1.0;', - ' };', - ' fi += 1.0;', - ' };', - - // calculate the convolution values for all the masks - - ' for (int i = 0; i < N_MATRICES; i++) {', - ' dp3 = dot(G[i][0], I[0]) + dot(G[i][1], I[1]) + dot(G[i][2], I[2]);', - ' cnv[i] = dp3 * dp3;', - ' };', - - //Sobel - '#ifdef SOBEL', - ' tc = vec3(0.5 * sqrt(cnv[0]*cnv[0]+cnv[1]*cnv[1]));', - '#else', - - //Frei-Chen - // Line detector - ' float M = (cnv[4] + cnv[5]) + (cnv[6] + cnv[7]);', - ' float S = (cnv[0] + cnv[1]) + (cnv[2] + cnv[3]) + (cnv[4] + cnv[5]) + (cnv[6] + cnv[7]) + cnv[8];', - ' tc = vec3(sqrt(M/S));', - '#endif', - - ' gl_FragColor = vec4(tc, 1.0);', - '}' - ].join('\n'); - - return shaderSource; - }, - resize: function () { - this.uniforms.pixelWidth = 1 / this.width; - this.uniforms.pixelHeight = 1 / this.height; - }, - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - mode: { - type: 'enum', - shaderDirty: true, - defaultValue: 'sobel', - options: [ - ['sobel', 'Sobel'], - ['frei-chen', 'Frei-Chen'] - ], - update: function () { - if (this.inputs.mode === 'sobel') { - this.uniforms.G = sobelMatrixConstants; - } else { - this.uniforms.G = freiChenMatrixConstants; - } - } - } - }, - description: 'Edge Detect', - title: 'Edge Detect' - }); -})); diff --git a/effects/seriously.emboss.js b/effects/seriously.emboss.js deleted file mode 100644 index e4b07ac..0000000 --- a/effects/seriously.emboss.js +++ /dev/null @@ -1,91 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('emboss', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.vertex = [ - 'precision mediump float;', - - 'attribute vec4 position;', - 'attribute vec2 texCoord;', - - 'uniform vec2 resolution;', - 'uniform mat4 transform;', - - 'varying vec2 vTexCoord1;', - 'varying vec2 vTexCoord2;', - - 'void main(void) {', - // first convert to screen space - ' vec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);', - ' screenPosition = transform * screenPosition;', - - // convert back to OpenGL coords - ' gl_Position.xy = screenPosition.xy * 2.0 / resolution;', - ' gl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);', - ' gl_Position.w = screenPosition.w;', - - ' vec2 offset = 1.0 / resolution;', - ' vTexCoord1 = texCoord - offset;', - ' vTexCoord2 = texCoord + offset;', - '}' - ].join('\n'); - - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord1;', - 'varying vec2 vTexCoord2;', - - 'uniform sampler2D source;', - 'uniform float amount;', - - 'const vec3 average = vec3(1.0 / 3.0);', - - 'void main (void) {', - ' vec4 pixel = vec4(0.5, 0.5, 0.5, 1.0);', - - ' pixel -= texture2D(source, vTexCoord1) * amount;', - ' pixel += texture2D(source, vTexCoord2) * amount;', - ' pixel.rgb = vec3(dot(pixel.rgb, average));', - - ' gl_FragColor = pixel;', - '}' - ].join('\n'); - return shaderSource; - }, - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - amount: { - type: 'number', - uniform: 'amount', - defaultValue: 1, - min: -255 / 3, - max: 255 / 3 - } - }, - title: 'Emboss', - categories: [], - description: 'Emboss' - }); -})); diff --git a/effects/seriously.exposure.js b/effects/seriously.exposure.js deleted file mode 100755 index be35cfa..0000000 --- a/effects/seriously.exposure.js +++ /dev/null @@ -1,58 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('exposure', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - - 'uniform float exposure;', - - 'void main (void) {', - ' vec4 pixel = texture2D(source, vTexCoord);', - ' gl_FragColor = vec4(pow(2.0, exposure) * pixel.rgb, pixel.a);', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - }, - exposure: { - type: 'number', - uniform: 'exposure', - defaultValue: 1, - min: -8, - max: 8 - } - }, - title: 'Exposure', - categories: ['film'], - description: 'Exposure control' - }); -})); diff --git a/effects/seriously.expression.js b/effects/seriously.expression.js deleted file mode 100644 index 0fd24bf..0000000 --- a/effects/seriously.expression.js +++ /dev/null @@ -1,541 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - function formatFloat(n) { - if (n - Math.floor(n) === 0) { - return n + '.0'; - } - return n; - } - - var symbols = { - red: 'rgba.r', - blue: 'rgba.b', - green: 'rgba.g', - alpha: 'rgba.a', - x: 'dim.x', - y: 'dim.y', - width: 'resolution.x', - height: 'resolution.y', - a: 'a', - b: 'b', - c: 'c', - d: 'd', - luma: ['luma', 'rgba'] - - /* - todo: - - time of day in seconds - - video time - - year, month, day - - datetime in milliseconds - - transform? - - transformed position? - */ - }, - definitions = { - dim: 'vec2 dim = vTexCoord * resolution;', - rgba: 'vec4 rgba = texture2D(source, vTexCoord);', - luma: 'float luma = dot(rgba.rgb, vec3(0.2125,0.7154,0.0721));', - atan2: { - source: '#define atan2(x, y) atan(x / y)', - global: true - }, - and: { - source: [ - 'float and(float a, float b) {', - ' if (a == 0.0) {', - ' return 0.0;', - ' }', - ' return b;', - '}' - ].join('\n'), - global: true - }, - or: { - source: [ - 'float or(float a, float b) {', - ' if (a != 0.0) {', - ' return a;', - ' }', - ' return b;', - '}' - ].join('\n'), - global: true - }, - luminance: { - source: [ - 'const vec3 lumaCoeffs = vec3(0.2125,0.7154,0.0721);', - 'float luminance(float r, float g, float b) {', - ' return dot(vec3(r, g, b), lumaCoeffs);', - '}' - ].join('\n'), - global: true - }, - saturation: { - source: [ - 'float saturation(float r, float g, float b) {', - ' float lo = min(r, min(g, b));', - ' float hi = max(r, max(g, b));', - ' float l = (lo + hi) / 2.0;', - ' float d = hi - lo;', - ' return l > 0.5 ? d / (2.0 - hi - lo) : d / (hi + lo);', - '}' - ].join('\n'), - global: true - }, - lightness: { - source: [ - 'float lightness(float r, float g, float b) {', - ' float lo = min(r, min(g, b));', - ' float hi = max(r, max(g, b));', - ' return (lo + hi) / 2.0;', - '}' - ].join('\n'), - global: true - }, - hue: { - source: [ - 'float hue(float r, float g, float b) {', - ' float h;', - ' if (r > g && r > b) {', //red is max - ' h = (g - b) / d + (g < b ? 6.0 : 0.0);', - ' } else if (g > r && g > b) {', //green is max - ' h = (b - r) / d + 2.0;', - ' } else {', //blue is max - ' h = (r - g) / d + 4.0;', - ' }', - ' return h / 6.0;', - '}' - ].join('\n'), - global: true - } - }, - functions = { - //built-in shader functions - radians: 1, - degrees: 1, - sin: 1, - cos: 1, - tan: 1, - asin: 1, - acos: 1, - atan: 1, - pow: 2, - exp: 1, - log: 1, - exp2: 1, - log2: 1, - sqrt: 1, - inversesqrt: 1, - abs: 1, - sign: 1, - floor: 1, - ceil: 1, - fract: 1, - mod: 2, - min: 2, - max: 2, - clamp: 3, - mix: 3, - step: 2, - smoothstep: 3, - - //custom logic functions - and: 2, - or: 2, - - //custom functions - atan2: 2, - hue: 3, - saturation: 3, - lightness: 3, - luminance: 3 - - /* - todo: - noise, random, hslRed, hslGreen, hslBlue, - int, sinh, cosh, tanh, mantissa, hypot, lerp, step - noise with multiple octaves (See fBm) - */ - }, - unaryOps = { - '-': true, - '!': true, - //'~': false, //todo: implement this or just get rid of it? - '+': true - }, - binaryOps = { - //true means it's a comparison and needs to be converted to float - '+': false, - '-': false, - '*': false, - '/': false, - '%': 'mod', - '&&': 'and', - '||': 'or', - //'^^': false, //todo: implement xor? - //'&', - //'|', - //'<<', - //'>>', - '===': '==', - '==': true, - '!==': '!=', - '!=': true, - '>=': true, - '<=': true, - '<': true, - '>': true - }, - pair, - key, - def, - - jsep; - - ['E', 'LN2', 'LN10', 'LOG2E', 'LOG10E', 'PI', 'SQRT1_2', 'SQRT2'].forEach(function (key) { - symbols[key] = key; - definitions[key] = { - source: 'const float ' + key + ' = ' + Math[key] + ';', - global: true - }; - }); - - //clean up lookup tables - for (key in symbols) { - if (symbols.hasOwnProperty(key)) { - def = symbols[key]; - if (typeof def === 'string') { - def = [def]; - } - - pair = def[0].split('.'); - if (pair.length > 1) { - def.push(pair[0]); - } - symbols[key] = def; - } - } - - for (key in definitions) { - if (definitions.hasOwnProperty(key)) { - def = definitions[key]; - if (typeof def === 'string') { - definitions[key] = { - source: def, - global: false - }; - } - } - } - - Seriously.plugin('expression', function () { - var me = this; - - function updateSingle() { - var inputs = me.inputs; - - if (inputs.blue === inputs.red && - inputs.green === inputs.blue) { - inputs.rgb = inputs.red; - } else { - inputs.rgb = ''; - } - } - - return { - shader: function (inputs, shaderSource) { - var expressions = {}, - channels = { - red: '', - green: '', - blue: '', - alpha: '' - }, - dependencies = {}, - deps, - expr, - key, - statements, - globalDefinitions = [], - nonGlobalDefinitions = [], - cs = [], - tree; - - function makeExpression(tree) { - var verb, x, i, - args; - /* - COMPOUND = 'Compound' - */ - - //We do not have any objects to offer - if (tree.type === 'MemberExpression') { - throw new Error('Expression Error: Unknown object "' + (tree.object.name || 'this') + '"'); - } - - if (tree.type === 'BinaryExpression' || tree.type === 'LogicalExpression') { - if (!tree.right) { - throw new Error('Expression Error: Bad binary expression'); - } - - //jsep seems to parse some unary expressions as binary with missing left side - //todo: consider removing this if/when jsep fixes it. file a github issue - if (!tree.left) { - tree.type = 'UnaryExpression'; - tree.argument = tree.right; - return makeExpression(tree); - } - - verb = tree.operator; - x = binaryOps[verb]; - if (x === undefined) { - throw new Error('Expression Error: Unknown operator "' + verb + '"'); - } - - if (typeof x === 'string') { - if (x in binaryOps) { - verb = binaryOps[x]; - x = binaryOps[verb]; - } else if (functions[x] === 2) { - deps[x] = true; - return x + '(' + makeExpression(tree.left) + ', ' + makeExpression(tree.right) + ')'; - } - } - - return (x ? 'float' : '') + '(' + makeExpression(tree.left) + ' ' + verb + ' ' + makeExpression(tree.right) + ')'; - } - - if (tree.type === 'CallExpression') { - if (tree.callee.type !== 'Identifier') { - throw new Error('Expression Error: Unknown function'); - } - - verb = tree.callee.name; - x = functions[verb]; - if (x === undefined) { - throw new Error('Expression Error: Unknown function "' + verb + '"'); - } - - if (x > tree.arguments.length) { - throw new Error('Expression Error: Function "' + verb + '" requires at least ' + x + ' arguments'); - } - - args = []; - for (i = 0; i < x; i++) { - args.push(makeExpression(tree.arguments[i])); - } - deps[verb] = true; - return verb + '(' + args.join(', ') + ')'; - } - - if (tree.type === 'Identifier') { - args = symbols[tree.name]; - if (!args) { - throw new Error('Expression Error: Unknown identifier "' + tree.name + '"'); - } - - for (i = args.length - 1; i >= 0; i--) { - x = args[i]; - if (definitions[x]) { - deps[x] = true; - } - } - return args[0]; - } - - if (tree.type === 'Literal') { - if (tree.raw === 'true') { - return 1.0; - } - - if (tree.raw === 'true') { - return 0.0; - } - - if (typeof tree.value !== 'number' || isNaN(tree.value)) { - throw new Error('Expression Error: Invalid literal ' + tree.raw); - } - - return formatFloat(tree.value); - } - - if (tree.type === 'UnaryExpression') { - verb = tree.operator; - x = unaryOps[verb]; - if (!x) { - throw new Error('Expression Error: Unknown operator "' + verb + '"'); - } - - //todo: are there any unary operators that could become functions? - return verb + '(' + makeExpression(tree.argument) + ')'; - } - } - - for (key in channels) { - if (channels.hasOwnProperty(key)) { - expr = inputs[key] || key; - channels[key] = expr; - expressions[expr] = ''; - } - } - - for (expr in expressions) { - if (expressions.hasOwnProperty(expr)) { - try { - deps = {}; - tree = jsep(expr); - //todo: convert this to a function? - expressions[expr] = makeExpression(tree); - - //flag any required declarations/precalculations - for (key in deps) { - if (deps.hasOwnProperty(key)) { - dependencies[key] = deps[key]; - } - } - - //special case for luma. todo: generalize if we need to - if (deps.luma) { - dependencies.rgba = true; - } - } catch (parseError) { - console.log(parseError.message); - expressions[expr] = '0.0'; - } - } - } - - for (key in dependencies) { - if (dependencies.hasOwnProperty(key)) { - deps = definitions[key]; - if (deps) { - if (deps.global) { - globalDefinitions.push(deps.source); - } else { - nonGlobalDefinitions.push('\t' + deps.source); - } - } - } - } - - /* - todo: assign duplicate expressions to temp variables - for (expr in expressions) { - if (expressions.hasOwnProperty(expr)) { - statements.push('float val' + index = ) - } - } - */ - - for (key in channels) { - if (channels.hasOwnProperty(key)) { - expr = channels[key]; - cs.push(expressions[expr]); - } - } - - statements = [ - 'precision mediump float;', - 'varying vec2 vTexCoord;', - 'varying vec4 vPosition;', - - 'uniform sampler2D source;', - 'uniform float a, b, c, d;', - 'uniform vec2 resolution;', - globalDefinitions.join('\n'), - 'void main(void) {', - nonGlobalDefinitions.join('\n'), - '\tgl_FragColor = vec4(', - '\t\t' + cs.join(',\n\t\t'), - '\t);', - '}' - ]; - - shaderSource.fragment = statements.join('\n'); - - return shaderSource; - }, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: true - }, - a: { - type: 'number', - uniform: 'a', - defaultValue: 0 - }, - b: { - type: 'number', - uniform: 'b', - defaultValue: 0 - }, - c: { - type: 'number', - uniform: 'c', - defaultValue: 0 - }, - d: { - type: 'number', - uniform: 'd', - defaultValue: 0 - }, - rgb: { - type: 'string', - update: function (val) { - var inputs = me.inputs; - inputs.red = inputs.green = inputs.blue = val; - }, - shaderDirty: true - }, - red: { - type: 'string', - update: updateSingle, - shaderDirty: true - }, - green: { - type: 'string', - update: updateSingle, - shaderDirty: true - }, - blue: { - type: 'string', - update: updateSingle, - shaderDirty: true - }, - alpha: { - type: 'string', - shaderDirty: true - } - } - }; - }, - { - inPlace: false, - title: 'Expression' - }); - - /* jsep v0.2.9 (http://jsep.from.so/) */ - !function(a){"use strict";var b="Compound",c="Identifier",d="MemberExpression",e="Literal",f="ThisExpression",g="CallExpression",h="UnaryExpression",i="BinaryExpression",j="LogicalExpression",k=!0,l={"-":k,"!":k,"~":k,"+":k},m={"||":1,"&&":2,"|":3,"^":4,"&":5,"==":6,"!=":6,"===":6,"!==":6,"<":7,">":7,"<=":7,">=":7,"<<":8,">>":8,">>>":8,"+":9,"-":9,"*":10,"/":10,"%":10},n=function(a){var b,c=0;for(var d in a)(b=d.length)>c&&a.hasOwnProperty(d)&&(c=b);return c},o=n(l),p=n(m),q={"true":!0,"false":!1,"null":null},r="this",s=function(a){return m[a]||0},t=function(a,b,c){var d="||"===a||"&&"===a?j:i;return{type:d,operator:a,left:b,right:c}},u=function(a){return a>=48&&57>=a},v=function(a){return 36===a||95===a||a>=65&&90>=a||a>=97&&122>=a},w=function(a){return 36===a||95===a||a>=65&&90>=a||a>=97&&122>=a||a>=48&&57>=a},x=function(a){for(var i,j,k=0,n=a.charAt,x=a.charCodeAt,y=function(b){return n.call(a,b)},z=function(b){return x.call(a,b)},A=a.length,B=function(){for(var a=z(k);32===a||9===a;)a=z(++k)},C=function(){B();for(var b=a.substr(k,p),c=b.length;c>0;){if(m.hasOwnProperty(b))return k+=c,b;b=b.substr(0,--c)}return!1},D=function(){var a,b,c,d,e,f,g,h;if(f=E(),b=C(),!b)return f;if(e={value:b,prec:s(b)},g=E(),!g)throw new Error("Expected expression after "+b+" at character "+k);for(d=[f,e,g];(b=C())&&(c=s(b),0!==c);){for(e={value:b,prec:c};d.length>2&&c<=d[d.length-2].prec;)g=d.pop(),b=d.pop().value,f=d.pop(),a=t(b,f,g),d.push(a);if(a=E(),!a)throw new Error("Expected expression after "+b+" at character "+k);d.push(e),d.push(a)}for(h=d.length-1,a=d[h];h>1;)a=t(d[h-1].value,d[h-2],a),h-=2;return a},E=function(){var b,c,d;if(B(),b=z(k),u(b)||46===b)return F();if(39===b||34===b)return G();if(v(b))return J();if(40===b)return K();for(c=a.substr(k,o),d=c.length;d>0;){if(l.hasOwnProperty(c))return k+=d,{type:h,operator:c,argument:E(),prefix:!0};c=c.substr(0,--d)}return!1},F=function(){for(var a="";u(z(k));)a+=y(k++);if("."===y(k))for(a+=y(k++);u(z(k));)a+=y(k++);if("e"===y(k)||"E"===y(k)){for(a+=y(k++),("+"===y(k)||"-"===y(k))&&(a+=y(k++));u(z(k));)a+=y(k++);if(!u(z(k-1)))throw new Error("Expected exponent ("+a+y(k)+") at character "+k)}if(v(z(k)))throw new Error("Variable names cannot start with a number ("+a+y(k)+") at character "+k);return{type:e,value:parseFloat(a),raw:a}},G=function(){for(var a,b="",c=y(k++),d=!1;A>k;){if(a=y(k++),a===c){d=!0;break}if("\\"===a)switch(a=y(k++)){case"n":b+="\n";break;case"r":b+="\r";break;case"t":b+=" ";break;case"b":b+="\b";break;case"f":b+="\f";break;case"v":b+=""}else b+=a}if(!d)throw new Error('Unclosed quote after "'+b+'"');return{type:e,value:b,raw:c+b+c}},H=function(){var b,d=z(k),g=k;if(!v(d))throw new Error("Unexpected "+y(k)+"at character "+k);for(k++;A>k&&(d=z(k),w(d));)k++;return b=a.slice(g,k),q.hasOwnProperty(b)?{type:e,value:q[b],raw:b}:b===r?{type:f}:{type:c,name:b}},I=function(){for(var a,c,d=[];A>k;){if(B(),a=y(k),")"===a){k++;break}if(","===a)k++;else{if(c=D(),!c||c.type===b)throw new Error("Expected comma at character "+k);d.push(c)}}return d},J=function(){var a,b,c;for(b=H(),B(),a=y(k);"."===a||"["===a||"("===a;){if("."===a)k++,B(),b={type:d,computed:!1,object:b,property:H()};else if("["===a){if(c=k,k++,b={type:d,computed:!0,object:b,property:D()},B(),a=y(k),"]"!==a)throw new Error("Unclosed [ at character "+k);k++,B()}else"("===a&&(k++,b={type:g,arguments:I(),callee:b});B(),a=y(k)}return b},K=function(){k++;var a=D();if(B(),")"===y(k))return k++,a;throw new Error("Unclosed ( at character "+k)},L=[];A>k;)if(i=y(k),";"===i||","===i)k++;else if(j=D())L.push(j);else if(A>k)throw new Error("Unexpected '"+y(k)+"' at character "+k);return 1===L.length?L[0]:{type:b,body:L}};if(x.version="0.2.9",x.toString=function(){return"JavaScript Expression Parser (JSEP) v"+x.version},x.addUnaryOp=function(a){return l[a]=k,this},x.addBinaryOp=function(a,b){return p=Math.max(a.length,p),m[a]=b,this},x.removeUnaryOp=function(a){return delete l[a],a.length===o&&(o=n(l)),this},x.removeBinaryOp=function(a){return delete m[a],a.length===p&&(p=n(m)),this},"undefined"==typeof exports){var y=a.jsep;a.jsep=x,x.noConflict=function(){return a.jsep===x&&(a.jsep=y),x}}else"undefined"!=typeof module&&module.exports?exports=module.exports=x:exports.parse=x}(window); - - jsep = window.jsep.noConflict(); -})); diff --git a/effects/seriously.fader.js b/effects/seriously.fader.js deleted file mode 100644 index ec4d46c..0000000 --- a/effects/seriously.fader.js +++ /dev/null @@ -1,64 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('fader', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform vec4 color;', - 'uniform float amount;', - - 'void main(void) {', - ' gl_FragColor = texture2D(source, vTexCoord);', - ' gl_FragColor = mix(gl_FragColor, color, amount);', - '}' - ].join('\n'); - return shaderSource; - }, - requires: function (sourceName, inputs) { - return inputs.amount < 1; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - color: { - type: 'color', - uniform: 'color', - defaultValue: [0, 0, 0, 1] - }, - amount: { - type: 'number', - uniform: 'amount', - defaultValue: 0.5, - min: 0, - max: 1 - } - }, - title: 'Fader', - description: 'Fade image to a color' - }); -})); diff --git a/effects/seriously.falsecolor.js b/effects/seriously.falsecolor.js deleted file mode 100644 index d846bf9..0000000 --- a/effects/seriously.falsecolor.js +++ /dev/null @@ -1,64 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('falsecolor', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform float amount;', - 'uniform vec4 black;', - 'uniform vec4 white;', - - 'const vec3 luma = vec3(0.2125, 0.7154, 0.0721);', - - 'void main(void) {', - ' vec4 pixel = texture2D(source, vTexCoord);', - ' float luminance = dot(pixel.rgb, luma);', - ' vec4 result = mix(black, white, luminance);', - ' gl_FragColor = vec4(result.rgb, pixel.a * result.a);', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - }, - black: { - type: 'color', - uniform: 'black', - defaultValue: [0, 0, 0.5, 1] - }, - white: { - type: 'color', - uniform: 'white', - defaultValue: [1, 0, 0, 1] - } - }, - title: 'False Color' - }); -})); diff --git a/effects/seriously.filmgrain.js b/effects/seriously.filmgrain.js deleted file mode 100644 index 65c2bba..0000000 --- a/effects/seriously.filmgrain.js +++ /dev/null @@ -1,157 +0,0 @@ -/* global define, require */ -/* -Film Grain - -Shader: -* Copyright Martins Upitis (martinsh) devlog-martinsh.blogspot.com -* Creative Commons Attribution 3.0 Unported License -http://devlog-martinsh.blogspot.com/2013/05/image-imperfections-and-film-grain-post.html - -Modified to preserve alpha - -*/ -(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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('filmgrain', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform vec2 resolution;', - 'uniform float time;', - 'uniform float amount;', - 'uniform bool colored;', - - 'float timer;', - - // Perm texture texel-size - 'const float permTexUnit = 1.0/256.0;', - - // Half perm texture texel-size - 'const float permTexUnitHalf = 0.5/256.0;', - - 'vec4 rnm(in vec2 tc) {', - ' float noise = sin(dot(tc + vec2(timer,timer),vec2(12.9898,78.233))) * 43758.5453;', - - ' float noiseR = fract(noise)*2.0-1.0;', - ' float noiseG = fract(noise*1.2154)*2.0-1.0; ', - ' float noiseB = fract(noise*1.3453)*2.0-1.0;', - ' float noiseA = fract(noise*1.3647)*2.0-1.0;', - ' ', - ' return vec4(noiseR,noiseG,noiseB,noiseA);', - '}', - - 'float fade(in float t) {', - ' return t*t*t*(t*(t*6.0-15.0)+10.0);', - '}', - - 'float pnoise3D(in vec3 p) {', - // Integer part, scaled so +1 moves permTexUnit texel - ' vec3 pi = permTexUnit*floor(p)+permTexUnitHalf;', - - // and offset 1/2 texel to sample texel centers - // Fractional part for interpolation' - ' vec3 pf = fract(p);', - - // Noise contributions from (x=0, y=0), z=0 and z=1 - ' float perm00 = rnm(pi.xy).a ;', - ' vec3 grad000 = rnm(vec2(perm00, pi.z)).rgb * 4.0 - 1.0;', - ' float n000 = dot(grad000, pf);', - ' vec3 grad001 = rnm(vec2(perm00, pi.z + permTexUnit)).rgb * 4.0 - 1.0;', - ' float n001 = dot(grad001, pf - vec3(0.0, 0.0, 1.0));', - - // Noise contributions from (x=0, y=1), z=0 and z=1 - ' float perm01 = rnm(pi.xy + vec2(0.0, permTexUnit)).a ;', - ' vec3 grad010 = rnm(vec2(perm01, pi.z)).rgb * 4.0 - 1.0;', - ' float n010 = dot(grad010, pf - vec3(0.0, 1.0, 0.0));', - ' vec3 grad011 = rnm(vec2(perm01, pi.z + permTexUnit)).rgb * 4.0 - 1.0;', - ' float n011 = dot(grad011, pf - vec3(0.0, 1.0, 1.0));', - - // Noise contributions from (x=1, y=0), z=0 and z=1 - ' float perm10 = rnm(pi.xy + vec2(permTexUnit, 0.0)).a ;', - ' vec3 grad100 = rnm(vec2(perm10, pi.z)).rgb * 4.0 - 1.0;', - ' float n100 = dot(grad100, pf - vec3(1.0, 0.0, 0.0));', - ' vec3 grad101 = rnm(vec2(perm10, pi.z + permTexUnit)).rgb * 4.0 - 1.0;', - ' float n101 = dot(grad101, pf - vec3(1.0, 0.0, 1.0));', - - // Noise contributions from (x=1, y=1), z=0 and z=1 - ' float perm11 = rnm(pi.xy + vec2(permTexUnit, permTexUnit)).a ;', - ' vec3 grad110 = rnm(vec2(perm11, pi.z)).rgb * 4.0 - 1.0;', - ' float n110 = dot(grad110, pf - vec3(1.0, 1.0, 0.0));', - ' vec3 grad111 = rnm(vec2(perm11, pi.z + permTexUnit)).rgb * 4.0 - 1.0;', - ' float n111 = dot(grad111, pf - vec3(1.0, 1.0, 1.0));', - - // Blend contributions along x - ' vec4 n_x = mix(vec4(n000, n001, n010, n011), vec4(n100, n101, n110, n111), fade(pf.x));', - - // Blend contributions along y - ' vec2 n_xy = mix(n_x.xy, n_x.zw, fade(pf.y));', - - //Blend contributions along z - ' float n_xyz = mix(n_xy.x, n_xy.y, fade(pf.z));', - - ' return n_xyz;', - '}', - - 'void main(void) {', - ' timer = mod(time, 10000.0) / 10000.0;', - ' vec4 pixel = texture2D(source, vTexCoord);', - ' vec3 noise = vec3(pnoise3D(vec3(vTexCoord * resolution, timer + 0.0)));', - ' if (colored) {', - ' noise.g = pnoise3D(vec3(vTexCoord * resolution, timer + 1.0));', - ' noise.b = pnoise3D(vec3(vTexCoord * resolution, timer + 2.0));', - ' }', - ' gl_FragColor = vec4(pixel.rgb + noise * amount, pixel.a);', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - }, - time: { - type: 'number', - uniform: 'time', - mod: 65536 - }, - amount: { - type: 'number', - uniform: 'amount', - min: 0, - max: 1, - defaultValue: 0.03 - }, - colored: { - type: 'boolean', - uniform: 'colored', - defaultValue: false - } - }, - title: 'Film Grain', - description: 'Don\'t over-do it.' - }); -})); diff --git a/effects/seriously.freeze.js b/effects/seriously.freeze.js deleted file mode 100644 index 1548ca4..0000000 --- a/effects/seriously.freeze.js +++ /dev/null @@ -1,44 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('freeze', { - draw: function (shader, model, uniforms, frameBuffer, draw) { - if (!this.inputs.frozen) { - draw(shader, model, uniforms, frameBuffer); - } - }, - requires: function () { - return !this.inputs.frozen; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - frozen: { - type: 'boolean', - defaultValue: false, - updateSources: true - } - }, - title: 'Freeze', - description: 'Freeze Frame' - }); -})); diff --git a/effects/seriously.fxaa.js b/effects/seriously.fxaa.js deleted file mode 100644 index d404b07..0000000 --- a/effects/seriously.fxaa.js +++ /dev/null @@ -1,142 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - /* - http://en.wikipedia.org/wiki/Fast_approximate_anti-aliasing - - adapted from: - http://horde3d.org/wiki/index.php5?title=Shading_Technique_-_FXAA - */ - - Seriously.plugin('fxaa', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.vertex = [ - 'precision mediump float;', - - 'attribute vec4 position;', - 'attribute vec2 texCoord;', - - 'uniform vec2 resolution;', - 'uniform mat4 transform;', - - 'varying vec2 vTexCoord;', - 'varying vec2 vTexCoordNW;', - 'varying vec2 vTexCoordNE;', - 'varying vec2 vTexCoordSW;', - 'varying vec2 vTexCoordSE;', - - 'const vec2 diag = vec2(1.0, -1.0);', - - 'void main(void) {', - // first convert to screen space - ' vec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);', - ' screenPosition = transform * screenPosition;', - - // convert back to OpenGL coords - ' gl_Position.xy = screenPosition.xy * 2.0 / resolution;', - ' gl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);', - ' gl_Position.w = screenPosition.w;', - - ' vTexCoord = texCoord;', - - ' vec2 invRes = 1.0 / resolution;', - ' vTexCoordNW = texCoord - invRes;', - ' vTexCoordNE = texCoord + invRes * diag;', - ' vTexCoordSW = texCoord - invRes * diag;', - ' vTexCoordSE = texCoord + invRes;', - '}\n' - ].join('\n'); - - shaderSource.fragment = [ - 'precision mediump float;', - - '#define FXAA_REDUCE_MIN (1.0 / 128.0)', - '#define FXAA_REDUCE_MUL (1.0 / 8.0)', - '#define FXAA_SPAN_MAX 8.0', - - 'varying vec2 vTexCoord;', - 'varying vec2 vTexCoordNW;', - 'varying vec2 vTexCoordNE;', - 'varying vec2 vTexCoordSW;', - 'varying vec2 vTexCoordSE;', - - 'uniform vec2 resolution;', - 'uniform sampler2D source;', - - 'const vec3 luma = vec3(0.299, 0.587, 0.114);', - - 'void main(void) {', - ' vec4 original = texture2D(source, vTexCoord);', - ' vec3 rgbNW = texture2D(source, vTexCoordNW).rgb;', - ' vec3 rgbNE = texture2D(source, vTexCoordNE).rgb;', - ' vec3 rgbSW = texture2D(source, vTexCoordSW).rgb;', - ' vec3 rgbSE = texture2D(source, vTexCoordSE).rgb;', - - ' float lumaNW = dot(rgbNW, luma);', - ' float lumaNE = dot(rgbNE, luma);', - ' float lumaSW = dot(rgbSW, luma);', - ' float lumaSE = dot(rgbSE, luma);', - ' float lumaM = dot(original.rgb, luma);', - - ' float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));', - ' float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));', - - ' vec2 dir = vec2(' + - '-((lumaNW + lumaNE) - (lumaSW + lumaSE)), ' + - '((lumaNW + lumaSW) - (lumaNE + lumaSE))' + - ');', - - ' float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * 0.25 * FXAA_REDUCE_MUL, FXAA_REDUCE_MIN);', - - ' float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);', - - ' dir = min(vec2(FXAA_SPAN_MAX), max(vec2(-FXAA_SPAN_MAX), dir * rcpDirMin)) / resolution;', - - ' vec3 rgbA = 0.5 * (', - ' texture2D(source, vTexCoord + dir * (1.0 / 3.0 - 0.5)).rgb +', - ' texture2D(source, vTexCoord + dir * (2.0 / 3.0 - 0.5)).rgb);', - - ' vec3 rgbB = rgbA * 0.5 + 0.25 * (', - ' texture2D(source, vTexCoord - dir * 0.5).rgb +', - ' texture2D(source, vTexCoord + dir * 0.5).rgb);', - - ' float lumaB = dot(rgbB, luma);', - ' if (lumaB < lumaMin || lumaB > lumaMax) {', - ' gl_FragColor = vec4(rgbA, original.a);', - ' } else {', - ' gl_FragColor = vec4(rgbB, original.a);', - ' }', - '}' - ].join('\n'); - - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - } - }, - title: 'FXAA', - description: 'Fast approximate anti-aliasing' - }); -})); diff --git a/effects/seriously.gradientwipe.js b/effects/seriously.gradientwipe.js deleted file mode 100644 index 9cbf7bf..0000000 --- a/effects/seriously.gradientwipe.js +++ /dev/null @@ -1,190 +0,0 @@ -/* global define, require */ -(function (root, factory) { - 'use strict'; - - if (typeof exports === 'object') { - // Node/CommonJS - factory(require('seriously')); - } else if (typeof define === 'function' && define.amd) { - // AMD. Register as an anonymous module. - define(['seriously'], factory); - } else { - if (!root.Seriously) { - root.Seriously = { plugin: function (name, opt) { this[name] = opt; } }; - } - factory(root.Seriously); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('gradientwipe', function () { - this.uniforms.resGradient = [1, 1]; - this.uniforms.resSource = [1, 1]; - - return { - shader: function (inputs, shaderSource) { - shaderSource.vertex = [ - 'precision mediump float;', - - 'attribute vec4 position;', - 'attribute vec2 texCoord;', - - 'uniform vec2 resolution;', - 'uniform vec2 resSource;', - 'uniform vec2 resGradient;', - - 'varying vec2 texCoordSource;', - 'varying vec2 texCoordGradient;', - - 'const vec2 HALF = vec2(0.5);', - - 'void main(void) {', - //we don't need to do a transform in this shader, since this effect is not "inPlace" - ' gl_Position = position;', - - ' vec2 adjusted = (texCoord - HALF) * resolution;', - - ' texCoordSource = adjusted / resSource + HALF;', - ' texCoordGradient = adjusted / resGradient + HALF;', - '}' - ].join('\n'); - - shaderSource.fragment = [ - 'precision mediump float;\n', - - 'varying vec2 texCoordSource;', - 'varying vec2 texCoordGradient;', - - 'uniform sampler2D source;', - 'uniform sampler2D gradient;', - - 'uniform float transition;', - 'uniform float smoothness;', - 'uniform bool invert;', - - 'const vec3 lumcoeff = vec3(0.2125,0.7154,0.0721);', - - 'void main(void) {', - ' float gradientVal = 1.0 - dot(texture2D(gradient, texCoordGradient).rgb, lumcoeff);', - - ' if (invert) {', - ' gradientVal = 1.0 - gradientVal;', - ' }', - - ' float amount = 1.0 - transition;', - - ' float mn = (amount - smoothness * (1.0 - amount));', - ' float mx = (amount + smoothness * amount);', - - ' if (gradientVal <= mn) {', - ' gl_FragColor = texture2D(source, texCoordSource);', - ' return;', - ' }', - - ' if (gradientVal >= mx) {', - ' gl_FragColor = vec4(0.0);', - ' return;', - ' }', - - ' float alpha = mix(1.0, 0.0, smoothstep(mn, mx, gradientVal));', - ' vec4 pixel = texture2D(source, texCoordSource);', - - ' gl_FragColor = vec4(pixel.rgb, pixel.a * alpha);', - '}' - ].join('\n'); - - return shaderSource; - }, - draw: function (shader, model, uniforms, frameBuffer, parent) { - var gl; - - //* - if (uniforms.transition <= 0) { - //uniforms.source = uniforms.sourceB; - parent(this.baseShader, model, uniforms, frameBuffer); - return; - } - //*/ - - //* - if (uniforms.transition >= 1) { - gl = this.gl; - - gl.viewport(0, 0, this.width, this.height); - gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer); - gl.clearColor(0.0, 0.0, 0.0, 0.0); - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - - return; - } - //*/ - - parent(shader, model, uniforms, frameBuffer); - }, - inPlace: false, - requires: function (sourceName, inputs) { - - if (sourceName === 'source' && inputs.transition >= 1) { - return false; - } - - if (sourceName === 'gradient' && - (inputs.transition <= 0 || inputs.transition >= 1)) { - return false; - } - - return true; - }, - resize: function () { - var source = this.inputs.source, - gradient = this.inputs.gradient; - - if (source) { - this.uniforms.resSource[0] = source.width; - this.uniforms.resSource[1] = source.height; - } else { - this.uniforms.resSource[0] = 1; - this.uniforms.resSource[1] = 1; - } - - if (gradient) { - this.uniforms.resGradient[0] = gradient.width; - this.uniforms.resGradient[1] = gradient.height; - } else { - this.uniforms.resGradient[0] = 1; - this.uniforms.resGradient[1] = 1; - } - } - }; - }, - { - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - gradient: { - type: 'image', - uniform: 'gradient' - }, - transition: { - type: 'number', - uniform: 'transition', - defaultValue: 0 - }, - invert: { - type: 'boolean', - uniform: 'invert', - defaultValue: false - }, - smoothness: { - type: 'number', - uniform: 'smoothness', - defaultValue: 0, - min: 0, - max: 1 - } - }, - title: 'Gradient Wipe' - }); -})); diff --git a/effects/seriously.hex.js b/effects/seriously.hex.js deleted file mode 100644 index 80cbb64..0000000 --- a/effects/seriously.hex.js +++ /dev/null @@ -1,105 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - /* - - Shader adapted from glfx.js by Evan Wallace - License: https://github.com/evanw/glfx.js/blob/master/LICENSE - */ - - Seriously.plugin('hex', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;\n', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform vec2 resolution;', - 'uniform vec2 center;', - 'uniform float size;', - - 'void main(void) {', - ' vec2 aspect = normalize(resolution);', - ' vec2 tex = (vTexCoord * aspect - center) / size;', - ' tex.y /= 0.866025404;', - ' tex.x -= tex.y * 0.5;', - ' vec2 a;', - ' if (tex.x + tex.y - floor(tex.x) - floor(tex.y) < 1.0) {', - ' a = vec2(floor(tex.x), floor(tex.y));', - ' } else {', - ' a = vec2(ceil(tex.x), ceil(tex.y));', - ' }', - ' vec2 b = vec2(ceil(tex.x), floor(tex.y));', - ' vec2 c = vec2(floor(tex.x), ceil(tex.y));', - ' vec3 tex3 = vec3(tex.x, tex.y, 1.0 - tex.x - tex.y);', - ' vec3 a3 = vec3(a.x, a.y, 1.0 - a.x - a.y);', - ' vec3 b3 = vec3(b.x, b.y, 1.0 - b.x - b.y);', - ' vec3 c3 = vec3(c.x, c.y, 1.0 - c.x - c.y);', - ' float alen =length(tex3 - a3);', - ' float blen =length(tex3 - b3);', - ' float clen =length(tex3 - c3);', - ' vec2 choice;', - ' if (alen < blen) {', - ' if (alen < clen) {', - ' choice = a;', - ' } else {', - ' choice = c;', - ' }', - ' } else {', - ' if (blen < clen) {', - ' choice = b;', - ' } else {', - ' choice = c;', - ' }', - ' }', - ' choice.x += choice.y * 0.5;', - ' choice.y *= 0.866025404;', - ' choice *= size / aspect;', - ' gl_FragColor = texture2D(source, choice + center / aspect);', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: false, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - }, - size: { - type: 'number', - uniform: 'size', - min: 0, - max: 0.4, - defaultValue: 0.01 - }, - center: { - type: 'vector', - uniform: 'center', - dimensions: 2, - defaultValue: [0, 0] - } - }, - title: 'Hex', - description: 'Hexagonal Pixelate' - }); -})); diff --git a/effects/seriously.highlights-shadows.js b/effects/seriously.highlights-shadows.js deleted file mode 100644 index e376156..0000000 --- a/effects/seriously.highlights-shadows.js +++ /dev/null @@ -1,71 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('highlights-shadows', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform float shadows;', - 'uniform float highlights;', - - 'const vec3 luma = vec3(0.2125, 0.7154, 0.0721);', - - 'void main(void) {', - ' vec4 pixel = texture2D(source, vTexCoord);', - ' float luminance = dot(pixel.rgb, luma);', - ' float shadow = clamp((pow(luminance, 1.0 / (shadows + 1.0)) + (-0.76) * pow(luminance, 2.0 / (shadows + 1.0))) - luminance, 0.0, 1.0);', - ' float highlight = clamp((1.0 - (pow(1.0 - luminance, 1.0 / (2.0 - highlights)) + (-0.8) * pow(1.0 - luminance, 2.0 / (2.0 - highlights)))) - luminance, -1.0, 0.0);', - ' vec3 rgb = (luminance + shadow + highlight) * (pixel.rgb / vec3(luminance));', - //' vec3 rgb = vec3(0.0, 0.0, 0.0) + ((luminance + shadow + highlight) - 0.0) * ((pixel.rgb - vec3(0.0, 0.0, 0.0))/(luminance - 0.0));', - ' gl_FragColor = vec4(rgb, pixel.a);', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - }, - highlights: { - type: 'number', - uniform: 'highlights', - min: 0, - max: 1, - defaultValue: 1 - }, - shadows: { - type: 'number', - uniform: 'shadows', - min: 0, - max: 1, - defaultValue: 0 - } - }, - title: 'Highlights/Shadows', - description: 'Darken highlights, lighten shadows' - }); -})); diff --git a/effects/seriously.hue-saturation.js b/effects/seriously.hue-saturation.js deleted file mode 100644 index 259ab6a..0000000 --- a/effects/seriously.hue-saturation.js +++ /dev/null @@ -1,119 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - //inspired by Evan Wallace (https://github.com/evanw/glfx.js) - - Seriously.plugin('hue-saturation', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.vertex = [ - 'precision mediump float;', - - 'attribute vec4 position;', - 'attribute vec2 texCoord;', - - 'uniform vec2 resolution;', - 'uniform mat4 projection;', - 'uniform mat4 transform;', - - 'uniform float hue;', - 'uniform float saturation;', - - 'varying vec2 vTexCoord;', - - 'varying vec3 weights;', - - 'void main(void) {', - ' float angle = hue * 3.14159265358979323846264;', - ' float s = sin(angle);', - ' float c = cos(angle);', - ' weights = (vec3(2.0 * c, -sqrt(3.0) * s - c, sqrt(3.0) * s - c) + 1.0) / 3.0;', - - // first convert to screen space - ' vec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);', - ' screenPosition = transform * screenPosition;', - - // convert back to OpenGL coords - ' gl_Position = screenPosition;', - ' gl_Position.xy = screenPosition.xy * 2.0 / resolution;', - ' gl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);', - ' vTexCoord = texCoord;', - '}' - ].join('\n'); - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'varying vec3 weights;', - - 'uniform sampler2D source;', - 'uniform float hue;', - 'uniform float saturation;', - - 'void main(void) {', - ' vec4 color = texture2D(source, vTexCoord);', - - //adjust hue - ' float len = length(color.rgb);', - ' color.rgb = vec3(' + - 'dot(color.rgb, weights.xyz), ' + - 'dot(color.rgb, weights.zxy), ' + - 'dot(color.rgb, weights.yzx) ' + - ');', - - //adjust saturation - ' vec3 adjustment = (color.r + color.g + color.b) / 3.0 - color.rgb;', - ' if (saturation > 0.0) {', - ' adjustment *= (1.0 - 1.0 / (1.0 - saturation));', - ' } else {', - ' adjustment *= (-saturation);', - ' }', - ' color.rgb += adjustment;', - - ' gl_FragColor = color;', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - hue: { - type: 'number', - uniform: 'hue', - defaultValue: 0.4, - min: -1, - max: 1 - }, - saturation: { - type: 'number', - uniform: 'saturation', - defaultValue: 0, - min: -1, - max: 1 - } - }, - title: 'Hue/Saturation', - description: 'Rotate hue and multiply saturation.' - }); -})); diff --git a/effects/seriously.invert.js b/effects/seriously.invert.js deleted file mode 100644 index 2210206..0000000 --- a/effects/seriously.invert.js +++ /dev/null @@ -1,48 +0,0 @@ -/* 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); - } -}(window, 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' - }); -})); diff --git a/effects/seriously.kaleidoscope.js b/effects/seriously.kaleidoscope.js deleted file mode 100644 index fe47b37..0000000 --- a/effects/seriously.kaleidoscope.js +++ /dev/null @@ -1,75 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('kaleidoscope', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform float segments;', - 'uniform float offset;', - - 'const float PI = ' + Math.PI + ';', - 'const float TAU = 2.0 * PI;', - - 'void main(void) {', - ' if (segments == 0.0) {', - ' gl_FragColor = texture2D(source, vTexCoord);', - ' } else {', - ' vec2 centered = vTexCoord - 0.5;', - - //to polar - ' float r = length(centered);', - ' float theta = atan(centered.y, centered.x);', - ' theta = mod(theta, TAU / segments);', - ' theta = abs(theta - PI / segments);', - - //back to cartesian - ' vec2 newCoords = r * vec2(cos(theta), sin(theta)) + 0.5;', - ' gl_FragColor = texture2D(source, mod(newCoords - offset, 1.0));', - ' }', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - }, - segments: { - type: 'number', - uniform: 'segments', - defaultValue: 6 - }, - offset: { - type: 'number', - uniform: 'offset', - defaultValue: 0 - } - }, - title: 'Kaleidoscope' - }); -})); diff --git a/effects/seriously.layers.js b/effects/seriously.layers.js deleted file mode 100644 index 50c7381..0000000 --- a/effects/seriously.layers.js +++ /dev/null @@ -1,255 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - var identity = new Float32Array([ - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 - ]), - intRegex = /\d+/; - - Seriously.plugin('layers', function (options) { - var count, - me = this, - topOpts = { - clear: false - }, - i, - inputs; - - function update() { - me.resize(); - } - - if (typeof options === 'number' && options >= 2) { - count = options; - } else { - count = options && options.count || 4; - count = Math.max(2, count); - } - - inputs = { - sizeMode: { - type: 'enum', - defaultValue: '0', - options: [ - 'union', - 'intersection' - ], - update: function () { - this.resize(); - } - } - }; - - for (i = 0; i < count; i++) { - inputs.sizeMode.options.push(i.toString()); - inputs.sizeMode.options.push('source' + i); - - //source - inputs['source' + i] = { - type: 'image', - update: update - }; - - //opacity - inputs['opacity' + i] = { - type: 'number', - defaultValue: 1, - min: 0, - max: 1, - updateSources: true - }; - } - - this.uniforms.layerResolution = [1, 1]; - - // custom resize method - this.resize = function () { - var width, - height, - mode = this.inputs.sizeMode, - i, - n, - source, - a; - - if (mode === 'union') { - width = 0; - height = 0; - for (i = 0; i < count; i++) { - source = this.inputs['source' + i]; - if (source) { - width = Math.max(width, source.width); - height = Math.max(height, source.height); - } - } - } else if (mode === 'intersection') { - width = Infinity; - height = Infinity; - for (i = 0; i < count; i++) { - source = this.inputs['source' + i]; - if (source) { - width = Math.min(width, source.width); - height = Math.min(height, source.height); - } - } - } else { - width = 1; - height = 1; - n = count - 1; - a = intRegex.exec(this.inputs.sizeMode); - if (a) { - n = Math.min(parseInt(a[0], 10), n); - } - - source = this.inputs['source' + n]; - if (source) { - width = source.width; - height = source.height; - } - } - - if (this.width !== width || this.height !== height) { - this.width = width; - this.height = height; - - this.uniforms.resolution[0] = width; - this.uniforms.resolution[1] = height; - - if (this.frameBuffer) { - this.frameBuffer.resize(width, height); - } - - this.emit('resize'); - this.setDirty(); - - for (i = 0; i < this.targets.length; i++) { - this.targets[i].resize(); - } - } - }; - - return { - initialize: function (initialize) { - var gl = this.gl; - initialize(); - - topOpts.blendEquation = gl.FUNC_ADD; - topOpts.srcRGB = gl.SRC_ALPHA; - topOpts.dstRGB = gl.ONE_MINUS_SRC_ALPHA; - topOpts.srcAlpha = gl.SRC_ALPHA; - topOpts.dstAlpha = gl.DST_ALPHA; - }, - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.vertex = [ - 'precision mediump float;', - - 'attribute vec4 position;', - 'attribute vec2 texCoord;', - - 'uniform vec2 resolution;', - 'uniform vec2 layerResolution;', - 'uniform mat4 transform;', - - 'varying vec2 vTexCoord;', - - 'void main(void) {', - // first convert to screen space - ' vec4 screenPosition = vec4(position.xy * layerResolution / 2.0, position.z, position.w);', - ' screenPosition = transform * screenPosition;', - - // convert back to OpenGL coords - ' gl_Position.xy = screenPosition.xy * 2.0 / layerResolution;', - ' gl_Position.z = screenPosition.z * 2.0 / (layerResolution.x / layerResolution.y);', - ' gl_Position.xy *= layerResolution / resolution;', - ' gl_Position.w = screenPosition.w;', - ' vTexCoord = texCoord;', - '}\n' - ].join('\n'); - - shaderSource.fragment = [ - 'precision mediump float;', - 'varying vec2 vTexCoord;', - 'uniform sampler2D source;', - 'uniform float opacity;', - 'void main(void) {', - ' if (any(lessThan(vTexCoord, vec2(0.0))) || any(greaterThanEqual(vTexCoord, vec2(1.0)))) {', - ' gl_FragColor = vec4(0.0);', - ' } else {', - ' gl_FragColor = texture2D(source, vTexCoord);', - ' gl_FragColor *= opacity;', - ' }', - '}' - ].join('\n'); - - return shaderSource; - }, - requires: function (sourceName, inputs) { - var a, index = count; - - a = intRegex.exec(this.inputs.sizeMode); - if (a) { - index = parseInt(a[0], 10); - } - if (index >= count) { - return false; - } - - return !!(inputs[sourceName] && inputs['opacity' + index]); - }, - draw: function (shader, model, uniforms, frameBuffer, draw) { - var i, - opacity, - source, - gl = this.gl; - - //clear in case we have no layers to draw - gl.viewport(0, 0, this.width, this.height); - gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer); - gl.clearColor(0.0, 0.0, 0.0, 0.0); - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - - for (i = 0; i < count; i++) { - source = this.inputs['source' + i]; - opacity = this.inputs['opacity' + i]; - - //don't draw if layer is disconnected or opacity is 0 - if (source && opacity) { - uniforms.opacity = opacity; - uniforms.layerResolution[0] = source.width; - uniforms.layerResolution[1] = source.height; - uniforms.source = source; - uniforms.transform = source.cumulativeMatrix || identity; - - draw(shader, model, uniforms, frameBuffer, null, topOpts); - } - } - }, - inputs: inputs - }; - }, - { - inPlace: true, - description: 'Multiple layers', - title: 'Layers' - }); -})); diff --git a/effects/seriously.linear-transfer.js b/effects/seriously.linear-transfer.js deleted file mode 100644 index 080f0b8..0000000 --- a/effects/seriously.linear-transfer.js +++ /dev/null @@ -1,63 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('linear-transfer', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform vec4 slope;', - 'uniform vec4 intercept;', - - 'const vec3 half3 = vec3(0.5);', - - 'void main(void) {', - ' vec4 pixel = texture2D(source, vTexCoord);', - ' gl_FragColor = pixel * slope + intercept;', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - slope: { - type: 'vector', - dimensions: 4, - uniform: 'slope', - defaultValue: [1, 1, 1, 1] - }, - intercept: { - type: 'vector', - uniform: 'intercept', - dimensions: 4, - defaultValue: [0, 0, 0, 0] - } - }, - title: 'Linear Transfer', - description: 'For each color channel: [slope] * [value] + [intercept]' - }); -})); diff --git a/effects/seriously.lumakey.js b/effects/seriously.lumakey.js deleted file mode 100644 index 1a6e224..0000000 --- a/effects/seriously.lumakey.js +++ /dev/null @@ -1,78 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('lumakey', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - - 'uniform float threshold;', - 'uniform float clipBlack;', - 'uniform float clipWhite;', - 'uniform bool invert;', - - 'const vec3 lumcoeff = vec3(0.2125,0.7154,0.0721);', - - 'void main (void) {', - ' vec4 pixel = texture2D(source, vTexCoord);', - ' float luma = dot(pixel.rgb,lumcoeff);', - ' float alpha = 1.0 - smoothstep(clipBlack, clipWhite, luma);', - ' if (invert) alpha = 1.0 - alpha;', - ' gl_FragColor = vec4(pixel.rgb, min(pixel.a, alpha) );', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - }, - clipBlack: { - type: 'number', - uniform: 'clipBlack', - defaultValue: 0.9, - min: 0, - max: 1 - }, - clipWhite: { - type: 'number', - uniform: 'clipWhite', - defaultValue: 1, - min: 0, - max: 1 - }, - invert: { - type: 'boolean', - uniform: 'invert', - defaultValue: false - } - }, - title: 'Luma Key', - categories: ['key'], - description: '' - }); -})); diff --git a/effects/seriously.lut.js b/effects/seriously.lut.js deleted file mode 100644 index 0ebb535..0000000 --- a/effects/seriously.lut.js +++ /dev/null @@ -1,87 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('lut', { - commonShader: true, - shader: function (inputs, shaderSource) { - /* - Shader borrowed from Paul Golds @ BBC R&D, with permission - */ - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform sampler2D lut;', - 'uniform float amount;', - - 'void main(void) {', - - ' vec4 textureColor = texture2D(source, vTexCoord);', - ' textureColor = clamp(textureColor, 0.0, 1.0);', - - ' float blueColor = textureColor.b * 63.0;', - - ' vec2 quad1;', - ' quad1.y = floor(floor(blueColor) / 8.0);', - ' quad1.x = floor(blueColor) - (quad1.y * 8.0);', - - ' vec2 quad2;', - ' quad2.y = floor(ceil(blueColor) / 8.0);', - ' quad2.x = ceil(blueColor) - (quad2.y * 8.0);', - - ' vec2 texPos1;', - ' texPos1 = (quad1 * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.rg);', - - ' vec2 texPos2;', - ' texPos2 = (quad2 * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.rg);', - - ' lowp vec4 newColor1 = texture2D(lut, vec2(texPos1.x, 1.0 - texPos1.y));', - ' lowp vec4 newColor2 = texture2D(lut, vec2(texPos2.x, 1.0 - texPos2.y));', - - ' vec4 newColor = mix(newColor1, newColor2, fract(blueColor));', - - ' gl_FragColor = mix(textureColor, newColor, amount);', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - lut: { - type: 'image', - uniform: 'lut' - }, - amount: { - type: 'number', - uniform: 'amount', - min: 0, - max: 1, - defaultValue: 1 - } - }, - title: 'Color Look-Up Table', - description: '' - }); -})); diff --git a/effects/seriously.mirror.js b/effects/seriously.mirror.js deleted file mode 100644 index e29ccc2..0000000 --- a/effects/seriously.mirror.js +++ /dev/null @@ -1,47 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('mirror', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'uniform vec2 resolution;', - 'uniform sampler2D source;', - - 'varying vec2 vTexCoord;', - - 'void main(void) {', - ' gl_FragColor = texture2D(source, vec2(0.5 - abs(0.5 - vTexCoord.x), vTexCoord.y));', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source' - } - }, - title: 'Mirror', - description: 'Shader Mirror Effect' - }); -})); diff --git a/effects/seriously.nightvision.js b/effects/seriously.nightvision.js deleted file mode 100644 index f2800fa..0000000 --- a/effects/seriously.nightvision.js +++ /dev/null @@ -1,87 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - //based on tutorial: http://www.geeks3d.com/20091009/shader-library-night-vision-post-processing-filter-glsl/ - //todo: make noise better? - - Seriously.plugin('nightvision', { - commonShader: true, - shader: function (inputs, shaderSource, utilities) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform float time;', - 'uniform float luminanceThreshold;', - 'uniform float amplification;', - 'uniform vec3 nightVisionColor;', - - utilities.shader.makeNoise, - - 'void main(void) {', - ' vec3 noise = vec3(' + - 'makeNoise(vTexCoord.x, vTexCoord.y, time), ' + - 'makeNoise(vTexCoord.x, vTexCoord.y, time * 200.0 + 1.0), ' + - 'makeNoise(vTexCoord.x, vTexCoord.y, time * 100.0 + 3.0)' + - ');', - ' vec4 pixel = texture2D(source, vTexCoord + noise.xy * 0.0025);', - ' float luminance = dot(vec3(0.299, 0.587, 0.114), pixel.rgb);', - ' pixel.rgb *= step(luminanceThreshold, luminance) * amplification;', - ' gl_FragColor = vec4( (pixel.rgb + noise * 0.1) * nightVisionColor, pixel.a);', - '}' - ].join('\n'); - return shaderSource; - }, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - }, - time: { - type: 'number', - uniform: 'time', - defaultValue: 0, - mod: 65536 - }, - luminanceThreshold: { - type: 'number', - uniform: 'luminanceThreshold', - defaultValue: 0.1, - min: 0, - max: 1 - }, - amplification: { - type: 'number', - uniform: 'amplification', - defaultValue: 1.4, - min: 0 - }, - color: { - type: 'color', - uniform: 'nightVisionColor', - defaultValue: [0.1, 0.95, 0.2] - } - }, - title: 'Night Vision', - description: '' - }); -})); diff --git a/effects/seriously.noise.js b/effects/seriously.noise.js deleted file mode 100644 index 42df1f6..0000000 --- a/effects/seriously.noise.js +++ /dev/null @@ -1,86 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('noise', { - shader: function (inputs, shaderSource, utilities) { - var frag = [ - 'precision mediump float;', - - '#define Blend(base, blend, funcf) vec3(funcf(base.r, blend.r), funcf(base.g, blend.g), funcf(base.b, blend.b))', - '#define BlendOverlayf(base, blend) (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)))', - '#define BlendOverlay(base, blend) Blend(base, blend, BlendOverlayf)', - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - - 'uniform vec2 resolution;', - 'uniform float amount;', - 'uniform float time;', - - utilities.shader.noiseHelpers, - utilities.shader.snoise3d, - utilities.shader.random, - - 'void main(void) {', - ' vec4 pixel = texture2D(source, vTexCoord);', - ' float r = random(vec2(time * vTexCoord.xy));', - ' float noise = snoise(vec3(vTexCoord * (1024.4 + r * 512.0), time)) * 0.5;' - ]; - - if (inputs.overlay) { - frag.push(' vec3 overlay = BlendOverlay(pixel.rgb, vec3(noise));'); - frag.push(' pixel.rgb = mix(pixel.rgb, overlay, amount);'); - } else { - frag.push(' pixel.rgb += noise * amount;'); - } - frag.push(' gl_FragColor = pixel;}'); - - shaderSource.fragment = frag.join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - }, - overlay: { - type: 'boolean', - shaderDirty: true, - defaultValue: true - }, - amount: { - type: 'number', - uniform: 'amount', - min: 0, - max: 1, - defaultValue: 1 - }, - time: { - type: 'number', - uniform: 'time', - defaultValue: 0, - mod: 65536 - } - }, - title: 'Noise', - description: 'Add noise' - }); -})); diff --git a/effects/seriously.opticalflow.js b/effects/seriously.opticalflow.js deleted file mode 100644 index b4ce2eb..0000000 --- a/effects/seriously.opticalflow.js +++ /dev/null @@ -1,145 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - /* - Horn-Schunke Optical Flow - Based on shader by Andrew Benson - https://github.com/v002/v002-Optical-Flow/blob/master/v002.GPUHSFlow.frag - - Creative Commons, Attribution – Non Commercial – Share Alike 3.0 - http://v002.info/licenses/ - */ - - Seriously.plugin('opticalflow', function () { - var previousFrameBuffer, - baseShader; - - return { - initialize: function (initialize) { - previousFrameBuffer = new Seriously.util.FrameBuffer(this.gl, this.width, this.height); - initialize(); - baseShader = this.baseShader; - }, - resize: function () { - previousFrameBuffer.resize(this.width, this.height); - }, - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform sampler2D previous;', - 'uniform vec2 resolution;', - - 'uniform vec2 scale;', - 'uniform float offsetX;', - 'uniform float lambda;', - // 'const vec4 lumcoeff = vec4(0.299, 0.587, 0.114, 0.0);', - - 'void main() {', - ' vec4 a = texture2D(previous, vTexCoord);', - ' vec4 b = texture2D(source, vTexCoord);', - ' vec2 offset = offsetX / resolution;', - ' vec2 x1 = vec2(offset.x, 0.0);', - ' vec2 y1 = vec2(0.0, offset.y);', - - //get the difference - ' vec4 curdif = b - a;', - - //calculate the gradient - ' vec4 gradx = texture2D(source, vTexCoord + x1) - texture2D(source, vTexCoord - x1);', - ' gradx += texture2D(previous, vTexCoord + x1) - texture2D(previous, vTexCoord - x1);', - - ' vec4 grady = texture2D(source, vTexCoord + y1) - texture2D(source, vTexCoord - y1);', - ' grady += texture2D(previous, vTexCoord + y1) - texture2D(previous, vTexCoord - y1);', - - ' vec4 gradmag = sqrt((gradx * gradx) + (grady * grady) + vec4(lambda));', - - ' vec4 vx = curdif * (gradx / gradmag);', - ' float vxd = vx.r;', //assumes greyscale - - //format output for flowrepos, out(-x,+x,-y,+y) - ' vec2 xout = vec2(max(vxd, 0.0), abs(min(vxd, 0.0))) * scale.x;', - - ' vec4 vy = curdif * (grady / gradmag);', - ' float vyd = vy.r;', //assumes greyscale - - //format output for flowrepos, out(-x,+x,-y,+y) - ' vec2 yout = vec2(max(vyd, 0.0), abs(min(vyd, 0.0))) * scale.y;', - - ' gl_FragColor = clamp(vec4(xout.xy, yout.xy), 0.0, 1.0);', - ' gl_FragColor.a = 1.0;', - '}' - ].join('\n'); - - return shaderSource; - }, - draw: function (shader, model, uniforms, frameBuffer, parent) { - uniforms.previous = previousFrameBuffer.texture; - - parent(shader, model, uniforms, frameBuffer); - - //todo: just swap buffers rather than copy? - parent(baseShader, model, uniforms, previousFrameBuffer.frameBuffer); - }, - destroy: function () { - if (previousFrameBuffer) { - previousFrameBuffer.destroy(); - previousFrameBuffer = null; - } - } - }; - }, - { - inPlace: false, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - }, - lambda: { - type: 'number', - uniform: 'lambda', - min: 0, - defaultValue: 0, - description: 'noise limiting' - }, - scaleResult: { - type: 'vector', - dimensions: 2, - uniform: 'scale', - defaultValue: [1, 1] - }, - offset: { - type: 'number', - uniform: 'offsetX', - defaultValue: 1, - min: 1, - max: 100, - description: 'distance between texel samples for gradient calculation' - } - }, - description: 'Horn-Schunke Optical Flow', - title: 'Optical Flow' - }); -})); diff --git a/effects/seriously.panorama.js b/effects/seriously.panorama.js deleted file mode 100644 index fa6d1a5..0000000 --- a/effects/seriously.panorama.js +++ /dev/null @@ -1,185 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('panorama', function () { - var me = this; - - function resize() { - me.resize(); - } - - // custom resize method - this.resize = function () { - var width = this.width, - height = this.height, - source = me.inputs.source, - i; - - if (this.source) { - width = this.source.width; - height = this.source.height; - } else if (this.sources && this.sources.source) { - width = this.sources.source.width; - height = this.sources.source.height; - } else { - width = 1; - height = 1; - } - - if (me.inputs.width) { - width = me.inputs.width; - if (me.inputs.height) { - height = me.inputs.height; - } else if (source) { - //match source aspect ratio - height = width * source.height / source.width; - } - } else if (me.inputs.height) { - height = me.inputs.height; - if (source) { - //match source aspect ratio - width = height * source.width / source.height; - } - } - - width = Math.floor(width); - height = Math.floor(height); - - if (source) { - this.uniforms.resolution[0] = width; - this.uniforms.resolution[1] = height; - } - - if (this.width !== width || this.height !== height) { - this.width = width; - this.height = height; - - if (this.frameBuffer) { - this.frameBuffer.resize(this.width, this.height); - } - - this.emit('resize'); - this.setDirty(); - } - - for (i = 0; i < this.targets.length; i++) { - this.targets[i].resize(); - } - }; - - return { - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform vec2 resolution;', - 'uniform sampler2D source;', - - 'uniform float fov;', - 'uniform float yaw;', - 'uniform float pitch;', - - 'const float M_PI = 3.141592653589793238462643;', - 'const float M_TWOPI = 6.283185307179586476925286;', - - 'mat3 rotationMatrix(vec2 euler) {', - ' vec2 se = sin(euler);', - ' vec2 ce = cos(euler);', - - ' return mat3(ce.x, 0, -se.x, 0, 1, 0, se.x, 0, ce.x) * ', - ' mat3(1, 0, 0, 0, ce.y, -se.y, 0, se.y, ce.y);', - '}', - - 'vec3 toCartesian( vec2 st ) {', - ' return normalize(vec3(st.x, st.y, 0.5 / tan(0.5 * radians(fov))));', - '}', - - 'vec2 toSpherical(vec3 cartesianCoord) {', - ' vec2 st = vec2(', - ' atan(cartesianCoord.x, cartesianCoord.z),', - ' acos(cartesianCoord.y)', - ' );', - ' if(st.x < 0.0)', - ' st.x += M_TWOPI;', - - ' return st;', - '}', - - 'void main(void) {', - ' vec2 sphericalCoord = gl_FragCoord.xy / resolution - vec2(0.5);', - ' sphericalCoord.y *= -resolution.y / resolution.x;', - - ' vec3 cartesianCoord = rotationMatrix(radians(vec2(yaw + 180., -pitch))) * toCartesian(sphericalCoord);', - - ' gl_FragColor = texture2D(source, toSpherical( cartesianCoord )/vec2(M_TWOPI, M_PI));', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: false, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - }, - width: { - type: 'number', - min: 0, - step: 1, - update: resize, - defaultValue: 640 - }, - height: { - type: 'number', - min: 0, - step: 1, - update: resize, - defaultValue: 360 - }, - yaw: { - type: 'number', - uniform: 'yaw', - min: 0, - max: 360, - defaultValue: 0 - }, - fov: { - type: 'number', - uniform: 'fov', - min: 0, - max: 180, - defaultValue: 80 - }, - pitch: { - type: 'number', - uniform: 'pitch', - min: -90, - max: 90, - defaultValue: 0 - } - } - }; - }, { - commonShader: true, - title: 'Panorama' - }); -})); diff --git a/effects/seriously.pixelate.js b/effects/seriously.pixelate.js deleted file mode 100644 index 1c8d70a..0000000 --- a/effects/seriously.pixelate.js +++ /dev/null @@ -1,56 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('pixelate', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform vec2 resolution;', - 'uniform vec2 pixelSize;', - - 'void main(void) {', - ' vec2 delta = pixelSize / resolution;', - ' gl_FragColor = texture2D(source, delta * floor(vTexCoord / delta));', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - }, - pixelSize: { - type: 'vector', - dimensions: 2, - defaultValue: [8, 8], - min: 0, - uniform: 'pixelSize' - } - }, - title: 'Pixelate' - }); -})); diff --git a/effects/seriously.polar.js b/effects/seriously.polar.js deleted file mode 100644 index 43782dc..0000000 --- a/effects/seriously.polar.js +++ /dev/null @@ -1,58 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('polar', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform float angle;', - - 'const float PI = ' + Math.PI + ';', - - 'void main(void) {', - ' vec2 norm = (1.0 - vTexCoord) * 2.0 - 1.0;', - ' float theta = mod(PI + atan(norm.x, norm.y) - angle * (PI / 180.0), PI * 2.0);', - ' vec2 polar = vec2(theta / (2.0 * PI), length(norm));', - ' gl_FragColor = texture2D(source, polar);', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: false, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - }, - angle: { - type: 'number', - uniform: 'angle', - defaultValue: 0 - } - }, - title: 'Polar Coordinates', - description: 'Convert cartesian to polar coordinates' - }); -})); diff --git a/effects/seriously.repeat.js b/effects/seriously.repeat.js deleted file mode 100644 index 701f7b7..0000000 --- a/effects/seriously.repeat.js +++ /dev/null @@ -1,204 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - var identity = new Float32Array([ - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 - ]), - mat4 = Seriously.util.mat4; - - Seriously.plugin('repeat', function () { - var drawOpts = { - clear: false - }, - transform = new Float32Array(16), - me = this; - - function resize() { - me.resize(); - } - - // custom resize method - this.resize = function () { - var width = this.width, - height = this.height, - source = me.inputs.source, - i; - - if (this.source) { - width = this.source.width; - height = this.source.height; - } else if (this.sources && this.sources.source) { - width = this.sources.source.width; - height = this.sources.source.height; - } else { - width = 1; - height = 1; - } - - if (me.inputs.width) { - width = me.inputs.width; - if (me.inputs.height) { - height = me.inputs.height; - } else if (source) { - //match source aspect ratio - height = width * source.height / source.width; - } - } else if (me.inputs.height) { - height = me.inputs.height; - if (source) { - //match source aspect ratio - width = height * source.width / source.height; - } - } - - width = Math.floor(width); - height = Math.floor(height); - - if (source) { - this.uniforms.resolution[0] = source.width; - this.uniforms.resolution[1] = source.height; - } - - if (this.width !== width || this.height !== height) { - this.width = width; - this.height = height; - - this.uniforms.targetRes[0] = this.width; - this.uniforms.targetRes[1] = this.height; - - if (this.frameBuffer) { - this.frameBuffer.resize(this.width, this.height); - } - - this.emit('resize'); - this.setDirty(); - } - - for (i = 0; i < this.targets.length; i++) { - this.targets[i].resize(); - } - }; - - this.uniforms.targetRes = [1, 1]; - - return { - initialize: function (initialize) { - initialize(); - this.uniforms.transform = transform; - }, - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.vertex = [ - 'precision mediump float;', - - 'attribute vec4 position;', - 'attribute vec2 texCoord;', - - 'uniform vec2 resolution;', - 'uniform vec2 targetRes;', - 'uniform mat4 transform;', - - 'varying vec2 vTexCoord;', - - 'void main(void) {', - // first convert to screen space - ' vec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);', - ' screenPosition = transform * screenPosition;', - - // convert back to OpenGL coords - ' gl_Position = screenPosition;', - ' gl_Position.xy = screenPosition.xy * 2.0 / resolution;', - ' gl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);', - ' gl_Position.xy *= resolution / targetRes;', - ' vTexCoord = texCoord;', - '}\n' - ].join('\n'); - return shaderSource; - }, - draw: function (shader, model, uniforms, frameBuffer, draw) { - var i, - source = this.inputs.source, - transform = this.inputs.transform, - transformMatrix = transform && transform.cumulativeMatrix, - repeat = this.inputs.repeat, - gl = this.gl; - - if (transformMatrix && transform.transformed) { - mat4.copy(uniforms.transform, source && source.cumulativeMatrix || identity); - } else { - repeat = Math.min(repeat, 1); - } - - // first, clear - gl.viewport(0, 0, this.width, this.height); - gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer); - gl.clearColor(0.0, 0.0, 0.0, 0.0); - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - - for (i = repeat - 1; i >= 0; i--) { - draw(shader, model, uniforms, frameBuffer, null, drawOpts); - if (i) { - mat4.multiply(uniforms.transform, transformMatrix, uniforms.transform); - } - } - }, - inputs: { - source: { - type: 'image', - uniform: 'source', - update: function () { - resize(); - this.uniforms.transform = transform; - } - }, - transform: { - type: 'image' - }, - repeat: { - type: 'number', - step: 1, - min: 0, - defaultValue: 8 - }, - width: { - type: 'number', - min: 0, - step: 1, - update: resize, - defaultValue: 0 - }, - height: { - type: 'number', - min: 0, - step: 1, - update: resize, - defaultValue: 0 - } - } - }; - }, - { - inPlace: true, - description: 'Draw image multiple times, transforming each time', - title: 'Repeat' - }); -})); diff --git a/effects/seriously.ripple.js b/effects/seriously.ripple.js deleted file mode 100644 index 36d3898..0000000 --- a/effects/seriously.ripple.js +++ /dev/null @@ -1,72 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - //http://msdn.microsoft.com/en-us/library/bb313868(v=xnagamestudio.10).aspx - Seriously.plugin('ripple', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform float wave;', - 'uniform float distortion;', - 'uniform vec2 center;', - - 'void main(void) {', - //todo: can at least move scalar into vertex shader - ' float scalar = abs(1.0 - abs(distance(vTexCoord, center)));', - ' float sinOffset = sin(wave / scalar);', - ' sinOffset = clamp(sinOffset, 0.0, 1.0);', - ' float sinSign = cos(wave / scalar);', - ' sinOffset = sinOffset * distortion / 32.0;', - ' gl_FragColor = texture2D(source, vTexCoord + sinOffset * sinSign);', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: false, - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - wave: { - type: 'number', - uniform: 'wave', - defaultValue: Math.PI / 0.75 - }, - distortion: { - type: 'number', - uniform: 'distortion', - defaultValue: 1 - }, - center: { - type: 'vector', - uniform: 'center', - dimensions: 2, - defaultValue: [0.5, 0.5] - } - }, - title: 'Ripple Distortion', - description: '' - }); -})); diff --git a/effects/seriously.scanlines.js b/effects/seriously.scanlines.js deleted file mode 100644 index ca36556..0000000 --- a/effects/seriously.scanlines.js +++ /dev/null @@ -1,74 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('scanlines', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform float lines;', - 'uniform float width;', - 'uniform float intensity;', - - //todo: add vertical offset for animating - - 'void main(void) {', - ' vec4 pixel = texture2D(source, vTexCoord);', - ' float darken = 2.0 * abs( fract(vTexCoord.y * lines / 2.0) - 0.5);', - ' darken = clamp(darken - width + 0.5, 0.0, 1.0);', - ' darken = 1.0 - ((1.0 - darken) * intensity);', - ' gl_FragColor = vec4(pixel.rgb * darken, 1.0);', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - lines: { - type: 'number', - uniform: 'lines', - defaultValue: 60 - }, - size: { - type: 'number', - uniform: 'size', - defaultValue: 0.2, - min: 0, - max: 1 - }, - intensity: { - type: 'number', - uniform: 'intensity', - defaultValue: 0.1, - min: 0, - max: 1 - } - }, - title: 'Scan Lines', - description: '' - }); -})); diff --git a/effects/seriously.select.js b/effects/seriously.select.js deleted file mode 100644 index c44ec7e..0000000 --- a/effects/seriously.select.js +++ /dev/null @@ -1,178 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - var intRegex = /\d+/; - - Seriously.plugin('select', function (options) { - var count, - me = this, - i, - inputs; - - function resize() { - me.resize(); - } - - function update() { - var i = me.inputs.active, - source; - - source = me.inputs['source' + i]; - me.texture = source && source.texture; - - resize(); - } - - if (typeof options === 'number' && options >= 2) { - count = options; - } else { - count = options && options.count || 4; - count = Math.max(2, count); - } - - inputs = { - active: { - type: 'number', - step: 1, - min: 0, - max: count - 1, - defaultValue: 0, - update: update, - updateSources: true - }, - sizeMode: { - type: 'enum', - defaultValue: '0', - options: [ - 'union', - 'intersection', - 'active' - ], - update: resize - } - }; - - for (i = 0; i < count; i++) { - inputs.sizeMode.options.push(i.toString()); - inputs.sizeMode.options.push('source' + i); - - //source - inputs['source' + i] = { - type: 'image', - update: update - }; - } - - this.uniforms.layerResolution = [1, 1]; - - // custom resize method - this.resize = function () { - var width, - height, - mode = this.inputs.sizeMode, - i, - n, - source, - a; - - if (mode === 'union') { - width = 0; - height = 0; - for (i = 0; i < count; i++) { - source = this.inputs['source' + i]; - if (source) { - width = Math.max(width, source.width); - height = Math.max(height, source.height); - } - } - } else if (mode === 'intersection') { - width = Infinity; - height = Infinity; - for (i = 0; i < count; i++) { - source = this.inputs['source' + i]; - if (source) { - width = Math.min(width, source.width); - height = Math.min(height, source.height); - } - } - } else if (mode === 'active') { - i = this.inputs.active; - source = this.inputs['source' + i]; - width = Math.max(1, source && source.width || 1); - height = Math.max(1, source && source.height || 1); - } else { - width = 1; - height = 1; - n = count - 1; - a = intRegex.exec(this.inputs.sizeMode); - if (a) { - n = Math.min(parseInt(a[0], 10), n); - } - - for (i = 0; i <= n; i++) { - source = this.inputs['source' + i]; - if (source) { - width = source.width; - height = source.height; - break; - } - } - } - - if (this.width !== width || this.height !== height) { - this.width = width; - this.height = height; - - this.emit('resize'); - this.setDirty(); - } - - for (i = 0; i < this.targets.length; i++) { - this.targets[i].resize(); - } - }; - - return { - initialize: function () { - this.initialized = true; - this.shaderDirty = false; - }, - requires: function (sourceName) { - return !!(this.inputs[sourceName] && sourceName === 'source' + this.inputs.active); - }, - - //check the source texture on every draw just in case the source nodes pulls - //shenanigans with its texture. - draw: function () { - var i = me.inputs.active, - source; - - source = me.inputs['source' + i]; - me.texture = source && source.texture; - }, - inputs: inputs - }; - }, - { - title: 'Select', - description: 'Select a single source image from a list of source nodes.', - inPlace: false, - commonShader: true - }); -})); diff --git a/effects/seriously.sepia.js b/effects/seriously.sepia.js deleted file mode 100644 index 05909f3..0000000 --- a/effects/seriously.sepia.js +++ /dev/null @@ -1,61 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - // sepia coefficients borrowed from: - // http://www.techrepublic.com/blog/howdoi/how-do-i-convert-images-to-grayscale-and-sepia-tone-using-c/120 - - Seriously.plugin('sepia', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform vec4 light;', - 'uniform vec4 dark;', - 'uniform float desat;', - 'uniform float toned;', - - 'const mat4 coeff = mat4(' + - '0.393, 0.349, 0.272, 1.0,' + - '0.796, 0.686, 0.534, 1.0, ' + - '0.189, 0.168, 0.131, 1.0, ' + - '0.0, 0.0, 0.0, 1.0 ' + - ');', - - 'void main(void) {', - ' vec4 sourcePixel = texture2D(source, vTexCoord);', - ' gl_FragColor = coeff * sourcePixel;', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source' - } - }, - title: 'Sepia', - description: '' - }); -})); diff --git a/effects/seriously.simplex.js b/effects/seriously.simplex.js deleted file mode 100644 index b40d968..0000000 --- a/effects/seriously.simplex.js +++ /dev/null @@ -1,145 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('simplex', function () { - var me = this; - - function resize() { - me.resize(); - } - - return { - shader: function (inputs, shaderSource, utilities) { - var frequency = 1, - amplitude = 1, - i, - adjust = 0; - - function fmtFloat(n) { - if (n - Math.floor(n) === 0) { - return n + '.0'; - } - return n; - } - - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform float amount;', - 'uniform vec2 noiseScale;', - 'uniform vec2 noiseOffset;', - 'uniform float time;', - 'uniform vec4 black;', - 'uniform vec4 white;', - - utilities.shader.noiseHelpers, - utilities.shader.snoise3d, - //utilities.shader.random, - - 'void main(void) {', - ' float total = 0.0;', - ' vec3 pos = vec3(vTexCoord.xy * noiseScale + noiseOffset, time);' - ].join('\n'); - - for (i = 0; i < inputs.octaves; i++) { - frequency = Math.pow(2, i); - amplitude = Math.pow(inputs.persistence, i); - adjust += amplitude; - shaderSource.fragment += '\ttotal += snoise(pos * ' + fmtFloat(frequency) + ') * ' + fmtFloat(amplitude) + ';\n'; - } - shaderSource.fragment += [ - ' total *= amount / ' + fmtFloat(adjust) + ';', - ' total = (total + 1.0)/ 2.0;', - ' gl_FragColor = mix(black, white, total);', - '}' - ].join('\n'); - - return shaderSource; - }, - inputs: { - noiseScale: { - type: 'vector', - dimensions: 2, - uniform: 'noiseScale', - defaultValue: [1, 1] - }, - noiseOffset: { - type: 'vector', - dimensions: 2, - uniform: 'noiseOffset', - defaultValue: [0, 0] - }, - octaves: { - type: 'number', - shaderDirty: true, - min: 1, - max: 8, - step: 1, - defaultValue: 1 - }, - persistence: { - type: 'number', - defaultValue: 0.5, - min: 0, - max: 0.5 - }, - amount: { - type: 'number', - uniform: 'amount', - min: 0, - defaultValue: 1 - }, - time: { - type: 'number', - uniform: 'time', - defaultValue: 0 - }, - width: { - type: 'number', - min: 0, - step: 1, - update: resize, - defaultValue: 0 - }, - height: { - type: 'number', - min: 0, - step: 1, - update: resize, - defaultValue: 0 - }, - black: { - type: 'color', - uniform: 'black', - defaultValue: [0, 0, 0, 1] - }, - white: { - type: 'color', - uniform: 'white', - defaultValue: [1, 1, 1, 1] - } - } - }; - }, { - title: 'Simplex Noise', - description: 'Generate Simplex Noise' - }); -})); diff --git a/effects/seriously.sketch.js b/effects/seriously.sketch.js deleted file mode 100644 index 8f04999..0000000 --- a/effects/seriously.sketch.js +++ /dev/null @@ -1,87 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - /* inspired by http://lab.adjazent.com/2009/01/09/more-pixel-bender/ */ - - Seriously.plugin('sketch', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - //todo: make adjust adjustable - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform vec2 resolution;', - - 'float res = resolution.x;', - 'float n0 = 97.0 / res;', - 'float n1 = 15.0 / res;', - 'float n2 = 97.0 / res;', - 'float n3 = 9.7 / res;', - 'float total = n2 + ( 4.0 * n0 ) + ( 4.0 * n1 );', - - 'const vec3 div3 = vec3(1.0 / 3.0);', - - 'void main(void) {', - ' float offset, temp1, temp2;', - ' vec4 m, p0, p1, p2, p3, p4, p5, p6, p7, p8;', - ' offset = n3;', - - ' p0=texture2D(source,vTexCoord);', - ' p1=texture2D(source,vTexCoord+vec2(-offset,-offset));', - ' p2=texture2D(source,vTexCoord+vec2( offset,-offset));', - ' p3=texture2D(source,vTexCoord+vec2( offset, offset));', - ' p4=texture2D(source,vTexCoord+vec2(-offset, offset));', - - ' offset=n3*2.0;', - - ' p5=texture2D(source,vTexCoord+vec2(-offset,-offset));', - ' p6=texture2D(source,vTexCoord+vec2( offset,-offset));', - ' p7=texture2D(source,vTexCoord+vec2( offset, offset));', - ' p8=texture2D(source,vTexCoord+vec2(-offset, offset));', - ' m = (p0 * n2 + (p1 + p2 + p3 + p4) * n0 + (p5 + p6 + p7 + p8) * n1) / total;', - - //convert to b/w - ' temp1 = dot(p0.rgb, div3);', - ' temp2 = dot(m.rgb, div3);', - - //color dodge blend mode - ' if (temp2 <= 0.0005) {', - ' gl_FragColor = vec4( 1.0, 1.0, 1.0, p0.a);', - ' } else {', - ' gl_FragColor = vec4( vec3(min(temp1 / temp2, 1.0)), p0.a);', - ' }', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: false, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - } - }, - title: 'Sketch', - description: 'Pencil/charcoal sketch' - }); -})); diff --git a/effects/seriously.split.js b/effects/seriously.split.js deleted file mode 100644 index 9c74197..0000000 --- a/effects/seriously.split.js +++ /dev/null @@ -1,281 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('split', function () { - var baseShader, - resolutionA = [1, 1], - resolutionB = [1, 1]; - - // custom resize method - this.resize = function () { - var width, - height, - mode = this.inputs.sizeMode, - node, - fn, - i, - sourceA = this.inputs.sourceA, - sourceB = this.inputs.sourceB; - - if (mode === 'a' || mode === 'b') { - node = mode === 'a' ? sourceA : sourceB; - if (node) { - width = node.width; - height = node.height; - } else { - width = 1; - height = 1; - } - } else { - if (sourceA) { - if (sourceB) { - fn = (mode === 'union' ? Math.max : Math.min); - width = fn(sourceA.width, sourceB.width); - height = fn(sourceA.height, sourceB.height); - } else { - width = sourceA.width; - height = sourceA.height; - } - } else if (sourceB) { - width = sourceB.width; - height = sourceB.height; - } else { - width = 1; - height = 1; - } - } - - if (this.width !== width || this.height !== height) { - this.width = width; - this.height = height; - - this.uniforms.resolution[0] = width; - this.uniforms.resolution[1] = height; - - if (this.frameBuffer) { - this.frameBuffer.resize(width, height); - } - - this.emit('resize'); - this.setDirty(); - } - - if (sourceA) { - resolutionA[0] = sourceA.width; - resolutionA[1] = sourceA.height; - } - if (sourceB) { - resolutionB[0] = sourceB.width; - resolutionB[1] = sourceB.height; - } - - for (i = 0; i < this.targets.length; i++) { - this.targets[i].resize(); - } - }; - - return { - initialize: function (initialize) { - initialize(); - this.uniforms.resolutionA = resolutionA; - this.uniforms.resolutionB = resolutionB; - baseShader = this.baseShader; - }, - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.vertex = [ - 'precision mediump float;', - - 'attribute vec4 position;', - 'attribute vec2 texCoord;', - - 'uniform vec2 resolution;', - 'uniform vec2 resolutionA;', - 'uniform vec2 resolutionB;', - 'uniform mat4 projection;', - //'uniform mat4 transform;', - - 'varying vec2 vTexCoord;', - 'varying vec2 vTexCoordA;', - 'varying vec2 vTexCoordB;', - - 'uniform float angle;', - 'varying float c;', - 'varying float s;', - 'varying float t;', - - 'void main(void) {', - ' c = cos(angle);', - ' s = sin(angle);', - ' t = abs(c + s);', - - // first convert to screen space - ' vec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);', - //' screenPosition = transform * screenPosition;', - - // convert back to OpenGL coords - ' gl_Position.xy = screenPosition.xy * 2.0 / resolution;', - ' gl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);', - ' gl_Position.w = screenPosition.w;', - - ' vec2 adjustedTexCoord = (texCoord - 0.5) * resolution;', - ' vTexCoordA = adjustedTexCoord / resolutionA + 0.5;', - ' vTexCoordB = adjustedTexCoord / resolutionB + 0.5;', - ' vTexCoord = texCoord;', - '}' - ].join('\n'); - shaderSource.fragment = [ - 'precision mediump float;\n', - - 'varying vec2 vTexCoord;', - 'varying vec2 vTexCoordA;', - 'varying vec2 vTexCoordB;', - - 'varying float c;', - 'varying float s;', - 'varying float t;', - - 'uniform sampler2D sourceA;', - 'uniform sampler2D sourceB;', - 'uniform float split;', - 'uniform float angle;', - 'uniform float fuzzy;', - 'uniform float blendGamma;', - - 'vec4 textureLookup(sampler2D tex, vec2 texCoord, vec3 exp) {', - ' if (any(lessThan(texCoord, vec2(0.0))) || any(greaterThan(texCoord, vec2(1.0)))) {', - ' return vec4(0.0);', - ' } else {', - ' vec4 pixel = texture2D(tex, texCoord);', - ' pixel.rgb = pow(pixel.rgb, exp);', - ' return pixel;', - ' }', - '}', - - 'void main(void) {', - ' vec3 exp = vec3(blendGamma);', - ' vec4 pixel1 = textureLookup(sourceA, vTexCoordA, exp);', - ' vec4 pixel2 = textureLookup(sourceB, vTexCoordB, exp);', - ' float mn = (split - fuzzy * (1.0 - split));', - ' float mx = (split + fuzzy * split);;', - ' vec2 coords = vTexCoord - vec2(0.5);', - ' coords = vec2(coords.x * c - coords.y * s, coords.x * s + coords.y * c);', - ' float scale = max(abs(c - s), abs(s + c));', - ' coords /= scale;', - ' coords += vec2(0.5);', - ' float x = coords.x;', - ' gl_FragColor = mix(pixel2, pixel1, smoothstep(mn, mx, x));', - ' gl_FragColor.rgb = pow(gl_FragColor.rgb, 1.0 / exp);', - '}' - ].join('\n'); - - return shaderSource; - }, - draw: function (shader, model, uniforms, frameBuffer, parent) { - if (uniforms.split >= 1) { - uniforms.source = uniforms.sourceB; - parent(baseShader, model, uniforms, frameBuffer); - return; - } - - if (uniforms.split <= 0) { - uniforms.source = uniforms.sourceA; - parent(baseShader, model, uniforms, frameBuffer); - return; - } - - parent(shader, model, uniforms, frameBuffer); - }, - inPlace: false, - requires: function (sourceName, inputs) { - if (sourceName === 'sourceA' && inputs.split >= 1) { - return false; - } - - if (sourceName === 'sourceB' && inputs.split <= 0) { - return false; - } - - return true; - } - }; - }, - { - inputs: { - sourceA: { - type: 'image', - uniform: 'sourceA', - shaderDirty: false, - update: function () { - this.resize(); - } - }, - sourceB: { - type: 'image', - uniform: 'sourceB', - shaderDirty: false, - update: function () { - this.resize(); - } - }, - sizeMode: { - type: 'enum', - defaultValue: 'a', - options: [ - 'a', - 'b', - 'union', - 'intersection' - ], - update: function () { - this.resize(); - } - }, - split: { - type: 'number', - uniform: 'split', - defaultValue: 0.5, - min: 0, - max: 1, - updateSources: true - }, - angle: { - type: 'number', - uniform: 'angle', - defaultValue: 0 - }, - fuzzy: { - type: 'number', - uniform: 'fuzzy', - defaultValue: 0, - min: 0, - max: 1 - }, - blendGamma: { - type: 'number', - uniform: 'blendGamma', - defaultValue: 2.2, - min: 0, - max: 4 - } - }, - description: 'Split screen or wipe', - title: 'Split' - }); -})); diff --git a/effects/seriously.temperature.js b/effects/seriously.temperature.js deleted file mode 100644 index 7586bad..0000000 --- a/effects/seriously.temperature.js +++ /dev/null @@ -1,101 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - // algorithm from http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/ - - Seriously.plugin('temperature', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.vertex = [ - 'precision mediump float;', - - 'attribute vec4 position;', - 'attribute vec2 texCoord;', - - 'uniform vec2 resolution;', - 'uniform mat4 transform;', - - 'uniform float temperature;', - - 'varying vec2 vTexCoord;', - 'varying vec3 tempFactor;', - - 'const vec3 luma = vec3(0.2125,0.7154,0.0721);', - - 'vec3 temperatureRGB(float t) {', - ' float temp = t / 100.0;', - ' vec3 color = vec3(1.0);', - ' if (temp < 66.0) {', - ' color.g = 0.3900815787690196 * log(temp) - 0.6318414437886275;', - ' color.b = 0.543206789110196 * log(temp - 10.0) - 1.19625408914;', - ' } else {', - ' color.r = 1.292936186062745 * pow(temp - 60.0, -0.1332047592);', - ' color.g = 1.129890860895294 * pow(temp - 60.0, -0.0755148492);', - ' }', - ' return color;', - '}', - - 'void main(void) {', - // first convert to screen space - ' vec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);', - ' screenPosition = transform * screenPosition;', - - // convert back to OpenGL coords - ' gl_Position.xy = screenPosition.xy * 2.0 / resolution;', - ' gl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);', - ' gl_Position.w = screenPosition.w;', - ' vTexCoord = texCoord;', - ' vec3 tempColor = temperatureRGB(temperature);', - ' tempFactor = dot(tempColor, luma) / tempColor;', - '}\n' - ].join('\n'); - - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - 'varying vec3 tempFactor;', - - 'uniform sampler2D source;', - - 'void main(void) {', - ' vec4 pixel = texture2D(source, vTexCoord);', - ' gl_FragColor = vec4(pixel.rgb * tempFactor, pixel.a);', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - temperature: { - type: 'number', - uniform: 'temperature', - defaultValue: 6500, - min: 3000, - max: 25000 - } - }, - title: 'Color Temperature', - description: '' - }); -})); diff --git a/effects/seriously.throttle.js b/effects/seriously.throttle.js deleted file mode 100644 index 402965c..0000000 --- a/effects/seriously.throttle.js +++ /dev/null @@ -1,55 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('throttle', function () { - var lastDrawTime = 0; - return { - draw: function (shader, model, uniforms, frameBuffer, draw) { - if (this.inputs.frameRate && Date.now() - lastDrawTime >= 1000 / this.inputs.frameRate) { - draw(shader, model, uniforms, frameBuffer); - lastDrawTime = Date.now(); - } - }, - requires: function (sourceName, inputs) { - if (inputs.frameRate && Date.now() - lastDrawTime >= 1000 / inputs.frameRate) { - return true; - } - - return false; - } - }; - }, { - inPlace: true, - commonShader: true, - title: 'Throttle', - description: 'Throttle frame rate', - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - frameRate: { - type: 'number', - uniform: 'opacity', - defaultValue: 15, - min: 0 - } - } - }); -})); diff --git a/effects/seriously.tone.js b/effects/seriously.tone.js deleted file mode 100644 index 67cf45e..0000000 --- a/effects/seriously.tone.js +++ /dev/null @@ -1,81 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('tone', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform vec4 light;', - 'uniform vec4 dark;', - 'uniform float desat;', - 'uniform float toned;', - - 'const vec3 lumcoeff = vec3(0.2125,0.7154,0.0721);', - - 'void main(void) {', - ' vec4 sourcePixel = texture2D(source, vTexCoord);', - ' vec3 sceneColor = light.rgb * sourcePixel.rgb;', - ' vec3 gray = vec3(dot(lumcoeff, sceneColor));', - ' vec3 muted = mix(sceneColor, gray, desat);', - ' vec3 tonedColor = mix(dark.rgb, light.rgb, gray);', - ' gl_FragColor = vec4(mix(muted, tonedColor, toned), sourcePixel.a);', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - light: { - type: 'color', - uniform: 'light', - defaultValue: [1, 0.9, 0.5, 1] - }, - dark: { - type: 'color', - uniform: 'dark', - defaultValue: [0.2, 0.05, 0, 1] - }, - toned: { - type: 'number', - uniform: 'toned', - defaultValue: 1, - minimumRange: 0, - maximumRange: 1 - }, - desat: { - type: 'number', - uniform: 'desat', - defaultValue: 0.5, - minimumRange: 0, - maximumRange: 1 - } - }, - title: 'Tone', - description: '' - }); -})); diff --git a/effects/seriously.tvglitch.js b/effects/seriously.tvglitch.js deleted file mode 100644 index 4034abc..0000000 --- a/effects/seriously.tvglitch.js +++ /dev/null @@ -1,310 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - //particle parameters - var minVelocity = 0.2, - maxVelocity = 0.8, - minSize = 0.02, - maxSize = 0.3, - particleCount = 20; - - Seriously.plugin('tvglitch', function () { - var lastHeight, - lastTime, - particleBuffer, - particleShader, - particleFrameBuffer, - gl; - - return { - initialize: function (parent) { - var i, - sizeRange, - velocityRange, - particleVertex, - particleFragment, - particles; - - gl = this.gl; - - lastHeight = this.height; - - //initialize particles - particles = []; - sizeRange = maxSize - minSize; - velocityRange = maxVelocity - minVelocity; - for (i = 0; i < particleCount; i++) { - particles.push(Math.random() * 2 - 1); //position - particles.push(Math.random() * velocityRange + minVelocity); //velocity - particles.push(Math.random() * sizeRange + minSize); //size - particles.push(Math.random() * 0.2); //intensity - } - - particleBuffer = gl.createBuffer(); - gl.bindBuffer(gl.ARRAY_BUFFER, particleBuffer); - gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(particles), gl.STATIC_DRAW); - particleBuffer.itemSize = 4; - particleBuffer.numItems = particleCount; - - particleVertex = [ - '#define SHADER_NAME seriously.tvglitch.particle', - 'precision mediump float;', - - 'attribute vec4 particle;', - - 'uniform float time;', - 'uniform float height;', - - 'varying float intensity;', - - 'void main(void) {', - ' float y = particle.x + time * particle.y;', - ' y = fract((y + 1.0) / 2.0) * 4.0 - 2.0;', - ' intensity = particle.w;', - ' gl_Position = vec4(0.0, -y , 1.0, 2.0);', - //' gl_Position = vec4(0.0, 1.0 , 1.0, 1.0);', - ' gl_PointSize = height * particle.z;', - '}' - ].join('\n'); - - particleFragment = [ - '#define SHADER_NAME seriously.tvglitch.particle', - 'precision mediump float;', - - 'varying float intensity;', - - 'void main(void) {', - ' gl_FragColor = vec4(1.0);', - ' gl_FragColor.a = 2.0 * intensity * (1.0 - abs(gl_PointCoord.y - 0.5));', - '}' - ].join('\n'); - - particleShader = new Seriously.util.ShaderProgram(gl, particleVertex, particleFragment); - - particleFrameBuffer = new Seriously.util.FrameBuffer(gl, 1, Math.max(1, this.height / 2)); - parent(); - }, - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - '#define HardLight(top, bottom) (1.0 - 2.0 * (1.0 - top) * (1.0 - bottom))', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform sampler2D particles;', - 'uniform float time;', - 'uniform float scanlines;', - 'uniform float lineSync;', - 'uniform float lineHeight;', //for scanlines and distortion - 'uniform float distortion;', - 'uniform float vsync;', - 'uniform float bars;', - 'uniform float frameSharpness;', - 'uniform float frameShape;', - 'uniform float frameLimit;', - 'uniform vec4 frameColor;', - - //todo: need much better pseudo-random number generator - Seriously.util.shader.noiseHelpers + - Seriously.util.shader.snoise2d + - - 'void main(void) {', - ' vec2 texCoord = vTexCoord;', - - //distortion - ' float drandom = snoise(vec2(time * 10.0, texCoord.y /lineHeight));', - ' float distortAmount = distortion * (drandom - 0.25) * 0.5;', - //line sync - ' vec4 particleOffset = texture2D(particles, vec2(0.0, texCoord.y));', - ' distortAmount -= lineSync * (2.0 * particleOffset.a - 0.5);', - - ' texCoord.x -= distortAmount;', - ' texCoord.x = mod(texCoord.x, 1.0);', - - //vertical sync - ' float roll;', - ' if (vsync != 0.0) {', - ' roll = fract(time / vsync);', - ' texCoord.y = mod(texCoord.y - roll, 1.0);', - ' }', - - ' vec4 pixel = texture2D(source, texCoord);', - - //horizontal bars - ' float barsAmount = particleOffset.r;', - ' if (barsAmount > 0.0) {', - ' pixel = vec4(pixel.r + bars * barsAmount,' + - 'pixel.g + bars * barsAmount,' + - 'pixel.b + bars * barsAmount,' + - 'pixel.a);', - ' }', - - ' if (mod(texCoord.y / lineHeight, 2.0) < 1.0 ) {', - ' pixel.rgb *= (1.0 - scanlines);', - ' }', - - ' float f = (1.0 - gl_FragCoord.x * gl_FragCoord.x) * (1.0 - gl_FragCoord.y * gl_FragCoord.y);', - ' float frame = clamp( frameSharpness * (pow(f, frameShape) - frameLimit), 0.0, 1.0);', - - ' gl_FragColor = mix(frameColor, pixel, frame);', - '}' - ].join('\n'); - - return shaderSource; - }, - resize: function () { - if (particleFrameBuffer) { - particleFrameBuffer.resize(1, Math.max(1, this.height / 2)); - } - }, - draw: function (shader, model, uniforms, frameBuffer, parent) { - var doParticles = (lastTime !== this.inputs.time), - vsyncPeriod; - - if (lastHeight !== this.height) { - lastHeight = this.height; - doParticles = true; - } - - //todo: make this configurable? - uniforms.lineHeight = 1 / this.height; - - if (this.inputs.verticalSync) { - vsyncPeriod = 0.2 / this.inputs.verticalSync; - uniforms.vsync = vsyncPeriod; - } else { - vsyncPeriod = 1; - uniforms.vsync = 0; - } - uniforms.time = (this.inputs.time % (1000 * vsyncPeriod)); - uniforms.distortion = Math.random() * this.inputs.distortion; - - //render particle canvas and attach uniform - //todo: this is a good spot for parallel processing. ParallelArray maybe? - if (doParticles && (this.inputs.lineSync || this.inputs.bars)) { - particleShader.use(); - gl.viewport(0, 0, 1, this.height / 2); - gl.bindFramebuffer(gl.FRAMEBUFFER, particleFrameBuffer.frameBuffer); - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - gl.enableVertexAttribArray(particleShader.location.particle); - gl.bindBuffer(gl.ARRAY_BUFFER, particleBuffer); - gl.vertexAttribPointer(particleShader.location.particle, particleBuffer.itemSize, gl.FLOAT, false, 0, 0); - gl.enable(gl.BLEND); - gl.blendFunc(gl.SRC_ALPHA, gl.ONE); - particleShader.time.set(uniforms.time * this.inputs.barsRate); - particleShader.height.set(this.height); - gl.drawArrays(gl.POINTS, 0, particleCount); - - lastTime = this.inputs.time; - } - uniforms.particles = particleFrameBuffer.texture; - - parent(shader, model, uniforms, frameBuffer); - }, - destroy: function () { - particleBuffer = null; - if (particleFrameBuffer) { - particleFrameBuffer.destroy(); - particleFrameBuffer = null; - } - } - }; - }, - { - inPlace: false, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - }, - time: { - type: 'number', - defaultValue: 0 - }, - distortion: { - type: 'number', - defaultValue: 0.1, - min: 0, - max: 1 - }, - verticalSync: { - type: 'number', - defaultValue: 0.1, - min: 0, - max: 1 - }, - lineSync: { - type: 'number', - uniform: 'lineSync', - defaultValue: 0.2, - min: 0, - max: 1 - }, - scanlines: { - type: 'number', - uniform: 'scanlines', - defaultValue: 0.3, - min: 0, - max: 1 - }, - bars: { - type: 'number', - uniform: 'bars', - defaultValue: 0, - min: 0, - max: 1 - }, - barsRate: { - type: 'number', - defaultValue: 1 - }, - frameShape: { - type: 'number', - uniform: 'frameShape', - min: 0, - max: 2, - defaultValue: 0.27 - }, - frameLimit: { - type: 'number', - uniform: 'frameLimit', - min: -1, - max: 1, - defaultValue: 0.34 - }, - frameSharpness: { - type: 'number', - uniform: 'frameSharpness', - min: 0, - max: 40, - defaultValue: 8.4 - }, - frameColor: { - type: 'color', - uniform: 'frameColor', - defaultValue: [0, 0, 0, 1] - } - }, - title: 'TV Glitch' - }); -})); diff --git a/effects/seriously.vibrance.js b/effects/seriously.vibrance.js deleted file mode 100644 index 85ff7e7..0000000 --- a/effects/seriously.vibrance.js +++ /dev/null @@ -1,78 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - /* - Vibrance is similar to saturation, but it has less effect on skin tones - http://www.iceflowstudios.com/2013/tips/vibrance-vs-saturation-in-photoshop/ - - Shader adapted from glfx.js by Evan Wallace - License: https://github.com/evanw/glfx.js/blob/master/LICENSE - */ - - Seriously.plugin('vibrance', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform float amount;', - - 'void main(void) {', - ' vec4 color = texture2D(source, vTexCoord);', - - ' float average = (color.r + color.g + color.b) / 3.0;', - ' float mx = max(color.r, max(color.g, color.b));', - ' float amt = (mx - average) * (-3.0 * amount);', - ' color.rgb = mix(color.rgb, vec3(mx), amt);', - ' gl_FragColor = color;', - - /* - https://github.com/v002/v002-Color-Controls - doesn't work so well with values < 0 - ' const vec4 lumacoeff = vec4(0.299,0.587,0.114, 0.);', - ' vec4 luma = vec4(dot(color, lumacoeff));', - ' vec4 mask = clamp(color - luma, 0.0, 1.0);', - ' float lumaMask = 1.0 - dot(lumacoeff, mask);', - ' gl_FragColor = mix(luma, color, 1.0 + amount * lumaMask);', - */ - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: true, - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - amount: { - type: 'number', - uniform: 'amount', - defaultValue: 0, - min: -1, - max: 1 - } - }, - title: 'Vibrance', - description: 'Non-peaking saturation effect' - }); -})); diff --git a/effects/seriously.vignette.js b/effects/seriously.vignette.js deleted file mode 100644 index 62e5e19..0000000 --- a/effects/seriously.vignette.js +++ /dev/null @@ -1,56 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - Seriously.plugin('vignette', { - commonShader: true, - shader: function (inputs, shaderSource) { - shaderSource.fragment = [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform float amount;', - - 'void main(void) {', - ' vec4 pixel = texture2D(source, vTexCoord);', - ' vec2 pos = vTexCoord.xy - 0.5;', - ' float vignette = 1.0 - (dot(pos, pos) * amount);', - ' gl_FragColor = vec4(pixel.rgb * vignette, pixel.a);', - '}' - ].join('\n'); - return shaderSource; - }, - inPlace: false, - inputs: { - source: { - type: 'image', - uniform: 'source' - }, - amount: { - type: 'number', - uniform: 'amount', - defaultValue: 1, - min: 0 - } - }, - title: 'Vignette', - description: 'Vignette' - }); -})); diff --git a/effects/seriously.whitebalance.js b/effects/seriously.whitebalance.js deleted file mode 100644 index c549bb7..0000000 --- a/effects/seriously.whitebalance.js +++ /dev/null @@ -1,249 +0,0 @@ -/* 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); - } -}(window, function (Seriously) { - 'use strict'; - - /* - - Math references: - en.wikipedia.org/wiki/Color_balance - http://scien.stanford.edu/pages/labsite/2010/psych221/projects/2010/JasonSu/adaptation.html - https://github.com/ikaros-project/ikaros/blob/master/Source/Modules/VisionModules/WhiteBalance/WhiteBalance.cc - - */ - - var identity = new Float32Array([ - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 - ]); - - Seriously.plugin('whitebalance', function () { - var pyramidShader, - pyramidBuffers = [], - width, - height, - pyramidSize, - log2 = Math.log(2), - me = this, - //baseShader, //todo: share one with main object - gl, - - MAX_TEXTURE_SIZE; - - /* - todo: handle special case where node is square and power of two. save on one pyramid iteration - */ - - function updateSize(w, h) { - var size, numLevels, n, - i; - - if (width === w && height === h) { - return; - } - - width = w; - height = h; - - numLevels = Math.ceil(Math.log(Math.max(h, w)) / log2); - size = Math.pow(2, numLevels); - - if (size > MAX_TEXTURE_SIZE) { - numLevels = Math.ceil(Math.log(MAX_TEXTURE_SIZE) / log2); - size = MAX_TEXTURE_SIZE; - } - - numLevels++; - if (pyramidSize === size) { - return; - } - - pyramidSize = size; - - while (pyramidBuffers.length > numLevels) { - (pyramidBuffers.pop()).fb.destroy(); - } - - while (pyramidBuffers.length < numLevels) { - i = pyramidBuffers.length; - n = Math.pow(2, i); - pyramidBuffers.push({ - fb: new Seriously.util.FrameBuffer(me.gl, n, n),//, true), - opts: { - width: n, - height: n - }, - uniforms: { - level: pyramidBuffers.length, - offset: 0.25 / n, - transform: identity, - projection: identity, - resolution: [n, n] - } - }); - - if (i) { - pyramidBuffers[i - 1].uniforms.source = pyramidBuffers[i].fb.texture; - } - } - } - - - return { - initialize: function (initialize) { - gl = this.gl; - - MAX_TEXTURE_SIZE = gl.getParameter(gl.MAX_TEXTURE_SIZE); - - if (this.inputs.auto) { - updateSize(this.width, this.height); - } - - initialize(); - }, - shader: function (inputs, shaderSource) { - var auto = inputs.auto; - //todo: gl.getExtension('OES_texture_float_linear') - - if (auto && !pyramidShader) { - pyramidShader = new Seriously.util.ShaderProgram(this.gl, shaderSource.vertex, [ - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - 'uniform float offset;', - 'uniform int level;', - - 'void main(void) {', - //gl.getExtension("OES_texture_float"), gl.getExtension("OES_texture_float_linear") - //' vec4 pixel = texture2D(source, vTexCoord);', - - ' vec4 pixel = texture2D(source, vTexCoord - vec2(offset)) +', - ' texture2D(source, vTexCoord + vec2(offset, -offset)) +', - ' texture2D(source, vTexCoord + vec2(offset)) +', - ' texture2D(source, vTexCoord + vec2(-offset, offset));', - ' pixel /= 4.0;', - ' gl_FragColor = pixel;', - '}' - ].join('\n')); - } - - shaderSource.fragment = [ - auto ? '#define AUTO' : '', - 'precision mediump float;', - - 'varying vec2 vTexCoord;', - - 'uniform sampler2D source;', - '#ifdef AUTO', - 'uniform sampler2D whiteSource;', - '#else', - 'uniform vec4 white;', - '#endif', - - // matrices from: http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html - /* - raw RGB just seems to work better so let's use that until we figure Bradford out - 'const mat3 rgbToBradford = mat3(', - ' 0.4360747, 0.2225045, 0.0139322,', - ' 0.3850649, 0.7168786, 0.0971045,', - ' 0.1430804, 0.0606169, 0.7141733', - ');', - - 'const mat3 bradfordToRgb = mat3(', - ' 3.1338561, -0.9787684, 0.0719453,', - ' -1.6168667, 1.9161415, -0.2289914,', - ' -0.4906146, 0.033454, 1.4052427', - ');', - */ - - 'const vec3 luma = vec3(0.2125, 0.7154, 0.0721);', - - 'void main(void) {', - ' vec4 pixel = texture2D(source, vTexCoord);', - '#ifdef AUTO', - ' vec4 white = texture2D(whiteSource, vTexCoord);', - '#endif', - /* - ' vec3 whiteBradford = rgbToBradford * white.rgb;', - ' vec3 targetBradford = rgbToBradford * vec3(dot(white.rgb, luma));', - ' vec3 colorBradford = rgbToBradford * pixel.rgb;', - ' pixel.rgb = clamp(bradfordToRgb * (colorBradford * targetBradford / whiteBradford), 0.0, 1.0);', - */ - ' vec3 target = vec3(dot(white.rgb, luma));', - ' pixel.rgb = pixel.rgb * target / white.rgb;', - ' gl_FragColor = pixel;', - '}' - ].join('\n'); - - return shaderSource; - }, - resize: function () { - if (this.gl && this.inputs.auto) { - updateSize(this.width, this.height); - } - }, - draw: function (shader, model, uniforms, frameBuffer, draw) { - var i, - buf; - - if (this.inputs.auto) { - i = pyramidBuffers.length - 1; - pyramidBuffers[i].uniforms.source = uniforms.source; - while (i >= 0) { - buf = pyramidBuffers[i]; - draw(pyramidShader, model, buf.uniforms, buf.fb.frameBuffer, null, buf.opts); - i--; - } - - uniforms.whiteSource = pyramidBuffers[0].fb.texture; - } - - draw(shader, model, uniforms, frameBuffer); - }, - destroy: function () { - while (pyramidBuffers.length) { - pyramidBuffers.pop().destroy(); - } - }, - inPlace: false, - inputs: { - source: { - type: 'image', - uniform: 'source', - shaderDirty: false - }, - white: { - type: 'color', - uniform: 'white', - defaultValue: [1, 1, 1] - }, - auto: { - type: 'boolean', - shaderDirty: true, - defaultValue: true - } - } - }; - }, - { - title: 'White Balance' - }); -})); diff --git a/examples/accumulator/index.html b/examples/accumulator/index.html index 060e441..9c3602a 100644 --- a/examples/accumulator/index.html +++ b/examples/accumulator/index.html @@ -70,80 +70,71 @@ -
+ - + - - + +