2
0

RenderPass.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. var oldClearColor, oldClearAlpha, oldOverrideMaterial;
  22. if ( this.overrideMaterial !== undefined ) {
  23. oldOverrideMaterial = this.scene.overrideMaterial;
  24. this.scene.overrideMaterial = this.overrideMaterial;
  25. }
  26. if ( this.clearColor ) {
  27. oldClearColor = renderer.getClearColor().getHex();
  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( oldClearColor, oldClearAlpha );
  40. }
  41. if ( this.overrideMaterial !== undefined ) {
  42. this.scene.overrideMaterial = oldOverrideMaterial;
  43. }
  44. renderer.autoClear = oldAutoClear;
  45. }
  46. } );
  47. export { RenderPass };