FilmPass.js 1.4 KB

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