RenderPass.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import {
  2. Color
  3. } from '../../../build/three.module.js';
  4. import { Pass } from './Pass.js';
  5. class RenderPass extends Pass {
  6. constructor( scene, camera, overrideMaterial, clearColor, clearAlpha ) {
  7. super();
  8. this.scene = scene;
  9. this.camera = camera;
  10. this.overrideMaterial = overrideMaterial;
  11. this.clearColor = clearColor;
  12. this.clearAlpha = ( clearAlpha !== undefined ) ? clearAlpha : 0;
  13. this.clear = true;
  14. this.clearDepth = false;
  15. this.needsSwap = false;
  16. this._oldClearColor = new Color();
  17. }
  18. render( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) {
  19. const oldAutoClear = renderer.autoClear;
  20. renderer.autoClear = false;
  21. let 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 );
  35. // TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600
  36. if ( this.clear ) renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  37. renderer.render( this.scene, this.camera );
  38. if ( this.clearColor ) {
  39. renderer.setClearColor( this._oldClearColor, oldClearAlpha );
  40. }
  41. if ( this.overrideMaterial !== undefined ) {
  42. this.scene.overrideMaterial = oldOverrideMaterial;
  43. }
  44. renderer.autoClear = oldAutoClear;
  45. }
  46. }
  47. export { RenderPass };