Pass.js 1.9 KB

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