Selaa lähdekoodia

Merge pull request #4184 from julien-moreau/master

FIxing standard rendering pipeline + comments + serialize / parse ssa…
David Catuhe 7 vuotta sitten
vanhempi
commit
8078be0db5

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

@@ -120,6 +120,7 @@
 - Add support for cameras to glTF 2.0 loader. ([bghgary](https://github.com/bghgary)]
 - Add support for preprocessing urls to glTF 2.0 loader. ([bghgary](https://github.com/bghgary)]
 - Viewer upgrade - see [PR](https://github.com/BabylonJS/Babylon.js/pull/4160) ([RaananW](https://github.com/RaananW))
+- New serialize and parse functions for SSAO2 Rendering Pipeline ([julien-moreau](https://github.com/julien-moreau))
 
 ## Bug fixes
 

+ 31 - 2
src/PostProcess/RenderPipeline/Pipelines/babylon.ssao2RenderingPipeline.ts

@@ -48,6 +48,12 @@
         private _samples: number = 8;
 
         /**
+         * Ratio object used for SSAO ratio and blur ratio
+         */
+        @serialize()
+        private _ratio: any;
+
+        /**
         * Dynamically generated sphere sampler.
         */
         private _sampleSphere: number[];
@@ -135,14 +141,15 @@
             super(scene.getEngine(), name);
 
             this._scene = scene;
+            this._ratio = ratio;
 
             if (!this.isSupported) {
                 Tools.Error("SSAO 2 needs WebGL 2 support.");
                 return;
             }
 
-            var ssaoRatio = ratio.ssaoRatio || ratio;
-            var blurRatio = ratio.blurRatio || ratio;
+            var ssaoRatio = this._ratio.ssaoRatio || ratio;
+            var blurRatio = this._ratio.blurRatio || ratio;
 
             // Set up assets
             let geometryBufferRenderer = <GeometryBufferRenderer>scene.enableGeometryBufferRenderer();
@@ -363,5 +370,27 @@
 
             this._randomTexture.update(false);
         }
+
+        /**
+         * Serialize the rendering pipeline (Used when exporting)
+         * @returns the serialized object
+         */
+        public serialize(): any {
+            var serializationObject = SerializationHelper.Serialize(this);
+            serializationObject.customType = "SSAO2RenderingPipeline";
+
+            return serializationObject;
+        }
+
+        /**
+         * Parse the serialized pipeline
+         * @param source Source pipeline.
+         * @param scene The scene to load the pipeline to.
+         * @param rootUrl The URL of the serialized pipeline.
+         * @returns An instantiated pipeline from the serialized object.
+         */
+        public static Parse(source: any, scene: Scene, rootUrl: string): SSAO2RenderingPipeline {
+            return SerializationHelper.Parse(() => new SSAO2RenderingPipeline(source._name, scene, source._ratio), source, scene, rootUrl);
+        }
     }
 }

+ 34 - 16
src/PostProcess/RenderPipeline/Pipelines/babylon.standardRenderingPipeline.ts

@@ -279,15 +279,6 @@
 
             this._currentDepthOfFieldSource = this.originalPostProcess;
 
-            if (this._vlsEnabled) {
-                // Create volumetric light
-                this._createVolumetricLightPostProcess(scene, ratio);
-
-                // Create volumetric light final post-process
-                this.volumetricLightFinalPostProcess = new PostProcess("HDRVLSFinal", "standard", [], [], ratio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, "#define PASS_POST_PROCESS", Engine.TEXTURETYPE_UNSIGNED_INT);
-                this.addEffect(new PostProcessRenderEffect(scene.getEngine(), "HDRVLSFinal", () => { return this.volumetricLightFinalPostProcess; }, true));
-            }
-
             if (this._bloomEnabled) {
                 // Create down sample X4 post-process
                 this._createDownSampleX4PostProcess(scene, ratio / 2);
@@ -306,6 +297,15 @@
                 this.addEffect(new PostProcessRenderEffect(scene.getEngine(), "HDRBaseDepthOfFieldSource", () => { return this.textureAdderFinalPostProcess; }, true));
             }
 
+            if (this._vlsEnabled) {
+                // Create volumetric light
+                this._createVolumetricLightPostProcess(scene, ratio);
+
+                // Create volumetric light final post-process
+                this.volumetricLightFinalPostProcess = new PostProcess("HDRVLSFinal", "standard", [], [], ratio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, "#define PASS_POST_PROCESS", Engine.TEXTURETYPE_UNSIGNED_INT);
+                this.addEffect(new PostProcessRenderEffect(scene.getEngine(), "HDRVLSFinal", () => { return this.volumetricLightFinalPostProcess; }, true));
+            }
+
             if (this._lensFlareEnabled) {
                 // Create lens flare post-process
                 this._createLensFlarePostProcess(scene, ratio);
@@ -486,7 +486,7 @@
             this.volumetricLightMergePostProces = new PostProcess("HDRVLSMerge", "standard", [], ["originalSampler"], ratio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, "#define VLSMERGE");
 
             this.volumetricLightMergePostProces.onApply = (effect: Effect) => {
-                effect.setTextureFromPostProcess("originalSampler", this.originalPostProcess);
+                effect.setTextureFromPostProcess("originalSampler", this._bloomEnabled ? this.textureAdderFinalPostProcess : this.originalPostProcess);
 
                 this._currentDepthOfFieldSource = this.volumetricLightFinalPostProcess;
             };
@@ -812,7 +812,9 @@
             this.blurVPostProcesses = [];
         }
 
-        // Dispose
+        /**
+         * Dispose of the pipeline and stop all post processes
+         */
         public dispose(): void {
             this._disposePostProcesses();
 
@@ -821,21 +823,37 @@
             super.dispose();
         }
 
-        // Serialize rendering pipeline
+        /**
+         * Serialize the rendering pipeline (Used when exporting)
+         * @returns the serialized object
+         */
         public serialize(): any {
             var serializationObject = SerializationHelper.Serialize(this);
+
+            if (this.sourceLight) {
+                serializationObject.sourceLightId = this.sourceLight.id;
+            }
+
             serializationObject.customType = "StandardRenderingPipeline";
 
             return serializationObject;
         }
 
         /**
-         * Static members
+         * Parse the serialized pipeline
+         * @param source Source pipeline.
+         * @param scene The scene to load the pipeline to.
+         * @param rootUrl The URL of the serialized pipeline.
+         * @returns An instantiated pipeline from the serialized object.
          */
-
-        // Parse serialized pipeline
         public static Parse(source: any, scene: Scene, rootUrl: string): StandardRenderingPipeline {
-            return SerializationHelper.Parse(() => new StandardRenderingPipeline(source._name, scene, source._ratio), source, scene, rootUrl);
+            var p = SerializationHelper.Parse(() => new StandardRenderingPipeline(source._name, scene, source._ratio), source, scene, rootUrl);
+
+            if (source.sourceLightId) {
+                p.sourceLight = <SpotLight | DirectionalLight> scene.getLightByID(source.sourceLightId);
+            }
+
+            return p;
         }
 
         // Luminance steps