ShaderPass.js 1.3 KB

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