diff --git a/src/filters/tiltshift/TiltShiftAxisFilter.js b/src/filters/tiltshift/TiltShiftAxisFilter.js new file mode 100644 index 0000000..8577586 --- /dev/null +++ b/src/filters/tiltshift/TiltShiftAxisFilter.js @@ -0,0 +1,121 @@ +var core = require('../../core'); + +/** + * @author Vico @vicocotea + * original filter https://github.com/evanw/glfx.js/blob/master/src/filters/blur/tiltshift.js by Evan Wallace : http://madebyevan.com/ + */ + +/** + * A TiltShiftAxisFilter. + * + * @class + * @extends AbstractFilter + * @namespace PIXI.filters + */ +function TiltShiftAxisFilter() +{ + core.AbstractFilter.call(this, + // vertex shader + null, + // fragment shader + require('fs').readFileSync(__dirname + '/tiltShift.frag', 'utf8'), + // custom uniforms + { + blur: { type: '1f', value: 100 }, + gradientBlur: { type: '1f', value: 600 }, + start: { type: 'v2', value: { x: 0, y: window.innerHeight / 2 } }, + end: { type: 'v2', value: { x: 600, y: window.innerHeight / 2 } }, + delta: { type: 'v2', value: { x: 30, y: 30 } }, + texSize: { type: 'v2', value: { x: window.innerWidth, y: window.innerHeight } } + } + ); + + this.updateDelta(); +} + +TiltShiftAxisFilter.prototype = Object.create(core.AbstractFilter.prototype); +TiltShiftAxisFilter.prototype.constructor = TiltShiftAxisFilter; +module.exports = TiltShiftAxisFilter; + +/** + * Updates the filter delta values. + * This is overridden in the X and Y filters, does nothing for this class. + * + */ +TiltShiftAxisFilter.prototype.updateDelta = function () +{ + this.uniforms.delta.value.x = 0; + this.uniforms.delta.value.y = 0; +}; + +Object.defineProperties(TiltShiftAxisFilter.prototype, { + /** + * The strength of the blur. + * + * @member {number} + * @memberof TiltShiftAxisFilter# + */ + blur: { + get: function () + { + return this.uniforms.blur.value; + }, + set: function (value) + { + this.uniforms.blur.value = value; + } + }, + + /** + * The strength of the gradient blur. + * + * @member {number} + * @memberof TiltShiftAxisFilter# + */ + gradientBlur: { + get: function () + { + return this.uniforms.gradientBlur.value; + }, + set: function (value) + { + this.uniforms.gradientBlur.value = value; + } + }, + + /** + * The X value to start the effect at. + * + * @member {Point} + * @memberof TiltShiftAxisFilter# + */ + start: { + get: function () + { + return this.uniforms.start.value; + }, + set: function (value) + { + this.uniforms.start.value = value; + this.updateDelta(); + } + }, + + /** + * The X value to end the effect at. + * + * @member {Point} + * @memberof TiltShiftAxisFilter# + */ + end: { + get: function () + { + return this.uniforms.end.value; + }, + set: function (value) + { + this.uniforms.end.value = value; + this.updateDelta(); + } + } +}); diff --git a/src/filters/tiltshift/TiltShiftAxisFilter.js b/src/filters/tiltshift/TiltShiftAxisFilter.js new file mode 100644 index 0000000..8577586 --- /dev/null +++ b/src/filters/tiltshift/TiltShiftAxisFilter.js @@ -0,0 +1,121 @@ +var core = require('../../core'); + +/** + * @author Vico @vicocotea + * original filter https://github.com/evanw/glfx.js/blob/master/src/filters/blur/tiltshift.js by Evan Wallace : http://madebyevan.com/ + */ + +/** + * A TiltShiftAxisFilter. + * + * @class + * @extends AbstractFilter + * @namespace PIXI.filters + */ +function TiltShiftAxisFilter() +{ + core.AbstractFilter.call(this, + // vertex shader + null, + // fragment shader + require('fs').readFileSync(__dirname + '/tiltShift.frag', 'utf8'), + // custom uniforms + { + blur: { type: '1f', value: 100 }, + gradientBlur: { type: '1f', value: 600 }, + start: { type: 'v2', value: { x: 0, y: window.innerHeight / 2 } }, + end: { type: 'v2', value: { x: 600, y: window.innerHeight / 2 } }, + delta: { type: 'v2', value: { x: 30, y: 30 } }, + texSize: { type: 'v2', value: { x: window.innerWidth, y: window.innerHeight } } + } + ); + + this.updateDelta(); +} + +TiltShiftAxisFilter.prototype = Object.create(core.AbstractFilter.prototype); +TiltShiftAxisFilter.prototype.constructor = TiltShiftAxisFilter; +module.exports = TiltShiftAxisFilter; + +/** + * Updates the filter delta values. + * This is overridden in the X and Y filters, does nothing for this class. + * + */ +TiltShiftAxisFilter.prototype.updateDelta = function () +{ + this.uniforms.delta.value.x = 0; + this.uniforms.delta.value.y = 0; +}; + +Object.defineProperties(TiltShiftAxisFilter.prototype, { + /** + * The strength of the blur. + * + * @member {number} + * @memberof TiltShiftAxisFilter# + */ + blur: { + get: function () + { + return this.uniforms.blur.value; + }, + set: function (value) + { + this.uniforms.blur.value = value; + } + }, + + /** + * The strength of the gradient blur. + * + * @member {number} + * @memberof TiltShiftAxisFilter# + */ + gradientBlur: { + get: function () + { + return this.uniforms.gradientBlur.value; + }, + set: function (value) + { + this.uniforms.gradientBlur.value = value; + } + }, + + /** + * The X value to start the effect at. + * + * @member {Point} + * @memberof TiltShiftAxisFilter# + */ + start: { + get: function () + { + return this.uniforms.start.value; + }, + set: function (value) + { + this.uniforms.start.value = value; + this.updateDelta(); + } + }, + + /** + * The X value to end the effect at. + * + * @member {Point} + * @memberof TiltShiftAxisFilter# + */ + end: { + get: function () + { + return this.uniforms.end.value; + }, + set: function (value) + { + this.uniforms.end.value = value; + this.updateDelta(); + } + } +}); diff --git a/src/filters/tiltshift/TiltShiftXFilter.js b/src/filters/tiltshift/TiltShiftXFilter.js index 7b87c08..54e0daa 100644 --- a/src/filters/tiltshift/TiltShiftXFilter.js +++ b/src/filters/tiltshift/TiltShiftXFilter.js @@ -1,4 +1,4 @@ -var core = require('../../core'); +var TiltShiftAxisFilter = require('./TiltShiftAxisFilter'); /** * @author Vico @vicocotea @@ -9,31 +9,15 @@ * A TiltShiftXFilter. * * @class - * @extends AbstractFilter + * @extends TiltShiftAxisFilter * @namespace PIXI.filters */ function TiltShiftXFilter() { - core.AbstractFilter.call(this, - // vertex shader - null, - // fragment shader - require('fs').readFileSync(__dirname + '/tiltShift.frag', 'utf8'), - // custom uniforms - { - blur: { type: '1f', value: 100 }, - gradientBlur: { type: '1f', value: 600 }, - start: { type: 'v2', value: { x: 0, y: window.innerHeight / 2 } }, - end: { type: 'v2', value: { x: 600, y: window.innerHeight / 2 } }, - delta: { type: 'v2', value: { x: 30, y: 30 } }, - texSize: { type: 'v2', value: { x: window.innerWidth, y: window.innerHeight } } - } - ); - - this.updateDelta(); + TiltShiftAxisFilter.call(this); } -TiltShiftXFilter.prototype = Object.create(core.AbstractFilter.prototype); +TiltShiftXFilter.prototype = Object.create(TiltShiftAxisFilter.prototype); TiltShiftXFilter.prototype.constructor = TiltShiftXFilter; module.exports = TiltShiftXFilter; @@ -47,80 +31,6 @@ var dy = this.uniforms.end.value.y - this.uniforms.start.value.y; var d = Math.sqrt(dx * dx + dy * dy); - // TODO (cengler) - These two lines are the only lines that are different between - // the TileShiftXFilter and TiltShiftYFilter.... this.uniforms.delta.value.x = dx / d; this.uniforms.delta.value.y = dy / d; }; - -Object.defineProperties(TiltShiftXFilter.prototype, { - /** - * The strength of the blur. - * - * @member {number} - * @memberof TilttShiftXFilter# - */ - blur: { - get: function () - { - return this.uniforms.blur.value; - }, - set: function (value) - { - this.uniforms.blur.value = value; - } - }, - - /** - * The strength of the gradient blur. - * - * @member {number} - * @memberof TilttShiftXFilter# - */ - gradientBlur: { - get: function () - { - return this.uniforms.gradientBlur.value; - }, - set: function (value) - { - this.uniforms.gradientBlur.value = value; - } - }, - - /** - * The X value to start the effect at. - * - * @member {Point} - * @memberof TilttShiftXFilter# - */ - start: { - get: function () - { - return this.uniforms.start.value; - }, - set: function (value) - { - this.uniforms.start.value = value; - this.updateDelta(); - } - }, - - /** - * The X value to end the effect at. - * - * @member {Point} - * @memberof TilttShiftXFilter# - */ - end: { - get: function () - { - return this.uniforms.end.value; - }, - set: function (value) - { - this.uniforms.end.value = value; - this.updateDelta(); - } - } -}); diff --git a/src/filters/tiltshift/TiltShiftAxisFilter.js b/src/filters/tiltshift/TiltShiftAxisFilter.js new file mode 100644 index 0000000..8577586 --- /dev/null +++ b/src/filters/tiltshift/TiltShiftAxisFilter.js @@ -0,0 +1,121 @@ +var core = require('../../core'); + +/** + * @author Vico @vicocotea + * original filter https://github.com/evanw/glfx.js/blob/master/src/filters/blur/tiltshift.js by Evan Wallace : http://madebyevan.com/ + */ + +/** + * A TiltShiftAxisFilter. + * + * @class + * @extends AbstractFilter + * @namespace PIXI.filters + */ +function TiltShiftAxisFilter() +{ + core.AbstractFilter.call(this, + // vertex shader + null, + // fragment shader + require('fs').readFileSync(__dirname + '/tiltShift.frag', 'utf8'), + // custom uniforms + { + blur: { type: '1f', value: 100 }, + gradientBlur: { type: '1f', value: 600 }, + start: { type: 'v2', value: { x: 0, y: window.innerHeight / 2 } }, + end: { type: 'v2', value: { x: 600, y: window.innerHeight / 2 } }, + delta: { type: 'v2', value: { x: 30, y: 30 } }, + texSize: { type: 'v2', value: { x: window.innerWidth, y: window.innerHeight } } + } + ); + + this.updateDelta(); +} + +TiltShiftAxisFilter.prototype = Object.create(core.AbstractFilter.prototype); +TiltShiftAxisFilter.prototype.constructor = TiltShiftAxisFilter; +module.exports = TiltShiftAxisFilter; + +/** + * Updates the filter delta values. + * This is overridden in the X and Y filters, does nothing for this class. + * + */ +TiltShiftAxisFilter.prototype.updateDelta = function () +{ + this.uniforms.delta.value.x = 0; + this.uniforms.delta.value.y = 0; +}; + +Object.defineProperties(TiltShiftAxisFilter.prototype, { + /** + * The strength of the blur. + * + * @member {number} + * @memberof TiltShiftAxisFilter# + */ + blur: { + get: function () + { + return this.uniforms.blur.value; + }, + set: function (value) + { + this.uniforms.blur.value = value; + } + }, + + /** + * The strength of the gradient blur. + * + * @member {number} + * @memberof TiltShiftAxisFilter# + */ + gradientBlur: { + get: function () + { + return this.uniforms.gradientBlur.value; + }, + set: function (value) + { + this.uniforms.gradientBlur.value = value; + } + }, + + /** + * The X value to start the effect at. + * + * @member {Point} + * @memberof TiltShiftAxisFilter# + */ + start: { + get: function () + { + return this.uniforms.start.value; + }, + set: function (value) + { + this.uniforms.start.value = value; + this.updateDelta(); + } + }, + + /** + * The X value to end the effect at. + * + * @member {Point} + * @memberof TiltShiftAxisFilter# + */ + end: { + get: function () + { + return this.uniforms.end.value; + }, + set: function (value) + { + this.uniforms.end.value = value; + this.updateDelta(); + } + } +}); diff --git a/src/filters/tiltshift/TiltShiftXFilter.js b/src/filters/tiltshift/TiltShiftXFilter.js index 7b87c08..54e0daa 100644 --- a/src/filters/tiltshift/TiltShiftXFilter.js +++ b/src/filters/tiltshift/TiltShiftXFilter.js @@ -1,4 +1,4 @@ -var core = require('../../core'); +var TiltShiftAxisFilter = require('./TiltShiftAxisFilter'); /** * @author Vico @vicocotea @@ -9,31 +9,15 @@ * A TiltShiftXFilter. * * @class - * @extends AbstractFilter + * @extends TiltShiftAxisFilter * @namespace PIXI.filters */ function TiltShiftXFilter() { - core.AbstractFilter.call(this, - // vertex shader - null, - // fragment shader - require('fs').readFileSync(__dirname + '/tiltShift.frag', 'utf8'), - // custom uniforms - { - blur: { type: '1f', value: 100 }, - gradientBlur: { type: '1f', value: 600 }, - start: { type: 'v2', value: { x: 0, y: window.innerHeight / 2 } }, - end: { type: 'v2', value: { x: 600, y: window.innerHeight / 2 } }, - delta: { type: 'v2', value: { x: 30, y: 30 } }, - texSize: { type: 'v2', value: { x: window.innerWidth, y: window.innerHeight } } - } - ); - - this.updateDelta(); + TiltShiftAxisFilter.call(this); } -TiltShiftXFilter.prototype = Object.create(core.AbstractFilter.prototype); +TiltShiftXFilter.prototype = Object.create(TiltShiftAxisFilter.prototype); TiltShiftXFilter.prototype.constructor = TiltShiftXFilter; module.exports = TiltShiftXFilter; @@ -47,80 +31,6 @@ var dy = this.uniforms.end.value.y - this.uniforms.start.value.y; var d = Math.sqrt(dx * dx + dy * dy); - // TODO (cengler) - These two lines are the only lines that are different between - // the TileShiftXFilter and TiltShiftYFilter.... this.uniforms.delta.value.x = dx / d; this.uniforms.delta.value.y = dy / d; }; - -Object.defineProperties(TiltShiftXFilter.prototype, { - /** - * The strength of the blur. - * - * @member {number} - * @memberof TilttShiftXFilter# - */ - blur: { - get: function () - { - return this.uniforms.blur.value; - }, - set: function (value) - { - this.uniforms.blur.value = value; - } - }, - - /** - * The strength of the gradient blur. - * - * @member {number} - * @memberof TilttShiftXFilter# - */ - gradientBlur: { - get: function () - { - return this.uniforms.gradientBlur.value; - }, - set: function (value) - { - this.uniforms.gradientBlur.value = value; - } - }, - - /** - * The X value to start the effect at. - * - * @member {Point} - * @memberof TilttShiftXFilter# - */ - start: { - get: function () - { - return this.uniforms.start.value; - }, - set: function (value) - { - this.uniforms.start.value = value; - this.updateDelta(); - } - }, - - /** - * The X value to end the effect at. - * - * @member {Point} - * @memberof TilttShiftXFilter# - */ - end: { - get: function () - { - return this.uniforms.end.value; - }, - set: function (value) - { - this.uniforms.end.value = value; - this.updateDelta(); - } - } -}); diff --git a/src/filters/tiltshift/TiltShiftYFilter.js b/src/filters/tiltshift/TiltShiftYFilter.js index d95f24d..651860e 100644 --- a/src/filters/tiltshift/TiltShiftYFilter.js +++ b/src/filters/tiltshift/TiltShiftYFilter.js @@ -1,4 +1,4 @@ -var core = require('../../core'); +var TiltShiftAxisFilter = require('./TiltShiftAxisFilter'); /** * @author Vico @vicocotea @@ -9,31 +9,15 @@ * A TiltShiftYFilter. * * @class - * @extends AbstractFilter + * @extends TiltShiftAxisFilter * @namespace PIXI.filters */ function TiltShiftYFilter() { - core.AbstractFilter.call(this, - // vertex shader - null, - // fragment shader - require('fs').readFileSync(__dirname + '/tiltShift.frag', 'utf8'), - // custom uniforms - { - blur: { type: '1f', value: 100 }, - gradientBlur: { type: '1f', value: 600 }, - start: { type: 'v2', value: { x: 0, y: window.innerHeight / 2 } }, - end: { type: 'v2', value: { x: 600, y: window.innerHeight / 2 } }, - delta: { type: 'v2', value: { x: 30, y: 30 } }, - texSize: { type: 'v2', value: { x: window.innerWidth, y: window.innerHeight } } - } - ); - - this.updateDelta(); + TiltShiftAxisFilter.call(this); } -TiltShiftYFilter.prototype = Object.create(core.AbstractFilter.prototype); +TiltShiftYFilter.prototype = Object.create(TiltShiftAxisFilter.prototype); TiltShiftYFilter.prototype.constructor = TiltShiftYFilter; module.exports = TiltShiftYFilter; @@ -47,80 +31,6 @@ var dy = this.uniforms.end.value.y - this.uniforms.start.value.y; var d = Math.sqrt(dx * dx + dy * dy); - // TODO (cengler) - These two lines are the only lines that are different between - // the TileShiftXFilter and TiltShiftYFilter.... this.uniforms.delta.value.x = -dy / d; this.uniforms.delta.value.y = dx / d; }; - -Object.defineProperties(TiltShiftYFilter.prototype, { - /** - * The strength of the blur. - * - * @member {number} - * @memberof TiltShiftYFilter# - */ - blur: { - get: function () - { - return this.uniforms.blur.value; - }, - set: function (value) - { - this.uniforms.blur.value = value; - } - }, - - /** - * The strength of the gradient blur. - * - * @member {number} - * @memberof TiltShiftYFilter# - */ - gradientBlur: { - get: function () - { - return this.uniforms.gradientBlur.value; - }, - set: function (value) - { - this.uniforms.gradientBlur.value = value; - } - }, - - /** - * The Y value to start the effect at. - * - * @member {number} - * @memberof TiltShiftYFilter# - */ - start: { - get: function () - { - return this.uniforms.start.value; - }, - set: function (value) - { - this.uniforms.start.value = value; - this.updateDelta(); - } - }, - - /** - * The Y value to end the effect at. - * - * @member {number} - * @memberof TiltShiftYFilter# - */ - end: { - get: function () - { - return this.uniforms.end.value; - }, - set: function (value) - { - this.uniforms.end.value = value; - this.updateDelta(); - } - } -});