Capítulo 488 de 859

Chapter 488: StorageTextureNode

Core Idea

This special version of a texture node can be used to write data into a storage texture with a compute shader.

This node can only be used with a WebGPU backend.

Key Concepts

  • access : string: The access type of the texture node.
  • isStorageTextureNode : boolean (readonly): This flag can be used for type testing.
  • mipLevel : number: The mip level to write to for storage textures.
  • storeNode : Node: The value node that should be stored in the texture.

Code Examples

const storageTexture = new THREE.StorageTexture( width, height );
const computeTexture = Fn( ( { storageTexture } ) => {
	const posX = instanceIndex.mod( width );
	const posY = instanceIndex.div( width );
	const indexUV = uvec2( posX, posY );
	// generate RGB values
	const r = 1;
	const g = 1;
	const b = 1;
	textureStore( storageTexture, indexUV, vec4( r, g, b, 1 ) ).toWriteOnly();
} );
const computeNode = computeTexture( { storageTexture } ).compute( width * height );
renderer.computeAsync( computeNode );
  • What it demonstrates: Typical usage of StorageTextureNode.

Reference Tables

Constructor

Signature
`new StorageTextureNode( value : StorageTexture, uvNode : Node.<(vec2

Properties

PropertyDescription
.access : stringThe access type of the texture node.
.isStorageTextureNode : boolean (readonly)This flag can be used for type testing.
.mipLevel : numberThe mip level to write to for storage textures.
.storeNode : NodeThe value node that should be stored in the texture.

Methods

MethodDescription
.generate( builder : NodeBuilder, output : string ) : stringGenerates the code snippet of the storage node. If no storeNode is defined, the texture node is generated as normal texture.
.generateSnippet( builder : NodeBuilder, textureProperty : string, uvSnippet : string, levelSnippet : string, biasSnippet : string, depthSnippet : string, compareSnippet : string, gradSnippet : Array.<string>, offsetSnippet : string ) : stringGenerates the snippet for the storage texture.
.generateStore( builder : NodeBuilder )Generates the code snippet of the storage texture node.
.getInputType( builder : NodeBuilder ) : stringOverwrites the default implementation to return a fixed value 'storageTexture'.
.getTransformedUV( uvNode : Node ) : NodeOverwrites the default implementation since storage texture coordinates are texel coordinates and should not be transformed by the texture uv matrix.
.setAccess( value : string ) : StorageTextureNodeDefines the node access.
.setMipLevel( level : number ) : StorageTextureNodeSets the mip level to write to.
`.store( uvNode : Node.<(vec2vec3)>, storeNode : Node ) : StorageTextureNode`
.toReadOnly() : StorageTextureNodeConvenience method for configuring a read-only node access.
.toReadWrite() : StorageTextureNodeConvenience method for configuring a read/write node access.
.toWriteOnly() : StorageTextureNodeConvenience method for configuring a write-only node access.

Key Takeaways

  1. StorageTextureNode extends: EventDispatcher → Node → InputNode → UniformNode → TextureNode
  2. Most relevant properties: access, isStorageTextureNode, mipLevel, storeNode.
  3. Key methods: generate, generateSnippet, generateStore, getInputType.

Connects To