RenderPass.js 1.8 KB

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