MaskPass.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. */
  4. THREE.MaskPass = function ( scene, camera ) {
  5. this.scene = scene;
  6. this.camera = camera;
  7. this.clear = true;
  8. this.needsSwap = false;
  9. };
  10. THREE.MaskPass.prototype = {
  11. render: function ( renderer, writeBuffer, readBuffer, delta ) {
  12. var context = renderer.context;
  13. // don't update color or depth
  14. context.colorMask( false, false, false, false );
  15. context.depthMask( false );
  16. // set up stencil
  17. context.enable( context.STENCIL_TEST );
  18. context.stencilOp( context.REPLACE, context.REPLACE, context.REPLACE );
  19. context.stencilFunc( context.ALWAYS, 1, 0xffffffff );
  20. // draw into the stencil buffer
  21. renderer.render( this.scene, this.camera, readBuffer, this.clear );
  22. renderer.render( this.scene, this.camera, writeBuffer, this.clear );
  23. // re-enable update of color and depth
  24. context.colorMask( true, true, true, true );
  25. context.depthMask( true );
  26. // only render where stencil is set to 1
  27. context.stencilFunc( context.EQUAL, 1, 0xffffffff ); // draw if == 1
  28. context.stencilOp( context.KEEP, context.KEEP, context.KEEP );
  29. }
  30. };
  31. THREE.ClearMaskPass = function () {
  32. };
  33. THREE.ClearMaskPass.prototype = {
  34. render: function ( renderer, writeBuffer, readBuffer, delta ) {
  35. var context = renderer.context;
  36. context.disable( context.STENCIL_TEST );
  37. }
  38. };