Capítulo 235 de 859

Chapter 235: TextureNode

Core Idea

This type of uniform node represents a 2D texture.

Key Concepts

  • biasNode : Node.<float>: Represents the bias to be applied during level-of-detail computation.
  • compareNode : Node.<float>: Represents a reference value a texture sample is compared to.
  • depthNode : Node.<int>: When using texture arrays, the depth node defines the layer to select.
  • gatherNode : Node.<int>: Represents the optional index constant of the channel to gather. This must be in range [0, 3] and a compile-time constant.
  • gradNode : Array.<Node.<vec2>>: When defined, a texture is sampled using explicit gradients.
  • isTextureNode : boolean (readonly): This flag can be used for type testing.
  • levelNode : Node.<int>: Represents the mip level that should be selected.
  • offsetNode : Node.<(ivec2|ivec3)>: Represents the optional texel offset applied to the unnormalized texture coordinate before sampling the texture.
  • referenceNode : Node: The reference node.
  • sampler : boolean: Whether texture values should be sampled or fetched.

Reference Tables

Constructor

Signature
`new TextureNode( value : Texture, uvNode : Node.<(vec2

Properties

PropertyDescription
.biasNode : Node.<float>Represents the bias to be applied during level-of-detail computation.
.compareNode : Node.<float>Represents a reference value a texture sample is compared to.
.depthNode : Node.<int>When using texture arrays, the depth node defines the layer to select.
.gatherNode : Node.<int>Represents the optional index constant of the channel to gather. This must be in range [0, 3] and a compile-time constant.
.gradNode : Array.<Node.<vec2>>When defined, a texture is sampled using explicit gradients.
.isTextureNode : boolean (readonly)This flag can be used for type testing.
.levelNode : Node.<int>Represents the mip level that should be selected.
`.offsetNode : Node.<(ivec2ivec3)>`
.referenceNode : NodeThe reference node.
.sampler : booleanWhether texture values should be sampled or fetched.
.updateMatrix : booleanWhether the uv transformation matrix should be automatically updated or not. Use setUpdateMatrix() if you want to change the value of the property.
.updateType : stringBy default the update() method is not executed. Depending on whether a uv transformation matrix and/or flipY is applied, update() is executed per object.
`.uvNode : Node.<(vec2vec3)>`
.value : TextureThe texture value.

Methods

MethodDescription
.bias( biasNode : Node.<float> ) : TextureNodeSamples the texture with the given bias.
.blur( amountNode : Node.<float> ) : TextureNodeSamples a blurred version of the texture by defining an internal bias.
.clone() : TextureNodeClones the texture node.
.compare( compareNode : Node.<float> ) : TextureNodeSamples the texture by executing a compare operation.
.depth( depthNode : Node.<int> ) : TextureNodeSamples the texture by defining a depth node.
.gather( gatherNode : Node.<int> ) : TextureNodeGathers four texels from the texture.
.generate( builder : NodeBuilder, output : string ) : stringGenerates the code snippet of the texture node.
.generateNodeType( builder : NodeBuilder ) : stringOverwritten since the node type is inferred from the texture type.
.generateOffset( builder : NodeBuilder, offsetNode : Node ) : stringGenerates the offset code snippet.
.generateSnippet( builder : NodeBuilder, textureProperty : string, uvSnippet : string, levelSnippet : string, biasSnippet : string, depthSnippet : string, compareSnippet : string, gradSnippet : Array.<string>, gatherSnippet : string, offsetSnippet : string, flipYSnippet : string ) : stringGenerates the snippet for the texture sampling.
.generateUV( builder : NodeBuilder, uvNode : Node ) : stringGenerates the uv code snippet.
.getBase() : TextureNodeReturns the base texture of this node.
.getDefaultUV() : AttributeNode.<vec2>Returns a default uvs based on the current texture's channel.
.getInputType( builder : NodeBuilder ) : stringOverwrites the default implementation to return a fixed value 'texture'.
.getSampler() : booleanReturns the sampler value.
.getTransformedUV( uvNode : Node ) : NodeTransforms the given uv node with the texture transformation matrix.
.getUniformHash( builder : NodeBuilder ) : stringOverwritten since the uniform hash is defined by the texture's UUID.
.grad( gradNodeX : Node.<vec2>, gradNodeY : Node.<vec2> ) : TextureNodeSamples the texture using an explicit gradient.
.level( levelNode : Node.<int> ) : TextureNodeSamples a specific mip of the texture.
.load( uvNode : Node.<uvec2> ) : TextureNodeTSL function for creating a texture node that fetches/loads texels without interpolation.
.offset( offsetNode : Node.<ivec2> ) : TextureNodeSamples the texture by defining an offset node.
.sample( uvNode : Node ) : TextureNodeSamples the texture with the given uv node.
.setSampler( value : boolean ) : TextureNodeSets the sampler value.
.setUpdateMatrix( value : boolean ) : TextureNodeDefines whether the uv transformation matrix should automatically be updated or not.
.setup( builder : NodeBuilder )Setups texture node by preparing the internal nodes for code generation.
.setupUV( builder : NodeBuilder, uvNode : Node ) : NodeSetups the uv node. Depending on the backend as well as texture's image and type, it might be necessary to modify the uv node for correct sampling.
.size( levelNode : Node.<int> ) : TextureSizeNodeReturns the texture size of the requested level.
.update()The update is used to implement the update of the uv transformation matrix.
.updateReference( state : any ) : TextureOverwritten to always return the texture reference of the node.

Key Takeaways

  1. TextureNode extends: EventDispatcher → Node → InputNode → UniformNode
  2. Most relevant properties: biasNode, compareNode, depthNode, gatherNode.
  3. Key methods: bias, blur, clone, compare.

Connects To