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 TiltShiftYFilter.
*
* @class
* @extends AbstractFilter
* @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();
}
TiltShiftYFilter.prototype = Object.create(core.AbstractFilter.prototype);
TiltShiftYFilter.prototype.constructor = TiltShiftYFilter;
module.exports = TiltShiftYFilter;
/**
* Updates the filter delta values.
*
*/
TiltShiftYFilter.prototype.updateDelta = function ()
{
var dx = this.uniforms.end.value.x - this.uniforms.start.value.x;
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();
}
}
});