FilmPass.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {
  2. ShaderMaterial,
  3. UniformsUtils
  4. } from 'three';
  5. import { Pass, FullScreenQuad } from './Pass.js';
  6. import { FilmShader } from '../shaders/FilmShader.js';
  7. class FilmPass extends Pass {
  8. constructor( noiseIntensity, scanlinesIntensity, scanlinesCount, grayscale ) {
  9. super();
  10. if ( FilmShader === undefined ) console.error( 'THREE.FilmPass relies on FilmShader' );
  11. const shader = FilmShader;
  12. this.uniforms = UniformsUtils.clone( shader.uniforms );
  13. this.material = new ShaderMaterial( {
  14. uniforms: this.uniforms,
  15. vertexShader: shader.vertexShader,
  16. fragmentShader: shader.fragmentShader
  17. } );
  18. if ( grayscale !== undefined ) this.uniforms.grayscale.value = grayscale;
  19. if ( noiseIntensity !== undefined ) this.uniforms.nIntensity.value = noiseIntensity;
  20. if ( scanlinesIntensity !== undefined ) this.uniforms.sIntensity.value = scanlinesIntensity;
  21. if ( scanlinesCount !== undefined ) this.uniforms.sCount.value = scanlinesCount;
  22. this.fsQuad = new FullScreenQuad( this.material );
  23. }
  24. render( renderer, writeBuffer, readBuffer, deltaTime /*, maskActive */ ) {
  25. this.uniforms[ 'tDiffuse' ].value = readBuffer.texture;
  26. this.uniforms[ 'time' ].value += deltaTime;
  27. if ( this.renderToScreen ) {
  28. renderer.setRenderTarget( null );
  29. this.fsQuad.render( renderer );
  30. } else {
  31. renderer.setRenderTarget( writeBuffer );
  32. if ( this.clear ) renderer.clear();
  33. this.fsQuad.render( renderer );
  34. }
  35. }
  36. }
  37. export { FilmPass };