Benjamin Guignabert 4 vuotta sitten
vanhempi
commit
3de30f3dee

+ 9 - 7
src/Rendering/geometryBufferRenderer.ts

@@ -95,7 +95,6 @@ export class GeometryBufferRenderer {
     protected _effect: Effect;
     protected _cachedDefines: string;
 
-
     /**
      * @hidden
      * Sets up internal structures to share outputs with PrePassRenderer
@@ -167,7 +166,7 @@ export class GeometryBufferRenderer {
     /**
      * @hidden
      * Replaces the first texture which is hard coded as a depth texture in the geometry buffer
-     * Useful when linking textures of the prepass renderer   
+     * Useful when linking textures of the prepass renderer
      */
     public linkInternalTexture(internalTexture: InternalTexture) {
         this._multiRenderTarget._texture = internalTexture;
@@ -225,7 +224,7 @@ export class GeometryBufferRenderer {
         // PrePass handles index and texture links
         if (!this._linkedWithPrePass) {
             this.dispose();
-            this._createRenderTargets();            
+            this._createRenderTargets();
         }
     }
 
@@ -248,7 +247,7 @@ export class GeometryBufferRenderer {
 
         if (!this._linkedWithPrePass) {
             this.dispose();
-            this._createRenderTargets();            
+            this._createRenderTargets();
         }
     }
 
@@ -267,7 +266,7 @@ export class GeometryBufferRenderer {
 
         if (!this._linkedWithPrePass) {
             this.dispose();
-            this._createRenderTargets();            
+            this._createRenderTargets();
         }
     }
 
@@ -363,7 +362,10 @@ export class GeometryBufferRenderer {
         // PrePass
         if (this._linkedWithPrePass) {
             defines.push("#define PREPASS");
-            defines.push("#define DEPTHNORMAL_INDEX " + this._depthNormalIndex);
+            if (this._depthNormalIndex !== -1) {
+                defines.push("#define DEPTHNORMAL_INDEX " + this._depthNormalIndex);
+                defines.push("#define PREPASS_DEPTHNORMAL");
+            }
         }
 
         // Buffers
@@ -499,7 +501,7 @@ export class GeometryBufferRenderer {
             count++;
         }
 
-        return count
+        return count;
     }
 
     protected _createRenderTargets(): void {

+ 1 - 8
src/Rendering/prePassRenderer.ts

@@ -325,14 +325,6 @@ export class PrePassRenderer {
             const gl = this._scene.getEngine()._gl;
             attachments[0] = gl.NONE;
 
-            // Depth + normal is always index 0 in geometry buffer
-            let index = this.getIndex(Constants.PREPASS_DEPTHNORMAL_TEXTURE_TYPE);
-            if (index !== -1) {
-                this._geometryBuffer.linkInternalTexture(this.prePassRT.getInternalTexture()!);
-            } else {
-                this._geometryBuffer.linkInternalTexture(this.prePassRT.getInternalTexture()!);
-            }
-
             const matches = [
                 {
                     prePassConstant: Constants.PREPASS_DEPTHNORMAL_TEXTURE_TYPE,
@@ -527,6 +519,7 @@ export class PrePassRenderer {
 
         if (!this.enabled) {
             // Prepass disabled, we render only on 1 color attachment
+            this._engine.restoreDefaultFramebuffer();
             this._engine.bindAttachments([this._engine._gl.BACK]);
         }
     }

+ 3 - 1
src/Shaders/geometry.fragment.fx

@@ -63,7 +63,9 @@ void main() {
     #endif
 
     #ifdef PREPASS
-    gl_FragData[DEPTHNORMAL_INDEX] = vec4(vViewPos.z / vViewPos.w, normalOutput);
+        #ifdef PREPASS_DEPTHNORMAL
+        gl_FragData[DEPTHNORMAL_INDEX] = vec4(vViewPos.z / vViewPos.w, normalOutput);
+        #endif
     #else
     gl_FragData[0] = vec4(vViewPos.z / vViewPos.w, 0.0, 0.0, 1.0);
     gl_FragData[1] = vec4(normalOutput, 1.0);