Browse Source

Prevent full path tracer updates on background and environment changes (#27847)

Garrett Johnson 1 year ago
parent
commit
c3fb29db61
2 changed files with 55 additions and 15 deletions
  1. 33 13
      editor/js/Viewport.Pathtracer.js
  2. 22 2
      editor/js/Viewport.js

+ 33 - 13
editor/js/Viewport.Pathtracer.js

@@ -72,8 +72,28 @@ function ViewportPathtracer( renderer ) {
 
 
 		//
 		//
 
 
-		const background = scene.background;
+		setBackground( scene.background );
 
 
+		//
+
+		setEnvironment( scene.environment );
+
+	}
+
+	function setSize( width, height ) {
+
+		if ( pathtracer === null ) return;
+
+		pathtracer.setSize( width, height );
+		pathtracer.reset();
+
+	}
+
+	function setBackground( background ) {
+
+		if ( pathtracer === null ) return;
+
+		const ptMaterial = pathtracer.material;
 		if ( background ) {
 		if ( background ) {
 
 
 			if ( background.isTexture ) {
 			if ( background.isTexture ) {
@@ -92,18 +112,23 @@ function ViewportPathtracer( renderer ) {
 
 
 		}
 		}
 
 
-		//
+		pathtracer.reset();
 
 
-		const environment = scene.environment;
+	}
+
+	function setEnvironment( environment ) {
+
+		if ( pathtracer === null ) return;
 
 
+		const ptMaterial = pathtracer.material;
 		if ( environment && environment.isDataTexture === true ) {
 		if ( environment && environment.isDataTexture === true ) {
 
 
 			// Avoid calling envMapInfo() with the same hdr
 			// Avoid calling envMapInfo() with the same hdr
 
 
-			if ( scene.environment !== hdr ) {
+			if ( environment !== hdr ) {
 
 
-				ptMaterial.envMapInfo.updateFrom( scene.environment );
-				hdr = scene.environment;
+				ptMaterial.envMapInfo.updateFrom( environment );
+				hdr = environment;
 
 
 			}
 			}
 
 
@@ -113,13 +138,6 @@ function ViewportPathtracer( renderer ) {
 
 
 		}
 		}
 
 
-	}
-
-	function setSize( width, height ) {
-
-		if ( pathtracer === null ) return;
-
-		pathtracer.setSize( width, height );
 		pathtracer.reset();
 		pathtracer.reset();
 
 
 	}
 	}
@@ -151,6 +169,8 @@ function ViewportPathtracer( renderer ) {
 	return {
 	return {
 		init: init,
 		init: init,
 		setSize: setSize,
 		setSize: setSize,
+		setBackground: setBackground,
+		setEnvironment: setEnvironment,
 		update: update,
 		update: update,
 		reset: reset
 		reset: reset
 	};
 	};

+ 22 - 2
editor/js/Viewport.js

@@ -513,7 +513,7 @@ function Viewport( editor ) {
 
 
 		}
 		}
 
 
-		initPT();
+		updatePTBackground();
 		render();
 		render();
 
 
 	} );
 	} );
@@ -560,7 +560,7 @@ function Viewport( editor ) {
 
 
 		}
 		}
 
 
-		initPT();
+		updatePTEnvironment();
 		render();
 		render();
 
 
 	} );
 	} );
@@ -754,6 +754,26 @@ function Viewport( editor ) {
 
 
 	}
 	}
 
 
+	function updatePTBackground() {
+
+		if ( editor.viewportShading === 'realistic' ) {
+
+			pathtracer.setBackground( scene.background );
+
+		}
+
+	}
+
+	function updatePTEnvironment() {
+
+		if ( editor.viewportShading === 'realistic' ) {
+
+			pathtracer.setEnvironment( scene.environment );
+
+		}
+
+	}
+
 	function updatePT() {
 	function updatePT() {
 
 
 		if ( editor.viewportShading === 'realistic' ) {
 		if ( editor.viewportShading === 'realistic' ) {