FilmPass.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. */
  4. import {
  5. ShaderMaterial,
  6. UniformsUtils
  7. } from "../../../build/three.module.js";
  8. import { Pass } from "../postprocessing/Pass.js";
  9. import { FilmShader } from "../shaders/FilmShader.js";
  10. var FilmPass = function ( noiseIntensity, scanlinesIntensity, scanlinesCount, grayscale ) {
  11. Pass.call( this );
  12. if ( FilmShader === undefined )
  13. console.error( "FilmPass relies on FilmShader" );
  14. var shader = FilmShader;
  15. this.uniforms = UniformsUtils.clone( shader.uniforms );
  16. this.material = new ShaderMaterial( {
  17. uniforms: this.uniforms,
  18. vertexShader: shader.vertexShader,
  19. fragmentShader: shader.fragmentShader
  20. } );
  21. if ( grayscale !== undefined ) this.uniforms.grayscale.value = grayscale;
  22. if ( noiseIntensity !== undefined ) this.uniforms.nIntensity.value = noiseIntensity;
  23. if ( scanlinesIntensity !== undefined ) this.uniforms.sIntensity.value = scanlinesIntensity;
  24. if ( scanlinesCount !== undefined ) this.uniforms.sCount.value = scanlinesCount;
  25. this.fsQuad = new Pass.FullScreenQuad( this.material );
  26. };
  27. FilmPass.prototype = Object.assign( Object.create( Pass.prototype ), {
  28. constructor: FilmPass,
  29. render: function ( renderer, writeBuffer, readBuffer, deltaTime /*, maskActive */ ) {
  30. this.uniforms[ "tDiffuse" ].value = readBuffer.texture;
  31. this.uniforms[ "time" ].value += deltaTime;
  32. if ( this.renderToScreen ) {
  33. renderer.setRenderTarget( null );
  34. this.fsQuad.render( renderer );
  35. } else {
  36. renderer.setRenderTarget( writeBuffer );
  37. if ( this.clear ) renderer.clear();
  38. this.fsQuad.render( renderer );
  39. }
  40. }
  41. } );
  42. export { FilmPass };