NodePass.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.material = new NodeMaterial();
  16. this.material.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.material.dispose();
  25. this.needsUpdate = false;
  26. }
  27. this.uniforms = this.material.uniforms;
  28. THREE.ShaderPass.prototype.render.apply( this, arguments );
  29. };
  30. NodePass.prototype.copy = function ( source ) {
  31. this.material = source.material;
  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.material = this.material.toJSON( meta ).uuid;
  49. }
  50. meta.pass = this.uuid;
  51. return meta;
  52. };
  53. export { NodePass };