RenderPass.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ( function () {
  2. var RenderPass = function ( scene, camera, overrideMaterial, clearColor, clearAlpha ) {
  3. THREE.Pass.call( this );
  4. this.scene = scene;
  5. this.camera = camera;
  6. this.overrideMaterial = overrideMaterial;
  7. this.clearColor = clearColor;
  8. this.clearAlpha = clearAlpha !== undefined ? clearAlpha : 0;
  9. this.clear = true;
  10. this.clearDepth = false;
  11. this.needsSwap = false;
  12. this._oldClearColor = new THREE.Color();
  13. };
  14. RenderPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
  15. constructor: RenderPass,
  16. render: function ( renderer, writeBuffer, readBuffer
  17. /*, deltaTime, maskActive */
  18. ) {
  19. var oldAutoClear = renderer.autoClear;
  20. renderer.autoClear = false;
  21. var oldClearAlpha, oldOverrideMaterial;
  22. if ( this.overrideMaterial !== undefined ) {
  23. oldOverrideMaterial = this.scene.overrideMaterial;
  24. this.scene.overrideMaterial = this.overrideMaterial;
  25. }
  26. if ( this.clearColor ) {
  27. renderer.getClearColor( this._oldClearColor );
  28. oldClearAlpha = renderer.getClearAlpha();
  29. renderer.setClearColor( this.clearColor, this.clearAlpha );
  30. }
  31. if ( this.clearDepth ) {
  32. renderer.clearDepth();
  33. }
  34. renderer.setRenderTarget( this.renderToScreen ? null : readBuffer ); // TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600
  35. if ( this.clear ) renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  36. renderer.render( this.scene, this.camera );
  37. if ( this.clearColor ) {
  38. renderer.setClearColor( this._oldClearColor, oldClearAlpha );
  39. }
  40. if ( this.overrideMaterial !== undefined ) {
  41. this.scene.overrideMaterial = oldOverrideMaterial;
  42. }
  43. renderer.autoClear = oldAutoClear;
  44. }
  45. } );
  46. THREE.RenderPass = RenderPass;
  47. } )();