NodePass.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.toJSON = function ( meta ) {
  33. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  34. if ( isRootObject ) {
  35. meta = {
  36. nodes: {}
  37. };
  38. }
  39. if ( meta && ! meta.passes ) meta.passes = {};
  40. if ( ! meta.passes[ this.uuid ] ) {
  41. var data = {};
  42. data.uuid = this.uuid;
  43. data.type = "NodePass";
  44. meta.passes[ this.uuid ] = data;
  45. if ( this.name !== "" ) data.name = this.name;
  46. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  47. data.value = this.value.toJSON( meta ).uuid;
  48. }
  49. meta.pass = this.uuid;
  50. return meta;
  51. };