소스 검색

Merge pull request #4908 from sebavan/master

 RenderingPipeline as a component
sebavan 7 년 전
부모
커밋
6e7b514888

+ 1 - 0
Tools/Gulp/config.json

@@ -974,6 +974,7 @@
         "renderingPipeline": {
         "renderingPipeline": {
             "files": [
             "files": [
                 "../../src/PostProcess/RenderPipeline/babylon.postProcessRenderPipelineManager.js",
                 "../../src/PostProcess/RenderPipeline/babylon.postProcessRenderPipelineManager.js",
+                "../../src/PostProcess/RenderPipeline/babylon.postProcessRenderPipelineManagerSceneComponent.js",
                 "../../src/PostProcess/RenderPipeline/babylon.postProcessRenderEffect.js",
                 "../../src/PostProcess/RenderPipeline/babylon.postProcessRenderEffect.js",
                 "../../src/PostProcess/RenderPipeline/babylon.postProcessRenderPipeline.js"
                 "../../src/PostProcess/RenderPipeline/babylon.postProcessRenderPipeline.js"
             ],
             ],

+ 7 - 2
dist/preview release/typedocValidationBaseline.json

@@ -1,7 +1,7 @@
 {
 {
-  "errors": 4025,
+  "errors": 4026,
   "babylon.typedoc.json": {
   "babylon.typedoc.json": {
-    "errors": 4025,
+    "errors": 4026,
     "AbstractMesh": {
     "AbstractMesh": {
       "Property": {
       "Property": {
         "showBoundingBox": {
         "showBoundingBox": {
@@ -14280,6 +14280,11 @@
             "NotPascalCase": true
             "NotPascalCase": true
           }
           }
         },
         },
+        "postProcessRenderPipelineManager": {
+          "Naming": {
+            "NotPascalCase": true
+          }
+        },
         "simplificationQueue": {
         "simplificationQueue": {
           "Naming": {
           "Naming": {
             "NotPascalCase": true
             "NotPascalCase": true

+ 91 - 0
src/PostProcess/RenderPipeline/babylon.postProcessRenderPipelineManagerSceneComponent.ts

@@ -0,0 +1,91 @@
+module BABYLON {
+    export interface Scene {
+        /** @hidden (Backing field) */
+        _postProcessRenderPipelineManager: PostProcessRenderPipelineManager
+
+        /**
+         * Gets the postprocess render pipeline manager
+         * @see http://doc.babylonjs.com/how_to/how_to_use_postprocessrenderpipeline
+         * @see http://doc.babylonjs.com/how_to/using_default_rendering_pipeline
+         */
+        readonly postProcessRenderPipelineManager: PostProcessRenderPipelineManager;
+    }
+
+    Object.defineProperty(Scene.prototype, "postProcessRenderPipelineManager", {
+        get: function (this:Scene) {
+            if (!this._postProcessRenderPipelineManager) {
+                // Register the G Buffer component to the scene.
+                let component = this._getComponent(SceneComponentConstants.NAME_POSTPROCESSRENDERPIPELINEMANAGER) as PostProcessRenderPipelineManagerSceneComponent;
+                if (!component) {
+                    component = new PostProcessRenderPipelineManagerSceneComponent(this);
+                    this._addComponent(component);
+                }
+                this._postProcessRenderPipelineManager = new PostProcessRenderPipelineManager();
+            }
+    
+            return this._postProcessRenderPipelineManager;
+        },
+        enumerable: true,
+        configurable: true
+    });
+
+    /**
+     * Defines the Render Pipeline scene component responsible to rendering pipelines
+     */
+    export class PostProcessRenderPipelineManagerSceneComponent implements ISceneComponent {
+        /**
+         * The component name helpfull to identify the component in the list of scene components.
+         */
+        public readonly name = SceneComponentConstants.NAME_POSTPROCESSRENDERPIPELINEMANAGER;
+
+        /**
+         * The scene the component belongs to.
+         */
+        public scene: Scene;
+
+        /**
+         * Creates a new instance of the component for the given scene
+         * @param scene Defines the scene to register the component in
+         */
+        constructor(scene: Scene) {
+            this.scene = scene;
+        }
+
+        /**
+         * Registers the component in a given scene
+         */
+        public register(): void {
+            this.scene._gatherRenderTargetsStage.registerStep(SceneComponentConstants.STEP_GATHERRENDERTARGETS_POSTPROCESSRENDERPIPELINEMANAGER, this, this._gatherRenderTargets);
+            this.scene._gatherRenderTargetsStage.registerStep(SceneComponentConstants.STEP_REBUILDGEOMETRY_POSTPROCESSRENDERPIPELINEMANAGER, this, this._rebuildGeometry);
+        }
+
+        /**
+         * Rebuilds the elements related to this component in case of
+         * context lost for instance.
+         */
+        public rebuild(): void {
+            // Nothing to do for this component
+        }
+
+        /**
+         * Disposes the component and the associated ressources
+         */
+        public dispose(): void {
+            if (this.scene._postProcessRenderPipelineManager) {
+                this.scene._postProcessRenderPipelineManager.dispose();
+            }
+        }
+
+        private _gatherRenderTargets(renderTargets: SmartArrayNoDuplicate<RenderTargetTexture>): void {
+            if (this.scene._postProcessRenderPipelineManager) {
+                this.scene._postProcessRenderPipelineManager.update();
+            }
+        }
+
+        private _rebuildGeometry(): void {
+            if (this.scene._postProcessRenderPipelineManager) {
+                this.scene._postProcessRenderPipelineManager._rebuild();
+            }
+        }
+    }
+} 

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

@@ -87,7 +87,7 @@
          * @param {number} samplingMode - The post-process filtering mode
          * @param {number} samplingMode - The post-process filtering mode
          * @param {BABYLON.Engine} engine - The babylon engine
          * @param {BABYLON.Engine} engine - The babylon engine
          * @param {boolean} reusable - If the post-process is reusable
          * @param {boolean} reusable - If the post-process is reusable
-         * @param {BABYLON.Scene} scene - The constructor needs a scene reference to initialize internal components. If "camera" is null (RenderPipelineà, "scene" must be provided
+         * @param {BABYLON.Scene} scene - The constructor needs a scene reference to initialize internal components. If "camera" is null a "scene" must be provided
          */
          */
         constructor(name: string, ratio: any, camera: Camera, mesh?: Mesh, samples: number = 100, samplingMode: number = Texture.BILINEAR_SAMPLINGMODE, engine?: Engine, reusable?: boolean, scene?: Scene) {
         constructor(name: string, ratio: any, camera: Camera, mesh?: Mesh, samples: number = 100, samplingMode: number = Texture.BILINEAR_SAMPLINGMODE, engine?: Engine, reusable?: boolean, scene?: Scene) {
             super(name, "volumetricLightScattering", ["decay", "exposure", "weight", "meshPositionOnScreen", "density"], ["lightScatteringSampler"], ratio.postProcessRatio || ratio, camera, samplingMode, engine, reusable, "#define NUM_SAMPLES " + samples);
             super(name, "volumetricLightScattering", ["decay", "exposure", "weight", "meshPositionOnScreen", "density"], ["lightScatteringSampler"], ratio.postProcessRatio || ratio, camera, samplingMode, engine, reusable, "#define NUM_SAMPLES " + samples);

+ 8 - 24
src/babylon.scene.ts

@@ -862,19 +862,6 @@
          * Gets the current postprocess manager
          * Gets the current postprocess manager
          */
          */
         public postProcessManager: PostProcessManager;
         public postProcessManager: PostProcessManager;
-        private _postProcessRenderPipelineManager: PostProcessRenderPipelineManager
-        /**
-         * Gets the postprocess render pipeline manager
-         * @see http://doc.babylonjs.com/how_to/how_to_use_postprocessrenderpipeline
-         * @see http://doc.babylonjs.com/how_to/using_default_rendering_pipeline
-         */
-        public get postProcessRenderPipelineManager(): PostProcessRenderPipelineManager {
-            if (!this._postProcessRenderPipelineManager) {
-                this._postProcessRenderPipelineManager = new PostProcessRenderPipelineManager();
-            }
-
-            return this._postProcessRenderPipelineManager;
-        }
 
 
         // Customs render targets
         // Customs render targets
         /**
         /**
@@ -1195,6 +1182,11 @@
          * Defines the actions happening just after the active camera has been drawn.
          * Defines the actions happening just after the active camera has been drawn.
          */
          */
         public _afterCameraDrawStage = Stage.Create<CameraStageAction>();
         public _afterCameraDrawStage = Stage.Create<CameraStageAction>();
+        /**
+         * @hidden
+         * Defines the actions happening when Geometries are rebuilding.
+         */
+        public _rebuildGeometryStage = Stage.Create<SimpleStageAction>();
 
 
         /**
         /**
          * Creates a new Scene
          * Creates a new Scene
@@ -4667,11 +4659,6 @@
                 step.action(this._renderTargets);
                 step.action(this._renderTargets);
             }
             }
 
 
-            // RenderPipeline
-            if (this._postProcessRenderPipelineManager) {
-                this._postProcessRenderPipelineManager.update();
-            }
-
             // Multi-cameras?
             // Multi-cameras?
             if (this.activeCameras.length > 0) {
             if (this.activeCameras.length > 0) {
                 for (var cameraIndex = 0; cameraIndex < this.activeCameras.length; cameraIndex++) {
                 for (var cameraIndex = 0; cameraIndex < this.activeCameras.length; cameraIndex++) {
@@ -4895,6 +4882,7 @@
             this._afterCameraDrawStage.clear();
             this._afterCameraDrawStage.clear();
             this._beforeCameraUpdateStage.clear();
             this._beforeCameraUpdateStage.clear();
             this._gatherRenderTargetsStage.clear();
             this._gatherRenderTargetsStage.clear();
+            this._rebuildGeometryStage.clear();
             for (let component of this._components) {
             for (let component of this._components) {
                 component.dispose();
                 component.dispose();
             }
             }
@@ -5043,10 +5031,6 @@
             // Post-processes
             // Post-processes
             this.postProcessManager.dispose();
             this.postProcessManager.dispose();
 
 
-            if (this._postProcessRenderPipelineManager) {
-                this._postProcessRenderPipelineManager.dispose();
-            }
-
             // Physics
             // Physics
             if (this._physicsEngine) {
             if (this._physicsEngine) {
                 this.disablePhysicsEngine();
                 this.disablePhysicsEngine();
@@ -5623,8 +5607,8 @@
                 system.rebuild();
                 system.rebuild();
             }
             }
 
 
-            if (this._postProcessRenderPipelineManager) {
-                this._postProcessRenderPipelineManager._rebuild();
+            for (let step of this._rebuildGeometryStage) {
+                step.action();
             }
             }
         }
         }
 
 

+ 4 - 0
src/babylon.sceneComponent.ts

@@ -13,6 +13,7 @@
         public static readonly NAME_SIMPLIFICATIONQUEUE = "SimplificationQueue";
         public static readonly NAME_SIMPLIFICATIONQUEUE = "SimplificationQueue";
         public static readonly NAME_GEOMETRYBUFFERRENDERER = "GeometryBufferRenderer";
         public static readonly NAME_GEOMETRYBUFFERRENDERER = "GeometryBufferRenderer";
         public static readonly NAME_DEPTHRENDERER = "DepthRenderer";
         public static readonly NAME_DEPTHRENDERER = "DepthRenderer";
+        public static readonly NAME_POSTPROCESSRENDERPIPELINEMANAGER = "PostProcessRenderPipelineManager";
 
 
         public static readonly STEP_ISREADYFORMESH_EFFECTLAYER = 0;
         public static readonly STEP_ISREADYFORMESH_EFFECTLAYER = 0;
 
 
@@ -40,6 +41,9 @@
 
 
         public static readonly STEP_GATHERRENDERTARGETS_GEOMETRYBUFFERRENDERER = 0;
         public static readonly STEP_GATHERRENDERTARGETS_GEOMETRYBUFFERRENDERER = 0;
         public static readonly STEP_GATHERRENDERTARGETS_DEPTHRENDERER = 1;
         public static readonly STEP_GATHERRENDERTARGETS_DEPTHRENDERER = 1;
+        public static readonly STEP_GATHERRENDERTARGETS_POSTPROCESSRENDERPIPELINEMANAGER = 2;
+
+        public static readonly STEP_REBUILDGEOMETRY_POSTPROCESSRENDERPIPELINEMANAGER = 0;
     }
     }
 
 
     /**
     /**