BufferAttributeNode

Last modified: Jun 30, 2024

In earlier three.js versions it was only possible to define attribute data on geometry level. With BufferAttributeNode, it is also possible to do this on the node level.

const geometry = new THREE.PlaneGeometry();
const positionAttribute = geometry.getAttribute( 'position' );

const colors = [];
for ( let i = 0; i < position.count; i ++ ) {
	colors.push( 1, 0, 0 );
}

material.colorNode = bufferAttribute( new THREE.Float32BufferAttribute( colors, 3 ) );
export {}

This new approach is especially interesting when geometry data are generated via compute shaders. The below line converts a storage buffer into an attribute node.

material.positionNode = positionBuffer.toAttribute();
export {}

Constructor

new BufferAttributeNode(value, bufferType?, bufferStride?, bufferOffset?)
ParameterTypeDefault Value
valueany
bufferType?null | stringnull
bufferStride?number0
bufferOffset?number0

Constructs a new buffer attribute node.

AccessorType

Properties

PropertyTypeDefault Value
isBufferNodeboolean
bufferTypenull | string
bufferStridenumber
bufferOffsetnumber
usagenumber
instancedboolean
attributeany
MethodType

Extends

InputNode

bufferAttribute

TSL function for creating a buffer attribute node.

ParameterTypeDefault Value
arrayany
type?null | stringnull
stride?number0
offset?number0

Returns

Node | BufferAttributeNode

dynamicBufferAttribute

TSL function for creating a buffer attribute node but with dynamic draw usage. Use this function if attribute data are updated per frame.

ParameterTypeDefault Value
arrayany
type?null | stringnull
stride?number0
offset?number0

Returns

Node | BufferAttributeNode

instancedBufferAttribute

TSL function for creating a buffer attribute node but with enabled instancing

ParameterTypeDefault Value
arrayany
type?null | stringnull
stride?number0
offset?number0

Returns

Node | BufferAttributeNode

instancedDynamicBufferAttribute

TSL function for creating a buffer attribute node but with dynamic draw usage and enabled instancing

ParameterTypeDefault Value
arrayany
type?null | stringnull
stride?number0
offset?number0

Returns

Node | BufferAttributeNode