Trevor Baron 7 lat temu
rodzic
commit
ecb3ce8a62

+ 25 - 2
src/PostProcess/RenderPipeline/Pipelines/babylon.defaultRenderingPipeline.ts

@@ -374,6 +374,21 @@
             this._buildAllowed = previousState;
         }
 
+        private _prevPostProcess:Nullable<PostProcess> = null;
+        private _prevPrevPostProcess:Nullable<PostProcess> = null;
+
+        private _setOutputTexture(postProcess:PostProcess){
+            if(this._prevPrevPostProcess){
+                postProcess.shareOutputWith(this._prevPrevPostProcess);
+            }else{
+                postProcess.useOwnOutput();
+            }
+            if(this._prevPostProcess){
+                this._prevPrevPostProcess = this._prevPostProcess;
+            }
+            this._prevPostProcess = postProcess;
+        }
+
         private _buildPipeline() {
             if (!this._buildAllowed) {
                 return;
@@ -388,18 +403,24 @@
                 this._cameras = this._originalCameras.slice();
             }
             this._reset();
-            
+            this._prevPostProcess = null;
+            this._prevPrevPostProcess = null;
+
             if (this.fxaaEnabled) {
                 this.fxaa = new FxaaPostProcess("fxaa", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType);
                 this.addEffect(new PostProcessRenderEffect(engine, this.FxaaPostProcessId, () => { return this.fxaa; }, true));
+                this._setOutputTexture(this.fxaa);
+                
             }
 
             if (this.sharpenEnabled) {
                 this.addEffect(this._sharpenEffect);
+                this._setOutputTexture(this.sharpen);
             }
 
             if (this.depthOfFieldEnabled) {
                 this.addEffect(this.depthOfField);
+                this._setOutputTexture(this.depthOfField._depthOfFieldMerge);
             }
 
             if (this.bloomEnabled) {
@@ -459,7 +480,8 @@
             else {
                 this.finalMerge = new PassPostProcess("finalMerge", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType);
                 this.addEffect(new PostProcessRenderEffect(engine, this.FinalMergePostProcessId, () => { return this.finalMerge; }, true));
-
+                this._setOutputTexture(this.finalMerge);
+                
                 this.finalMerge.autoClear = !this.bloomEnabled && (!this._hdr || !this.imageProcessing);
             }
 
@@ -479,6 +501,7 @@
 
             if (this.chromaticAberrationEnabled) {
                 this.addEffect(this._chromaticAberrationEffect);
+                this._setOutputTexture(this.chromaticAberration);
             }
 
             if (this._cameras !== null) {

+ 1 - 1
src/PostProcess/babylon.depthOfFieldEffect.ts

@@ -24,7 +24,7 @@ module BABYLON {
         private _circleOfConfusion: CircleOfConfusionPostProcess;
         private _depthOfFieldBlurX: Array<DepthOfFieldBlurPostProcess>;
         private _depthOfFieldBlurY: Array<DepthOfFieldBlurPostProcess>;
-        private _depthOfFieldMerge: DepthOfFieldMergePostProcess;
+        public _depthOfFieldMerge: DepthOfFieldMergePostProcess;
 
         private _effects: Array<PostProcess> = [];
 

+ 11 - 1
src/PostProcess/babylon.postProcess.ts

@@ -85,7 +85,7 @@
         private _parameters: string[];
         private _scaleRatio = new Vector2(1, 1);
         protected _indexParameters: any;
-        private _shareOutputWithPostProcess: PostProcess;
+        private _shareOutputWithPostProcess: Nullable<PostProcess>;
         private _texelSize = Vector2.Zero();
         private _forcedOutputTexture: InternalTexture;
 
@@ -296,6 +296,16 @@
             return this;
         }
 
+        public useOwnOutput(): PostProcess {
+            if(this._textures.length == 0){
+                this._textures = new SmartArray<InternalTexture>(2);
+            }
+
+            this._shareOutputWithPostProcess = null;
+
+            return this;
+        }
+
         /**
          * Updates the effect with the current post process compile time values and recompiles the shader.
          * @param defines Define statements that should be added at the beginning of the shader. (default: null)