Skip to content

Commit 6be2805

Browse files
committedJan 28, 2016
Revert "mrdoob#7952 New Stencil Buffer Management"
This reverts commit 644d6a2. Conflicts: src/materials/Material.js
1 parent 6bbf832 commit 6be2805

19 files changed

+94
-99
lines changed
 

‎examples/js/postprocessing/AdaptiveToneMappingPass.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ THREE.AdaptiveToneMappingPass.prototype = {
163163
}
164164

165165
this.quad.material = this.materialToneMap;
166-
this.quad.material.stencilTest = maskActive;
167166
this.materialToneMap.uniforms.tDiffuse.value = readBuffer;
168167
renderer.render( this.scene, this.camera, writeBuffer, this.clear );
169168

‎examples/js/postprocessing/BloomPass.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ THREE.BloomPass.prototype = {
7878

7979
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
8080

81+
if ( maskActive ) renderer.context.disable( renderer.context.STENCIL_TEST );
82+
8183
// Render quad with blured scene into texture (convolution pass 1)
8284

8385
this.quad.material = this.materialConvolution;
@@ -98,11 +100,13 @@ THREE.BloomPass.prototype = {
98100
// Render original scene with superimposed blur to texture
99101

100102
this.quad.material = this.materialCopy;
101-
this.quad.material.stencilTest = maskActive;
102103

103104
this.copyUniforms[ "tDiffuse" ].value = this.renderTargetY;
104105

106+
if ( maskActive ) renderer.context.enable( renderer.context.STENCIL_TEST );
107+
105108
renderer.render( this.scene, this.camera, readBuffer, this.clear );
109+
106110
}
107111

108112
};

‎examples/js/postprocessing/BokehPass.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ THREE.BokehPass = function ( scene, camera, params ) {
3737
console.error( "THREE.BokehPass relies on THREE.BokehShader" );
3838

3939
}
40-
40+
4141
var bokehShader = THREE.BokehShader;
4242
var bokehUniforms = THREE.UniformsUtils.clone( bokehShader.uniforms );
4343

@@ -63,17 +63,16 @@ THREE.BokehPass = function ( scene, camera, params ) {
6363
this.camera2 = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
6464
this.scene2 = new THREE.Scene();
6565

66-
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
67-
this.scene2.add( this.quad );
66+
this.quad2 = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
67+
this.scene2.add( this.quad2 );
6868

6969
};
7070

7171
THREE.BokehPass.prototype = {
7272

7373
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
7474

75-
this.quad.material = this.materialBokeh;
76-
this.quad.material.stencilTest = maskActive;
75+
this.quad2.material = this.materialBokeh;
7776

7877
// Render depth into texture
7978

@@ -100,3 +99,4 @@ THREE.BokehPass.prototype = {
10099
}
101100

102101
};
102+

