2
0

RenderPass.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. this._oldClearColor = new THREE.Color();
  12. };
  13. THREE.RenderPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
  14. constructor: THREE.RenderPass,
  15. render: function ( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) {
  16. var oldAutoClear = renderer.autoClear;
  17. renderer.autoClear = false;
  18. var oldClearAlpha, oldOverrideMaterial;
  19. if ( this.overrideMaterial !== undefined ) {
  20. oldOverrideMaterial = this.scene.overrideMaterial;
  21. this.scene.overrideMaterial = this.overrideMaterial;
  22. }
  23. if ( this.clearColor ) {
  24. renderer.getClearColor( this._oldClearColor );
  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( this._oldClearColor, oldClearAlpha );
  37. }
  38. if ( this.overrideMaterial !== undefined ) {
  39. this.scene.overrideMaterial = oldOverrideMaterial;
  40. }
  41. renderer.autoClear = oldAutoClear;
  42. }
  43. } );