DotScreenPass.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import {
  2. ShaderMaterial,
  3. UniformsUtils
  4. } from '../../../build/three.module.js';
  5. import { Pass, FullScreenQuad } from './Pass.js';
  6. import { DotScreenShader } from '../shaders/DotScreenShader.js';
  7. class DotScreenPass extends Pass {
  8. constructor( center, angle, scale ) {
  9. super();
  10. if ( DotScreenShader === undefined ) console.error( 'THREE.DotScreenPass relies on DotScreenShader' );
  11. var shader = DotScreenShader;
  12. this.uniforms = UniformsUtils.clone( shader.uniforms );
  13. if ( center !== undefined ) this.uniforms[ 'center' ].value.copy( center );
  14. if ( angle !== undefined ) this.uniforms[ 'angle' ].value = angle;
  15. if ( scale !== undefined ) this.uniforms[ 'scale' ].value = scale;
  16. this.material = new ShaderMaterial( {
  17. uniforms: this.uniforms,
  18. vertexShader: shader.vertexShader,
  19. fragmentShader: shader.fragmentShader
  20. } );
  21. this.fsQuad = new FullScreenQuad( this.material );
  22. }
  23. render( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) {
  24. this.uniforms[ 'tDiffuse' ].value = readBuffer.texture;
  25. this.uniforms[ 'tSize' ].value.set( readBuffer.width, readBuffer.height );
  26. if ( this.renderToScreen ) {
  27. renderer.setRenderTarget( null );
  28. this.fsQuad.render( renderer );
  29. } else {
  30. renderer.setRenderTarget( writeBuffer );
  31. if ( this.clear ) renderer.clear();
  32. this.fsQuad.render( renderer );
  33. }
  34. }
  35. }
  36. export { DotScreenPass };