NodePass.js 1.5 KB

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