|
@@ -1,14 +1,9 @@
|
|
module BABYLON {
|
|
module BABYLON {
|
|
- export class DepthOfFieldBlurOptions {
|
|
|
|
- constructor(public depthMap: BaseTexture, public original: Nullable<PostProcess> = null){
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
export class BlurPostProcess extends PostProcess {
|
|
export class BlurPostProcess extends PostProcess {
|
|
protected _kernel: number;
|
|
protected _kernel: number;
|
|
protected _idealKernel: number;
|
|
protected _idealKernel: number;
|
|
protected _packedFloat: boolean = false;
|
|
protected _packedFloat: boolean = false;
|
|
- protected depthOfFieldBlurOptions:any;
|
|
|
|
|
|
+ protected _staticDefines:string = ""
|
|
/**
|
|
/**
|
|
* Sets the length in pixels of the blur sample region
|
|
* Sets the length in pixels of the blur sample region
|
|
*/
|
|
*/
|
|
@@ -48,30 +43,11 @@
|
|
return this._packedFloat;
|
|
return this._packedFloat;
|
|
}
|
|
}
|
|
|
|
|
|
- constructor(name: string, public direction: Vector2, kernel: number, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode: number = Texture.BILINEAR_SAMPLINGMODE, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT, depthOfFieldBlurOptions?:DepthOfFieldBlurOptions) {
|
|
|
|
|
|
+ constructor(name: string, public direction: Vector2, kernel: number, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode: number = Texture.BILINEAR_SAMPLINGMODE, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
|
|
super(name, "kernelBlur", ["delta", "direction", "near", "far"], ["depthSampler"], options, camera, samplingMode, engine, reusable, null, textureType, "kernelBlur", {varyingCount: 0, depCount: 0}, true);
|
|
super(name, "kernelBlur", ["delta", "direction", "near", "far"], ["depthSampler"], options, camera, samplingMode, engine, reusable, null, textureType, "kernelBlur", {varyingCount: 0, depCount: 0}, true);
|
|
|
|
|
|
- if(depthOfFieldBlurOptions){
|
|
|
|
- this.depthOfFieldBlurOptions = depthOfFieldBlurOptions;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
this.onApplyObservable.add((effect: Effect) => {
|
|
this.onApplyObservable.add((effect: Effect) => {
|
|
- if(this.depthOfFieldBlurOptions){
|
|
|
|
- // TODO: setTextureFromPostProcess seems to be setting the input texture instead of output of the post process passed in
|
|
|
|
- if(this.depthOfFieldBlurOptions.original != null){
|
|
|
|
- effect.setTextureFromPostProcess("textureSampler", this.depthOfFieldBlurOptions.original)
|
|
|
|
- }
|
|
|
|
- effect.setTexture("depthSampler", this.depthOfFieldBlurOptions.depthMap)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
effect.setFloat2('delta', (1 / this.width) * this.direction.x, (1 / this.height) * this.direction.y);
|
|
effect.setFloat2('delta', (1 / this.width) * this.direction.x, (1 / this.height) * this.direction.y);
|
|
-
|
|
|
|
- // TODO: is there a better way to get camera?
|
|
|
|
- var camera = this.getEngine().scenes[0].activeCamera;
|
|
|
|
- if(camera){
|
|
|
|
- effect.setFloat('near', camera.minZ);
|
|
|
|
- effect.setFloat('far', camera.maxZ);
|
|
|
|
- }
|
|
|
|
});
|
|
});
|
|
|
|
|
|
this.kernel = kernel;
|
|
this.kernel = kernel;
|
|
@@ -145,7 +121,8 @@
|
|
|
|
|
|
let varyingCount = Math.min(offsets.length, freeVaryingVec2);
|
|
let varyingCount = Math.min(offsets.length, freeVaryingVec2);
|
|
|
|
|
|
- let defines = "";
|
|
|
|
|
|
+ let defines = "";
|
|
|
|
+ defines+=this._staticDefines;
|
|
for (let i = 0; i < varyingCount; i++) {
|
|
for (let i = 0; i < varyingCount; i++) {
|
|
defines += `#define KERNEL_OFFSET${i} ${this._glslFloat(offsets[i])}\r\n`;
|
|
defines += `#define KERNEL_OFFSET${i} ${this._glslFloat(offsets[i])}\r\n`;
|
|
defines += `#define KERNEL_WEIGHT${i} ${this._glslFloat(weights[i])}\r\n`;
|
|
defines += `#define KERNEL_WEIGHT${i} ${this._glslFloat(weights[i])}\r\n`;
|
|
@@ -162,10 +139,6 @@
|
|
defines += `#define PACKEDFLOAT 1`;
|
|
defines += `#define PACKEDFLOAT 1`;
|
|
}
|
|
}
|
|
|
|
|
|
- if(this.depthOfFieldBlurOptions){
|
|
|
|
- defines += `#define DOF 1`;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
this.updateEffect(defines, null, null, {
|
|
this.updateEffect(defines, null, null, {
|
|
varyingCount: varyingCount,
|
|
varyingCount: varyingCount,
|
|
depCount: depCount
|
|
depCount: depCount
|