FilmPass.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 = THREE.UniformsUtils.clone( 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.quad.frustumCulled = false; // Avoid getting clipped
  23. this.scene.add( this.quad );
  24. };
  25. THREE.FilmPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
  26. constructor: THREE.FilmPass,
  27. render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
  28. this.uniforms[ "tDiffuse" ].value = readBuffer.texture;
  29. this.uniforms[ "time" ].value += delta;
  30. this.quad.material = this.material;
  31. if ( this.renderToScreen ) {
  32. renderer.render( this.scene, this.camera );
  33. } else {
  34. renderer.render( this.scene, this.camera, writeBuffer, this.clear );
  35. }
  36. }
  37. } );