r3-legacy/src/r3-d3-pass-fxaa.js

114 lines
2.3 KiB
JavaScript

/**
* R3.D3.Pass.FXAA
* @param graphics R3.Runtime.Graphics
* @param apiPassFXAA R3.D3.API.Pass.FXAA
* @constructor
*/
R3.D3.Pass.FXAA = function(
graphics,
apiPassFXAA
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiPassFXAA)) {
apiPassFXAA = {
passType : R3.D3.API.Pass.PASS_TYPE_FXAA
};
}
R3.D3.API.Pass.FXAA.call(
this,
apiPassFXAA,
apiPassFXAA.autoUpdateSize,
apiPassFXAA.width,
apiPassFXAA.height
);
R3.D3.Pass.call(
this,
this.graphics,
this
);
};
R3.D3.Pass.FXAA.prototype = Object.create(R3.D3.Pass.prototype);
R3.D3.Pass.FXAA.prototype.constructor = R3.D3.Pass.FXAA;
/**
* Create Pass.FXAA instance
* @returns {*}
*/
R3.D3.Pass.FXAA.prototype.createInstance = function() {
this.instance = new THREE.ShaderPass(THREE.FXAAShader);
if (this.autoUpdateSize) {
R3.Utils.UpdateWindowSize(this);
}
this.instance.uniforms['resolution'].value.set(
1 / this.width,
1 / this.height
);
console.log('Constructed an FXAA pass instance');
R3.D3.Pass.prototype.createInstance.call(this);
};
/**
* Update Pass.FXAA instance
*/
R3.D3.Pass.FXAA.prototype.updateInstance = function(property) {
if (
property === 'width' ||
property === 'height' ||
property === 'autoUpdateSize'
) {
if (this.autoUpdateSize) {
R3.Utils.UpdateWindowSize(this);
}
this.instance.uniforms['resolution'].value.set(
1 / this.width,
1 / this.height
);
return;
}
R3.D3.Pass.prototype.updateInstance.call(this, property);
};
/**
* Convenience function to set size
* @param width
* @param height
*/
R3.D3.Pass.FXAA.prototype.setSize = function(width, height) {
this.width = width;
this.height = height;
this.updateInstance('width');
};
/**
* R3.D3.Pass.FXAA to R3.D3.API.Pass.FXAA
* @returns {R3.D3.API.Pass.FXAA}
*/
R3.D3.Pass.FXAA.prototype.toApiObject = function() {
var apiPass = R3.D3.Pass.prototype.toApiObject.call(this);
var apiFXAAPass = new R3.D3.API.Pass.FXAA(
apiPass,
this.autoUpdateSize,
this.width,
this.height
);
return apiFXAAPass;
};