Pass.js 1.7 KB

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