RenderPass.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ( function () {
  2. class RenderPass extends THREE.Pass {
  3. constructor( scene, camera, overrideMaterial, clearColor, clearAlpha ) {
  4. super();
  5. this.scene = scene;
  6. this.camera = camera;
  7. this.overrideMaterial = overrideMaterial;
  8. this.clearColor = clearColor;
  9. this.clearAlpha = clearAlpha !== undefined ? clearAlpha : 0;
  10. this.clear = true;
  11. this.clearDepth = false;
  12. this.needsSwap = false;
  13. this._oldClearColor = new THREE.Color();
  14. }
  15. render( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) {
  16. const oldAutoClear = renderer.autoClear;
  17. renderer.autoClear = false;
  18. let 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. }
  44. THREE.RenderPass = RenderPass;
  45. } )();