Skip to content

Commit 7973543

Browse files
authored
Merge pull request #17136 from gkjohnson/fix-mask-pass
MaskPass: Add stencil state locking in MaskPass effect
2 parents f9e0046 + ccf62e4 commit 7973543

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

examples/js/postprocessing/MaskPass.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ THREE.MaskPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ),
5555
state.buffers.stencil.setOp( context.REPLACE, context.REPLACE, context.REPLACE );
5656
state.buffers.stencil.setFunc( context.ALWAYS, writeValue, 0xffffffff );
5757
state.buffers.stencil.setClear( clearValue );
58+
state.buffers.stencil.setLocked( true );
5859

5960
// draw into the stencil buffer
6061

@@ -73,8 +74,10 @@ THREE.MaskPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ),
7374

7475
// only render where stencil is set to 1
7576

77+
state.buffers.stencil.setLocked( false );
7678
state.buffers.stencil.setFunc( context.EQUAL, 1, 0xffffffff ); // draw if == 1
7779
state.buffers.stencil.setOp( context.KEEP, context.KEEP, context.KEEP );
80+
state.buffers.stencil.setLocked( true );
7881

7982
}
8083

@@ -95,6 +98,7 @@ Object.assign( THREE.ClearMaskPass.prototype, {
9598

9699
render: function ( renderer /*, writeBuffer, readBuffer, deltaTime, maskActive */ ) {
97100

101+
renderer.state.buffers.stencil.setLocked( false );
98102
renderer.state.buffers.stencil.setTest( false );
99103

100104
}

examples/jsm/postprocessing/MaskPass.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ MaskPass.prototype = Object.assign( Object.create( Pass.prototype ), {
5858
state.buffers.stencil.setOp( context.REPLACE, context.REPLACE, context.REPLACE );
5959
state.buffers.stencil.setFunc( context.ALWAYS, writeValue, 0xffffffff );
6060
state.buffers.stencil.setClear( clearValue );
61+
state.buffers.stencil.setLocked( true );
6162

6263
// draw into the stencil buffer
6364

@@ -76,8 +77,10 @@ MaskPass.prototype = Object.assign( Object.create( Pass.prototype ), {
7677

7778
// only render where stencil is set to 1
7879

80+
state.buffers.stencil.setLocked( false );
7981
state.buffers.stencil.setFunc( context.EQUAL, 1, 0xffffffff ); // draw if == 1
8082
state.buffers.stencil.setOp( context.KEEP, context.KEEP, context.KEEP );
83+
state.buffers.stencil.setLocked( true );
8184

8285
}
8386

@@ -98,6 +101,7 @@ Object.assign( ClearMaskPass.prototype, {
98101

99102
render: function ( renderer /*, writeBuffer, readBuffer, deltaTime, maskActive */ ) {
100103

104+
renderer.state.buffers.stencil.setLocked( false );
101105
renderer.state.buffers.stencil.setTest( false );
102106

103107
}

src/renderers/webgl/WebGLState.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,17 @@ function WebGLState( gl, extensions, utils, capabilities ) {
215215

216216
setTest: function ( stencilTest ) {
217217

218-
if ( stencilTest ) {
218+
if ( ! locked ) {
219219

220-
enable( gl.STENCIL_TEST );
220+
if ( stencilTest ) {
221221

222-
} else {
222+
enable( gl.STENCIL_TEST );
223+
224+
} else {
223225

224-
disable( gl.STENCIL_TEST );
226+
disable( gl.STENCIL_TEST );
227+
228+
}
225229

226230
}
227231

0 commit comments

Comments
 (0)