Pass.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. const _geometry = new BufferGeometry();
  29. _geometry.setAttribute( 'position', new Float32BufferAttribute( [ - 1, 3, 0, - 1, - 1, 0, 3, - 1, 0 ], 3 ) );
  30. _geometry.setAttribute( 'uv', new Float32BufferAttribute( [ 0, 2, 0, 0, 2, 0 ], 2 ) );
  31. class FullScreenQuad {
  32. constructor( material ) {
  33. this._mesh = new Mesh( _geometry, material );
  34. }
  35. dispose() {
  36. this._mesh.geometry.dispose();
  37. }
  38. render( renderer ) {
  39. renderer.render( this._mesh, _camera );
  40. }
  41. get material() {
  42. return this._mesh.material;
  43. }
  44. set material( value ) {
  45. this._mesh.material = value;
  46. }
  47. }
  48. export { Pass, FullScreenQuad };