NodePass.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.NodePass = function () {
  5. THREE.ShaderPass.call( this );
  6. this.name = "";
  7. this.uuid = THREE.Math.generateUUID();
  8. this.userData = {};
  9. this.textureID = 'renderTexture';
  10. this.fragment = new THREE.RawNode( new THREE.ScreenNode() );
  11. this.node = new THREE.NodeMaterial();
  12. this.node.fragment = this.fragment;
  13. this.build();
  14. };
  15. THREE.NodePass.prototype = Object.create( THREE.ShaderPass.prototype );
  16. THREE.NodePass.prototype.constructor = THREE.NodePass;
  17. THREE.NodeMaterial.addShortcuts( THREE.NodePass.prototype, 'fragment', [ 'value' ] );
  18. THREE.NodePass.prototype.build = function () {
  19. this.node.build();
  20. this.uniforms = this.node.uniforms;
  21. this.material = this.node;
  22. };
  23. THREE.NodePass.prototype.toJSON = function ( meta ) {
  24. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  25. if ( isRootObject ) {
  26. meta = {
  27. nodes: {}
  28. };
  29. }
  30. if ( meta && ! meta.passes ) meta.passes = {};
  31. if ( ! meta.passes[ this.uuid ] ) {
  32. var data = {};
  33. data.uuid = this.uuid;
  34. data.type = "NodePass";
  35. meta.passes[ this.uuid ] = data;
  36. if ( this.name !== "" ) data.name = this.name;
  37. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  38. data.value = this.value.toJSON( meta ).uuid;
  39. }
  40. meta.pass = this.uuid;
  41. return meta;
  42. };