|
@@ -1,27 +1,26 @@
|
|
|
module BABYLON {
|
|
|
export class PostProcessRenderEffect {
|
|
|
private _engine: Engine;
|
|
|
- private _name: string;
|
|
|
|
|
|
private _postProcesses: PostProcess[];
|
|
|
- private _postProcessType;
|
|
|
+ private _postProcessType; //The type must inherit from PostProcess (example: BABYLON.BlackAndWhitePostProcess, like this without quotes).
|
|
|
|
|
|
private _ratio: number;
|
|
|
private _samplingMode: number;
|
|
|
private _singleInstance: boolean;
|
|
|
|
|
|
private _cameras: Camera[];
|
|
|
- private _indicesForCamera: number[];
|
|
|
+ private _indicesForCamera: number[][];
|
|
|
|
|
|
private _renderPasses: PostProcessRenderPass[];
|
|
|
private _renderEffectAsPasses: PostProcessRenderEffect[];
|
|
|
|
|
|
- public name: string;
|
|
|
- public parameters: (effect) => void;
|
|
|
+ // private
|
|
|
+ public _name: string;
|
|
|
|
|
|
+ public parameters: (effect: Effect) => void;
|
|
|
|
|
|
- constructor(engine: Engine, name: string, postProcessType, ratio: number, samplingMode: number, singleInstance: boolean) {
|
|
|
- this.name = name;
|
|
|
+ constructor(engine: Engine, name: string, postProcessType, ratio?: number, samplingMode?: number, singleInstance?: boolean) {
|
|
|
this._engine = engine;
|
|
|
this._name = name;
|
|
|
this._postProcessType = postProcessType;
|
|
@@ -37,15 +36,15 @@ module BABYLON {
|
|
|
this._renderPasses = [];
|
|
|
this._renderEffectAsPasses = [];
|
|
|
|
|
|
- this.parameters = function (effect) { };
|
|
|
+ this.parameters = (effect: Effect) => { };
|
|
|
}
|
|
|
|
|
|
- public static getInstance(engine: Engine, postProcessType, ratio: number, samplingMode: number): PostProcess {
|
|
|
+ private static _GetInstance(engine: Engine, postProcessType, ratio: number, samplingMode: number): PostProcess {
|
|
|
var postProcess;
|
|
|
var instance;
|
|
|
- var args = new Array();
|
|
|
+ var args = [];
|
|
|
|
|
|
- var parameters = PostProcessRenderEffect.getParametersNames(postProcessType);
|
|
|
+ var parameters = PostProcessRenderEffect._GetParametersNames(postProcessType);
|
|
|
for (var i = 0; i < parameters.length; i++) {
|
|
|
switch (parameters[i]) {
|
|
|
case "name":
|
|
@@ -81,9 +80,9 @@ module BABYLON {
|
|
|
return instance;
|
|
|
}
|
|
|
|
|
|
- public static getParametersNames(func): string[] {
|
|
|
+ private static _GetParametersNames(func): string[] {
|
|
|
var commentsRegex = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
|
|
|
- var functWithoutComments = eval(func).toString().replace(commentsRegex, '');
|
|
|
+ var functWithoutComments = eval(func).toString().replace(commentsRegex, ''); //TODO: delete eval
|
|
|
|
|
|
var parameters = functWithoutComments.slice(functWithoutComments.indexOf('(') + 1, functWithoutComments.indexOf(')')).match(/([^\s,]+)/g);
|
|
|
|
|
@@ -99,26 +98,26 @@ module BABYLON {
|
|
|
}
|
|
|
|
|
|
public addPass(renderPass: PostProcessRenderPass): void {
|
|
|
- this._renderPasses[renderPass.name] = renderPass;
|
|
|
+ this._renderPasses[renderPass._name] = renderPass;
|
|
|
|
|
|
this._linkParameters();
|
|
|
}
|
|
|
|
|
|
public removePass(renderPass: PostProcessRenderPass): void {
|
|
|
- delete this._renderPasses[renderPass.name];
|
|
|
+ delete this._renderPasses[renderPass._name];
|
|
|
|
|
|
this._linkParameters();
|
|
|
}
|
|
|
|
|
|
public addRenderEffectAsPass(renderEffect: PostProcessRenderEffect): void {
|
|
|
- this._renderEffectAsPasses[renderEffect.name] = renderEffect;
|
|
|
+ this._renderEffectAsPasses[renderEffect._name] = renderEffect;
|
|
|
|
|
|
this._linkParameters();
|
|
|
}
|
|
|
|
|
|
public getPass(passName: string): void {
|
|
|
for (var renderPassName in this._renderPasses) {
|
|
|
- if (renderPassName == passName) {
|
|
|
+ if (renderPassName === passName) {
|
|
|
return this._renderPasses[passName];
|
|
|
}
|
|
|
}
|
|
@@ -130,110 +129,119 @@ module BABYLON {
|
|
|
this._linkParameters();
|
|
|
}
|
|
|
|
|
|
- public attachCameras(cameras: Camera[]): void {
|
|
|
- var postProcess = null;
|
|
|
+ // private
|
|
|
+ public _attachCameras(cameras: Camera);
|
|
|
+ public _attachCameras(cameras: Camera[]);
|
|
|
+ public _attachCameras(cameras: any): void {
|
|
|
+ var cameraKey;
|
|
|
|
|
|
- cameras = Tools.MakeArray(cameras || this._cameras);
|
|
|
+ var _cam = Tools.MakeArray(cameras || this._cameras);
|
|
|
+
|
|
|
+ for (var i = 0; i < _cam.length; i++) {
|
|
|
+ var camera = _cam[i];
|
|
|
+ var cameraName = camera.name;
|
|
|
|
|
|
- for (var i = 0; i < cameras.length; i++) {
|
|
|
if (this._singleInstance) {
|
|
|
- postProcess = this._postProcesses[0] || PostProcessRenderEffect.getInstance(this._engine, this._postProcessType, this._ratio, this._samplingMode);
|
|
|
- this._postProcesses[0] = postProcess;
|
|
|
+ cameraKey = 0;
|
|
|
}
|
|
|
else {
|
|
|
- postProcess = this._postProcesses[cameras[i].name] || PostProcessRenderEffect.getInstance(this._engine, this._postProcessType, this._ratio, this._samplingMode);
|
|
|
- this._postProcesses[cameras[i].name] = postProcess;
|
|
|
+ cameraKey = cameraName;
|
|
|
}
|
|
|
- var index = cameras[i].attachPostProcess(postProcess);
|
|
|
|
|
|
- if (this._indicesForCamera[cameras[i].name] == null) {
|
|
|
- this._indicesForCamera[cameras[i].name] = [];
|
|
|
+ this._postProcesses[cameraKey] = this._postProcesses[cameraKey] || PostProcessRenderEffect._GetInstance(this._engine, this._postProcessType, this._ratio, this._samplingMode);
|
|
|
+
|
|
|
+ var index = camera.attachPostProcess(this._postProcesses[cameraKey]);
|
|
|
+
|
|
|
+ if (this._indicesForCamera[cameraName] == null) {
|
|
|
+ this._indicesForCamera[cameraName] = [];
|
|
|
}
|
|
|
|
|
|
- this._indicesForCamera[cameras[i].name].push(index);
|
|
|
+ this._indicesForCamera[cameraName].push(index);
|
|
|
|
|
|
- if (this._cameras.indexOf(cameras[i]) == -1) {
|
|
|
- this._cameras[cameras[i].name] = cameras[i];
|
|
|
+ if (this._cameras.indexOf(camera) == -1) {
|
|
|
+ this._cameras[cameraName] = camera;
|
|
|
}
|
|
|
|
|
|
for (var passName in this._renderPasses) {
|
|
|
- this._renderPasses[passName].incRefCount();
|
|
|
+ this._renderPasses[passName]._incRefCount();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
this._linkParameters();
|
|
|
}
|
|
|
|
|
|
- public detachCameras(cameras): void {
|
|
|
- cameras = Tools.MakeArray(cameras || this._cameras);
|
|
|
+ // private
|
|
|
+ public _detachCameras(cameras: Camera);
|
|
|
+ public _detachCameras(cameras: Camera[]);
|
|
|
+ public _detachCameras(cameras: any): void {
|
|
|
+ var _cam = Tools.MakeArray(cameras || this._cameras);
|
|
|
|
|
|
- for (var i = 0; i < cameras.length; i++) {
|
|
|
- if (this._singleInstance) {
|
|
|
- cameras[i].detachPostProcess(this._postProcesses[0], this._indicesForCamera[cameras[i].name]);
|
|
|
- }
|
|
|
- else {
|
|
|
- cameras[i].detachPostProcess(this._postProcesses[cameras[i].name], this._indicesForCamera[cameras[i].name]);
|
|
|
- }
|
|
|
+ for (var i = 0; i < _cam.length; i++) {
|
|
|
+ var camera = _cam[i];
|
|
|
+ var cameraName = camera.Name;
|
|
|
|
|
|
- var index = this._cameras.indexOf(cameras[i].name);
|
|
|
+ camera.detachPostProcess(this._postProcesses[this._singleInstance ? 0 : cameraName], this._indicesForCamera[cameraName]);
|
|
|
+
|
|
|
+ var index = this._cameras.indexOf(cameraName);
|
|
|
|
|
|
this._indicesForCamera.splice(index, 1);
|
|
|
this._cameras.splice(index, 1);
|
|
|
|
|
|
for (var passName in this._renderPasses) {
|
|
|
- this._renderPasses[passName].decRefCount();
|
|
|
+ this._renderPasses[passName]._decRefCount();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public enable(cameras: Camera[]): void {
|
|
|
- cameras = Tools.MakeArray(cameras || this._cameras);
|
|
|
+ // private
|
|
|
+ public _enable(cameras: Camera);
|
|
|
+ public _enable(cameras: Camera[]);
|
|
|
+ public _enable(cameras: any): void {
|
|
|
+ var _cam = Tools.MakeArray(cameras || this._cameras);
|
|
|
+
|
|
|
+ for (var i = 0; i < _cam.length; i++) {
|
|
|
+ var camera = _cam[i];
|
|
|
+ var cameraName = camera.Name;
|
|
|
|
|
|
- for (var i = 0; i < cameras.length; i++) {
|
|
|
- for (var j = 0; j < this._indicesForCamera[cameras[i].name].length; j++) {
|
|
|
- if (cameras[i]._postProcesses[this._indicesForCamera[cameras[i].name][j]] === undefined) {
|
|
|
- if (this._singleInstance) {
|
|
|
- cameras[i].attachPostProcess(this._postProcesses[0], this._indicesForCamera[cameras[i].name][j]);
|
|
|
- }
|
|
|
- else {
|
|
|
- cameras[i].attachPostProcess(this._postProcesses[cameras[i].name], this._indicesForCamera[cameras[i].name][j]);
|
|
|
- }
|
|
|
+ for (var j = 0; j < this._indicesForCamera[cameraName].length; j++) {
|
|
|
+ if (camera._postProcesses[this._indicesForCamera[cameraName][j]] === undefined) {
|
|
|
+ cameras[i].attachPostProcess(this._postProcesses[this._singleInstance ? 0 : cameraName], this._indicesForCamera[cameraName][j]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (var passName in this._renderPasses) {
|
|
|
- this._renderPasses[passName].incRefCount();
|
|
|
+ this._renderPasses[passName]._incRefCount();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public disable(cameras: Camera[]): void {
|
|
|
- cameras = Tools.MakeArray(cameras || this._cameras);
|
|
|
+ // private
|
|
|
+ public _disable(cameras: Camera);
|
|
|
+ public _disable(cameras: Camera[]);
|
|
|
+ public _disable(cameras: any): void {
|
|
|
+ var _cam = Tools.MakeArray(cameras || this._cameras);
|
|
|
|
|
|
- for (var i = 0; i < cameras.length; i++) {
|
|
|
- if (this._singleInstance) {
|
|
|
- cameras[i].detachPostProcess(this._postProcesses[0], this._indicesForCamera[cameras[i].name]);
|
|
|
- }
|
|
|
- else {
|
|
|
- cameras[i].detachPostProcess(this._postProcesses[cameras[i].name], this._indicesForCamera[cameras[i].name]);
|
|
|
- }
|
|
|
+ for (var i = 0; i < _cam.length; i++) {
|
|
|
+ var camera = _cam[i];
|
|
|
+ var cameraName = camera.Name;
|
|
|
+
|
|
|
+ camera.detachPostProcess(this._postProcesses[this._singleInstance ? 0 : cameraName], this._indicesForCamera[cameraName]);
|
|
|
|
|
|
for (var passName in this._renderPasses) {
|
|
|
- this._renderPasses[passName].decRefCount();
|
|
|
+ this._renderPasses[passName]._decRefCount();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public getPostProcess(): PostProcess {
|
|
|
- return this._postProcesses[0];
|
|
|
+ return this._postProcesses[0]; // todo: always 0?
|
|
|
}
|
|
|
|
|
|
private _linkParameters(): void {
|
|
|
- var that = this;
|
|
|
for (var index in this._postProcesses) {
|
|
|
- this._postProcesses[index].onApply = function (effect) {
|
|
|
- that.parameters(effect);
|
|
|
- that._linkTextures(effect);
|
|
|
+ this._postProcesses[index].onApply = (effect: Effect) => {
|
|
|
+ this.parameters(effect);
|
|
|
+ this._linkTextures(effect);
|
|
|
};
|
|
|
}
|
|
|
}
|