TexturePass.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. */
  4. THREE.TexturePass = function ( texture, opacity ) {
  5. if ( THREE.CopyShader === undefined )
  6. console.error( "THREE.TexturePass relies on THREE.CopyShader" );
  7. var shader = THREE.CopyShader;
  8. this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
  9. this.uniforms[ "opacity" ].value = ( opacity !== undefined ) ? opacity : 1.0;
  10. this.uniforms[ "tDiffuse" ].value = texture;
  11. this.material = new THREE.ShaderMaterial( {
  12. uniforms: this.uniforms,
  13. vertexShader: shader.vertexShader,
  14. fragmentShader: shader.fragmentShader
  15. } );
  16. this.enabled = true;
  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 = {
  24. render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
  25. this.quad.material = this.material;
  26. this.quad.material.stencilTest = maskActive;
  27. renderer.render( this.scene, this.camera, readBuffer );
  28. }
  29. };