FilmPass.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. */
  4. THREE.FilmPass = function ( noiseIntensity, scanlinesIntensity, scanlinesCount, grayscale ) {
  5. if ( THREE.FilmShader === undefined )
  6. console.error( "THREE.FilmPass relies on THREE.FilmShader" );
  7. var shader = THREE.FilmShader;
  8. this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
  9. this.material = new THREE.ShaderMaterial( {
  10. uniforms: this.uniforms,
  11. vertexShader: shader.vertexShader,
  12. fragmentShader: shader.fragmentShader
  13. } );
  14. if ( grayscale !== undefined ) this.uniforms.grayscale.value = grayscale;
  15. if ( noiseIntensity !== undefined ) this.uniforms.nIntensity.value = noiseIntensity;
  16. if ( scanlinesIntensity !== undefined ) this.uniforms.sIntensity.value = scanlinesIntensity;
  17. if ( scanlinesCount !== undefined ) this.uniforms.sCount.value = scanlinesCount;
  18. this.enabled = true;
  19. this.renderToScreen = false;
  20. this.needsSwap = true;
  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 = {
  27. render: function ( renderer, writeBuffer, readBuffer, delta ) {
  28. this.uniforms[ "tDiffuse" ].value = readBuffer;
  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, false );
  35. }
  36. }
  37. };