NodePass.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.needsUpdate = true;
  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.render = function () {
  19. if ( this.needsUpdate ) {
  20. this.node.dispose();
  21. this.needsUpdate = false;
  22. }
  23. this.uniforms = this.node.uniforms;
  24. this.material = this.node;
  25. THREE.ShaderPass.prototype.render.apply( this, arguments );
  26. };
  27. THREE.NodePass.prototype.copy = function ( source ) {
  28. this.value = source.value;
  29. };
  30. THREE.NodePass.prototype.toJSON = function ( meta ) {
  31. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  32. if ( isRootObject ) {
  33. meta = {
  34. nodes: {}
  35. };
  36. }
  37. if ( meta && ! meta.passes ) meta.passes = {};
  38. if ( ! meta.passes[ this.uuid ] ) {
  39. var data = {};
  40. data.uuid = this.uuid;
  41. data.type = "NodePass";
  42. meta.passes[ this.uuid ] = data;
  43. if ( this.name !== "" ) data.name = this.name;
  44. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  45. data.value = this.value.toJSON( meta ).uuid;
  46. }
  47. meta.pass = this.uuid;
  48. return meta;
  49. };