ShaderPass.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. ( function () {
  2. class ShaderPass extends THREE.Pass {
  3. constructor( shader, textureID ) {
  4. super();
  5. this.textureID = textureID !== undefined ? textureID : 'tDiffuse';
  6. if ( shader instanceof THREE.ShaderMaterial ) {
  7. this.uniforms = shader.uniforms;
  8. this.material = shader;
  9. } else if ( shader ) {
  10. this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
  11. this.material = new THREE.ShaderMaterial( {
  12. defines: Object.assign( {}, shader.defines ),
  13. uniforms: this.uniforms,
  14. vertexShader: shader.vertexShader,
  15. fragmentShader: shader.fragmentShader
  16. } );
  17. }
  18. this.fsQuad = new THREE.FullScreenQuad( this.material );
  19. }
  20. render( renderer, writeBuffer, readBuffer
  21. /*, deltaTime, maskActive */
  22. ) {
  23. if ( this.uniforms[ this.textureID ] ) {
  24. this.uniforms[ this.textureID ].value = readBuffer.texture;
  25. }
  26. this.fsQuad.material = this.material;
  27. if ( this.renderToScreen ) {
  28. renderer.setRenderTarget( null );
  29. this.fsQuad.render( renderer );
  30. } else {
  31. renderer.setRenderTarget( writeBuffer ); // TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600
  32. if ( this.clear ) renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  33. this.fsQuad.render( renderer );
  34. }
  35. }
  36. }
  37. THREE.ShaderPass = ShaderPass;
  38. } )();