Browse Source

Merge pull request #5072 from sebavan/master

Default rendering pipeline multi cam depth of field
David Catuhe 7 years ago
parent
commit
214b2229fa

+ 1 - 0
dist/preview release/what's new.md

@@ -208,6 +208,7 @@
 - Oimo.js now receives quaternion and not euler when a body is being constructed ([RaananW](https://github.com/RaananW))
 - Improving visual quality on SSAO2 shader ([CraigFeldspar](https://github.com/CraigFeldspar))
 - Fixed a bug where changing the sample count on `PostProcess` would not update the WebGL Texture ([CraigFeldspar](https://github.com/CraigFeldspar))
+- Fixed multi camera support in defaultRenderingPipeline depth of field ([sebavan](http://www.github.com/sebavan))
 
 ### Viewer
 

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

@@ -482,7 +482,8 @@
                 // Multi camera suport
                 if (this._cameras.length > 1) {
                     for (let camera of this._cameras) {
-                        this._scene.enableDepthRenderer(camera).getDepthMap();
+                        const depthRenderer = this._scene.enableDepthRenderer(camera);
+                        depthRenderer.useOnlyInActiveCamera = true;
                     }
 
                     this._depthOfFieldSceneObserver = this._scene.onAfterRenderTargetsRenderObservable.add((scene) => {

+ 7 - 0
src/Rendering/babylon.depthRenderer.ts

@@ -12,6 +12,13 @@
         private _camera:Nullable<Camera>;
 
         /**
+         * Specifiess that the depth renderer will only be used within
+         * the camera it is created for.
+         * This can help forcing its rendering during the camera processing.
+         */
+        public useOnlyInActiveCamera: boolean = false;
+
+        /**
          * Instantiates a depth renderer
          * @param scene The scene the renderer belongs to
          * @param type The texture type of the depth map (default: Engine.TEXTURETYPE_FLOAT)

+ 16 - 1
src/Rendering/babylon.depthRendererSceneComponent.ts

@@ -79,6 +79,7 @@
          */
         public register(): void {
             this.scene._gatherRenderTargetsStage.registerStep(SceneComponentConstants.STEP_GATHERRENDERTARGETS_DEPTHRENDERER, this, this._gatherRenderTargets);
+            this.scene._gatherActiveCameraRenderTargetsStage.registerStep(SceneComponentConstants.STEP_GATHERACTIVECAMERARENDERTARGETS_DEPTHRENDERER, this, this._gatherActiveCameraRenderTargets);
         }
 
         /**
@@ -101,7 +102,21 @@
         private _gatherRenderTargets(renderTargets: SmartArrayNoDuplicate<RenderTargetTexture>): void {
             if (this.scene._depthRenderer) {
                 for (var key in this.scene._depthRenderer) {
-                    renderTargets.push(this.scene._depthRenderer[key].getDepthMap());
+                    let depthRenderer = this.scene._depthRenderer[key];
+                    if (!depthRenderer.useOnlyInActiveCamera) {
+                        renderTargets.push(depthRenderer.getDepthMap());
+                    }
+                }
+            }
+        }
+
+        private _gatherActiveCameraRenderTargets(renderTargets: SmartArrayNoDuplicate<RenderTargetTexture>): void {
+            if (this.scene._depthRenderer) {
+                for (var key in this.scene._depthRenderer) {
+                    let depthRenderer = this.scene._depthRenderer[key];
+                    if (depthRenderer.useOnlyInActiveCamera && this.scene.activeCamera!.id === key) {
+                        renderTargets.push(depthRenderer.getDepthMap());
+                    }
                 }
             }
         }

+ 12 - 1
src/babylon.scene.ts

@@ -1084,11 +1084,16 @@
         public _beforeClearStage = Stage.Create<SimpleStageAction>();
         /**
          * @hidden
-         * Defines the actions happening before camera updates.
+         * Defines the actions when collecting render targets for the frame.
          */
         public _gatherRenderTargetsStage = Stage.Create<RenderTargetsStageAction>();
         /**
          * @hidden
+         * Defines the actions happening for one camera in the frame.
+         */
+        public _gatherActiveCameraRenderTargetsStage = Stage.Create<RenderTargetsStageAction>();
+        /**
+         * @hidden
          * Defines the actions happening during the per mesh ready checks.
          */
         public _isReadyForMeshStage = Stage.Create<MeshStageAction>();
@@ -4248,6 +4253,11 @@
                 this._renderTargets.concatWithNoDuplicate(rigParent.customRenderTargets);
             }
 
+            // Collects render targets from external components.
+            for (let step of this._gatherActiveCameraRenderTargetsStage) {
+                step.action(this._renderTargets);
+            }
+
             if (this.renderTargetsEnabled) {
                 this._intermediateRendering = true;
 
@@ -4767,6 +4777,7 @@
             this._beforeCameraUpdateStage.clear();
             this._beforeClearStage.clear();
             this._gatherRenderTargetsStage.clear();
+            this._gatherActiveCameraRenderTargetsStage.clear();
             this._pointerMoveStage.clear();
             this._pointerDownStage.clear();
             this._pointerUpStage.clear();

+ 2 - 0
src/babylon.sceneComponent.ts

@@ -55,6 +55,8 @@
         public static readonly STEP_GATHERRENDERTARGETS_DEPTHRENDERER = 2;
         public static readonly STEP_GATHERRENDERTARGETS_POSTPROCESSRENDERPIPELINEMANAGER = 3;
 
+        public static readonly STEP_GATHERACTIVECAMERARENDERTARGETS_DEPTHRENDERER = 0;
+
         public static readonly STEP_POINTERMOVE_SPRITE = 0;
         public static readonly STEP_POINTERDOWN_SPRITE = 0;
         public static readonly STEP_POINTERUP_SPRITE = 0;