TextureNode.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. import UniformNode, { uniform } from '../core/UniformNode.js';
  2. import { uv } from './UV.js';
  3. import { textureSize } from './TextureSizeNode.js';
  4. import { colorSpaceToWorking } from '../display/ColorSpaceNode.js';
  5. import { expression } from '../code/ExpressionNode.js';
  6. import { maxMipLevel } from '../utils/MaxMipLevelNode.js';
  7. import { nodeProxy, vec3, nodeObject, int } from '../tsl/TSLBase.js';
  8. import { NodeUpdateType } from '../core/constants.js';
  9. import { IntType, NearestFilter, UnsignedIntType } from '../../constants.js';
  10. import { Texture } from '../../textures/Texture.js';
  11. const EmptyTexture = /*@__PURE__*/ new Texture();
  12. /**
  13. * This type of uniform node represents a 2D texture.
  14. *
  15. * @augments UniformNode
  16. */
  17. class TextureNode extends UniformNode {
  18. static get type() {
  19. return 'TextureNode';
  20. }
  21. /**
  22. * Constructs a new texture node.
  23. *
  24. * @param {Texture} [value=EmptyTexture] - The texture.
  25. * @param {?Node<vec2|vec3>} [uvNode=null] - The uv node.
  26. * @param {?Node<int>} [levelNode=null] - The level node.
  27. * @param {?Node<float>} [biasNode=null] - The bias node.
  28. */
  29. constructor( value = EmptyTexture, uvNode = null, levelNode = null, biasNode = null ) {
  30. super( value );
  31. /**
  32. * This flag can be used for type testing.
  33. *
  34. * @type {boolean}
  35. * @readonly
  36. * @default true
  37. */
  38. this.isTextureNode = true;
  39. /**
  40. * Represents the texture coordinates.
  41. *
  42. * @type {?Node<vec2|vec3>}
  43. * @default null
  44. */
  45. this.uvNode = uvNode;
  46. /**
  47. * Represents the mip level that should be selected.
  48. *
  49. * @type {?Node<int>}
  50. * @default null
  51. */
  52. this.levelNode = levelNode;
  53. /**
  54. * Represents the bias to be applied during level-of-detail computation.
  55. *
  56. * @type {?Node<float>}
  57. * @default null
  58. */
  59. this.biasNode = biasNode;
  60. /**
  61. * Represents a reference value a texture sample is compared to.
  62. *
  63. * @type {?Node<float>}
  64. * @default null
  65. */
  66. this.compareNode = null;
  67. /**
  68. * When using texture arrays, the depth node defines the layer to select.
  69. *
  70. * @type {?Node<int>}
  71. * @default null
  72. */
  73. this.depthNode = null;
  74. /**
  75. * When defined, a texture is sampled using explicit gradients.
  76. *
  77. * @type {?Array<Node<vec2>>}
  78. * @default null
  79. */
  80. this.gradNode = null;
  81. /**
  82. * Whether texture values should be sampled or fetched.
  83. *
  84. * @type {boolean}
  85. * @default true
  86. */
  87. this.sampler = true;
  88. /**
  89. * Whether the uv transformation matrix should be
  90. * automatically updated or not. Use `setUpdateMatrix()`
  91. * if you want to change the value of the property.
  92. *
  93. * @type {boolean}
  94. * @default false
  95. */
  96. this.updateMatrix = false;
  97. /**
  98. * By default the `update()` method is not executed. `setUpdateMatrix()`
  99. * sets the value to `frame` when the uv transformation matrix should
  100. * automatically be updated.
  101. *
  102. * @type {string}
  103. * @default 'none'
  104. */
  105. this.updateType = NodeUpdateType.NONE;
  106. /**
  107. * The reference node.
  108. *
  109. * @type {?Node}
  110. * @default null
  111. */
  112. this.referenceNode = null;
  113. /**
  114. * The texture value is stored in a private property.
  115. *
  116. * @private
  117. * @type {Texture}
  118. */
  119. this._value = value;
  120. /**
  121. * The uniform node that represents the uv transformation matrix.
  122. *
  123. * @private
  124. * @type {?UniformNode<mat3>}
  125. */
  126. this._matrixUniform = null;
  127. this.setUpdateMatrix( uvNode === null );
  128. }
  129. set value( value ) {
  130. if ( this.referenceNode ) {
  131. this.referenceNode.value = value;
  132. } else {
  133. this._value = value;
  134. }
  135. }
  136. /**
  137. * The texture value.
  138. *
  139. * @type {Texture}
  140. */
  141. get value() {
  142. return this.referenceNode ? this.referenceNode.value : this._value;
  143. }
  144. /**
  145. * Overwritten since the uniform hash is defined by the texture's UUID.
  146. *
  147. * @param {NodeBuilder} builder - The current node builder.
  148. * @return {string} The uniform hash.
  149. */
  150. getUniformHash( /*builder*/ ) {
  151. return this.value.uuid;
  152. }
  153. /**
  154. * Overwritten since the node type is inferred from the texture type.
  155. *
  156. * @param {NodeBuilder} builder - The current node builder.
  157. * @return {string} The node type.
  158. */
  159. getNodeType( /*builder*/ ) {
  160. if ( this.value.isDepthTexture === true ) return 'float';
  161. if ( this.value.type === UnsignedIntType ) {
  162. return 'uvec4';
  163. } else if ( this.value.type === IntType ) {
  164. return 'ivec4';
  165. }
  166. return 'vec4';
  167. }
  168. /**
  169. * Overwrites the default implementation to return a fixed value `'texture'`.
  170. *
  171. * @param {NodeBuilder} builder - The current node builder.
  172. * @return {string} The input type.
  173. */
  174. getInputType( /*builder*/ ) {
  175. return 'texture';
  176. }
  177. /**
  178. * Returns a default uvs based on the current texture's channel.
  179. *
  180. * @return {AttributeNode<vec2>} The default uvs.
  181. */
  182. getDefaultUV() {
  183. return uv( this.value.channel );
  184. }
  185. /**
  186. * Overwritten to always return the texture reference of the node.
  187. *
  188. * @param {any} state - This method can be invocated in different contexts so `state` can refer to any object type.
  189. * @return {Texture} The texture reference.
  190. */
  191. updateReference( /*state*/ ) {
  192. return this.value;
  193. }
  194. /**
  195. * Transforms the given uv node with the texture transformation matrix.
  196. *
  197. * @param {Node} uvNode - The uv node to transform.
  198. * @return {Node} The transformed uv node.
  199. */
  200. getTransformedUV( uvNode ) {
  201. if ( this._matrixUniform === null ) this._matrixUniform = uniform( this.value.matrix );
  202. return this._matrixUniform.mul( vec3( uvNode, 1 ) ).xy;
  203. }
  204. /**
  205. * Defines whether the uv transformation matrix should automatically be updated or not.
  206. *
  207. * @param {boolean} value - The update toggle.
  208. * @return {TextureNode} A reference to this node.
  209. */
  210. setUpdateMatrix( value ) {
  211. this.updateMatrix = value;
  212. this.updateType = value ? NodeUpdateType.OBJECT : NodeUpdateType.NONE;
  213. return this;
  214. }
  215. /**
  216. * Setups the uv node. Depending on the backend as well as texture's image and type, it might be necessary
  217. * to modify the uv node for correct sampling.
  218. *
  219. * @param {NodeBuilder} builder - The current node builder.
  220. * @param {Node} uvNode - The uv node to setup.
  221. * @return {Node} The updated uv node.
  222. */
  223. setupUV( builder, uvNode ) {
  224. const texture = this.value;
  225. if ( builder.isFlipY() && ( ( texture.image instanceof ImageBitmap && texture.flipY === true ) || texture.isRenderTargetTexture === true || texture.isFramebufferTexture === true || texture.isDepthTexture === true ) ) {
  226. if ( this.sampler ) {
  227. uvNode = uvNode.flipY();
  228. } else {
  229. uvNode = uvNode.setY( int( textureSize( this, this.levelNode ).y ).sub( uvNode.y ).sub( 1 ) );
  230. }
  231. }
  232. return uvNode;
  233. }
  234. /**
  235. * Setups texture node by preparing the internal nodes for code generation.
  236. *
  237. * @param {NodeBuilder} builder - The current node builder.
  238. */
  239. setup( builder ) {
  240. const properties = builder.getNodeProperties( this );
  241. properties.referenceNode = this.referenceNode;
  242. //
  243. const texture = this.value;
  244. if ( ! texture || texture.isTexture !== true ) {
  245. throw new Error( 'THREE.TSL: `texture( value )` function expects a valid instance of THREE.Texture().' );
  246. }
  247. //
  248. let uvNode = this.uvNode;
  249. if ( ( uvNode === null || builder.context.forceUVContext === true ) && builder.context.getUV ) {
  250. uvNode = builder.context.getUV( this, builder );
  251. }
  252. if ( ! uvNode ) uvNode = this.getDefaultUV();
  253. if ( this.updateMatrix === true ) {
  254. uvNode = this.getTransformedUV( uvNode );
  255. }
  256. uvNode = this.setupUV( builder, uvNode );
  257. //
  258. let levelNode = this.levelNode;
  259. if ( levelNode === null && builder.context.getTextureLevel ) {
  260. levelNode = builder.context.getTextureLevel( this );
  261. }
  262. //
  263. properties.uvNode = uvNode;
  264. properties.levelNode = levelNode;
  265. properties.biasNode = this.biasNode;
  266. properties.compareNode = this.compareNode;
  267. properties.gradNode = this.gradNode;
  268. properties.depthNode = this.depthNode;
  269. }
  270. /**
  271. * Generates the uv code snippet.
  272. *
  273. * @param {NodeBuilder} builder - The current node builder.
  274. * @param {Node} uvNode - The uv node to generate code for.
  275. * @return {string} The generated code snippet.
  276. */
  277. generateUV( builder, uvNode ) {
  278. return uvNode.build( builder, this.sampler === true ? 'vec2' : 'ivec2' );
  279. }
  280. /**
  281. * Generates the snippet for the texture sampling.
  282. *
  283. * @param {NodeBuilder} builder - The current node builder.
  284. * @param {string} textureProperty - The texture property.
  285. * @param {string} uvSnippet - The uv snippet.
  286. * @param {?string} levelSnippet - The level snippet.
  287. * @param {?string} biasSnippet - The bias snippet.
  288. * @param {?string} depthSnippet - The depth snippet.
  289. * @param {?string} compareSnippet - The compare snippet.
  290. * @param {?Array<string>} gradSnippet - The grad snippet.
  291. * @return {string} The generated code snippet.
  292. */
  293. generateSnippet( builder, textureProperty, uvSnippet, levelSnippet, biasSnippet, depthSnippet, compareSnippet, gradSnippet ) {
  294. const texture = this.value;
  295. let snippet;
  296. if ( levelSnippet ) {
  297. snippet = builder.generateTextureLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet );
  298. } else if ( biasSnippet ) {
  299. snippet = builder.generateTextureBias( texture, textureProperty, uvSnippet, biasSnippet, depthSnippet );
  300. } else if ( gradSnippet ) {
  301. snippet = builder.generateTextureGrad( texture, textureProperty, uvSnippet, gradSnippet, depthSnippet );
  302. } else if ( compareSnippet ) {
  303. snippet = builder.generateTextureCompare( texture, textureProperty, uvSnippet, compareSnippet, depthSnippet );
  304. } else if ( this.sampler === false ) {
  305. snippet = builder.generateTextureLoad( texture, textureProperty, uvSnippet, depthSnippet );
  306. } else {
  307. snippet = builder.generateTexture( texture, textureProperty, uvSnippet, depthSnippet );
  308. }
  309. return snippet;
  310. }
  311. /**
  312. * Generates the code snippet of the texture node.
  313. *
  314. * @param {NodeBuilder} builder - The current node builder.
  315. * @param {string} output - The current output.
  316. * @return {string} The generated code snippet.
  317. */
  318. generate( builder, output ) {
  319. const texture = this.value;
  320. const properties = builder.getNodeProperties( this );
  321. const textureProperty = super.generate( builder, 'property' );
  322. if ( /^sampler/.test( output ) ) {
  323. return textureProperty + '_sampler';
  324. } else if ( builder.isReference( output ) ) {
  325. return textureProperty;
  326. } else {
  327. const nodeData = builder.getDataFromNode( this );
  328. let propertyName = nodeData.propertyName;
  329. if ( propertyName === undefined ) {
  330. const { uvNode, levelNode, biasNode, compareNode, depthNode, gradNode } = properties;
  331. const uvSnippet = this.generateUV( builder, uvNode );
  332. const levelSnippet = levelNode ? levelNode.build( builder, 'float' ) : null;
  333. const biasSnippet = biasNode ? biasNode.build( builder, 'float' ) : null;
  334. const depthSnippet = depthNode ? depthNode.build( builder, 'int' ) : null;
  335. const compareSnippet = compareNode ? compareNode.build( builder, 'float' ) : null;
  336. const gradSnippet = gradNode ? [ gradNode[ 0 ].build( builder, 'vec2' ), gradNode[ 1 ].build( builder, 'vec2' ) ] : null;
  337. const nodeVar = builder.getVarFromNode( this );
  338. propertyName = builder.getPropertyName( nodeVar );
  339. const snippet = this.generateSnippet( builder, textureProperty, uvSnippet, levelSnippet, biasSnippet, depthSnippet, compareSnippet, gradSnippet );
  340. builder.addLineFlowCode( `${propertyName} = ${snippet}`, this );
  341. nodeData.snippet = snippet;
  342. nodeData.propertyName = propertyName;
  343. }
  344. let snippet = propertyName;
  345. const nodeType = this.getNodeType( builder );
  346. if ( builder.needsToWorkingColorSpace( texture ) ) {
  347. snippet = colorSpaceToWorking( expression( snippet, nodeType ), texture.colorSpace ).setup( builder ).build( builder, nodeType );
  348. }
  349. return builder.format( snippet, nodeType, output );
  350. }
  351. }
  352. /**
  353. * Sets the sampler value.
  354. *
  355. * @param {boolean} value - The sampler value to set.
  356. * @return {TextureNode} A reference to this texture node.
  357. */
  358. setSampler( value ) {
  359. this.sampler = value;
  360. return this;
  361. }
  362. /**
  363. * Returns the sampler value.
  364. *
  365. * @return {boolean} The sampler value.
  366. */
  367. getSampler() {
  368. return this.sampler;
  369. }
  370. // @TODO: Move to TSL
  371. /**
  372. * @function
  373. * @deprecated since r172. Use {@link TextureNode#sample} instead.
  374. *
  375. * @param {Node} uvNode - The uv node.
  376. * @return {TextureNode} A texture node representing the texture sample.
  377. */
  378. uv( uvNode ) { // @deprecated, r172
  379. console.warn( 'THREE.TextureNode: .uv() has been renamed. Use .sample() instead.' );
  380. return this.sample( uvNode );
  381. }
  382. /**
  383. * Samples the texture with the given uv node.
  384. *
  385. * @param {Node} uvNode - The uv node.
  386. * @return {TextureNode} A texture node representing the texture sample.
  387. */
  388. sample( uvNode ) {
  389. const textureNode = this.clone();
  390. textureNode.uvNode = nodeObject( uvNode );
  391. textureNode.referenceNode = this.getSelf();
  392. return nodeObject( textureNode );
  393. }
  394. /**
  395. * Samples a blurred version of the texture by defining an internal bias.
  396. *
  397. * @param {Node<float>} amountNode - How blurred the texture should be.
  398. * @return {TextureNode} A texture node representing the texture sample.
  399. */
  400. blur( amountNode ) {
  401. const textureNode = this.clone();
  402. textureNode.biasNode = nodeObject( amountNode ).mul( maxMipLevel( textureNode ) );
  403. textureNode.referenceNode = this.getSelf();
  404. const map = textureNode.value;
  405. if ( textureNode.generateMipmaps === false && ( map && map.generateMipmaps === false || map.minFilter === NearestFilter || map.magFilter === NearestFilter ) ) {
  406. console.warn( 'THREE.TSL: texture().blur() requires mipmaps and sampling. Use .generateMipmaps=true and .minFilter/.magFilter=THREE.LinearFilter in the Texture.' );
  407. textureNode.biasNode = null;
  408. }
  409. return nodeObject( textureNode );
  410. }
  411. /**
  412. * Samples a specific mip of the texture.
  413. *
  414. * @param {Node<int>} levelNode - The mip level to sample.
  415. * @return {TextureNode} A texture node representing the texture sample.
  416. */
  417. level( levelNode ) {
  418. const textureNode = this.clone();
  419. textureNode.levelNode = nodeObject( levelNode );
  420. textureNode.referenceNode = this.getSelf();
  421. return nodeObject( textureNode );
  422. }
  423. /**
  424. * Returns the texture size of the requested level.
  425. *
  426. * @param {Node<int>} levelNode - The level to compute the size for.
  427. * @return {TextureSizeNode} The texture size.
  428. */
  429. size( levelNode ) {
  430. return textureSize( this, levelNode );
  431. }
  432. /**
  433. * Samples the texture with the given bias.
  434. *
  435. * @param {Node<float>} biasNode - The bias node.
  436. * @return {TextureNode} A texture node representing the texture sample.
  437. */
  438. bias( biasNode ) {
  439. const textureNode = this.clone();
  440. textureNode.biasNode = nodeObject( biasNode );
  441. textureNode.referenceNode = this.getSelf();
  442. return nodeObject( textureNode );
  443. }
  444. /**
  445. * Samples the texture by executing a compare operation.
  446. *
  447. * @param {Node<float>} compareNode - The node that defines the compare value.
  448. * @return {TextureNode} A texture node representing the texture sample.
  449. */
  450. compare( compareNode ) {
  451. const textureNode = this.clone();
  452. textureNode.compareNode = nodeObject( compareNode );
  453. textureNode.referenceNode = this.getSelf();
  454. return nodeObject( textureNode );
  455. }
  456. /**
  457. * Samples the texture using an explicit gradient.
  458. *
  459. * @param {Node<vec2>} gradNodeX - The gradX node.
  460. * @param {Node<vec2>} gradNodeY - The gradY node.
  461. * @return {TextureNode} A texture node representing the texture sample.
  462. */
  463. grad( gradNodeX, gradNodeY ) {
  464. const textureNode = this.clone();
  465. textureNode.gradNode = [ nodeObject( gradNodeX ), nodeObject( gradNodeY ) ];
  466. textureNode.referenceNode = this.getSelf();
  467. return nodeObject( textureNode );
  468. }
  469. /**
  470. * Samples the texture by defining a depth node.
  471. *
  472. * @param {Node<int>} depthNode - The depth node.
  473. * @return {TextureNode} A texture node representing the texture sample.
  474. */
  475. depth( depthNode ) {
  476. const textureNode = this.clone();
  477. textureNode.depthNode = nodeObject( depthNode );
  478. textureNode.referenceNode = this.getSelf();
  479. return nodeObject( textureNode );
  480. }
  481. // --
  482. serialize( data ) {
  483. super.serialize( data );
  484. data.value = this.value.toJSON( data.meta ).uuid;
  485. data.sampler = this.sampler;
  486. data.updateMatrix = this.updateMatrix;
  487. data.updateType = this.updateType;
  488. }
  489. deserialize( data ) {
  490. super.deserialize( data );
  491. this.value = data.meta.textures[ data.value ];
  492. this.sampler = data.sampler;
  493. this.updateMatrix = data.updateMatrix;
  494. this.updateType = data.updateType;
  495. }
  496. /**
  497. * The update is used to implement the update of the uv transformation matrix.
  498. */
  499. update() {
  500. const texture = this.value;
  501. const matrixUniform = this._matrixUniform;
  502. if ( matrixUniform !== null ) matrixUniform.value = texture.matrix;
  503. if ( texture.matrixAutoUpdate === true ) {
  504. texture.updateMatrix();
  505. }
  506. }
  507. /**
  508. * Clones the texture node.
  509. *
  510. * @return {TextureNode} The cloned texture node.
  511. */
  512. clone() {
  513. const newNode = new this.constructor( this.value, this.uvNode, this.levelNode, this.biasNode );
  514. newNode.sampler = this.sampler;
  515. newNode.depthNode = this.depthNode;
  516. newNode.compareNode = this.compareNode;
  517. newNode.gradNode = this.gradNode;
  518. return newNode;
  519. }
  520. }
  521. export default TextureNode;
  522. /**
  523. * TSL function for creating a texture node.
  524. *
  525. * @tsl
  526. * @function
  527. * @param {?Texture} value - The texture.
  528. * @param {?Node<vec2|vec3>} [uvNode=null] - The uv node.
  529. * @param {?Node<int>} [levelNode=null] - The level node.
  530. * @param {?Node<float>} [biasNode=null] - The bias node.
  531. * @returns {TextureNode}
  532. */
  533. const textureBase = /*@__PURE__*/ nodeProxy( TextureNode ).setParameterLength( 1, 4 ).setName( 'texture' );
  534. /**
  535. * TSL function for creating a texture node or sample a texture node already existing.
  536. *
  537. * @tsl
  538. * @function
  539. * @param {?Texture|TextureNode} [value=EmptyTexture] - The texture.
  540. * @param {?Node<vec2|vec3>} [uvNode=null] - The uv node.
  541. * @param {?Node<int>} [levelNode=null] - The level node.
  542. * @param {?Node<float>} [biasNode=null] - The bias node.
  543. * @returns {TextureNode}
  544. */
  545. export const texture = ( value = EmptyTexture, uvNode = null, levelNode = null, biasNode = null ) => {
  546. let textureNode;
  547. if ( value && value.isTextureNode === true ) {
  548. textureNode = nodeObject( value.clone() );
  549. textureNode.referenceNode = value.getSelf(); // Ensure the reference is set to the original node
  550. if ( uvNode !== null ) textureNode.uvNode = nodeObject( uvNode );
  551. if ( levelNode !== null ) textureNode.levelNode = nodeObject( levelNode );
  552. if ( biasNode !== null ) textureNode.biasNode = nodeObject( biasNode );
  553. } else {
  554. textureNode = textureBase( value, uvNode, levelNode, biasNode );
  555. }
  556. return textureNode;
  557. };
  558. /**
  559. * TSL function for creating a uniform texture node.
  560. *
  561. * @tsl
  562. * @function
  563. * @param {?Texture} value - The texture.
  564. * @returns {TextureNode}
  565. */
  566. export const uniformTexture = ( value = EmptyTexture ) => texture( value );
  567. /**
  568. * TSL function for creating a texture node that fetches/loads texels without interpolation.
  569. *
  570. * @tsl
  571. * @function
  572. * @param {?Texture|TextureNode} [value=EmptyTexture] - The texture.
  573. * @param {?Node<vec2|vec3>} [uvNode=null] - The uv node.
  574. * @param {?Node<int>} [levelNode=null] - The level node.
  575. * @param {?Node<float>} [biasNode=null] - The bias node.
  576. * @returns {TextureNode}
  577. */
  578. export const textureLoad = ( ...params ) => texture( ...params ).setSampler( false );
  579. //export const textureLevel = ( value, uv, level ) => texture( value, uv ).level( level );
  580. /**
  581. * Converts a texture or texture node to a sampler.
  582. *
  583. * @tsl
  584. * @function
  585. * @param {TextureNode|Texture} value - The texture or texture node to convert.
  586. * @returns {Node}
  587. */
  588. export const sampler = ( value ) => ( value.isNode === true ? value : texture( value ) ).convert( 'sampler' );
  589. /**
  590. * Converts a texture or texture node to a sampler comparison.
  591. *
  592. * @tsl
  593. * @function
  594. * @param {TextureNode|Texture} value - The texture or texture node to convert.
  595. * @returns {Node}
  596. */
  597. export const samplerComparison = ( value ) => ( value.isNode === true ? value : texture( value ) ).convert( 'samplerComparison' );
粤ICP备19079148号