RenderPass.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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
  16. /*, deltaTime, maskActive */
  17. ) {
  18. const oldAutoClear = renderer.autoClear;
  19. renderer.autoClear = false;
  20. let oldClearAlpha, oldOverrideMaterial;
  21. if ( this.overrideMaterial !== undefined ) {
  22. oldOverrideMaterial = this.scene.overrideMaterial;
  23. this.scene.overrideMaterial = this.overrideMaterial;
  24. }
  25. if ( this.clearColor ) {
  26. renderer.getClearColor( this._oldClearColor );
  27. oldClearAlpha = renderer.getClearAlpha();
  28. renderer.setClearColor( this.clearColor, this.clearAlpha );
  29. }
  30. if ( this.clearDepth ) {
  31. renderer.clearDepth();
  32. }
  33. renderer.setRenderTarget( this.renderToScreen ? null : readBuffer ); // TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600
  34. if ( this.clear ) renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  35. renderer.render( this.scene, this.camera );
  36. if ( this.clearColor ) {
  37. renderer.setClearColor( this._oldClearColor, oldClearAlpha );
  38. }
  39. if ( this.overrideMaterial !== undefined ) {
  40. this.scene.overrideMaterial = oldOverrideMaterial;
  41. }
  42. renderer.autoClear = oldAutoClear;
  43. }
  44. }
  45. THREE.RenderPass = RenderPass;
  46. } )();