Explorar el Código

activating/desactivating textures works properly

Benjamin Guignabert hace 5 años
padre
commit
91ef49ab0b

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 1666 - 1
dist/preview release/babylon.ktx2Decoder.js


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 1 - 1
dist/preview release/babylon.ktx2Decoder.js.map


+ 12 - 0
src/Cameras/camera.ts

@@ -625,6 +625,12 @@ export class Camera extends Node {
             this._postProcesses.splice(insertAt, 0, postProcess);
         }
         this._cascadePostProcessesToRigCams(); // also ensures framebuffer invalidated
+
+        // Update prePass
+        if (this._scene.prePassRenderer) {
+            this._scene.prePassRenderer.markAsDirty();
+        }
+
         return this._postProcesses.indexOf(postProcess);
     }
 
@@ -638,6 +644,12 @@ export class Camera extends Node {
         if (idx !== -1) {
             this._postProcesses[idx] = null;
         }
+
+        // Update prePass
+        if (this._scene.prePassRenderer) {
+            this._scene.prePassRenderer.markAsDirty();
+        }
+
         this._cascadePostProcessesToRigCams(); // also ensures framebuffer invalidated
     }
 

+ 3 - 0
src/Materials/materialHelper.ts

@@ -359,6 +359,9 @@ export class MaterialHelper {
 
         } else {
             defines.PREPASS = false;
+            for (let i = 0; i < texturesList.length; i++) {
+                defines[texturesList[i].define] = false;
+            }
         }
 
         if (defines.PREPASS != previousPrePass) {

+ 4 - 20
src/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.ts

@@ -119,8 +119,6 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
     */
     private _sampleSphere: number[];
 
-    private _ssao2PrePassConfiguration: SSAO2Configuration;
-
     /**
     * Blur filter offsets
     */
@@ -212,7 +210,6 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
             scene.enableGeometryBufferRenderer();
         } else {
             this._prePassRenderer = <PrePassRenderer>scene.enablePrePassRenderer();
-            this._prePassRenderer.markAsDirty();
         }
 
         this._createRandomTexture();
@@ -268,7 +265,6 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
         }
 
         this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._scene.cameras);
-        this._ssao2PrePassConfiguration.enabled = false;
 
         super.dispose();
     }
@@ -449,6 +445,10 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
             effect.setTextureFromPostProcess("originalColor", this._originalColorPostProcess);
         };
         this._ssaoCombinePostProcess.samples = this.textureSamples;
+
+        if (!this._forceGeometryBuffer) {
+            this._ssaoCombinePostProcess.prePassEffectConfiguration = new SSAO2Configuration();
+        }
     }
 
     private _createRandomTexture(): void {
@@ -507,22 +507,6 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
     public static Parse(source: any, scene: Scene, rootUrl: string): SSAO2RenderingPipeline {
         return SerializationHelper.Parse(() => new SSAO2RenderingPipeline(source._name, scene, source._ratio), source, scene, rootUrl);
     }
-
-    /**
-     * Sets the required values to the prepass renderer.
-     * @param prePassRenderer defines the prepass renderer to setup
-     * @returns true if the pre pass is needed.
-     */
-    public setPrePassRenderer(prePassRenderer: PrePassRenderer): boolean {
-        let cfg = this._ssao2PrePassConfiguration;
-        if (!cfg) {
-            cfg = new SSAO2Configuration();
-        }
-
-        cfg.enabled = true;
-        this._ssao2PrePassConfiguration = prePassRenderer.addEffectConfiguration(cfg);
-        return true;
-    }
 }
 
 _TypeStore.RegisteredTypes["BABYLON.SSAO2RenderingPipeline"] = SSAO2RenderingPipeline;

+ 1 - 17
src/PostProcesses/motionBlurPostProcess.ts

