|
@@ -1,21 +1,20 @@
|
|
module BABYLON {
|
|
module BABYLON {
|
|
export type PostProcessOptions = { width: number, height: number };
|
|
export type PostProcessOptions = { width: number, height: number };
|
|
|
|
|
|
- export class PostProcess
|
|
|
|
- {
|
|
|
|
|
|
+ export class PostProcess {
|
|
public width = -1;
|
|
public width = -1;
|
|
public height = -1;
|
|
public height = -1;
|
|
public renderTargetSamplingMode: number;
|
|
public renderTargetSamplingMode: number;
|
|
public clearColor: Color4;
|
|
public clearColor: Color4;
|
|
public autoClear = true;
|
|
public autoClear = true;
|
|
public alphaMode = Engine.ALPHA_DISABLE;
|
|
public alphaMode = Engine.ALPHA_DISABLE;
|
|
- public alphaConstants: Color4;
|
|
|
|
- public animations = new Array<Animation>();
|
|
|
|
|
|
+ public alphaConstants: Color4;
|
|
|
|
+ public animations = new Array<Animation>();
|
|
|
|
|
|
/*
|
|
/*
|
|
Enable Pixel Perfect mode where texture is not scaled to be power of 2.
|
|
Enable Pixel Perfect mode where texture is not scaled to be power of 2.
|
|
Can only be used on a single postprocess or on the last one of a chain.
|
|
Can only be used on a single postprocess or on the last one of a chain.
|
|
- */
|
|
|
|
|
|
+ */
|
|
public enablePixelPerfectMode = false;
|
|
public enablePixelPerfectMode = false;
|
|
|
|
|
|
public scaleMode = Engine.SCALEMODE_FLOOR;
|
|
public scaleMode = Engine.SCALEMODE_FLOOR;
|
|
@@ -41,7 +40,7 @@
|
|
private _shareOutputWithPostProcess: PostProcess;
|
|
private _shareOutputWithPostProcess: PostProcess;
|
|
private _texelSize = Vector2.Zero();
|
|
private _texelSize = Vector2.Zero();
|
|
private _forcedOutputTexture: InternalTexture;
|
|
private _forcedOutputTexture: InternalTexture;
|
|
-
|
|
|
|
|
|
+
|
|
// Events
|
|
// Events
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -118,11 +117,11 @@
|
|
|
|
|
|
public get outputTexture(): InternalTexture {
|
|
public get outputTexture(): InternalTexture {
|
|
return this._textures.data[this._currentRenderTextureInd];
|
|
return this._textures.data[this._currentRenderTextureInd];
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
public set outputTexture(value: InternalTexture) {
|
|
public set outputTexture(value: InternalTexture) {
|
|
this._forcedOutputTexture = value;
|
|
this._forcedOutputTexture = value;
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
public getCamera(): Camera {
|
|
public getCamera(): Camera {
|
|
return this._camera;
|
|
return this._camera;
|
|
@@ -140,8 +139,8 @@
|
|
return this._texelSize;
|
|
return this._texelSize;
|
|
}
|
|
}
|
|
|
|
|
|
- constructor(public name: string, fragmentUrl: string, parameters: Nullable<string[]>, samplers: Nullable<string[]>, options: number | PostProcessOptions, camera: Nullable<Camera>,
|
|
|
|
- samplingMode: number = Texture.NEAREST_SAMPLINGMODE, engine?: Engine, reusable?: boolean, defines: Nullable<string> = null, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT, vertexUrl: string = "postprocess", indexParameters?: any, blockCompilation = false) {
|
|
|
|
|
|
+ constructor(public name: string, fragmentUrl: string, parameters: Nullable<string[]>, samplers: Nullable<string[]>, options: number | PostProcessOptions, camera: Nullable<Camera>,
|
|
|
|
+ samplingMode: number = Texture.NEAREST_SAMPLINGMODE, engine?: Engine, reusable?: boolean, defines: Nullable<string> = null, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT, vertexUrl: string = "postprocess", indexParameters?: any, blockCompilation = false) {
|
|
if (camera != null) {
|
|
if (camera != null) {
|
|
this._camera = camera;
|
|
this._camera = camera;
|
|
this._scene = camera.getScene();
|
|
this._scene = camera.getScene();
|
|
@@ -174,11 +173,11 @@
|
|
if (!blockCompilation) {
|
|
if (!blockCompilation) {
|
|
this.updateEffect(defines);
|
|
this.updateEffect(defines);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
public getEngine(): Engine {
|
|
public getEngine(): Engine {
|
|
return this._engine;
|
|
return this._engine;
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
public getEffect(): Effect {
|
|
public getEffect(): Effect {
|
|
return this._effect;
|
|
return this._effect;
|
|
@@ -191,33 +190,33 @@
|
|
|
|
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public updateEffect(defines: Nullable<string> = null, uniforms: Nullable<string[]> = null, samplers: Nullable<string[]> = null, indexParameters?: any,
|
|
public updateEffect(defines: Nullable<string> = null, uniforms: Nullable<string[]> = null, samplers: Nullable<string[]> = null, indexParameters?: any,
|
|
- onCompiled?: (effect: Effect) => void, onError?: (effect: Effect, errors: string) => void) {
|
|
|
|
|
|
+ onCompiled?: (effect: Effect) => void, onError?: (effect: Effect, errors: string) => void) {
|
|
this._effect = this._engine.createEffect({ vertex: this._vertexUrl, fragment: this._fragmentUrl },
|
|
this._effect = this._engine.createEffect({ vertex: this._vertexUrl, fragment: this._fragmentUrl },
|
|
["position"],
|
|
["position"],
|
|
uniforms || this._parameters,
|
|
uniforms || this._parameters,
|
|
- samplers || this._samplers,
|
|
|
|
|
|
+ samplers || this._samplers,
|
|
defines !== null ? defines : "",
|
|
defines !== null ? defines : "",
|
|
undefined,
|
|
undefined,
|
|
onCompiled,
|
|
onCompiled,
|
|
onError,
|
|
onError,
|
|
indexParameters || this._indexParameters
|
|
indexParameters || this._indexParameters
|
|
- );
|
|
|
|
- }
|
|
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
|
|
public isReusable(): boolean {
|
|
public isReusable(): boolean {
|
|
return this._reusable;
|
|
return this._reusable;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/** invalidate frameBuffer to hint the postprocess to create a depth buffer */
|
|
/** invalidate frameBuffer to hint the postprocess to create a depth buffer */
|
|
- public markTextureDirty() : void{
|
|
|
|
|
|
+ public markTextureDirty(): void {
|
|
this.width = -1;
|
|
this.width = -1;
|
|
}
|
|
}
|
|
|
|
|
|
- public activate(camera: Camera, sourceTexture: Nullable<InternalTexture> = null, forceDepthStencil?: boolean): void {
|
|
|
|
|
|
+ public activate(camera: Nullable<Camera>, sourceTexture: Nullable<InternalTexture> = null, forceDepthStencil?: boolean): void {
|
|
camera = camera || this._camera;
|
|
camera = camera || this._camera;
|
|
-
|
|
|
|
|
|
+
|
|
var scene = camera.getScene();
|
|
var scene = camera.getScene();
|
|
var engine = scene.getEngine();
|
|
var engine = scene.getEngine();
|
|
var maxSize = engine.getCaps().maxTextureSize;
|
|
var maxSize = engine.getCaps().maxTextureSize;
|
|
@@ -255,17 +254,17 @@
|
|
this._engine._releaseTexture(this._textures.data[i]);
|
|
this._engine._releaseTexture(this._textures.data[i]);
|
|
}
|
|
}
|
|
this._textures.reset();
|
|
this._textures.reset();
|
|
- }
|
|
|
|
|
|
+ }
|
|
this.width = desiredWidth;
|
|
this.width = desiredWidth;
|
|
this.height = desiredHeight;
|
|
this.height = desiredHeight;
|
|
|
|
|
|
let textureSize = { width: this.width, height: this.height };
|
|
let textureSize = { width: this.width, height: this.height };
|
|
- let textureOptions = {
|
|
|
|
- generateMipMaps: false,
|
|
|
|
- generateDepthBuffer: forceDepthStencil || camera._postProcesses.indexOf(this) === 0,
|
|
|
|
|
|
+ let textureOptions = {
|
|
|
|
+ generateMipMaps: false,
|
|
|
|
+ generateDepthBuffer: forceDepthStencil || camera._postProcesses.indexOf(this) === 0,
|
|
generateStencilBuffer: (forceDepthStencil || camera._postProcesses.indexOf(this) === 0) && this._engine.isStencilEnable,
|
|
generateStencilBuffer: (forceDepthStencil || camera._postProcesses.indexOf(this) === 0) && this._engine.isStencilEnable,
|
|
- samplingMode: this.renderTargetSamplingMode,
|
|
|
|
- type: this._textureType
|
|
|
|
|
|
+ samplingMode: this.renderTargetSamplingMode,
|
|
|
|
+ type: this._textureType
|
|
};
|
|
};
|
|
|
|
|
|
this._textures.push(this._engine.createRenderTargetTexture(textureSize, textureOptions));
|
|
this._textures.push(this._engine.createRenderTargetTexture(textureSize, textureOptions));
|
|
@@ -273,7 +272,7 @@
|
|
if (this._reusable) {
|
|
if (this._reusable) {
|
|
this._textures.push(this._engine.createRenderTargetTexture(textureSize, textureOptions));
|
|
this._textures.push(this._engine.createRenderTargetTexture(textureSize, textureOptions));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
this._texelSize.copyFromFloats(1.0 / this.width, 1.0 / this.height);
|
|
this._texelSize.copyFromFloats(1.0 / this.width, 1.0 / this.height);
|
|
|
|
|
|
this.onSizeChangedObservable.notifyObservers(this);
|
|
this.onSizeChangedObservable.notifyObservers(this);
|
|
@@ -287,7 +286,7 @@
|
|
}
|
|
}
|
|
|
|
|
|
var target: InternalTexture;
|
|
var target: InternalTexture;
|
|
-
|
|
|
|
|
|
+
|
|
if (this._shareOutputWithPostProcess) {
|
|
if (this._shareOutputWithPostProcess) {
|
|
target = this._shareOutputWithPostProcess.outputTexture;
|
|
target = this._shareOutputWithPostProcess.outputTexture;
|
|
} else if (this._forcedOutputTexture) {
|
|
} else if (this._forcedOutputTexture) {
|
|
@@ -334,7 +333,7 @@
|
|
}
|
|
}
|
|
return this.width / this.height;
|
|
return this.width / this.height;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public apply(): Nullable<Effect> {
|
|
public apply(): Nullable<Effect> {
|
|
// Check
|
|
// Check
|
|
if (!this._effect || !this._effect.isReady())
|
|
if (!this._effect || !this._effect.isReady())
|
|
@@ -350,17 +349,17 @@
|
|
this._engine.setAlphaMode(this.alphaMode);
|
|
this._engine.setAlphaMode(this.alphaMode);
|
|
if (this.alphaConstants) {
|
|
if (this.alphaConstants) {
|
|
this.getEngine().setAlphaConstants(this.alphaConstants.r, this.alphaConstants.g, this.alphaConstants.b, this.alphaConstants.a);
|
|
this.getEngine().setAlphaConstants(this.alphaConstants.r, this.alphaConstants.g, this.alphaConstants.b, this.alphaConstants.a);
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
// Texture
|
|
// Texture
|
|
- var source: InternalTexture;
|
|
|
|
|
|
+ var source: InternalTexture;
|
|
if (this._shareOutputWithPostProcess) {
|
|
if (this._shareOutputWithPostProcess) {
|
|
source = this._shareOutputWithPostProcess.outputTexture;
|
|
source = this._shareOutputWithPostProcess.outputTexture;
|
|
} else if (this._forcedOutputTexture) {
|
|
} else if (this._forcedOutputTexture) {
|
|
source = this._forcedOutputTexture;
|
|
source = this._forcedOutputTexture;
|
|
} else {
|
|
} else {
|
|
source = this.outputTexture;
|
|
source = this.outputTexture;
|
|
- }
|
|
|
|
|
|
+ }
|
|
this._effect._bindTexture("textureSampler", source);
|
|
this._effect._bindTexture("textureSampler", source);
|
|
|
|
|
|
// Parameters
|
|
// Parameters
|
|
@@ -384,7 +383,7 @@
|
|
}
|
|
}
|
|
|
|
|
|
public dispose(camera?: Camera): void {
|
|
public dispose(camera?: Camera): void {
|
|
- camera = camera || this._camera;
|
|
|
|
|
|
+ camera = camera || this._camera;
|
|
|
|
|
|
this._disposeTextures();
|
|
this._disposeTextures();
|
|
|
|
|
|
@@ -392,12 +391,12 @@
|
|
let index = this._scene.postProcesses.indexOf(this);
|
|
let index = this._scene.postProcesses.indexOf(this);
|
|
if (index !== -1) {
|
|
if (index !== -1) {
|
|
this._scene.postProcesses.splice(index, 1);
|
|
this._scene.postProcesses.splice(index, 1);
|
|
- }
|
|
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
let index = this._engine.postProcesses.indexOf(this);
|
|
let index = this._engine.postProcesses.indexOf(this);
|
|
if (index !== -1) {
|
|
if (index !== -1) {
|
|
this._engine.postProcesses.splice(index, 1);
|
|
this._engine.postProcesses.splice(index, 1);
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
if (!camera) {
|
|
if (!camera) {
|
|
@@ -407,7 +406,7 @@
|
|
|
|
|
|
var index = camera._postProcesses.indexOf(this);
|
|
var index = camera._postProcesses.indexOf(this);
|
|
if (index === 0 && camera._postProcesses.length > 0) {
|
|
if (index === 0 && camera._postProcesses.length > 0) {
|
|
- this._camera._postProcesses[0].markTextureDirty();
|
|
|
|
|
|
+ this._camera._postProcesses[0].markTextureDirty();
|
|
}
|
|
}
|
|
|
|
|
|
this.onActivateObservable.clear();
|
|
this.onActivateObservable.clear();
|
|
@@ -415,6 +414,6 @@
|
|
this.onApplyObservable.clear();
|
|
this.onApplyObservable.clear();
|
|
this.onBeforeRenderObservable.clear();
|
|
this.onBeforeRenderObservable.clear();
|
|
this.onSizeChangedObservable.clear();
|
|
this.onSizeChangedObservable.clear();
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|