RenderPass.js 1.7 KB

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