Skip to content

Commit 9866c8f

Browse files
committed
GTAOPass: Replace visibility cache Map with an array for improved performance
1 parent 297385a commit 9866c8f

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

examples/jsm/postprocessing/GTAOPass.js

Lines changed: 12 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.
@@ -653,29 +653,32 @@ class GTAOPass extends Pass {
653653
const scene = this.scene;
654654
const cache = this._visibilityCache;
655655

656+
cache.length = 0;
657+
656658
scene.traverse( function ( object ) {
657659

658-
cache.set( object, object.visible );
660+
if ( ( object.isPoints || object.isLine || object.isLine2 ) && object.visible ) {
661+
662+
object.visible = false;
663+
cache.push( object );
659664

660-
if ( object.isPoints || object.isLine || object.isLine2 ) object.visible = false;
665+
}
661666

662667
} );
663668

664669
}
665670

666671
_restoreVisibility() {
667672

668-
const scene = this.scene;
669673
const cache = this._visibilityCache;
670674

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

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

676-
} );
679+
}
677680

678-
cache.clear();
681+
cache.length = 0;
679682

680683
}
681684

0 commit comments

Comments
 (0)