OutputPass.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import {
  2. ShaderMaterial,
  3. UniformsUtils,
  4. NoToneMapping,
  5. LinearToneMapping,
  6. ReinhardToneMapping,
  7. CineonToneMapping,
  8. ACESFilmicToneMapping
  9. } from 'three';
  10. import { Pass, FullScreenQuad } from './Pass.js';
  11. import { OutputShader } from '../shaders/OutputShader.js';
  12. class OutputPass extends Pass {
  13. constructor( toneMapping = NoToneMapping, toneMappingExposure = 1 ) {
  14. super();
  15. this.toneMapping = toneMapping;
  16. this.toneMappingExposure = toneMappingExposure;
  17. //
  18. const shader = OutputShader;
  19. this.uniforms = UniformsUtils.clone( shader.uniforms );
  20. this.material = new ShaderMaterial( {
  21. uniforms: this.uniforms,
  22. vertexShader: shader.vertexShader,
  23. fragmentShader: shader.fragmentShader
  24. } );
  25. if ( toneMapping === LinearToneMapping ) this.material.defines.LINEAR_TONE_MAPPING = '';
  26. else if ( toneMapping === ReinhardToneMapping ) this.material.defines.REINHARD_TONE_MAPPING = '';
  27. else if ( toneMapping === CineonToneMapping ) this.material.defines.CINEON_TONE_MAPPING = '';
  28. else if ( toneMapping === ACESFilmicToneMapping ) this.material.defines.ACES_FILMIC_TONE_MAPPING = '';
  29. this.fsQuad = new FullScreenQuad( this.material );
  30. }
  31. render( renderer, writeBuffer, readBuffer/*, deltaTime, maskActive */ ) {
  32. this.uniforms[ 'tDiffuse' ].value = readBuffer.texture;
  33. this.uniforms[ 'toneMappingExposure' ].value = this.toneMappingExposure;
  34. if ( this.renderToScreen === true ) {
  35. renderer.setRenderTarget( null );
  36. this.fsQuad.render( renderer );
  37. } else {
  38. renderer.setRenderTarget( writeBuffer );
  39. if ( this.clear ) renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  40. this.fsQuad.render( renderer );
  41. }
  42. }
  43. dispose() {
  44. this.material.dispose();
  45. this.fsQuad.dispose();
  46. }
  47. }
  48. export { OutputPass };