ShaderPass.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. */
  4. THREE.ShaderPass = function( shader, textureID ) {
  5. THREE.Pass.call( this );
  6. this.textureID = ( textureID !== undefined ) ? textureID : "tDiffuse";
  7. if ( shader instanceof THREE.ShaderMaterial ) {
  8. this.uniforms = shader.uniforms;
  9. this.material = shader;
  10. }
  11. else if ( shader ) {
  12. this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
  13. this.material = new THREE.ShaderMaterial( {
  14. defines: shader.defines || {},
  15. uniforms: this.uniforms,
  16. vertexShader: shader.vertexShader,
  17. fragmentShader: shader.fragmentShader
  18. } );
  19. }
  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.ShaderPass.prototype = Object.create( THREE.Pass.prototype );
  26. Object.assign( THREE.ShaderPass.prototype, {
  27. render: function( renderer, writeBuffer, readBuffer, delta, maskActive ) {
  28. if ( this.uniforms[ this.textureID ] ) {
  29. this.uniforms[ this.textureID ].value = readBuffer.texture;
  30. }
  31. this.quad.material = this.material;
  32. if ( this.renderToScreen ) {
  33. renderer.render( this.scene, this.camera );
  34. } else {
  35. renderer.render( this.scene, this.camera, writeBuffer, this.clear );
  36. }
  37. }
  38. } );