NodeBuilder.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. import { NodeUniform } from './NodeUniform.js';
  5. import { NodeUtils } from './NodeUtils.js';
  6. import { NodeLib } from './NodeLib.js';
  7. import { FunctionNode } from './FunctionNode.js';
  8. import { ConstNode } from './ConstNode.js';
  9. import { StructNode } from './StructNode.js';
  10. import { Vector2Node } from '../inputs/Vector2Node.js';
  11. import { Vector3Node } from '../inputs/Vector3Node.js';
  12. import { Vector4Node } from '../inputs/Vector4Node.js';
  13. import { TextureNode } from '../inputs/TextureNode.js';
  14. import { CubeTextureNode } from '../inputs/CubeTextureNode.js';
  15. var elements = NodeUtils.elements,
  16. constructors = [ 'float', 'vec2', 'vec3', 'vec4' ],
  17. formatToType = {
  18. float: 'fv1',
  19. vec2: 'v2',
  20. vec3: 'v3',
  21. vec4: 'v4',
  22. mat4: 'v4',
  23. int: 'iv1'
  24. },
  25. typeToFormat = {
  26. t: 'sampler2D',
  27. tc: 'samplerCube',
  28. bv1: 'bool',
  29. iv1: 'int',
  30. fv1: 'float',
  31. c: 'vec3',
  32. v2: 'vec2',
  33. v3: 'vec3',
  34. v4: 'vec4',
  35. m3: 'mat3',
  36. m4: 'mat4'
  37. };
  38. function NodeBuilder() {
  39. this.caches = [];
  40. this.slots = [];
  41. this.keywords = {};
  42. this.nodeData = {};
  43. this.requires = {
  44. uv: [],
  45. color: [],
  46. lights: false,
  47. fog: false
  48. };
  49. this.includes = {
  50. consts: [],
  51. functions: [],
  52. structs: []
  53. };
  54. this.attributes = {};
  55. this.prefixCode = [
  56. "#ifdef GL_EXT_shader_texture_lod",
  57. " #define texCube(a, b) textureCube(a, b)",
  58. " #define texCubeBias(a, b, c) textureCubeLodEXT(a, b, c)",
  59. " #define tex2D(a, b) texture2D(a, b)",
  60. " #define tex2DBias(a, b, c) texture2DLodEXT(a, b, c)",
  61. "#else",
  62. " #define texCube(a, b) textureCube(a, b)",
  63. " #define texCubeBias(a, b, c) textureCube(a, b, c)",
  64. " #define tex2D(a, b) texture2D(a, b)",
  65. " #define tex2DBias(a, b, c) texture2D(a, b, c)",
  66. "#endif",
  67. "#include <packing>"
  68. ].join( "\n" );
  69. this.parsCode = {
  70. vertex: '',
  71. fragment: ''
  72. };
  73. this.code = {
  74. vertex: '',
  75. fragment: ''
  76. };
  77. this.nodeCode = {
  78. vertex: '',
  79. fragment: ''
  80. };
  81. this.resultCode = {
  82. vertex: '',
  83. fragment: ''
  84. };
  85. this.finalCode = {
  86. vertex: '',
  87. fragment: ''
  88. };
  89. this.inputs = {
  90. uniforms: {
  91. list: [],
  92. vertex: [],
  93. fragment: []
  94. },
  95. vars: {
  96. varying: [],
  97. vertex: [],
  98. fragment: []
  99. }
  100. };
  101. // send to material
  102. this.defines = {};
  103. this.uniforms = {};
  104. this.extensions = {};
  105. this.nodes = [];
  106. this.updaters = [];
  107. // --
  108. this.parsing = false;
  109. this.optimize = true;
  110. this.update();
  111. };
  112. NodeBuilder.prototype = {
  113. constructor: NodeBuilder,
  114. build: function( vertex, fragment ) {
  115. this.buildShader( 'vertex', vertex );
  116. this.buildShader( 'fragment', fragment );
  117. if ( this.requires.uv[ 0 ] ) {
  118. this.addVaryCode( 'varying vec2 vUv;' );
  119. this.addVertexFinalCode( 'vUv = uv;' );
  120. }
  121. if ( this.requires.uv[ 1 ] ) {
  122. this.addVaryCode( 'varying vec2 vUv2;' );
  123. this.addVertexParsCode( 'attribute vec2 uv2;' );
  124. this.addVertexFinalCode( 'vUv2 = uv2;' );
  125. }
  126. if ( this.requires.color[ 0 ] ) {
  127. this.addVaryCode( 'varying vec4 vColor;' );
  128. this.addVertexParsCode( 'attribute vec4 color;' );
  129. this.addVertexFinalCode( 'vColor = color;' );
  130. }
  131. if ( this.requires.color[ 1 ] ) {
  132. this.addVaryCode( 'varying vec4 vColor2;' );
  133. this.addVertexParsCode( 'attribute vec4 color2;' );
  134. this.addVertexFinalCode( 'vColor2 = color2;' );
  135. }
  136. if ( this.requires.position ) {
  137. this.addVaryCode( 'varying vec3 vPosition;' );
  138. this.addVertexFinalCode( 'vPosition = transformed;' );
  139. }
  140. if ( this.requires.worldPosition ) {
  141. this.addVaryCode( 'varying vec3 vWPosition;' );
  142. this.addVertexFinalCode( 'vWPosition = ( modelMatrix * vec4( transformed, 1.0 ) ).xyz;' );
  143. }
  144. if ( this.requires.normal ) {
  145. this.addVaryCode( 'varying vec3 vObjectNormal;' );
  146. this.addVertexFinalCode( 'vObjectNormal = normal;' );
  147. }
  148. if ( this.requires.worldNormal ) {
  149. this.addVaryCode( 'varying vec3 vWNormal;' );
  150. this.addVertexFinalCode( 'vWNormal = ( modelMatrix * vec4( objectNormal, 0.0 ) ).xyz;' );
  151. }
  152. return this;
  153. },
  154. buildShader: function( shader, node ) {
  155. this.resultCode[shader] = node.build( this.setShader( shader ), 'v4' );
  156. },
  157. setMaterial: function( material, renderer ) {
  158. //this.material = material;
  159. this.renderer = renderer;
  160. this.requires.lights = material.lights;
  161. this.requires.fog = material.fog;
  162. return this;
  163. },
  164. addCache: function ( name, context ) {
  165. this.caches.push( {
  166. name: name || '',
  167. context: context || {}
  168. } );
  169. return this.update();
  170. },
  171. removeCache: function () {
  172. this.caches.pop();
  173. return this.update();
  174. },
  175. addSlot: function ( name ) {
  176. this.slots.push( {
  177. name: name || ''
  178. } );
  179. return this.update();
  180. },
  181. removeSlot: function () {
  182. this.slots.pop();
  183. return this.update();
  184. },
  185. addVertexCode: function ( code ) {
  186. this.addCode( code, 'vertex' );
  187. },
  188. addFragmentCode: function ( code ) {
  189. this.addCode( code, 'fragment' );
  190. },
  191. addCode: function ( code, shader ) {
  192. this.code[shader || this.shader] += code + '\n';
  193. },
  194. addVertexNodeCode: function ( code ) {
  195. this.addNodeCode( code, 'vertex' );
  196. },
  197. addFragmentNodeCode: function ( code ) {
  198. this.addNodeCode( code, 'fragment' );
  199. },
  200. addNodeCode: function ( code, shader ) {
  201. this.nodeCode[shader || this.shader] += code + '\n';
  202. },
  203. clearNodeCode: function ( shader ) {
  204. shader = shader || this.shader;
  205. var code = this.nodeCode[shader];
  206. this.nodeCode[shader] = '';
  207. return code;
  208. },
  209. clearVertexNodeCode: function ( ) {
  210. return this.clearNodeCode( 'vertex' );
  211. },
  212. clearFragmentNodeCode: function ( ) {
  213. return this.clearNodeCode( 'fragment' );
  214. },
  215. addVertexFinalCode: function ( code ) {
  216. this.addFinalCode( code, 'vertex' );
  217. },
  218. addFragmentFinalCode: function ( code ) {
  219. this.addFinalCode( code, 'fragment' );
  220. },
  221. addFinalCode: function ( code, shader ) {
  222. this.finalCode[shader || this.shader] += code + '\n';
  223. },
  224. addVertexParsCode: function ( code ) {
  225. this.addParsCode( code, 'vertex' );
  226. },
  227. addFragmentParsCode: function ( code ) {
  228. this.addParsCode( code, 'fragment' );
  229. },
  230. addParsCode: function ( code, shader ) {
  231. this.parsCode[shader || this.shader] += code + '\n';
  232. },
  233. addVaryCode: function ( code ) {
  234. this.addVertexParsCode( code );
  235. this.addFragmentParsCode( code );
  236. },
  237. isCache: function ( name ) {
  238. var i = this.caches.length;
  239. while ( i -- ) {
  240. if ( this.caches[ i ].name === name ) return true;
  241. }
  242. return false;
  243. },
  244. isSlot: function ( name ) {
  245. var i = this.slots.length;
  246. while ( i -- ) {
  247. if ( this.slots[ i ].name === name ) return true;
  248. }
  249. return false;
  250. },
  251. update: function () {
  252. var cache = this.caches[ this.caches.length - 1 ];
  253. var slot = this.slots[ this.slots.length - 1 ];
  254. this.slot = slot ? slot.name : '';
  255. this.cache = cache ? cache.name : '';
  256. this.context = cache ? cache.context : {};
  257. return this;
  258. },
  259. define: function ( name, value ) {
  260. this.defines[ name ] = value === undefined ? 1 : value;
  261. },
  262. isDefined: function ( name ) {
  263. return this.defines[ name ] !== undefined;
  264. },
  265. getVar: function ( uuid, type, ns, shader ) {
  266. shader = shader || 'varying';
  267. var vars = this.getVars(shader),
  268. data = vars[ uuid ];
  269. if ( ! data ) {
  270. var index = vars.length,
  271. name = ns ? ns : 'nVv' + index;
  272. data = { name: name, type: type };
  273. vars.push( data );
  274. vars[ uuid ] = data;
  275. }
  276. return data;
  277. },
  278. getTempVar: function ( uuid, type, ns ) {
  279. return this.getVar( uuid, type, ns, this.shader );
  280. },
  281. getAttribute: function ( name, type ) {
  282. if ( ! this.attributes[ name ] ) {
  283. var varying = this.getVar( name, type );
  284. this.addVertexParsCode( 'attribute ' + type + ' ' + name + ';' );
  285. this.addVertexFinalCode( varying.name + ' = ' + name + ';' );
  286. this.attributes[ name ] = { varying: varying, name: name, type: type };
  287. }
  288. return this.attributes[ name ];
  289. },
  290. getCode: function( shader ) {
  291. return [
  292. this.prefixCode,
  293. this.parsCode[ shader ],
  294. this.getVarListCode( this.getVars('varying'), 'varying' ),
  295. this.getVarListCode( this.inputs.uniforms[shader], 'uniform' ),
  296. this.getIncludesCode( 'consts', shader ),
  297. this.getIncludesCode( 'structs', shader ),
  298. this.getIncludesCode( 'functions', shader ),
  299. 'void main() {',
  300. this.getVarListCode( this.getVars(shader) ),
  301. this.code[ shader ],
  302. this.resultCode[ shader ],
  303. this.finalCode[ shader ],
  304. '}'
  305. ].join( "\n" );
  306. },
  307. getVarListCode: function ( vars, prefix ) {
  308. prefix = prefix || '';
  309. var code = '';
  310. for ( var i = 0, l = vars.length; i < l; ++ i ) {
  311. var nVar = vars[i],
  312. type = nVar.type,
  313. name = nVar.name;
  314. var formatType = this.getFormatByType( type );
  315. if ( formatType === undefined ) {
  316. throw new Error( "Node pars " + formatType + " not found." );
  317. }
  318. code += prefix + ' ' + formatType + ' ' + name + ';\n';
  319. }
  320. return code;
  321. },
  322. getVars: function ( shader ) {
  323. return this.inputs.vars[ shader || this.shader ];
  324. },
  325. getNodeData: function ( node ) {
  326. var uuid = node.isNode ? node.uuid : node;
  327. return this.nodeData[ uuid ] = this.nodeData[ uuid ] || {};
  328. },
  329. createUniform: function ( shader, type, node, ns, needsUpdate ) {
  330. var uniforms = this.inputs.uniforms,
  331. index = uniforms.list.length;
  332. var uniform = new NodeUniform( {
  333. type: type,
  334. name: ns ? ns : 'nVu' + index + '_' + THREE.Math.generateUUID().substr(0, 8),
  335. node: node,
  336. needsUpdate: needsUpdate
  337. } );
  338. uniforms.list.push( uniform );
  339. uniforms[shader].push( uniform );
  340. uniforms[shader][ uniform.name ] = uniform;
  341. this.uniforms[ uniform.name ] = uniform;
  342. return uniform;
  343. },
  344. createVertexUniform: function ( type, node, ns, needsUpdate ) {
  345. return this.createUniform( 'vertex', type, node, ns, needsUpdate );
  346. },
  347. createFragmentUniform: function ( type, node, ns, needsUpdate ) {
  348. return this.createUniform( 'fragment', type, node, ns, needsUpdate );
  349. },
  350. include: function ( node, parent, source ) {
  351. var includesStruct;
  352. node = typeof node === 'string' ? NodeLib.get( node ) : node;
  353. if ( node instanceof FunctionNode ) {
  354. includesStruct = this.includes.functions;
  355. } else if ( node instanceof ConstNode ) {
  356. includesStruct = this.includes.consts;
  357. } else if ( node instanceof StructNode ) {
  358. includesStruct = this.includes.structs;
  359. }
  360. var includes = includesStruct[ this.shader ] = includesStruct[ this.shader ] || [];
  361. if (node) {
  362. var included = includes[ node.name ];
  363. if ( ! included ) {
  364. included = includes[ node.name ] = {
  365. node: node,
  366. deps: []
  367. };
  368. includes.push( included );
  369. included.src = node.build( this, 'source' );
  370. }
  371. if ( node instanceof FunctionNode && parent && includes[ parent.name ] && includes[ parent.name ].deps.indexOf( node ) == - 1 ) {
  372. includes[ parent.name ].deps.push( node );
  373. if ( node.includes && node.includes.length ) {
  374. var i = 0;
  375. do {
  376. this.include( node.includes[ i ++ ], parent );
  377. } while ( i < node.includes.length );
  378. }
  379. }
  380. if ( source ) {
  381. included.src = source;
  382. }
  383. return node.name;
  384. } else {
  385. throw new Error("Include not found.");
  386. }
  387. },
  388. colorToVector: function ( color ) {
  389. return color.replace( 'r', 'x' ).replace( 'g', 'y' ).replace( 'b', 'z' ).replace( 'a', 'w' );
  390. },
  391. getIncludes: function ( type, shader ) {
  392. return this.includes[type][shader || this.shader];
  393. },
  394. getIncludesCode: function () {
  395. function sortByPosition( a, b ) {
  396. return a.deps.length - b.deps.length;
  397. }
  398. return function getIncludesCode( type, shader ) {
  399. var includes = this.getIncludes( type, shader );
  400. if ( ! includes ) return '';
  401. var code = '',
  402. includes = includes.sort( sortByPosition );
  403. for ( var i = 0; i < includes.length; i ++ ) {
  404. if ( includes[ i ].src ) code += includes[ i ].src + '\n';
  405. }
  406. return code;
  407. };
  408. }(),
  409. getConstructorFromLength: function ( len ) {
  410. return constructors[ len - 1 ];
  411. },
  412. getFormatName: function ( format ) {
  413. return format.replace( /c/g, 'v3' ).replace( /fv1/g, 'v1' ).replace( /iv1/g, 'i' );
  414. },
  415. isFormatMatrix: function ( format ) {
  416. return /^m/.test( format );
  417. },
  418. getFormatLength: function ( format ) {
  419. return parseInt( this.getFormatName( format ).substr( 1 ) );
  420. },
  421. getFormatFromLength: function ( len ) {
  422. if ( len === 1 ) return 'fv1';
  423. return 'v' + len;
  424. },
  425. resolve: function() {
  426. for(var i = 0; i < arguments.length; i++) {
  427. var nodeCandidate = arguments[i];
  428. if (nodeCandidate !== undefined) {
  429. if (nodeCandidate.isNode) {
  430. return nodeCandidate;
  431. } else if (nodeCandidate.isTexture) {
  432. switch( nodeCandidate.mapping ) {
  433. case THREE.CubeReflectionMapping:
  434. case THREE.CubeRefractionMapping:
  435. return new CubeTextureNode( nodeCandidate );
  436. break;
  437. case THREE.CubeUVReflectionMapping:
  438. case THREE.CubeUVRefractionMapping:
  439. return new TextureCubeNode( new TextureNode( nodeCandidate ) );
  440. break;
  441. default:
  442. return new TextureNode( nodeCandidate );
  443. }
  444. } else if (nodeCandidate.isVector2) {
  445. return new Vector2Node( nodeCandidate );
  446. } else if (nodeCandidate.isVector3) {
  447. return new Vector3Node( nodeCandidate );
  448. } else if (nodeCandidate.isVector4) {
  449. return new Vector4Node( nodeCandidate );
  450. }
  451. }
  452. }
  453. },
  454. format: function ( code, from, to ) {
  455. var format = this.getFormatName( to + ' = ' + from );
  456. switch ( format ) {
  457. case 'v1 = v2': return code + '.x';
  458. case 'v1 = v3': return code + '.x';
  459. case 'v1 = v4': return code + '.x';
  460. case 'v1 = i': return 'float( ' + code + ' )';
  461. case 'v2 = v1': return 'vec2( ' + code + ' )';
  462. case 'v2 = v3': return code + '.xy';
  463. case 'v2 = v4': return code + '.xy';
  464. case 'v2 = i': return 'vec2( float( ' + code + ' ) )';
  465. case 'v3 = v1': return 'vec3( ' + code + ' )';
  466. case 'v3 = v2': return 'vec3( ' + code + ', 0.0 )';
  467. case 'v3 = v4': return code + '.xyz';
  468. case 'v3 = i': return 'vec2( float( ' + code + ' ) )';
  469. case 'v4 = v1': return 'vec4( ' + code + ' )';
  470. case 'v4 = v2': return 'vec4( ' + code + ', 0.0, 1.0 )';
  471. case 'v4 = v3': return 'vec4( ' + code + ', 1.0 )';
  472. case 'v4 = i': return 'vec4( float( ' + code + ' ) )';
  473. case 'i = v1': return 'int( ' + code + ' )';
  474. case 'i = v2': return 'int( ' + code + '.x )';
  475. case 'i = v3': return 'int( ' + code + '.x )';
  476. case 'i = v4': return 'int( ' + code + '.x )';
  477. }
  478. return code;
  479. },
  480. getTypeByFormat: function ( format ) {
  481. return formatToType[ format ] || format;
  482. },
  483. getFormatByType: function ( type ) {
  484. return typeToFormat[ type ] || type;
  485. },
  486. getUuid: function ( uuid, useCache ) {
  487. useCache = useCache !== undefined ? useCache : true;
  488. if ( useCache && this.cache ) uuid = this.cache + '-' + uuid;
  489. return uuid;
  490. },
  491. getElementByIndex: function ( index ) {
  492. return elements[ index ];
  493. },
  494. getIndexByElement: function ( elm ) {
  495. return elements.indexOf( elm );
  496. },
  497. isShader: function ( shader ) {
  498. return this.shader === shader;
  499. },
  500. setShader: function ( shader ) {
  501. this.shader = shader;
  502. return this;
  503. },
  504. mergeUniform: function ( uniforms ) {
  505. for ( var name in uniforms ) {
  506. this.uniforms[ name ] = uniforms[ name ];
  507. }
  508. },
  509. getTexelDecodingFunctionFromTexture: function( code, texture ) {
  510. var gammaOverrideLinear = this.getTextureEncodingFromMap( texture, this.context.gamma && ( this.renderer ? this.renderer.gammaInput : false ) )
  511. return this.getTexelDecodingFunction( code, gammaOverrideLinear );
  512. },
  513. getTexelDecodingFunction: function( value, encoding ) {
  514. var components = this.getEncodingComponents( encoding );
  515. return components[ 0 ] + 'ToLinear' + components[ 1 ].replace( 'value', value );
  516. },
  517. getTexelEncodingFunction: function( value, encoding ) {
  518. var components = this.getEncodingComponents( encoding );
  519. return 'LinearTo' + components[ 0 ] + components[ 1 ].replace( 'value', value );
  520. },
  521. getEncodingComponents: function( encoding ) {
  522. switch ( encoding ) {
  523. case THREE.LinearEncoding:
  524. return [ 'Linear', '( value )' ];
  525. case THREE.sRGBEncoding:
  526. return [ 'sRGB', '( value )' ];
  527. case THREE.RGBEEncoding:
  528. return [ 'RGBE', '( value )' ];
  529. case THREE.RGBM7Encoding:
  530. return [ 'RGBM', '( value, 7.0 )' ];
  531. case THREE.RGBM16Encoding:
  532. return [ 'RGBM', '( value, 16.0 )' ];
  533. case THREE.RGBDEncoding:
  534. return [ 'RGBD', '( value, 256.0 )' ];
  535. case THREE.GammaEncoding:
  536. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  537. default:
  538. throw new Error( 'unsupported encoding: ' + encoding );
  539. }
  540. },
  541. getEncodingComponents: function( encoding ) {
  542. switch ( encoding ) {
  543. case THREE.LinearEncoding:
  544. return [ 'Linear', '( value )' ];
  545. case THREE.sRGBEncoding:
  546. return [ 'sRGB', '( value )' ];
  547. case THREE.RGBEEncoding:
  548. return [ 'RGBE', '( value )' ];
  549. case THREE.RGBM7Encoding:
  550. return [ 'RGBM', '( value, 7.0 )' ];
  551. case THREE.RGBM16Encoding:
  552. return [ 'RGBM', '( value, 16.0 )' ];
  553. case THREE.RGBDEncoding:
  554. return [ 'RGBD', '( value, 256.0 )' ];
  555. case THREE.GammaEncoding:
  556. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  557. default:
  558. throw new Error( 'unsupported encoding: ' + encoding );
  559. }
  560. },
  561. getTextureEncodingFromMap: function ( map, gammaOverrideLinear ) {
  562. var encoding;
  563. if ( ! map ) {
  564. encoding = THREE.LinearEncoding;
  565. } else if ( map.isTexture ) {
  566. encoding = map.encoding;
  567. } else if ( map.isWebGLRenderTarget ) {
  568. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  569. encoding = map.texture.encoding;
  570. }
  571. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  572. if ( encoding === THREE.LinearEncoding && gammaOverrideLinear ) {
  573. encoding = THREE.GammaEncoding;
  574. }
  575. return encoding;
  576. }
  577. };
  578. export { NodeBuilder };