Browse Source

Merge pull request #18748 from habx/fix/renderpass-preserve-overridematerial

RenderPass: Avoid discarding Scene.overrideMaterial.
Mr.doob 5 years ago
parent
commit
92556a538a
2 changed files with 29 additions and 6 deletions
  1. 14 3
      examples/js/postprocessing/RenderPass.js
  2. 15 3
      examples/jsm/postprocessing/RenderPass.js

+ 14 - 3
examples/js/postprocessing/RenderPass.js

@@ -29,9 +29,15 @@ THREE.RenderPass.prototype = Object.assign( Object.create( THREE.Pass.prototype
 		var oldAutoClear = renderer.autoClear;
 		renderer.autoClear = false;
 
-		this.scene.overrideMaterial = this.overrideMaterial;
+		var oldClearColor, oldClearAlpha, oldOverrideMaterial;
 
-		var oldClearColor, oldClearAlpha;
+		if ( this.overrideMaterial !== undefined ) {
+
+			oldOverrideMaterial = this.scene.overrideMaterial;
+
+			this.scene.overrideMaterial = this.overrideMaterial;
+
+		}
 
 		if ( this.clearColor ) {
 
@@ -60,7 +66,12 @@ THREE.RenderPass.prototype = Object.assign( Object.create( THREE.Pass.prototype
 
 		}
 
-		this.scene.overrideMaterial = null;
+		if ( this.overrideMaterial !== undefined ) {
+
+			this.scene.overrideMaterial = oldOverrideMaterial;
+
+		}
+
 		renderer.autoClear = oldAutoClear;
 
 	}

+ 15 - 3
examples/jsm/postprocessing/RenderPass.js

@@ -32,9 +32,16 @@ RenderPass.prototype = Object.assign( Object.create( Pass.prototype ), {
 		var oldAutoClear = renderer.autoClear;
 		renderer.autoClear = false;
 
-		this.scene.overrideMaterial = this.overrideMaterial;
 
-		var oldClearColor, oldClearAlpha;
+		var oldClearColor, oldClearAlpha, oldOverrideMaterial;
+
+		if ( this.overrideMaterial !== undefined ) {
+
+			oldOverrideMaterial = this.scene.overrideMaterial;
+
+			this.scene.overrideMaterial = this.overrideMaterial;
+
+		}
 
 		if ( this.clearColor ) {
 
@@ -63,7 +70,12 @@ RenderPass.prototype = Object.assign( Object.create( Pass.prototype ), {
 
 		}
 
-		this.scene.overrideMaterial = null;
+		if ( this.overrideMaterial !== undefined ) {
+
+			this.scene.overrideMaterial = oldOverrideMaterial;
+
+		}
+
 		renderer.autoClear = oldAutoClear;
 
 	}