FilmPass.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. */
  4. THREE.FilmPass = function ( noiseIntensity, scanlinesIntensity, scanlinesCount, grayscale ) {
  5. THREE.Pass.call( this );
  6. if ( THREE.FilmShader === undefined )
  7. console.error( "THREE.FilmPass relies on THREE.FilmShader" );
  8. var shader = THREE.FilmShader;
  9. this.uniforms = Object.assign( {}, shader.uniforms );
  10. this.material = new THREE.ShaderMaterial( {
  11. uniforms: this.uniforms,
  12. vertexShader: shader.vertexShader,
  13. fragmentShader: shader.fragmentShader
  14. } );
  15. this.uniforms[ "tDiffuse" ] = new THREE.Uniform();
  16. this.uniforms[ "time" ] = new THREE.Uniform( 0 );
  17. if ( grayscale !== undefined ) this.uniforms.grayscale = new THREE.Uniform( grayscale );
  18. if ( noiseIntensity !== undefined ) this.uniforms.nIntensity = new THREE.Uniform( noiseIntensity );
  19. if ( scanlinesIntensity !== undefined ) this.uniforms.sIntensity = new THREE.Uniform( scanlinesIntensity );
  20. if ( scanlinesCount !== undefined ) this.uniforms.sCount = new THREE.Uniform( scanlinesCount );
  21. this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  22. this.scene = new THREE.Scene();
  23. this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
  24. this.scene.add( this.quad );
  25. };
  26. THREE.FilmPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
  27. constructor: THREE.FilmPass,
  28. render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
  29. this.uniforms[ "tDiffuse" ].value = readBuffer.texture;
  30. this.uniforms[ "time" ].value += delta;
  31. this.quad.material = this.material;
  32. if ( this.renderToScreen ) {
  33. renderer.render( this.scene, this.camera );
  34. } else {
  35. renderer.render( this.scene, this.camera, writeBuffer, this.clear );
  36. }
  37. }
  38. } );