RenderPass.js 1.7 KB

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