NodeBuilder.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
  1. import NodeUniform from './NodeUniform.js';
  2. import NodeAttribute from './NodeAttribute.js';
  3. import NodeVarying from './NodeVarying.js';
  4. import NodeVar from './NodeVar.js';
  5. import NodeCode from './NodeCode.js';
  6. import NodeKeywords from './NodeKeywords.js';
  7. import NodeCache from './NodeCache.js';
  8. import { NodeUpdateType, defaultBuildStages, shaderStages } from './constants.js';
  9. import { REVISION, NoColorSpace, LinearEncoding, sRGBEncoding, SRGBColorSpace, Color, Vector2, Vector3, Vector4, Float16BufferAttribute } from 'three';
  10. import { stack } from './StackNode.js';
  11. import { maxMipLevel } from '../utils/MaxMipLevelNode.js';
  12. const typeFromLength = new Map( [
  13. [ 2, 'vec2' ],
  14. [ 3, 'vec3' ],
  15. [ 4, 'vec4' ],
  16. [ 9, 'mat3' ],
  17. [ 16, 'mat4' ]
  18. ] );
  19. const typeFromArray = new Map( [
  20. [ Int8Array, 'int' ],
  21. [ Int16Array, 'int' ],
  22. [ Int32Array, 'int' ],
  23. [ Uint8Array, 'uint' ],
  24. [ Uint16Array, 'uint' ],
  25. [ Uint32Array, 'uint' ],
  26. [ Float32Array, 'float' ]
  27. ] );
  28. const isNonPaddingElementArray = new Set( [ Int32Array, Uint32Array, Float32Array ] );
  29. const toFloat = ( value ) => {
  30. value = Number( value );
  31. return value + ( value % 1 ? '' : '.0' );
  32. };
  33. class NodeBuilder {
  34. constructor( object, renderer, parser ) {
  35. this.object = object;
  36. this.material = object && ( object.material || null );
  37. this.geometry = object && ( object.geometry || null );
  38. this.renderer = renderer;
  39. this.parser = parser;
  40. this.nodes = [];
  41. this.updateNodes = [];
  42. this.updateBeforeNodes = [];
  43. this.hashNodes = {};
  44. this.lightsNode = null;
  45. this.environmentNode = null;
  46. this.fogNode = null;
  47. this.toneMappingNode = null;
  48. this.vertexShader = null;
  49. this.fragmentShader = null;
  50. this.computeShader = null;
  51. this.flowNodes = { vertex: [], fragment: [], compute: [] };
  52. this.flowCode = { vertex: '', fragment: '', compute: [] };
  53. this.uniforms = { vertex: [], fragment: [], compute: [], index: 0 };
  54. this.codes = { vertex: [], fragment: [], compute: [] };
  55. this.bindings = { vertex: [], fragment: [], compute: [] };
  56. this.bindingsOffset = { vertex: 0, fragment: 0, compute: 0 };
  57. this.bindingsArray = null;
  58. this.attributes = [];
  59. this.bufferAttributes = [];
  60. this.varyings = [];
  61. this.vars = { vertex: [], fragment: [], compute: [] };
  62. this.flow = { code: '' };
  63. this.chaining = [];
  64. this.stack = stack();
  65. this.tab = '\t';
  66. this.context = {
  67. keywords: new NodeKeywords(),
  68. material: this.material,
  69. getMIPLevelAlgorithmNode: ( textureNode, levelNode ) => levelNode.mul( maxMipLevel( textureNode ) )
  70. };
  71. this.cache = new NodeCache();
  72. this.globalCache = this.cache;
  73. this.flowsData = new WeakMap();
  74. this.shaderStage = null;
  75. this.buildStage = null;
  76. }
  77. getBindings() {
  78. let bindingsArray = this.bindingsArray;
  79. if ( bindingsArray === null ) {
  80. const bindings = this.bindings;
  81. this.bindingsArray = bindingsArray = ( this.material !== null ) ? [ ...bindings.vertex, ...bindings.fragment ] : bindings.compute;
  82. }
  83. return bindingsArray;
  84. }
  85. setHashNode( node, hash ) {
  86. this.hashNodes[ hash ] = node;
  87. }
  88. addNode( node ) {
  89. if ( this.nodes.indexOf( node ) === - 1 ) {
  90. const updateType = node.getUpdateType();
  91. const updateBeforeType = node.getUpdateBeforeType();
  92. if ( updateType !== NodeUpdateType.NONE ) {
  93. this.updateNodes.push( node );
  94. }
  95. if ( updateBeforeType !== NodeUpdateType.NONE ) {
  96. this.updateBeforeNodes.push( node );
  97. }
  98. this.nodes.push( node );
  99. this.setHashNode( node, node.getHash( this ) );
  100. }
  101. }
  102. get currentNode() {
  103. return this.chaining[ this.chaining.length - 1 ];
  104. }
  105. addChain( node ) {
  106. /*
  107. if ( this.chaining.indexOf( node ) !== - 1 ) {
  108. console.warn( 'Recursive node: ', node );
  109. }
  110. */
  111. this.chaining.push( node );
  112. }
  113. removeChain( node ) {
  114. const lastChain = this.chaining.pop();
  115. if ( lastChain !== node ) {
  116. throw new Error( 'NodeBuilder: Invalid node chaining!' );
  117. }
  118. }
  119. getMethod( method ) {
  120. return method;
  121. }
  122. getNodeFromHash( hash ) {
  123. return this.hashNodes[ hash ];
  124. }
  125. addFlow( shaderStage, node ) {
  126. this.flowNodes[ shaderStage ].push( node );
  127. return node;
  128. }
  129. setContext( context ) {
  130. this.context = context;
  131. }
  132. getContext() {
  133. return this.context;
  134. }
  135. setCache( cache ) {
  136. this.cache = cache;
  137. }
  138. getCache() {
  139. return this.cache;
  140. }
  141. isAvailable( /*name*/ ) {
  142. return false;
  143. }
  144. getInstanceIndex() {
  145. console.warn( 'Abstract function.' );
  146. }
  147. getFrontFacing() {
  148. console.warn( 'Abstract function.' );
  149. }
  150. getFragCoord() {
  151. console.warn( 'Abstract function.' );
  152. }
  153. isFlipY() {
  154. return false;
  155. }
  156. getTexture( /* texture, textureProperty, uvSnippet */ ) {
  157. console.warn( 'Abstract function.' );
  158. }
  159. getTextureLevel( /* texture, textureProperty, uvSnippet, levelSnippet */ ) {
  160. console.warn( 'Abstract function.' );
  161. }
  162. // @TODO: rename to .generateConst()
  163. getConst( type, value = null ) {
  164. if ( value === null ) {
  165. if ( type === 'float' || type === 'int' || type === 'uint' ) value = 0;
  166. else if ( type === 'bool' ) value = false;
  167. else if ( type === 'color' ) value = new Color();
  168. else if ( type === 'vec2' ) value = new Vector2();
  169. else if ( type === 'vec3' ) value = new Vector3();
  170. else if ( type === 'vec4' ) value = new Vector4();
  171. }
  172. if ( type === 'float' ) return toFloat( value );
  173. if ( type === 'int' ) return `${ Math.round( value ) }`;
  174. if ( type === 'uint' ) return value >= 0 ? `${ Math.round( value ) }u` : '0u';
  175. if ( type === 'bool' ) return value ? 'true' : 'false';
  176. if ( type === 'color' ) return `${ this.getType( 'vec3' ) }( ${ toFloat( value.r ) }, ${ toFloat( value.g ) }, ${ toFloat( value.b ) } )`;
  177. const typeLength = this.getTypeLength( type );
  178. const componentType = this.getComponentType( type );
  179. const getConst = value => this.getConst( componentType, value );
  180. if ( typeLength === 2 ) {
  181. return `${ this.getType( type ) }( ${ getConst( value.x ) }, ${ getConst( value.y ) } )`;
  182. } else if ( typeLength === 3 ) {
  183. return `${ this.getType( type ) }( ${ getConst( value.x ) }, ${ getConst( value.y ) }, ${ getConst( value.z ) } )`;
  184. } else if ( typeLength === 4 ) {
  185. return `${ this.getType( type ) }( ${ getConst( value.x ) }, ${ getConst( value.y ) }, ${ getConst( value.z ) }, ${ getConst( value.w ) } )`;
  186. } else if ( typeLength > 4 && value && ( value.isMatrix3 || value.isMatrix4 ) ) {
  187. return `${ this.getType( type ) }( ${ value.elements.map( getConst ).join( ', ' ) } )`;
  188. } else if ( typeLength > 4 ) {
  189. return `${ this.getType( type ) }()`;
  190. }
  191. throw new Error( `NodeBuilder: Type '${type}' not found in generate constant attempt.` );
  192. }
  193. getType( type ) {
  194. return type;
  195. }
  196. generateMethod( method ) {
  197. return method;
  198. }
  199. hasGeometryAttribute( name ) {
  200. return this.geometry && this.geometry.getAttribute( name ) !== undefined;
  201. }
  202. getAttribute( name, type ) {
  203. const attributes = this.attributes;
  204. // find attribute
  205. for ( const attribute of attributes ) {
  206. if ( attribute.name === name ) {
  207. return attribute;
  208. }
  209. }
  210. // create a new if no exist
  211. const attribute = new NodeAttribute( name, type );
  212. attributes.push( attribute );
  213. return attribute;
  214. }
  215. getPropertyName( node/*, shaderStage*/ ) {
  216. return node.name;
  217. }
  218. isVector( type ) {
  219. return /vec\d/.test( type );
  220. }
  221. isMatrix( type ) {
  222. return /mat\d/.test( type );
  223. }
  224. isReference( type ) {
  225. return type === 'void' || type === 'property' || type === 'sampler' || type === 'texture' || type === 'cubeTexture';
  226. }
  227. /** @deprecated, r152 */
  228. getTextureEncodingFromMap( map ) {
  229. console.warn( 'THREE.NodeBuilder: Method .getTextureEncodingFromMap replaced by .getTextureColorSpaceFromMap in r152+.' );
  230. return this.getTextureColorSpaceFromMap( map ) === SRGBColorSpace ? sRGBEncoding : LinearEncoding;
  231. }
  232. getTextureColorSpaceFromMap( map ) {
  233. let colorSpace;
  234. if ( map && map.isTexture ) {
  235. colorSpace = map.colorSpace;
  236. } else if ( map && map.isWebGLRenderTarget ) {
  237. colorSpace = map.texture.colorSpace;
  238. } else {
  239. colorSpace = NoColorSpace;
  240. }
  241. return colorSpace;
  242. }
  243. getComponentType( type ) {
  244. type = this.getVectorType( type );
  245. if ( type === 'float' || type === 'bool' || type === 'int' || type === 'uint' ) return type;
  246. const componentType = /(b|i|u|)(vec|mat)([2-4])/.exec( type );
  247. if ( componentType === null ) return null;
  248. if ( componentType[ 1 ] === 'b' ) return 'bool';
  249. if ( componentType[ 1 ] === 'i' ) return 'int';
  250. if ( componentType[ 1 ] === 'u' ) return 'uint';
  251. return 'float';
  252. }
  253. getVectorType( type ) {
  254. if ( type === 'color' ) return 'vec3';
  255. if ( type === 'texture' ) return 'vec4';
  256. return type;
  257. }
  258. getTypeFromLength( length, componentType = 'float' ) {
  259. if ( length === 1 ) return componentType;
  260. const baseType = typeFromLength.get( length );
  261. const prefix = componentType === 'float' ? '' : componentType[ 0 ];
  262. return prefix + baseType;
  263. }
  264. getTypeFromArray( array ) {
  265. return typeFromArray.get( array.constructor );
  266. }
  267. getTypeFromAttribute( attribute ) {
  268. let dataAttribute = attribute;
  269. if ( attribute.isInterleavedBufferAttribute ) dataAttribute = attribute.data;
  270. const array = dataAttribute.array;
  271. const itemSize = isNonPaddingElementArray.has( array.constructor ) ? attribute.itemSize : dataAttribute.stride || attribute.itemSize;
  272. const normalized = attribute.normalized;
  273. let arrayType;
  274. if ( ! ( attribute instanceof Float16BufferAttribute ) && normalized !== true ) {
  275. arrayType = this.getTypeFromArray( array );
  276. }
  277. return this.getTypeFromLength( itemSize, arrayType );
  278. }
  279. getTypeLength( type ) {
  280. const vecType = this.getVectorType( type );
  281. const vecNum = /vec([2-4])/.exec( vecType );
  282. if ( vecNum !== null ) return Number( vecNum[ 1 ] );
  283. if ( vecType === 'float' || vecType === 'bool' || vecType === 'int' || vecType === 'uint' ) return 1;
  284. if ( /mat3/.test( type ) === true ) return 9;
  285. if ( /mat4/.test( type ) === true ) return 16;
  286. return 0;
  287. }
  288. getVectorFromMatrix( type ) {
  289. return type.replace( 'mat', 'vec' );
  290. }
  291. changeComponentType( type, newComponentType ) {
  292. return this.getTypeFromLength( this.getTypeLength( type ), newComponentType );
  293. }
  294. getIntegerType( type ) {
  295. const componentType = this.getComponentType( type );
  296. if ( componentType === 'int' || componentType === 'uint' ) return type;
  297. return this.changeComponentType( type, 'int' );
  298. }
  299. addStack() {
  300. this.stack = stack( this.stack );
  301. return this.stack;
  302. }
  303. removeStack() {
  304. const currentStack = this.stack;
  305. this.stack = currentStack.parent;
  306. return currentStack;
  307. }
  308. getDataFromNode( node, shaderStage = this.shaderStage ) {
  309. const cache = node.isGlobal( this ) ? this.globalCache : this.cache;
  310. let nodeData = cache.getNodeData( node );
  311. if ( nodeData === undefined ) {
  312. nodeData = { vertex: {}, fragment: {}, compute: {} };
  313. cache.setNodeData( node, nodeData );
  314. }
  315. return shaderStage !== null ? nodeData[ shaderStage ] : nodeData;
  316. }
  317. getNodeProperties( node, shaderStage = this.shaderStage ) {
  318. const nodeData = this.getDataFromNode( node, shaderStage );
  319. return nodeData.properties || ( nodeData.properties = { outputNode: null } );
  320. }
  321. getBufferAttributeFromNode( node, type ) {
  322. const nodeData = this.getDataFromNode( node );
  323. let bufferAttribute = nodeData.bufferAttribute;
  324. if ( bufferAttribute === undefined ) {
  325. const index = this.uniforms.index ++;
  326. bufferAttribute = new NodeAttribute( 'nodeAttribute' + index, type, node );
  327. this.bufferAttributes.push( bufferAttribute );
  328. nodeData.bufferAttribute = bufferAttribute;
  329. }
  330. return bufferAttribute;
  331. }
  332. getUniformFromNode( node, type, shaderStage = this.shaderStage ) {
  333. const nodeData = this.getDataFromNode( node, shaderStage );
  334. let nodeUniform = nodeData.uniform;
  335. if ( nodeUniform === undefined ) {
  336. const index = this.uniforms.index ++;
  337. nodeUniform = new NodeUniform( 'nodeUniform' + index, type, node );
  338. this.uniforms[ shaderStage ].push( nodeUniform );
  339. nodeData.uniform = nodeUniform;
  340. }
  341. return nodeUniform;
  342. }
  343. getVarFromNode( node, type, shaderStage = this.shaderStage ) {
  344. const nodeData = this.getDataFromNode( node, shaderStage );
  345. let nodeVar = nodeData.variable;
  346. if ( nodeVar === undefined ) {
  347. const vars = this.vars[ shaderStage ];
  348. const index = vars.length;
  349. nodeVar = new NodeVar( 'nodeVar' + index, type );
  350. vars.push( nodeVar );
  351. nodeData.variable = nodeVar;
  352. }
  353. return nodeVar;
  354. }
  355. getVaryingFromNode( node, type ) {
  356. const nodeData = this.getDataFromNode( node, null );
  357. let nodeVarying = nodeData.varying;
  358. if ( nodeVarying === undefined ) {
  359. const varyings = this.varyings;
  360. const index = varyings.length;
  361. nodeVarying = new NodeVarying( 'nodeVarying' + index, type );
  362. varyings.push( nodeVarying );
  363. nodeData.varying = nodeVarying;
  364. }
  365. return nodeVarying;
  366. }
  367. getCodeFromNode( node, type, shaderStage = this.shaderStage ) {
  368. const nodeData = this.getDataFromNode( node );
  369. let nodeCode = nodeData.code;
  370. if ( nodeCode === undefined ) {
  371. const codes = this.codes[ shaderStage ];
  372. const index = codes.length;
  373. nodeCode = new NodeCode( 'nodeCode' + index, type );
  374. codes.push( nodeCode );
  375. nodeData.code = nodeCode;
  376. }
  377. return nodeCode;
  378. }
  379. addLineFlowCode( code ) {
  380. if ( code === '' ) return this;
  381. code = this.tab + code;
  382. if ( ! /;\s*$/.test( code ) ) {
  383. code = code + ';\n';
  384. }
  385. this.flow.code += code;
  386. return this;
  387. }
  388. addFlowCode( code ) {
  389. this.flow.code += code;
  390. return this;
  391. }
  392. addFlowTab() {
  393. this.tab += '\t';
  394. return this;
  395. }
  396. removeFlowTab() {
  397. this.tab = this.tab.slice( 0, - 1 );
  398. return this;
  399. }
  400. getFlowData( node/*, shaderStage*/ ) {
  401. return this.flowsData.get( node );
  402. }
  403. flowNode( node ) {
  404. const output = node.getNodeType( this );
  405. const flowData = this.flowChildNode( node, output );
  406. this.flowsData.set( node, flowData );
  407. return flowData;
  408. }
  409. flowChildNode( node, output = null ) {
  410. const previousFlow = this.flow;
  411. const flow = {
  412. code: '',
  413. };
  414. this.flow = flow;
  415. flow.result = node.build( this, output );
  416. this.flow = previousFlow;
  417. return flow;
  418. }
  419. flowNodeFromShaderStage( shaderStage, node, output = null, propertyName = null ) {
  420. const previousShaderStage = this.shaderStage;
  421. this.setShaderStage( shaderStage );
  422. const flowData = this.flowChildNode( node, output );
  423. if ( propertyName !== null ) {
  424. flowData.code += `${ this.tab + propertyName } = ${ flowData.result };\n`;
  425. }
  426. this.flowCode[ shaderStage ] = this.flowCode[ shaderStage ] + flowData.code;
  427. this.setShaderStage( previousShaderStage );
  428. return flowData;
  429. }
  430. getAttributesArray() {
  431. return this.attributes.concat( this.bufferAttributes );
  432. }
  433. getAttributes( /*shaderStage*/ ) {
  434. console.warn( 'Abstract function.' );
  435. }
  436. getVaryings( /*shaderStage*/ ) {
  437. console.warn( 'Abstract function.' );
  438. }
  439. getVar( type, name ) {
  440. return `${type} ${name}`;
  441. }
  442. getVars( shaderStage ) {
  443. let snippet = '';
  444. const vars = this.vars[ shaderStage ];
  445. for ( const variable of vars ) {
  446. snippet += `${ this.getVar( variable.type, variable.name ) }; `;
  447. }
  448. return snippet;
  449. }
  450. getUniforms( /*shaderStage*/ ) {
  451. console.warn( 'Abstract function.' );
  452. }
  453. getCodes( shaderStage ) {
  454. const codes = this.codes[ shaderStage ];
  455. let code = '';
  456. for ( const nodeCode of codes ) {
  457. code += nodeCode.code + '\n';
  458. }
  459. return code;
  460. }
  461. getHash() {
  462. return this.vertexShader + this.fragmentShader + this.computeShader;
  463. }
  464. setShaderStage( shaderStage ) {
  465. this.shaderStage = shaderStage;
  466. }
  467. getShaderStage() {
  468. return this.shaderStage;
  469. }
  470. setBuildStage( buildStage ) {
  471. this.buildStage = buildStage;
  472. }
  473. getBuildStage() {
  474. return this.buildStage;
  475. }
  476. buildCode() {
  477. console.warn( 'Abstract function.' );
  478. }
  479. build() {
  480. // construct() -> stage 1: create possible new nodes and returns an output reference node
  481. // analyze() -> stage 2: analyze nodes to possible optimization and validation
  482. // generate() -> stage 3: generate shader
  483. for ( const buildStage of defaultBuildStages ) {
  484. this.setBuildStage( buildStage );
  485. if ( this.context.vertex && this.context.vertex.isNode ) {
  486. this.flowNodeFromShaderStage( 'vertex', this.context.vertex );
  487. }
  488. for ( const shaderStage of shaderStages ) {
  489. this.setShaderStage( shaderStage );
  490. const flowNodes = this.flowNodes[ shaderStage ];
  491. for ( const node of flowNodes ) {
  492. if ( buildStage === 'generate' ) {
  493. this.flowNode( node );
  494. } else {
  495. node.build( this );
  496. }
  497. }
  498. }
  499. }
  500. this.setBuildStage( null );
  501. this.setShaderStage( null );
  502. // stage 4: build code for a specific output
  503. this.buildCode();
  504. return this;
  505. }
  506. format( snippet, fromType, toType ) {
  507. fromType = this.getVectorType( fromType );
  508. toType = this.getVectorType( toType );
  509. if ( fromType === toType || toType === null || this.isReference( toType ) ) {
  510. return snippet;
  511. }
  512. const fromTypeLength = this.getTypeLength( fromType );
  513. const toTypeLength = this.getTypeLength( toType );
  514. if ( fromTypeLength > 4 ) { // fromType is matrix-like
  515. // @TODO: ignore for now
  516. return snippet;
  517. }
  518. if ( toTypeLength > 4 || toTypeLength === 0 ) { // toType is matrix-like or unknown
  519. // @TODO: ignore for now
  520. return snippet;
  521. }
  522. if ( fromTypeLength === toTypeLength ) {
  523. return `${ this.getType( toType ) }( ${ snippet } )`;
  524. }
  525. if ( fromTypeLength > toTypeLength ) {
  526. return this.format( `${ snippet }.${ 'xyz'.slice( 0, toTypeLength ) }`, this.getTypeFromLength( toTypeLength, this.getComponentType( fromType ) ), toType );
  527. }
  528. if ( toTypeLength === 4 ) { // toType is vec4-like
  529. return `${ this.getType( toType ) }( ${ this.format( snippet, fromType, 'vec3' ) }, 1.0 )`;
  530. }
  531. if ( fromTypeLength === 2 ) { // fromType is vec2-like and toType is vec3-like
  532. return `${ this.getType( toType ) }( ${ this.format( snippet, fromType, 'vec2' ) }, 0.0 )`;
  533. }
  534. return `${ this.getType( toType ) }( ${ snippet } )`; // fromType is float-like
  535. }
  536. getSignature() {
  537. return `// Three.js r${ REVISION } - NodeMaterial System\n`;
  538. }
  539. }
  540. export default NodeBuilder;