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

161 lines
3.4 KiB
JavaScript
Raw Normal View History

2018-04-09 09:35:04 +02:00
/**
* R3.D3.Pass.SSAO
* @param graphics R3.GraphicsRuntime
* @param apiPassSSAO R3.D3.API.Pass.SSAO
* @constructor
*/
R3.D3.Pass.SSAO = function (
graphics,
apiPassSSAO
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiPassSSAO)) {
apiPassSSAO = {
passType : R3.D3.API.Pass.PASS_TYPE_SSAO
};
}
R3.D3.API.Pass.SSAO.call(
this,
apiPassSSAO,
apiPassSSAO.scene,
apiPassSSAO.camera,
apiPassSSAO.radius,
apiPassSSAO.onlyAO,
apiPassSSAO.aoClamp,
apiPassSSAO.lumInfluence
);
if (this.scene instanceof R3.D3.API.Scene) {
this.scene = new R3.D3.Scene(
this.graphics,
this.scene
)
}
if (this.camera instanceof R3.D3.API.Camera) {
this.camera = new R3.D3.Camera(
this.graphics,
this.camera
)
}
R3.D3.Pass.call(
this,
this.graphics,
this
);
};
R3.D3.Pass.SSAO.prototype = Object.create(R3.D3.Pass.prototype);
R3.D3.Pass.SSAO.prototype.constructor = R3.D3.Pass.SSAO;
/**
* Create Pass.SSAO instance
* @returns {*}
*/
R3.D3.Pass.SSAO.prototype.createInstance = function() {
if (R3.Utils.UndefinedOrNull(this.scene) ||
R3.Utils.UndefinedOrNull(this.scene.instance)
) {
console.warn('scene not ready');
return;
}
if (R3.Utils.UndefinedOrNull(this.camera) ||
R3.Utils.UndefinedOrNull(this.camera.instance)
) {
console.warn('camera not ready');
return;
}
this.instance = new THREE.SSAOPass(
this.scene.instance,
this.camera.instance
);
this.instance.radius = this.radius;
this.instance.onlyAO = this.onlyAO;
this.instance.aoClamp = this.aoClamp;
this.instance.lumInfluence = this.lumInfluence;
console.log('Constructed an SSAO pass instance');
R3.D3.Pass.prototype.createInstance.call(this);
};
/**
* Update Pass.SSAO instance
*/
R3.D3.Pass.SSAO.prototype.updateInstance = function(property) {
if (property === 'scene') {
if (R3.Utils.UndefinedOrNull(this.instance)) {
this.createInstance();
}
return;
}
if (property === 'camera') {
if (R3.Utils.UndefinedOrNull(this.instance)) {
this.createInstance();
}
return;
}
if (!this.instance) {
return;
}
if (property === 'radius') {
this.instance.radius = this.radius;
return;
}
if (property === 'onlyAO') {
this.instance.onlyAO = this.onlyAO;
return;
}
if (property === 'aoClamp') {
this.instance.aoClamp = this.aoClamp;
return;
}
if (property === 'lumInfluence') {
this.instance.lumInfluence = this.lumInfluence;
return;
}
R3.D3.Pass.prototype.updateInstance.call(this, property);
};
/**
* R3.D3.Pass.SSAO to R3.D3.API.Pass.SSAO
* @returns {R3.D3.API.Pass.SSAO}
*/
R3.D3.Pass.SSAO.prototype.toApiObject = function() {
var apiPass = R3.D3.Pass.prototype.toApiObject.call(this);
var apiSSAOPass = new R3.D3.API.Pass.SSAO(
apiPass,
R3.Utils.IdOrNull(this.scene),
R3.Utils.IdOrNull(this.camera),
this.radius,
this.onlyAO,
this.aoClamp,
this.lumInfluence
);
return apiSSAOPass;
};