ShaderPass.js 995 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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.MeshShaderMaterial( {
  8. uniforms: this.uniforms,
  9. vertexShader: shader.vertexShader,
  10. fragmentShader: shader.fragmentShader
  11. } );
  12. this.renderToScreen = false;
  13. this.needsSwap = true;
  14. this.clear = false;
  15. };
  16. THREE.ShaderPass.prototype = {
  17. render: function ( renderer, writeBuffer, readBuffer, delta ) {
  18. if ( this.uniforms[ this.textureID ] ) {
  19. this.uniforms[ this.textureID ].texture = readBuffer;
  20. }
  21. THREE.EffectComposer.quad.materials[ 0 ] = this.material;
  22. if ( this.renderToScreen ) {
  23. renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera );
  24. } else {
  25. renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, writeBuffer, this.clear );
  26. }
  27. }
  28. };