浏览代码

replacing sceneCompositor post process by image processor

Benjamin Guignabert 5 年之前
父节点
当前提交
afb69fb518

+ 1 - 2
src/Materials/PBR/pbrBaseMaterial.ts

@@ -1576,8 +1576,7 @@ export abstract class PBRBaseMaterial extends PushMaterial {
         }
         }
 
 
         if (defines._areImageProcessingDirty && this._imageProcessingConfiguration) {
         if (defines._areImageProcessingDirty && this._imageProcessingConfiguration) {
-            const prePassRenderer = this.getScene()._prePassRenderer;
-            this._imageProcessingConfiguration.prepareDefines(defines, false, prePassRenderer ? prePassRenderer.enabled : false);
+            this._imageProcessingConfiguration.prepareDefines(defines);
         }
         }
 
 
         defines.FORCENORMALFORWARD = this._forceNormalForward;
         defines.FORCENORMALFORWARD = this._forceNormalForward;

+ 3 - 3
src/Materials/imageProcessingConfiguration.ts

@@ -438,8 +438,8 @@ export class ImageProcessingConfiguration {
      * @param defines the list of defines to complete
      * @param defines the list of defines to complete
      * @param forPostProcess Define if we are currently in post process mode or not
      * @param forPostProcess Define if we are currently in post process mode or not
      */
      */
-    public prepareDefines(defines: IImageProcessingConfigurationDefines, forPostProcess: boolean = false, prePassEnabled: boolean = false): void {
-        if (forPostProcess !== this.applyByPostProcess || !this._isEnabled || prePassEnabled) {
+    public prepareDefines(defines: IImageProcessingConfigurationDefines, forPostProcess: boolean = false): void {
+        if (forPostProcess !== this.applyByPostProcess || !this._isEnabled) {
             defines.VIGNETTE = false;
             defines.VIGNETTE = false;
             defines.TONEMAPPING = false;
             defines.TONEMAPPING = false;
             defines.TONEMAPPING_ACES = false;
             defines.TONEMAPPING_ACES = false;
@@ -449,7 +449,7 @@ export class ImageProcessingConfiguration {
             defines.COLORGRADING = false;
             defines.COLORGRADING = false;
             defines.COLORGRADING3D = false;
             defines.COLORGRADING3D = false;
             defines.IMAGEPROCESSING = false;
             defines.IMAGEPROCESSING = false;
-            defines.IMAGEPROCESSINGPOSTPROCESS = prePassEnabled || (this.applyByPostProcess && this._isEnabled);
+            defines.IMAGEPROCESSINGPOSTPROCESS = (this.applyByPostProcess && this._isEnabled);
             return;
             return;
         }
         }
 
 

+ 6 - 5
src/PostProcesses/SubSurfaceScatteringPostProcess.ts

@@ -8,7 +8,8 @@ import { Scene } from "../scene";
 import { Constants } from "../Engines/constants";
 import { Constants } from "../Engines/constants";
 import { Logger } from "../Misc/logger";
 import { Logger } from "../Misc/logger";
 
 
-import "../Shaders/sceneCompositor.fragment";
+import "../Shaders/imageProcessing.fragment";
+import "../Shaders/subSurfaceScattering.fragment";
 import "../Shaders/postprocess.vertex";
 import "../Shaders/postprocess.vertex";
 
 
 /**
 /**
@@ -56,10 +57,10 @@ export class SubSurfaceScatteringPostProcess extends PostProcess {
 
 
         let defines = "";
         let defines = "";
 
 
-        if (this._scene.imageProcessingConfiguration.applyByPostProcess) {
-            // We must output linear color for post process
-            defines = defines + "#define LINEAR_OUTPUT\n";
-        }
+        // if (this._scene.imageProcessingConfiguration.applyByPostProcess) {
+        //     // We must output linear color for post process
+        //     defines = defines + "#define LINEAR_OUTPUT\n";
+        // }
 
 
         return defines;
         return defines;
     }
     }

+ 13 - 11
src/Rendering/prePassRenderer.ts

@@ -3,7 +3,7 @@ import { MultiRenderTarget } from "../Materials/Textures/multiRenderTarget";
 import { Scene } from "../scene";
 import { Scene } from "../scene";
 import { Engine } from "../Engines/Engine";
 import { Engine } from "../Engines/Engine";
 import { Constants } from "../Engines/constants";
 import { Constants } from "../Engines/constants";
-import { SceneCompositorPostProcess } from "../PostProcesses/sceneCompositorPostProcess";
+import { ImageProcessingPostProcess } from "../PostProcesses/imageProcessingPostProcess";
 import { SubSurfaceScatteringPostProcess } from "../PostProcesses/subSurfaceScatteringPostProcess";
 import { SubSurfaceScatteringPostProcess } from "../PostProcesses/subSurfaceScatteringPostProcess";
 import { Effect } from "../Materials/effect";
 import { Effect } from "../Materials/effect";
 import { Logger } from "../Misc/logger";
 import { Logger } from "../Misc/logger";
@@ -36,7 +36,7 @@ export class PrePassRenderer {
     public ssFilterRadii: number[] = [];
     public ssFilterRadii: number[] = [];
     public ssDiffusionD: number[] = [];
     public ssDiffusionD: number[] = [];
 
 
-    public sceneCompositorPostProcess: SceneCompositorPostProcess;
+    public imageProcessingPostProcess: ImageProcessingPostProcess;
     public subSurfaceScatteringPostProcess: SubSurfaceScatteringPostProcess;
     public subSurfaceScatteringPostProcess: SubSurfaceScatteringPostProcess;
     private _enabled: boolean = false;
     private _enabled: boolean = false;
 
 
@@ -65,9 +65,9 @@ export class PrePassRenderer {
 
 
         // Adding default diffusion profile
         // Adding default diffusion profile
         this.addDiffusionProfile(new Color3(1, 1, 1));
         this.addDiffusionProfile(new Color3(1, 1, 1));
-        this.sceneCompositorPostProcess = new SceneCompositorPostProcess("sceneCompositor", 1, null, undefined, this._engine);
-        this.sceneCompositorPostProcess.inputTexture = this.prePassRT.getInternalTexture()!;
+        this.imageProcessingPostProcess = new ImageProcessingPostProcess("sceneCompositionPass", 1, null, undefined, this._engine);
         this.subSurfaceScatteringPostProcess = new SubSurfaceScatteringPostProcess("subSurfaceScattering", this._scene, 1, null, undefined, this._engine);
         this.subSurfaceScatteringPostProcess = new SubSurfaceScatteringPostProcess("subSurfaceScattering", this._scene, 1, null, undefined, this._engine);
+        this.subSurfaceScatteringPostProcess.inputTexture = this.prePassRT.getInternalTexture()!;
     }
     }
 
 
     private _initializeAttachments() {
     private _initializeAttachments() {
@@ -112,14 +112,14 @@ export class PrePassRenderer {
 
 
     public _afterCameraDraw() {
     public _afterCameraDraw() {
         if (this._enabled) {
         if (this._enabled) {
-            // this.sceneCompositorPostProcess.activate(this._scene.activeCamera);
-            this.sceneCompositorPostProcess.autoClear = false;
-            this.sceneCompositorPostProcess.activate(this._scene.activeCamera);
+            // this.imageProcessingPostProcess.activate(this._scene.activeCamera);
+            this.subSurfaceScatteringPostProcess.autoClear = false;
             this.subSurfaceScatteringPostProcess.activate(this._scene.activeCamera);
             this.subSurfaceScatteringPostProcess.activate(this._scene.activeCamera);
-            this._scene.postProcessManager.directRender([this.sceneCompositorPostProcess], this.subSurfaceScatteringPostProcess.inputTexture);
+            this.imageProcessingPostProcess.activate(this._scene.activeCamera);
+            this._scene.postProcessManager.directRender([this.subSurfaceScatteringPostProcess], this.imageProcessingPostProcess.inputTexture);
+            this._scene.postProcessManager.directRender([this.imageProcessingPostProcess], null, false, 0, 0, false);
             // this.getEngine().restoreDefaultFramebuffer(); // Restore back buffer if needed
             // this.getEngine().restoreDefaultFramebuffer(); // Restore back buffer if needed
             // this._scene.postProcessManager._prepareFrame();
             // this._scene.postProcessManager._prepareFrame();
-            this._scene.postProcessManager.directRender([this.subSurfaceScatteringPostProcess], null, false, 0, 0, false);
         }
         }
     }
     }
 
 
@@ -131,7 +131,7 @@ export class PrePassRenderer {
 
 
         if (width !== requiredWidth || height !== requiredHeight) {
         if (width !== requiredWidth || height !== requiredHeight) {
             this.prePassRT.resize({ width: requiredWidth, height: requiredHeight });
             this.prePassRT.resize({ width: requiredWidth, height: requiredHeight });
-            this.sceneCompositorPostProcess.inputTexture = this.prePassRT.getInternalTexture()!;
+            this.subSurfaceScatteringPostProcess.inputTexture = this.prePassRT.getInternalTexture()!;
         }
         }
     }
     }
 
 
@@ -162,11 +162,13 @@ export class PrePassRenderer {
     private _enable() {
     private _enable() {
         this._enabled = true;
         this._enabled = true;
         this._scene.prePass = true;
         this._scene.prePass = true;
+        this.imageProcessingPostProcess.imageProcessingConfiguration.applyByPostProcess = true;
     }
     }
 
 
     private _disable() {
     private _disable() {
         this._enabled = false;
         this._enabled = false;
         this._scene.prePass = false;
         this._scene.prePass = false;
+        this.imageProcessingPostProcess.imageProcessingConfiguration.applyByPostProcess = false;
     }
     }
 
 
     public markAsDirty() {
     public markAsDirty() {
@@ -260,7 +262,7 @@ export class PrePassRenderer {
     }
     }
 
 
     public dispose() {
     public dispose() {
-        this.sceneCompositorPostProcess.dispose();
+        this.imageProcessingPostProcess.dispose();
         this.subSurfaceScatteringPostProcess.dispose();
         this.subSurfaceScatteringPostProcess.dispose();
         this.prePassRT.dispose();
         this.prePassRT.dispose();
     }
     }

+ 0 - 8
src/Shaders/subSurfaceScattering.fragment.fx

@@ -199,10 +199,6 @@ void main(void)
         #endif
         #endif
 
 
 	    gl_FragColor = vec4(inputColor.rgb + albedo * centerIrradiance, 1.0);
 	    gl_FragColor = vec4(inputColor.rgb + albedo * centerIrradiance, 1.0);
-        #ifndef LINEAR_OUTPUT
-            gl_FragColor.rgb = toGammaSpace(gl_FragColor.rgb);
-            gl_FragColor.rgb = saturate(gl_FragColor.rgb);
-        #endif
         return;
         return;
 	}
 	}
 
 
@@ -233,9 +229,5 @@ void main(void)
     totalWeight = max(totalWeight, 1e-12);
     totalWeight = max(totalWeight, 1e-12);
 
 
     gl_FragColor = vec4(inputColor.rgb + albedo * (totalIrradiance / totalWeight), 1.);
     gl_FragColor = vec4(inputColor.rgb + albedo * (totalIrradiance / totalWeight), 1.);
-    #ifndef LINEAR_OUTPUT
-        gl_FragColor.rgb = toGammaSpace(gl_FragColor.rgb);
-        gl_FragColor.rgb = saturate(gl_FragColor.rgb);
-    #endif
 	// gl_FragColor = mix(texture2D(textureSampler, vUV), centerIrradiance, 0.5);
 	// gl_FragColor = mix(texture2D(textureSampler, vUV), centerIrradiance, 0.5);
 }
 }