Pass.js 1.5 KB

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