|
@@ -1,34 +1,46 @@
|
|
module BABYLON {
|
|
module BABYLON {
|
|
|
|
+ /**
|
|
|
|
+ * This represents a set of one or more post processes in Babylon.
|
|
|
|
+ * A post process can be used to apply a shader to a texture after it is rendered.
|
|
|
|
+ * @example https://doc.babylonjs.com/how_to/how_to_use_postprocessrenderpipeline
|
|
|
|
+ */
|
|
export class PostProcessRenderEffect {
|
|
export class PostProcessRenderEffect {
|
|
private _postProcesses: any;
|
|
private _postProcesses: any;
|
|
- private _getPostProcess: () => Nullable<PostProcess | Array<PostProcess>>;
|
|
|
|
|
|
+ private _getPostProcesses: () => Nullable<PostProcess | Array<PostProcess>>;
|
|
|
|
|
|
private _singleInstance: boolean;
|
|
private _singleInstance: boolean;
|
|
|
|
|
|
private _cameras: { [key: string]: Nullable<Camera> };
|
|
private _cameras: { [key: string]: Nullable<Camera> };
|
|
private _indicesForCamera: { [key: string]: number[] };
|
|
private _indicesForCamera: { [key: string]: number[] };
|
|
|
|
|
|
- private _renderEffectAsPasses: any;
|
|
|
|
-
|
|
|
|
- // private
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Name of the effect
|
|
|
|
+ */
|
|
public _name: string;
|
|
public _name: string;
|
|
-
|
|
|
|
- public applyParameters: (postProcess: PostProcess) => void;
|
|
|
|
|
|
|
|
- constructor(engine: Engine, name: string, getPostProcess: () => Nullable<PostProcess | Array<PostProcess>>, singleInstance?: boolean) {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Instantiates a post process render effect.
|
|
|
|
+ * A post process can be used to apply a shader to a texture after it is rendered.
|
|
|
|
+ * @param engine The engine the effect is tied to
|
|
|
|
+ * @param name The name of the effect
|
|
|
|
+ * @param getPostProcesses A function that returns a set of post processes which the effect will run in order to be run.
|
|
|
|
+ * @param singleInstance False if this post process can be run on multiple cameras. (default: true)
|
|
|
|
+ */
|
|
|
|
+ constructor(engine: Engine, name: string, getPostProcesses: () => Nullable<PostProcess | Array<PostProcess>>, singleInstance?: boolean) {
|
|
this._name = name;
|
|
this._name = name;
|
|
this._singleInstance = singleInstance || true;
|
|
this._singleInstance = singleInstance || true;
|
|
|
|
|
|
- this._getPostProcess = getPostProcess;
|
|
|
|
|
|
+ this._getPostProcesses = getPostProcesses;
|
|
|
|
|
|
this._cameras = {};
|
|
this._cameras = {};
|
|
this._indicesForCamera = {};
|
|
this._indicesForCamera = {};
|
|
|
|
|
|
this._postProcesses = {};
|
|
this._postProcesses = {};
|
|
-
|
|
|
|
- this._renderEffectAsPasses = {};
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Checks if all the post processes in the effect are supported.
|
|
|
|
+ */
|
|
public get isSupported(): boolean {
|
|
public get isSupported(): boolean {
|
|
for (var index in this._postProcesses) {
|
|
for (var index in this._postProcesses) {
|
|
for(var ppIndex in this._postProcesses[index]){
|
|
for(var ppIndex in this._postProcesses[index]){
|
|
@@ -40,17 +52,26 @@ module BABYLON {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Updates the current state of the effect
|
|
|
|
+ */
|
|
public _update(): void {
|
|
public _update(): void {
|
|
}
|
|
}
|
|
- public addRenderEffectAsPass(renderEffect: PostProcessRenderEffect): void {
|
|
|
|
- this._renderEffectAsPasses[renderEffect._name] = renderEffect;
|
|
|
|
-
|
|
|
|
- this._linkParameters();
|
|
|
|
- }
|
|
|
|
|
|
|
|
- // private
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Attaches the effect on cameras
|
|
|
|
+ * @param cameras The camera to attach to.
|
|
|
|
+ */
|
|
public _attachCameras(cameras: Camera): void;
|
|
public _attachCameras(cameras: Camera): void;
|
|
|
|
+ /**
|
|
|
|
+ * Attaches the effect on cameras
|
|
|
|
+ * @param cameras The camera to attach to.
|
|
|
|
+ */
|
|
public _attachCameras(cameras: Camera[]): void;
|
|
public _attachCameras(cameras: Camera[]): void;
|
|
|
|
+ /**
|
|
|
|
+ * Attaches the effect on cameras
|
|
|
|
+ * @param cameras The camera to attach to.
|
|
|
|
+ */
|
|
public _attachCameras(cameras: any): void {
|
|
public _attachCameras(cameras: any): void {
|
|
var cameraKey;
|
|
var cameraKey;
|
|
|
|
|
|
@@ -72,7 +93,7 @@ module BABYLON {
|
|
}
|
|
}
|
|
|
|
|
|
if(!this._postProcesses[cameraKey]){
|
|
if(!this._postProcesses[cameraKey]){
|
|
- var postProcess = this._getPostProcess();
|
|
|
|
|
|
+ var postProcess = this._getPostProcesses();
|
|
if(postProcess){
|
|
if(postProcess){
|
|
this._postProcesses[cameraKey] = Array.isArray(postProcess) ? postProcess :[postProcess];
|
|
this._postProcesses[cameraKey] = Array.isArray(postProcess) ? postProcess :[postProcess];
|
|
}
|
|
}
|
|
@@ -93,13 +114,22 @@ module BABYLON {
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
- this._linkParameters();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- // private
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Detatches the effect on cameras
|
|
|
|
+ * @param cameras The camera to detatch from.
|
|
|
|
+ */
|
|
public _detachCameras(cameras: Camera): void;
|
|
public _detachCameras(cameras: Camera): void;
|
|
|
|
+ /**
|
|
|
|
+ * Detatches the effect on cameras
|
|
|
|
+ * @param cameras The camera to detatch from.
|
|
|
|
+ */
|
|
public _detachCameras(cameras: Camera[]): void;
|
|
public _detachCameras(cameras: Camera[]): void;
|
|
|
|
+ /**
|
|
|
|
+ * Detatches the effect on cameras
|
|
|
|
+ * @param cameras The camera to detatch from.
|
|
|
|
+ */
|
|
public _detachCameras(cameras: any): void {
|
|
public _detachCameras(cameras: any): void {
|
|
var cams = Tools.MakeArray(cameras || this._cameras);
|
|
var cams = Tools.MakeArray(cameras || this._cameras);
|
|
|
|
|
|
@@ -121,9 +151,20 @@ module BABYLON {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- // private
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Enables the effect on given cameras
|
|
|
|
+ * @param cameras The camera to enable.
|
|
|
|
+ */
|
|
public _enable(cameras: Camera): void;
|
|
public _enable(cameras: Camera): void;
|
|
|
|
+ /**
|
|
|
|
+ * Enables the effect on given cameras
|
|
|
|
+ * @param cameras The camera to enable.
|
|
|
|
+ */
|
|
public _enable(cameras: Nullable<Camera[]>): void;
|
|
public _enable(cameras: Nullable<Camera[]>): void;
|
|
|
|
+ /**
|
|
|
|
+ * Enables the effect on given cameras
|
|
|
|
+ * @param cameras The camera to enable.
|
|
|
|
+ */
|
|
public _enable(cameras: any): void {
|
|
public _enable(cameras: any): void {
|
|
var cams = Tools.MakeArray(cameras || this._cameras);
|
|
var cams = Tools.MakeArray(cameras || this._cameras);
|
|
|
|
|
|
@@ -143,9 +184,20 @@ module BABYLON {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- // private
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Disables the effect on the given cameras
|
|
|
|
+ * @param cameras The camera to disable.
|
|
|
|
+ */
|
|
public _disable(cameras: Camera): void;
|
|
public _disable(cameras: Camera): void;
|
|
|
|
+ /**
|
|
|
|
+ * Disables the effect on the given cameras
|
|
|
|
+ * @param cameras The camera to disable.
|
|
|
|
+ */
|
|
public _disable(cameras: Nullable<Camera[]>): void;
|
|
public _disable(cameras: Nullable<Camera[]>): void;
|
|
|
|
+ /**
|
|
|
|
+ * Disables the effect on the given cameras
|
|
|
|
+ * @param cameras The camera to disable.
|
|
|
|
+ */
|
|
public _disable(cameras: any): void {
|
|
public _disable(cameras: any): void {
|
|
var cams = Tools.MakeArray(cameras || this._cameras);
|
|
var cams = Tools.MakeArray(cameras || this._cameras);
|
|
|
|
|
|
@@ -161,36 +213,20 @@ module BABYLON {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public getPostProcess(camera?: Camera): Nullable<PostProcess> {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Gets a list of the post processes contained in the effect.
|
|
|
|
+ * @param camera The camera to get the post processes on.
|
|
|
|
+ * @returns The list of the post processes in the effect.
|
|
|
|
+ */
|
|
|
|
+ public getPostProcesses(camera?: Camera): Nullable<Array<PostProcess>> {
|
|
if (this._singleInstance) {
|
|
if (this._singleInstance) {
|
|
- return this._postProcesses[0][0];
|
|
|
|
|
|
+ return this._postProcesses[0];
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
-
|
|
|
|
if (!camera) {
|
|
if (!camera) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
- return this._postProcesses[camera.name][0];
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private _linkParameters(): void {
|
|
|
|
- for (var index in this._postProcesses) {
|
|
|
|
- this._postProcesses[index].forEach((postProcess:PostProcess)=>{
|
|
|
|
- if (this.applyParameters) {
|
|
|
|
- this.applyParameters(postProcess);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- postProcess.onBeforeRenderObservable.add((effect: Effect) => {
|
|
|
|
- this._linkTextures(effect);
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private _linkTextures(effect: Effect): void {
|
|
|
|
- for (var renderEffectName in this._renderEffectAsPasses) {
|
|
|
|
- effect.setTextureFromPostProcess(renderEffectName + "Sampler", this._renderEffectAsPasses[renderEffectName].getPostProcess());
|
|
|
|
|
|
+ return this._postProcesses[camera.name];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|