NodePass.js 1.4 KB

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