RenderPass.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. */
  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. };
  16. RenderPass.prototype = Object.assign( Object.create( Pass.prototype ), {
  17. constructor: RenderPass,
  18. render: function ( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) {
  19. var oldAutoClear = renderer.autoClear;
  20. renderer.autoClear = false;
  21. this.scene.overrideMaterial = this.overrideMaterial;
  22. var oldClearColor, oldClearAlpha;
  23. if ( this.clearColor ) {
  24. oldClearColor = renderer.getClearColor().getHex();
  25. oldClearAlpha = renderer.getClearAlpha();
  26. renderer.setClearColor( this.clearColor, this.clearAlpha );
  27. }
  28. if ( this.clearDepth ) {
  29. renderer.clearDepth();
  30. }
  31. renderer.setRenderTarget( this.renderToScreen ? null : readBuffer );
  32. // TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600
  33. if ( this.clear ) renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  34. renderer.render( this.scene, this.camera );
  35. if ( this.clearColor ) {
  36. renderer.setClearColor( oldClearColor, oldClearAlpha );
  37. }
  38. this.scene.overrideMaterial = null;
  39. renderer.autoClear = oldAutoClear;
  40. }
  41. } );
  42. export { RenderPass };