@@ -62,7 +62,6 @@ export class MotionBlurPostProcess extends PostProcess {
     private _forceGeometryBuffer: boolean = false;
     private _geometryBufferRenderer: Nullable<GeometryBufferRenderer>;
     private _prePassRenderer: PrePassRenderer;
-    private _motionBlurConfiguration: MotionBlurConfiguration;
 
     /**
      * Gets a string identifying the name of the class
@@ -99,6 +98,7 @@ export class MotionBlurPostProcess extends PostProcess {
         } else {
             this._prePassRenderer = <PrePassRenderer>scene.enablePrePassRenderer();
             this._prePassRenderer.markAsDirty();
+            this.prePassEffectConfiguration = new MotionBlurConfiguration();
         }
 
         if (!this._geometryBufferRenderer && !this._prePassRenderer) {
@@ -166,22 +166,6 @@ export class MotionBlurPostProcess extends PostProcess {
         super.dispose(camera);
     }
 
-    /**
-     * Sets the required values to the prepass renderer.
-     * @param prePassRenderer defines the prepass renderer to setup
-     * @returns true if the pre pass is needed.
-     */
-    public setPrePassRenderer(prePassRenderer: PrePassRenderer): boolean {
-        let cfg = this._motionBlurConfiguration;
-        if (!cfg) {
-            cfg = new MotionBlurConfiguration();
-        }
-
-        cfg.enabled = true;
-        this._motionBlurConfiguration = prePassRenderer.addEffectConfiguration(cfg) as MotionBlurConfiguration;
-        return true;
-    }
-
     /** @hidden */
     public static _Parse(parsedPostProcess: any, targetCamera: Camera, scene: Scene, rootUrl: string): Nullable<MotionBlurPostProcess> {
         return SerializationHelper.Parse(() => {

+ 13 - 1
src/PostProcesses/postProcess.ts

@@ -20,6 +20,7 @@ declare type InternalTexture = import("../Materials/Textures/internalTexture").I
 declare type WebVRFreeCamera = import("../Cameras/VR/webVRCamera").WebVRFreeCamera;
 declare type Animation = import("../Animations/animation").Animation;
 declare type PrePassRenderer = import("../Rendering/prePassRenderer").PrePassRenderer;
+declare type PrePassEffectConfiguration = import("../Rendering/prePassEffectConfiguration").PrePassEffectConfiguration;
 
 /**
  * Size options for a post process
@@ -188,6 +189,12 @@ export class PostProcess {
     private _forcedOutputTexture: Nullable<InternalTexture>;
 
     /**
+    * Prepass configuration in case this post process needs a texture from prepass
+    * @hidden
+    */
+    public prePassEffectConfiguration: PrePassEffectConfiguration;
+
+    /**
      * Returns the fragment url or shader name used in the post process.
      * @returns the fragment url or name in the shader store.
      */
@@ -685,7 +692,12 @@ export class PostProcess {
      * @returns true if the pre pass is needed.
      */
     public setPrePassRenderer(prePassRenderer: PrePassRenderer): boolean {
-        // Do Nothing by default
+        if (this.prePassEffectConfiguration) {
+            this.prePassEffectConfiguration = prePassRenderer.addEffectConfiguration(this.prePassEffectConfiguration);
+            this.prePassEffectConfiguration.enabled = true;
+            return true;
+        }
+
         return false;
     }
 

+ 1 - 17
src/PostProcesses/screenSpaceReflectionPostProcess.ts

@@ -51,7 +51,6 @@ export class ScreenSpaceReflectionPostProcess extends PostProcess {
     private _enableSmoothReflections: boolean = false;
     private _reflectionSamples: number = 64;
     private _smoothSteps: number = 5;
-    private _ssrConfiguration: ScreenSpaceReflectionsConfiguration;
 
     /**
      * Gets a string identifying the name of the class
@@ -97,6 +96,7 @@ export class ScreenSpaceReflectionPostProcess extends PostProcess {
         } else {
             this._prePassRenderer = <PrePassRenderer>scene.enablePrePassRenderer();
             this._prePassRenderer.markAsDirty();
+            this.prePassEffectConfiguration = new ScreenSpaceReflectionsConfiguration();
         }
 
         this._updateEffectDefines();
@@ -234,22 +234,6 @@ export class ScreenSpaceReflectionPostProcess extends PostProcess {
         this.updateEffect(defines.join("\n"));
     }
 
-    /**
-     * Sets the required values to the prepass renderer.
-     * @param prePassRenderer defines the prepass renderer to setup
-     * @returns true if the pre pass is needed.
-     */
-    public setPrePassRenderer(prePassRenderer: PrePassRenderer): boolean {
-        let cfg = this._ssrConfiguration;
-        if (!cfg) {
-            cfg = new ScreenSpaceReflectionsConfiguration();
-        }
-
-        cfg.enabled = true;
-        this._ssrConfiguration = prePassRenderer.addEffectConfiguration(cfg) as ScreenSpaceReflectionsConfiguration;
-        return true;
-    }
-
     /** @hidden */
     public static _Parse(parsedPostProcess: any, targetCamera: Camera, scene: Scene, rootUrl: string) {
         return SerializationHelper.Parse(() => {

+ 26 - 10
src/Rendering/prePassRenderer.ts

@@ -409,17 +409,32 @@ export class PrePassRenderer {
             }
         }
 
-        const pipelines = this._scene.postProcessRenderPipelineManager.supportedPipelines;
-        for (let i = 0; i < pipelines.length; i++) {
-            if (pipelines[i].setPrePassRenderer(this)) {
-                enablePrePass = true;
-            }
+        // const pipelines = this._scene.postProcessRenderPipelineManager.supportedPipelines;
+        // for (let i = 0; i < pipelines.length; i++) {
+        //     if (pipelines[i].setPrePassRenderer(this)) {
+        //         enablePrePass = true;
+        //     }
+        // }
+
+        // const postProcesses = this._scene.postProcesses;
+        // for (let i = 0; i < postProcesses.length; i++) {
+        //     if (postProcesses[i].setPrePassRenderer(this)) {
+        //         enablePrePass = true;
+        //     }
+        // }
+
+        const camera = this._scene.activeCamera;
+        if (!camera) {
+            return;
         }
 
-        const postProcesses = this._scene.postProcesses;
-        for (let i = 0; i < postProcesses.length; i++) {
-            if (postProcesses[i].setPrePassRenderer(this)) {
-                enablePrePass = true;
+        const postProcesses = (<Nullable<PostProcess[]>>camera._postProcesses.filter((pp) => { return pp != null; }));
+
+        if (postProcesses) {
+            for (let i = 0; i < postProcesses.length; i++) {
+                if (postProcesses[i].setPrePassRenderer(this)) {
+                    enablePrePass = true;
+                }
             }
         }
 
@@ -430,7 +445,8 @@ export class PrePassRenderer {
         }
 
         if (!this.enabled) {
-            this._engine.bindAttachments(this._defaultAttachments);
+            // Prepass disabled, we render only on 1 color attachment
+            this._engine.bindAttachments([this._engine._gl.COLOR_ATTACHMENT0]);
         }
     }