‎examples/js/postprocessing/ClearPass.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@ THREE.ClearPass = function () {
1010

1111
THREE.ClearPass.prototype = {
1212

13-
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
13+
render: function ( renderer, writeBuffer, readBuffer ) {
1414

1515
renderer.setRenderTarget( readBuffer );
1616
renderer.clear();
1717

18-
renderer.setRenderTarget( writeBuffer );
19-
renderer.clear();
20-
2118
}
2219

2320
};

‎examples/js/postprocessing/DotScreenPass.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ THREE.DotScreenPass = function ( center, angle, scale ) {
3838

3939
THREE.DotScreenPass.prototype = {
4040

41-
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
41+
render: function ( renderer, writeBuffer, readBuffer, delta ) {
4242

4343
this.uniforms[ "tDiffuse" ].value = readBuffer;
4444
this.uniforms[ "tSize" ].value.set( readBuffer.width, readBuffer.height );
4545

4646
this.quad.material = this.material;
47-
this.quad.material.stencilTest = maskActive;
4847

4948
if ( this.renderToScreen ) {
5049

‎examples/js/postprocessing/EffectComposer.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ THREE.EffectComposer = function ( renderer, renderTarget ) {
2424
this.writeBuffer = this.renderTarget1;
2525
this.readBuffer = this.renderTarget2;
2626

27-
if ( THREE.MaskPass === undefined )
28-
console.error( "THREE.EffectComposer relies on THREE.MaskPass" );
29-
3027
this.passes = [];
28+
29+
if ( THREE.CopyShader === undefined )
30+
console.error( "THREE.EffectComposer relies on THREE.CopyShader" );
31+
32+
this.copyPass = new THREE.ShaderPass( THREE.CopyShader );
33+
3134
};
3235

3336
THREE.EffectComposer.prototype = {
@@ -54,11 +57,11 @@ THREE.EffectComposer.prototype = {
5457

5558
render: function ( delta ) {
5659

57-
var maskActive = false;
58-
5960
this.writeBuffer = this.renderTarget1;
6061
this.readBuffer = this.renderTarget2;
6162

63+
var maskActive = false;
64+
6265
var pass, i, il = this.passes.length;
6366

6467
for ( i = 0; i < il; i ++ ) {
@@ -71,6 +74,18 @@ THREE.EffectComposer.prototype = {
7174

7275
if ( pass.needsSwap ) {
7376

77+
if ( maskActive ) {
78+
79+
var context = this.renderer.context;
80+
81+
context.stencilFunc( context.NOTEQUAL, 1, 0xffffffff );
82+
83+
this.copyPass.render( this.renderer, this.writeBuffer, this.readBuffer, delta );
84+
85+
context.stencilFunc( context.EQUAL, 1, 0xffffffff );
86+
87+
}
88+
7489
this.swapBuffers();
7590

7691
}

‎examples/js/postprocessing/FilmPass.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@ THREE.FilmPass = function ( noiseIntensity, scanlinesIntensity, scanlinesCount,
3939

4040
THREE.FilmPass.prototype = {
4141

42-
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
42+
render: function ( renderer, writeBuffer, readBuffer, delta ) {
4343

4444
this.uniforms[ "tDiffuse" ].value = readBuffer;
4545
this.uniforms[ "time" ].value += delta;
4646

4747
this.quad.material = this.material;
48-
this.quad.material.stencilTest = maskActive;
4948

5049
if ( this.renderToScreen ) {
5150

‎examples/js/postprocessing/GlitchPass.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/**
2-
2+
33
*/
44

55
THREE.GlitchPass = function ( dt_size ) {
66

77
if ( THREE.DigitalGlitch === undefined ) console.error( "THREE.GlitchPass relies on THREE.DigitalGlitch" );
8-
8+
99
var shader = THREE.DigitalGlitch;
1010
this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
1111

1212
if ( dt_size == undefined ) dt_size = 64;
13-
14-
13+
14+
1515
this.uniforms[ "tDisp" ].value = this.generateHeightmap( dt_size );
16-
16+
1717

1818
this.material = new THREE.ShaderMaterial( {
1919
uniforms: this.uniforms,
@@ -31,21 +31,21 @@ THREE.GlitchPass = function ( dt_size ) {
3131

3232
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
3333
this.scene.add( this.quad );
34-
34+
3535
this.goWild = false;
3636
this.curF = 0;
3737
this.generateTrigger();
38-
38+
3939
};
4040

4141
THREE.GlitchPass.prototype = {
4242

43-
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
43+
render: function ( renderer, writeBuffer, readBuffer, delta ) {
4444

4545
this.uniforms[ "tDiffuse" ].value = readBuffer;
4646
this.uniforms[ 'seed' ].value = Math.random();//default seeding
4747
this.uniforms[ 'byp' ].value = 0;
48-
48+
4949
if ( this.curF % this.randX == 0 || this.goWild == true ) {
5050

5151
this.uniforms[ 'amount' ].value = Math.random() / 30;
@@ -72,10 +72,8 @@ THREE.GlitchPass.prototype = {
7272

7373
}
7474
this.curF ++;
75-
75+
7676
this.quad.material = this.material;
77-
this.quad.material.stencilTest = maskActive;
78-
7977
if ( this.renderToScreen ) {
8078

8179
renderer.render( this.scene, this.camera );
@@ -96,7 +94,7 @@ THREE.GlitchPass.prototype = {
9694

9795
var data_arr = new Float32Array( dt_size * dt_size * 3 );
9896
var length = dt_size * dt_size;
99-
97+
10098
for ( var i = 0; i < length; i ++ ) {
10199

102100
var val = THREE.Math.randFloat( 0, 1 );
@@ -105,7 +103,7 @@ THREE.GlitchPass.prototype = {
105103
data_arr[ i * 3 + 2 ] = val;
106104

107105
}
108-
106+
109107
var texture = new THREE.DataTexture( data_arr, dt_size, dt_size, THREE.RGBFormat, THREE.FloatType );
110108
texture.needsUpdate = true;
111109
return texture;

‎examples/js/postprocessing/MaskPass.js

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ THREE.MaskPass = function ( scene, camera ) {
88
this.camera = camera;
99

1010
this.enabled = true;
11-
this.clear = false;
11+
this.clear = true;
1212
this.needsSwap = false;
1313

1414
this.inverse = false;
@@ -17,16 +17,20 @@ THREE.MaskPass = function ( scene, camera ) {
1717

1818
THREE.MaskPass.prototype = {
1919

20-
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
21-
22-
var writeValue, clearValue;
20+
render: function ( renderer, writeBuffer, readBuffer, delta ) {
2321

2422
var context = renderer.context;
25-
var state = renderer.state;
2623

27-
// check inverse masking
24+
// don't update color or depth
25+
26+
context.colorMask( false, false, false, false );
27+
context.depthMask( false );
28+
29+
// set up stencil
2830

29-
if ( this.inverse === true ) {
31+
var writeValue, clearValue;
32+
33+
if ( this.inverse ) {
3034

3135
writeValue = 0;
3236
clearValue = 1;
@@ -38,28 +42,26 @@ THREE.MaskPass.prototype = {
3842

3943
}
4044

41-
// setup WebGL state to prepare the stencil test
42-
43-
state.clearStencil( clearValue );
44-
45-
state.setStencilFunc( context.ALWAYS, writeValue, 0xffffffff );
46-
state.setStencilOp( context.REPLACE, context.REPLACE, context.REPLACE );
47-
48-
// clear the stencil buffer before drawing
49-
50-
renderer.clearTarget( readBuffer, false, false, true );
51-
renderer.clearTarget( writeBuffer, false, false, true );
45+
context.enable( context.STENCIL_TEST );
46+
context.stencilOp( context.REPLACE, context.REPLACE, context.REPLACE );
47+
context.stencilFunc( context.ALWAYS, writeValue, 0xffffffff );
48+
context.clearStencil( clearValue );
5249

5350
// draw into the stencil buffer
5451

5552
renderer.render( this.scene, this.camera, readBuffer, this.clear );
5653
renderer.render( this.scene, this.camera, writeBuffer, this.clear );
5754

58-
// setup WebGL state for upcoming stencil tests.
55+
// re-enable update of color and depth
56+
57+
context.colorMask( true, true, true, true );
58+
context.depthMask( true );
59+
5960
// only render where stencil is set to 1
6061

61-
state.setStencilFunc( context.EQUAL, 1, 0xffffffff ); // draw if == 1
62-
state.setStencilOp( context.KEEP, context.KEEP, context.KEEP );
62+
context.stencilFunc( context.EQUAL, 1, 0xffffffff ); // draw if == 1
63+
context.stencilOp( context.KEEP, context.KEEP, context.KEEP );
64+
6365
}
6466

6567
};
@@ -73,7 +75,11 @@ THREE.ClearMaskPass = function () {
7375

7476
THREE.ClearMaskPass.prototype = {
7577

76-
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
78+
render: function ( renderer, writeBuffer, readBuffer, delta ) {
79+
80+
var context = renderer.context;
81+
82+
context.disable( context.STENCIL_TEST );
7783

7884
}
7985

‎examples/js/postprocessing/RenderPass.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ THREE.RenderPass = function ( scene, camera, overrideMaterial, clearColor, clear
2323

2424
THREE.RenderPass.prototype = {
2525

26-
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
26+
render: function ( renderer, writeBuffer, readBuffer, delta ) {
2727

2828
this.scene.overrideMaterial = this.overrideMaterial;
2929

‎examples/js/postprocessing/SavePass.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ THREE.SavePass = function ( renderTarget ) {
4545

4646
THREE.SavePass.prototype = {
4747

48-
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
48+
render: function ( renderer, writeBuffer, readBuffer, delta ) {
4949

5050
if ( this.uniforms[ this.textureID ] ) {
5151

@@ -54,7 +54,6 @@ THREE.SavePass.prototype = {
5454
}
5555

5656
this.quad.material = this.material;
57-
this.quad.material.stencilTest = maskActive;
5857

5958
renderer.render( this.scene, this.camera, this.renderTarget, this.clear );
6059

‎examples/js/postprocessing/ShaderPass.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ THREE.ShaderPass = function( shader, textureID ) {
4545

4646
THREE.ShaderPass.prototype = {
4747

48-
render: function( renderer, writeBuffer, readBuffer, delta, maskActive ) {
48+
render: function( renderer, writeBuffer, readBuffer, delta ) {
4949

5050
if ( this.uniforms[ this.textureID ] ) {
5151

@@ -54,7 +54,6 @@ THREE.ShaderPass.prototype = {
5454
}
5555

5656
this.quad.material = this.material;
57-
this.quad.material.stencilTest = maskActive;
5857

5958
if ( this.renderToScreen ) {
6059

‎examples/js/postprocessing/TexturePass.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ THREE.TexturePass = function ( texture, opacity ) {
2525
this.enabled = true;
2626
this.needsSwap = false;
2727

28+
2829
this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
2930
this.scene = new THREE.Scene();
3031

@@ -35,10 +36,9 @@ THREE.TexturePass = function ( texture, opacity ) {
3536

3637
THREE.TexturePass.prototype = {
3738

38-
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
39+
render: function ( renderer, writeBuffer, readBuffer, delta ) {
3940

4041
this.quad.material = this.material;
41-
this.quad.material.stencilTest = maskActive;
4242

4343
renderer.render( this.scene, this.camera, readBuffer );
4444

0 commit comments

Comments
 (0)