mirror of
https://github.com/wahyd4/three.js.git
synced 2026-08-09 13:06:01 +10:00
Masking was real pain to get working with multiple render targets :/. Unfortunately this introduced dependencies on MaskPass.js and ShaderPass.js even for use cases that do not use masking. Bah, will need to figure out some better way for deployment.
67 lines
1.3 KiB
JavaScript
67 lines
1.3 KiB
JavaScript
/**
|
|
* @author alteredq / http://alteredqualia.com/
|
|
*/
|
|
|
|
THREE.MaskPass = function ( scene, camera ) {
|
|
|
|
this.scene = scene;
|
|
this.camera = camera;
|
|
|
|
this.clear = true;
|
|
this.needsSwap = false;
|
|
|
|
};
|
|
|
|
THREE.MaskPass.prototype = {
|
|
|
|
render: function ( renderer, writeBuffer, readBuffer, delta ) {
|
|
|
|
var context = renderer.context;
|
|
|
|
// don't update color or depth
|
|
|
|
context.colorMask( false, false, false, false );
|
|
context.depthMask( false );
|
|
|
|
// set up stencil
|
|
|
|
context.enable( context.STENCIL_TEST );
|
|
context.stencilOp( context.REPLACE, context.REPLACE, context.REPLACE );
|
|
context.stencilFunc( context.ALWAYS, 1, 0xffffffff );
|
|
|
|
// draw into the stencil buffer
|
|
|
|
renderer.render( this.scene, this.camera, readBuffer, this.clear );
|
|
renderer.render( this.scene, this.camera, writeBuffer, this.clear );
|
|
|
|
// re-enable update of color and depth
|
|
|
|
context.colorMask( true, true, true, true );
|
|
context.depthMask( true );
|
|
|
|
// only render where stencil is set to 1
|
|
|
|
context.stencilFunc( context.EQUAL, 1, 0xffffffff ); // draw if == 1
|
|
context.stencilOp( context.KEEP, context.KEEP, context.KEEP );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
THREE.ClearMaskPass = function () {
|
|
|
|
};
|
|
|
|
THREE.ClearMaskPass.prototype = {
|
|
|
|
render: function ( renderer, writeBuffer, readBuffer, delta ) {
|
|
|
|
var context = renderer.context;
|
|
|
|
context.disable( context.STENCIL_TEST );
|
|
|
|
}
|
|
|
|
};
|