NodePass.js 1.6 KB

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