HalftonePass.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ( function () {
  2. /**
  3. * RGB Halftone pass for three.js effects composer. Requires THREE.HalftoneShader.
  4. */
  5. class HalftonePass extends THREE.Pass {
  6. constructor( width, height, params ) {
  7. super();
  8. if ( THREE.HalftoneShader === undefined ) {
  9. console.error( 'THREE.HalftonePass requires THREE.HalftoneShader' );
  10. }
  11. this.uniforms = THREE.UniformsUtils.clone( THREE.HalftoneShader.uniforms );
  12. this.material = new THREE.ShaderMaterial( {
  13. uniforms: this.uniforms,
  14. fragmentShader: THREE.HalftoneShader.fragmentShader,
  15. vertexShader: THREE.HalftoneShader.vertexShader
  16. } ); // set params
  17. this.uniforms.width.value = width;
  18. this.uniforms.height.value = height;
  19. for ( const key in params ) {
  20. if ( params.hasOwnProperty( key ) && this.uniforms.hasOwnProperty( key ) ) {
  21. this.uniforms[ key ].value = params[ key ];
  22. }
  23. }
  24. this.fsQuad = new THREE.FullScreenQuad( this.material );
  25. }
  26. render( renderer, writeBuffer, readBuffer
  27. /*, deltaTime, maskActive*/
  28. ) {
  29. this.material.uniforms[ 'tDiffuse' ].value = readBuffer.texture;
  30. if ( this.renderToScreen ) {
  31. renderer.setRenderTarget( null );
  32. this.fsQuad.render( renderer );
  33. } else {
  34. renderer.setRenderTarget( writeBuffer );
  35. if ( this.clear ) renderer.clear();
  36. this.fsQuad.render( renderer );
  37. }
  38. }
  39. setSize( width, height ) {
  40. this.uniforms.width.value = width;
  41. this.uniforms.height.value = height;
  42. }
  43. }
  44. THREE.HalftonePass = HalftonePass;
  45. } )();