FilmPass.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. if ( grayscale !== undefined ) this.uniforms.grayscale.value = grayscale;
  16. if ( noiseIntensity !== undefined ) this.uniforms.nIntensity.value = noiseIntensity;
  17. if ( scanlinesIntensity !== undefined ) this.uniforms.sIntensity.value = scanlinesIntensity;
  18. if ( scanlinesCount !== undefined ) this.uniforms.sCount.value = scanlinesCount;
  19. this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  20. this.scene = new THREE.Scene();
  21. this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
  22. this.scene.add( this.quad );
  23. };
  24. THREE.FilmPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
  25. constructor: THREE.FilmPass,
  26. render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
  27. this.uniforms[ "tDiffuse" ].value = readBuffer.texture;
  28. this.uniforms[ "time" ].value += delta;
  29. this.quad.material = this.material;
  30. if ( this.renderToScreen ) {
  31. renderer.render( this.scene, this.camera );
  32. } else {
  33. renderer.render( this.scene, this.camera, writeBuffer, this.clear );
  34. }
  35. }
  36. } );