RenderPass.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. console.warn( "THREE.RenderPass: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/index.html#manual/en/introduction/Import-via-modules." );
  2. /**
  3. * @author alteredq / http://alteredqualia.com/
  4. */
  5. THREE.RenderPass = function ( scene, camera, overrideMaterial, clearColor, clearAlpha ) {
  6. THREE.Pass.call( this );
  7. this.scene = scene;
  8. this.camera = camera;
  9. this.overrideMaterial = overrideMaterial;
  10. this.clearColor = clearColor;
  11. this.clearAlpha = ( clearAlpha !== undefined ) ? clearAlpha : 0;
  12. this.clear = true;
  13. this.clearDepth = false;
  14. this.needsSwap = false;
  15. };
  16. THREE.RenderPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
  17. constructor: THREE.RenderPass,
  18. render: function ( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) {
  19. var oldAutoClear = renderer.autoClear;
  20. renderer.autoClear = false;
  21. var oldClearColor, oldClearAlpha, oldOverrideMaterial;
  22. if ( this.overrideMaterial !== undefined ) {
  23. oldOverrideMaterial = this.scene.overrideMaterial;
  24. this.scene.overrideMaterial = this.overrideMaterial;
  25. }
  26. if ( this.clearColor ) {
  27. oldClearColor = renderer.getClearColor().getHex();
  28. oldClearAlpha = renderer.getClearAlpha();
  29. renderer.setClearColor( this.clearColor, this.clearAlpha );
  30. }
  31. if ( this.clearDepth ) {
  32. renderer.clearDepth();
  33. }
  34. renderer.setRenderTarget( this.renderToScreen ? null : readBuffer );
  35. // TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600
  36. if ( this.clear ) renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  37. renderer.render( this.scene, this.camera );
  38. if ( this.clearColor ) {
  39. renderer.setClearColor( oldClearColor, oldClearAlpha );
  40. }
  41. if ( this.overrideMaterial !== undefined ) {
  42. this.scene.overrideMaterial = oldOverrideMaterial;
  43. }
  44. renderer.autoClear = oldAutoClear;
  45. }
  46. } );