RenderPass.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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, delta, 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.render( this.scene, this.camera, this.renderToScreen ? null : readBuffer, this.clear );
  31. if ( this.clearColor ) {
  32. renderer.setClearColor( oldClearColor, oldClearAlpha );
  33. }
  34. this.scene.overrideMaterial = null;
  35. renderer.autoClear = oldAutoClear;
  36. }
  37. } );