RenderPass.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. this.scene.overrideMaterial = this.overrideMaterial;
  21. var oldClearColor, oldClearAlpha;
  22. if ( this.clearColor ) {
  23. oldClearColor = renderer.getClearColor().getHex();
  24. oldClearAlpha = renderer.getClearAlpha();
  25. renderer.setClearColor( this.clearColor, this.clearAlpha );
  26. }
  27. if ( this.clearDepth ) {
  28. renderer.clearDepth();
  29. }
  30. renderer.setRenderTarget( this.renderToScreen ? null : readBuffer );
  31. if ( this.clear ) renderer.clear();
  32. renderer.render( this.scene, this.camera );
  33. if ( this.clearColor ) {
  34. renderer.setClearColor( oldClearColor, oldClearAlpha );
  35. }
  36. this.scene.overrideMaterial = null;
  37. renderer.autoClear = oldAutoClear;
  38. }
  39. } );