Pass.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {
  2. BufferGeometry,
  3. Float32BufferAttribute,
  4. OrthographicCamera,
  5. Mesh
  6. } from '../../../build/three.module.js';
  7. class Pass {
  8. constructor() {
  9. // if set to true, the pass is processed by the composer
  10. this.enabled = true;
  11. // if set to true, the pass indicates to swap read and write buffer after rendering
  12. this.needsSwap = true;
  13. // if set to true, the pass clears its buffer before rendering
  14. this.clear = false;
  15. // if set to true, the result of the pass is rendered to screen. This is set automatically by EffectComposer.
  16. this.renderToScreen = false;
  17. }
  18. setSize( /* width, height */ ) {}
  19. render( /* 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. const _camera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  25. // https://github.com/mrdoob/three.js/pull/21358
  26. const _geometry = new BufferGeometry();
  27. _geometry.setAttribute( 'position', new Float32BufferAttribute( [ - 1, 3, 0, - 1, - 1, 0, 3, - 1, 0 ], 3 ) );
  28. _geometry.setAttribute( 'uv', new Float32BufferAttribute( [ 0, 2, 0, 0, 2, 0 ], 2 ) );
  29. class FullScreenQuad {
  30. constructor( material ) {
  31. this._mesh = new Mesh( _geometry, material );
  32. }
  33. dispose() {
  34. this._mesh.geometry.dispose();
  35. }
  36. render( renderer ) {
  37. renderer.render( this._mesh, _camera );
  38. }
  39. get material() {
  40. return this._mesh.material;
  41. }
  42. set material( value ) {
  43. this._mesh.material = value;
  44. }
  45. }
  46. export { Pass, FullScreenQuad };