소스 검색

buggy pp uses only composition when SSS is enabled

Benjamin Guignabert 4 년 전
부모
커밋
986a187b2e

+ 1 - 14
src/Materials/Textures/prePassRenderTarget.ts

@@ -30,10 +30,6 @@ export class PrePassRenderTarget extends MultiRenderTarget {
     }
     }
 
 
     public set samples(n: number) {
     public set samples(n: number) {
-        if (!this.imageProcessingPostProcess) {
-            this._createCompositionEffect();
-        }
-
         this._samples = n;
         this._samples = n;
     }
     }
 
 
@@ -55,18 +51,9 @@ export class PrePassRenderTarget extends MultiRenderTarget {
         super(name, size, count, scene, options);
         super(name, size, count, scene, options);
 
 
         this.renderTargetTexture = renderTargetTexture;
         this.renderTargetTexture = renderTargetTexture;
-        // TODO : poser dans prepassrenderer ?
-        // this._resetLayout();
-        // this._reinitializeAttachments();
     }
     }
 
 
     public _createCompositionEffect() {
     public _createCompositionEffect() {
-        // TODO : GBR
-        // if (this._useGeometryBufferFallback && !this._geometryBuffer) {
-        //     // Initializes the link with geometry buffer
-        //     this.useGeometryBufferFallback = true;
-        // }
-
         const applyByPostProcess = this._scene.imageProcessingConfiguration?.applyByPostProcess;
         const applyByPostProcess = this._scene.imageProcessingConfiguration?.applyByPostProcess;
         this.imageProcessingPostProcess = new ImageProcessingPostProcess("prePassComposition", 1, null, undefined, this._engine);
         this.imageProcessingPostProcess = new ImageProcessingPostProcess("prePassComposition", 1, null, undefined, this._engine);
         this.imageProcessingPostProcess.imageProcessingConfiguration.applyByPostProcess = applyByPostProcess;
         this.imageProcessingPostProcess.imageProcessingConfiguration.applyByPostProcess = applyByPostProcess;
@@ -93,7 +80,7 @@ export class PrePassRenderTarget extends MultiRenderTarget {
         if (width !== requiredWidth || height !== requiredHeight) {
         if (width !== requiredWidth || height !== requiredHeight) {
             this.resize({ width: requiredWidth, height: requiredHeight });
             this.resize({ width: requiredWidth, height: requiredHeight });
 
 
-            // TODO : geometry buffer
+            // TODO : geometry buffer ?
             // this._updateGeometryBufferLayout();
             // this._updateGeometryBufferLayout();
         }
         }
     }
     }

+ 6 - 5
src/Rendering/prePassRenderer.ts

@@ -489,10 +489,6 @@ export class PrePassRenderer {
                     }
                     }
                 }
                 }
             }
             }
-
-            if (!this.renderTargets[i].imageProcessingPostProcess) {
-                this.renderTargets[i]._createCompositionEffect();
-            }
         }
         }
 
 
         this._reinitializeAttachments();
         this._reinitializeAttachments();
@@ -539,13 +535,18 @@ export class PrePassRenderer {
 
 
         this._needsCompositionForThisPass = !this._hasImageProcessing(this._postProcessesSourceForThisPass) &&
         this._needsCompositionForThisPass = !this._hasImageProcessing(this._postProcessesSourceForThisPass) &&
             !this.disableGammaTransform &&
             !this.disableGammaTransform &&
-            // prePassRenderTarget._beforeCompositionPostProcesses.length > 0 && // TODO : remove the need for composition by including it in the SSS post process
+            prePassRenderTarget._beforeCompositionPostProcesses.length > 0 && // TODO : this test should be cleaner and precisely target SSS
             !secondaryCamera;
             !secondaryCamera;
 
 
         const firstCameraPP = this._getFirstPostProcess(this._postProcessesSourceForThisPass);
         const firstCameraPP = this._getFirstPostProcess(this._postProcessesSourceForThisPass);
         const firstPrePassPP = prePassRenderTarget._beforeCompositionPostProcesses && prePassRenderTarget._beforeCompositionPostProcesses[0];
         const firstPrePassPP = prePassRenderTarget._beforeCompositionPostProcesses && prePassRenderTarget._beforeCompositionPostProcesses[0];
         let firstPP = null;
         let firstPP = null;
 
 
+        // Create composition effect if needed
+        if (this._needsCompositionForThisPass && !prePassRenderTarget.imageProcessingPostProcess) {
+            prePassRenderTarget._createCompositionEffect();
+        }
+
         // Setting the prePassRenderTarget as input texture of the first PP
         // Setting the prePassRenderTarget as input texture of the first PP
         if (firstPrePassPP) {
         if (firstPrePassPP) {
             firstPrePassPP.inputTexture = prePassRenderTarget.getInternalTexture()!;
             firstPrePassPP.inputTexture = prePassRenderTarget.getInternalTexture()!;

+ 3 - 1
src/Shaders/ShadersInclude/pbrBlockImageProcessing.fx

@@ -1,6 +1,8 @@
-#ifdef IMAGEPROCESSINGPOSTPROCESS
+#if defined(IMAGEPROCESSINGPOSTPROCESS) || defined(SS_SCATTERING)
     // Sanitize output incase invalid normals or tangents have caused div by 0 or undefined behavior
     // Sanitize output incase invalid normals or tangents have caused div by 0 or undefined behavior
     // this also limits the brightness which helpfully reduces over-sparkling in bloom (native handles this in the bloom blur shader)
     // this also limits the brightness which helpfully reduces over-sparkling in bloom (native handles this in the bloom blur shader)
+    //
+    // Subsurface scattering also requires to stay in linear space
     finalColor.rgb = clamp(finalColor.rgb, 0., 30.0);
     finalColor.rgb = clamp(finalColor.rgb, 0., 30.0);
 #else
 #else
     // Alway run to ensure we are going back to gamma space.
     // Alway run to ensure we are going back to gamma space.

+ 1 - 1
src/Shaders/ShadersInclude/pbrFragmentDeclaration.fx

@@ -151,7 +151,7 @@ uniform mat4 view;
 #endif
 #endif
 
 
 #ifdef PREPASS
 #ifdef PREPASS
-    #ifdef PREPASS_IRRADIANCE
+    #ifdef SS_SCATTERING
         uniform float scatteringDiffusionProfile;
         uniform float scatteringDiffusionProfile;
     #endif
     #endif
 #endif
 #endif