Skip to content

Commit 8e3fd3c

Browse files
authored
GTAOPass: Replace visibility cache Map with an array for improved performance (#31454)
* GTAOPass: Replace visibility cache Map with an array for improved performance * GTAOPass: review comment #31453 (comment)
1 parent 3e77c57 commit 8e3fd3c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

examples/jsm/postprocessing/GTAOPass.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class GTAOPass extends Pass {
103103
*/
104104
this.output = 0;
105105
this._renderGBuffer = true;
106-
this._visibilityCache = new Map();
106+
this._visibilityCache = [];
107107

108108
/**
109109
* The AO blend intensity.
@@ -655,27 +655,28 @@ class GTAOPass extends Pass {
655655

656656
scene.traverse( function ( object ) {
657657

658-
cache.set( object, object.visible );
658+
if ( ( object.isPoints || object.isLine || object.isLine2 ) && object.visible ) {
659659

660-
if ( object.isPoints || object.isLine || object.isLine2 ) object.visible = false;
660+
object.visible = false;
661+
cache.push( object );
662+
663+
}
661664

662665
} );
663666

664667
}
665668

666669
_restoreVisibility() {
667670

668-
const scene = this.scene;
669671
const cache = this._visibilityCache;
670672

671-
scene.traverse( function ( object ) {
673+
for ( let i = 0; i < cache.length; i ++ ) {
672674

673-
const visible = cache.get( object );
674-
object.visible = visible;
675+
cache[ i ].visible = true;
675676

676-
} );
677+
}
677678

678-
cache.clear();
679+
cache.length = 0;
679680

680681
}
681682

0 commit comments

Comments
 (0)