TexturePass.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. */
  4. THREE.TexturePass = function ( map, 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.map = map;
  10. this.opacity = ( opacity !== undefined ) ? opacity : 1.0;
  11. this.uniforms = Object.assign( {}, shader.uniforms );
  12. this.material = new THREE.ShaderMaterial( {
  13. uniforms: this.uniforms,
  14. vertexShader: shader.vertexShader,
  15. fragmentShader: shader.fragmentShader,
  16. depthTest: false,
  17. depthWrite: false
  18. } );
  19. this.needsSwap = false;
  20. this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  21. this.scene = new THREE.Scene();
  22. this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
  23. this.scene.add( this.quad );
  24. };
  25. THREE.TexturePass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
  26. constructor: THREE.TexturePass,
  27. render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
  28. var oldAutoClear = renderer.autoClear;
  29. renderer.autoClear = false;
  30. this.quad.material = this.material;
  31. this.uniforms[ "opacity" ].value = this.opacity;
  32. this.uniforms[ "tDiffuse" ].value = this.map;
  33. this.material.transparent = ( this.opacity < 1.0 );
  34. renderer.render( this.scene, this.camera, this.renderToScreen ? null : readBuffer, this.clear );
  35. renderer.autoClear = oldAutoClear;
  36. }
  37. } );