NodePass.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. import { NodeMaterial } from '../materials/NodeMaterial.js';
  5. import { ScreenNode } from '../inputs/ScreenNode.js';
  6. function NodePass() {
  7. THREE.ShaderPass.call( this );
  8. this.name = "";
  9. this.uuid = THREE.Math.generateUUID();
  10. this.userData = {};
  11. this.textureID = 'renderTexture';
  12. this.input = new ScreenNode();
  13. this.material = new NodeMaterial();
  14. this.needsUpdate = true;
  15. };
  16. NodePass.prototype = Object.create( THREE.ShaderPass.prototype );
  17. NodePass.prototype.constructor = NodePass;
  18. NodePass.prototype.render = function () {
  19. if ( this.needsUpdate ) {
  20. this.material.dispose();
  21. this.material.fragment.value = this.input;
  22. this.needsUpdate = false;
  23. }
  24. this.uniforms = this.material.uniforms;
  25. THREE.ShaderPass.prototype.render.apply( this, arguments );
  26. };
  27. NodePass.prototype.copy = function ( source ) {
  28. this.input = source.input;
  29. };
  30. NodePass.prototype.toJSON = function ( meta ) {
  31. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  32. if ( isRootObject ) {
  33. meta = {
  34. nodes: {}
  35. };
  36. }
  37. if ( meta && ! meta.passes ) meta.passes = {};
  38. if ( ! meta.passes[ this.uuid ] ) {
  39. var data = {};
  40. data.uuid = this.uuid;
  41. data.type = "NodePass";
  42. meta.passes[ this.uuid ] = data;
  43. if ( this.name !== "" ) data.name = this.name;
  44. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  45. data.input = this.input.toJSON( meta ).uuid;
  46. }
  47. meta.pass = this.uuid;
  48. return meta;
  49. };
  50. export { NodePass };