NodePass.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. this.node.build = function ( params ) {
  16. THREE.NodeMaterial.prototype.build.call( this, params );
  17. self.uniforms = this.uniforms;
  18. };
  19. };
  20. THREE.NodePass.prototype = Object.create( THREE.ShaderPass.prototype );
  21. THREE.NodePass.prototype.constructor = THREE.NodePass;
  22. THREE.NodeMaterial.addShortcuts( THREE.NodePass.prototype, 'fragment', [ 'value' ] );
  23. THREE.NodePass.prototype.render = function () {
  24. if ( this.needsUpdate ) {
  25. this.node.dispose();
  26. this.needsUpdate = false;
  27. }
  28. this.uniforms = this.node.uniforms;
  29. this.material = this.node;
  30. THREE.ShaderPass.prototype.render.apply( this, arguments );
  31. };
  32. THREE.NodePass.prototype.build = function () {
  33. this.node.build();
  34. this.needsUpdate = false;
  35. };
  36. THREE.NodePass.prototype.toJSON = function ( meta ) {
  37. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  38. if ( isRootObject ) {
  39. meta = {
  40. nodes: {}
  41. };
  42. }
  43. if ( meta && ! meta.passes ) meta.passes = {};
  44. if ( ! meta.passes[ this.uuid ] ) {
  45. var data = {};
  46. data.uuid = this.uuid;
  47. data.type = "NodePass";
  48. meta.passes[ this.uuid ] = data;
  49. if ( this.name !== "" ) data.name = this.name;
  50. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  51. data.value = this.value.toJSON( meta ).uuid;
  52. }
  53. meta.pass = this.uuid;
  54. return meta;
  55. };