TexturePass.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. */
  4. THREE.TexturePass = function ( texture, opacity ) {
  5. THREE.Pass.call( this );
  6. if ( THREE.CopyShader === undefined )
  7. console.error( "THREE.TexturePass relies on THREE.CopyShader" );
  8. var shader = THREE.CopyShader;
  9. this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
  10. this.uniforms[ "opacity" ].value = ( opacity !== undefined ) ? opacity : 1.0;
  11. this.uniforms[ "tDiffuse" ].value = texture;
  12. this.material = new THREE.ShaderMaterial( {
  13. uniforms: this.uniforms,
  14. vertexShader: shader.vertexShader,
  15. fragmentShader: shader.fragmentShader
  16. } );
  17. this.needsSwap = false;
  18. this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  19. this.scene = new THREE.Scene();
  20. this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
  21. this.scene.add( this.quad );
  22. };
  23. THREE.TexturePass.prototype = Object.create( THREE.Pass.prototype );
  24. Object.assign( THREE.TexturePass.prototype, {
  25. render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
  26. this.quad.material = this.material;
  27. renderer.render( this.scene, this.camera, readBuffer, this.clear );
  28. }
  29. } );