NodePass.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. function NodePass() {
  6. ShaderPass.call( this );
  7. this.name = '';
  8. this.uuid = MathUtils.generateUUID();
  9. this.userData = {};
  10. this.textureID = 'renderTexture';
  11. this.input = new ScreenNode();
  12. this.material = new NodeMaterial();
  13. this.needsUpdate = true;
  14. }
  15. NodePass.prototype = Object.create( ShaderPass.prototype );
  16. NodePass.prototype.constructor = NodePass;
  17. NodePass.prototype.render = function () {
  18. if ( this.needsUpdate ) {
  19. this.material.dispose();
  20. this.material.fragment.value = this.input;
  21. this.needsUpdate = false;
  22. }
  23. this.uniforms = this.material.uniforms;
  24. ShaderPass.prototype.render.apply( this, arguments );
  25. };
  26. NodePass.prototype.copy = function ( source ) {
  27. this.input = source.input;
  28. return this;
  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 };