Capítulo 486 de 859

Chapter 486: StorageBufferNode

Core Idea

This node is used in context of compute shaders and allows to define a storage buffer for data. A typical workflow is to create instances of this node with the convenience functions attributeArray() or instancedArray(), setup up a compute shader that writes into the buffers and then convert the storage buffers to attribute nodes for rendering.

Key Concepts

  • access : string: The access type of the texture node.
  • global : boolean: StorageBufferNode sets this property to true by default.
  • isAtomic : boolean: Whether the node is atomic or not.
  • isPBO : boolean: Whether the node represents a PBO or not. Only relevant for WebGL.
  • isStorageBufferNode : boolean (readonly): This flag can be used for type testing.
  • structTypeNode : StructTypeNode: The buffer struct type.

Code Examples

const positionBuffer = instancedArray( particleCount, 'vec3' ); // the storage buffer node
const computeInit = Fn( () => { // the compute shader
	const position = positionBuffer.element( instanceIndex );
	// compute position data
	position.x = 1;
	position.y = 1;
	position.z = 1;
} )().compute( particleCount );
const particleMaterial = new THREE.SpriteNodeMaterial();
particleMaterial.positionNode = positionBuffer.toAttribute();
renderer.computeAsync( computeInit );
  • What it demonstrates: Typical usage of StorageBufferNode.

Reference Tables

Constructor

Signature
`new StorageBufferNode( value : StorageBufferAttribute

Properties

PropertyDescription
.access : stringThe access type of the texture node.
.global : booleanStorageBufferNode sets this property to true by default.
.isAtomic : booleanWhether the node is atomic or not.
.isPBO : booleanWhether the node represents a PBO or not. Only relevant for WebGL.
.isStorageBufferNode : boolean (readonly)This flag can be used for type testing.
.structTypeNode : StructTypeNodeThe buffer struct type.

Methods

MethodDescription
.element( indexNode : IndexNode ) : StorageArrayElementNodeEnables element access with the given index node.
.generate( builder : NodeBuilder ) : stringGenerates the code snippet of the storage buffer node.
.generateNodeType( builder : NodeBuilder ) : stringThis method is overwritten since the node type from the availability of storage buffers and the attribute data.
.getAttributeData() : ObjectReturns attribute data for this storage buffer node.
.getHash( builder : NodeBuilder ) : stringThis method is overwritten since the buffer data might be shared and thus the hash should be shared as well.
.getInputType( builder : NodeBuilder ) : stringOverwrites the default implementation to return a fixed value 'indirectStorageBuffer' or 'storageBuffer'.
.getMemberType( builder : NodeBuilder, name : string ) : stringReturns the type of a member of the struct.
.getPBO() : booleanReturns the isPBO value.
.setAccess( value : string ) : StorageBufferNodeDefines the node access.
.setAtomic( value : boolean ) : StorageBufferNodeDefines whether the node is atomic or not.
.setPBO( value : boolean ) : StorageBufferNodeDefines whether this node is a PBO or not. Only relevant for WebGL.
.toAtomic() : StorageBufferNodeConvenience method for making this node atomic.
.toReadOnly() : StorageBufferNodeConvenience method for configuring a read-only node access.

Key Takeaways

  1. StorageBufferNode extends: EventDispatcher → Node → InputNode → UniformNode → BufferNode
  2. Most relevant properties: access, global, isAtomic, isPBO.
  3. Key methods: element, generate, generateNodeType, getAttributeData.

Connects To