TexturePass.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 = THREE.UniformsUtils.clone( 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.quad.frustumCulled = false; // Avoid getting clipped
  24. this.scene.add( this.quad );
  25. };
  26. THREE.TexturePass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
  27. constructor: THREE.TexturePass,
  28. render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
  29. var oldAutoClear = renderer.autoClear;
  30. renderer.autoClear = false;
  31. this.quad.material = this.material;
  32. this.uniforms[ "opacity" ].value = this.opacity;
  33. this.uniforms[ "tDiffuse" ].value = this.map;
  34. this.material.transparent = ( this.opacity < 1.0 );
  35. renderer.render( this.scene, this.camera, this.renderToScreen ? null : readBuffer, this.clear );
  36. renderer.autoClear = oldAutoClear;
  37. }
  38. } );