2
0

HalftonePass.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * @author meatbags / xavierburrow.com, github/meatbags
  3. *
  4. * RGB Halftone pass for three.js effects composer. Requires THREE.HalftoneShader.
  5. *
  6. */
  7. THREE.HalftonePass = function ( width, height ) {
  8. THREE.Pass.call( this );
  9. this.width = width;
  10. this.height = height;
  11. if ( THREE.HalftoneShader === undefined ) {
  12. console.error( 'THREE.HalftonePass requires THREE.HalftoneShader' );
  13. }
  14. this.uniforms = THREE.UniformsUtils.clone( THREE.HalftoneShader.uniforms );
  15. this.material = new THREE.ShaderMaterial( {
  16. uniforms: this.uniforms,
  17. fragmentShader: THREE.HalftoneShader.fragmentShader,
  18. vertexShader: THREE.HalftoneShader.vertexShader
  19. } );
  20. this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  21. this.scene = new THREE.Scene();
  22. this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
  23. this.quad.frustumCulled = false;
  24. this.scene.add( this.quad );
  25. };
  26. THREE.HalftonePass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
  27. constructor: THREE.HalftonePass,
  28. render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
  29. this.material.uniforms[ "tDiffuse" ].value = readBuffer.texture;
  30. this.quad.material = this.material;
  31. if ( this.renderToScreen ) {
  32. renderer.render( this.scene, this.camera );
  33. } else {
  34. renderer.render( this.scene, this.camera, writeBuffer, this.clear );
  35. }
  36. },
  37. setSize: function ( width, height ) {
  38. this.width = width;
  39. this.height = height;
  40. this.uniforms[ 'width' ].value = this.width;
  41. this.uniforms[ 'height' ].value = this.height;
  42. }
  43. } );