RenderPass.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/#manual/en/introduction/Installation." );
  2. THREE.RenderPass = function ( scene, camera, overrideMaterial, clearColor, clearAlpha ) {
  3. THREE.Pass.call( this );
  4. this.scene = scene;
  5. this.camera = camera;
  6. this.overrideMaterial = overrideMaterial;
  7. this.clearColor = clearColor;
  8. this.clearAlpha = ( clearAlpha !== undefined ) ? clearAlpha : 0;
  9. this.clear = true;
  10. this.clearDepth = false;
  11. this.needsSwap = false;
  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 oldClearColor, oldClearAlpha, oldOverrideMaterial;
  19. if ( this.overrideMaterial !== undefined ) {
  20. oldOverrideMaterial = this.scene.overrideMaterial;
  21. this.scene.overrideMaterial = this.overrideMaterial;
  22. }
  23. if ( this.clearColor ) {
  24. oldClearColor = renderer.getClearColor().getHex();
  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( oldClearColor, oldClearAlpha );
  37. }
  38. if ( this.overrideMaterial !== undefined ) {
  39. this.scene.overrideMaterial = oldOverrideMaterial;
  40. }
  41. renderer.autoClear = oldAutoClear;
  42. }
  43. } );