Pass.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import {
  2. BufferGeometry,
  3. Float32BufferAttribute,
  4. OrthographicCamera,
  5. Mesh
  6. } from '../../../build/three.module.js';
  7. function Pass() {
  8. // if set to true, the pass is processed by the composer
  9. this.enabled = true;
  10. // if set to true, the pass indicates to swap read and write buffer after rendering
  11. this.needsSwap = true;
  12. // if set to true, the pass clears its buffer before rendering
  13. this.clear = false;
  14. // if set to true, the result of the pass is rendered to screen. This is set automatically by EffectComposer.
  15. this.renderToScreen = false;
  16. }
  17. Object.assign( Pass.prototype, {
  18. setSize: function ( /* width, height */ ) {},
  19. render: function ( /* renderer, writeBuffer, readBuffer, deltaTime, maskActive */ ) {
  20. console.error( 'THREE.Pass: .render() must be implemented in derived pass.' );
  21. }
  22. } );
  23. // Helper for passes that need to fill the viewport with a single quad.
  24. // Important: It's actually a hack to put FullScreenQuad into the Pass namespace. This is only
  25. // done to make examples/js code work. Normally, FullScreenQuad should be exported
  26. // from this module like Pass.
  27. Pass.FullScreenQuad = ( function () {
  28. var camera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  29. // https://github.com/mrdoob/three.js/pull/21358
  30. var geometry = new BufferGeometry();
  31. geometry.setAttribute( 'position', new Float32BufferAttribute( [ - 1, 3, 0, - 1, - 1, 0, 3, - 1, 0 ], 3 ) );
  32. geometry.setAttribute( 'uv', new Float32BufferAttribute( [ 0, 2, 0, 0, 2, 0 ], 2 ) );
  33. var FullScreenQuad = function ( material ) {
  34. this._mesh = new Mesh( geometry, material );
  35. };
  36. Object.defineProperty( FullScreenQuad.prototype, 'material', {
  37. get: function () {
  38. return this._mesh.material;
  39. },
  40. set: function ( value ) {
  41. this._mesh.material = value;
  42. }
  43. } );
  44. Object.assign( FullScreenQuad.prototype, {
  45. dispose: function () {
  46. this._mesh.geometry.dispose();
  47. },
  48. render: function ( renderer ) {
  49. renderer.render( this._mesh, camera );
  50. }
  51. } );
  52. return FullScreenQuad;
  53. } )();
  54. export { Pass };