HalftonePass.js 1.3 KB

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