ShaderPass.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. */
  4. THREE.ShaderPass = function ( shader, textureID ) {
  5. this.textureID = ( textureID !== undefined ) ? textureID : "tDiffuse";
  6. this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
  7. this.material = new THREE.ShaderMaterial( {
  8. uniforms: this.uniforms,
  9. vertexShader: shader.vertexShader,
  10. fragmentShader: shader.fragmentShader
  11. } );
  12. this.renderToScreen = false;
  13. this.enabled = true;
  14. this.needsSwap = true;
  15. this.clear = false;
  16. this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
  17. this.scene = new THREE.Scene();
  18. this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
  19. this.scene.add( this.quad );
  20. };
  21. THREE.ShaderPass.prototype = {
  22. render: function ( renderer, writeBuffer, readBuffer, delta ) {
  23. if ( this.uniforms[ this.textureID ] ) {
  24. this.uniforms[ this.textureID ].value = readBuffer;
  25. }
  26. this.quad.material = this.material;
  27. if ( this.renderToScreen ) {
  28. renderer.render( this.scene, this.camera );
  29. } else {
  30. renderer.render( this.scene, this.camera, writeBuffer, this.clear );
  31. }
  32. }
  33. };