Skip to content

Commit

Permalink
Prevent full path tracer updates on background and environment changes (
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson authored and mrdoob committed Mar 1, 2024
1 parent de2a2da commit 10052e3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 15 deletions.
46 changes: 33 additions & 13 deletions editor/js/Viewport.Pathtracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.isTexture ) {
Expand All @@ -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 ) {

// 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;

}

Expand All @@ -113,13 +138,6 @@ function ViewportPathtracer( renderer ) {

}

}

function setSize( width, height ) {

if ( pathtracer === null ) return;

pathtracer.setSize( width, height );
pathtracer.reset();

}
Expand Down Expand Up @@ -151,6 +169,8 @@ function ViewportPathtracer( renderer ) {
return {
init: init,
setSize: setSize,
setBackground: setBackground,
setEnvironment: setEnvironment,
update: update,
reset: reset
};
Expand Down
24 changes: 22 additions & 2 deletions editor/js/Viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ function Viewport( editor ) {

}

initPT();
updatePTBackground();
render();

} );
Expand Down Expand Up @@ -560,7 +560,7 @@ function Viewport( editor ) {

}

initPT();
updatePTEnvironment();
render();

} );
Expand Down Expand Up @@ -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() {

if ( editor.viewportShading === 'realistic' ) {
Expand Down

0 comments on commit 10052e3

Please sign in to comment.