NodePass.js 1.7 KB

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