Based on WebGLRenderer , I can create a mat4 attribute and pass it to the shader for computations. However, after switching to WebGPURenderer , WebGPU does not support mat4 attributes, and it supports a maximum of 8 vertex buffers. Using four vec4 attributes to simulate a mat4 seems a bit wasteful, and updating this mat4 in WebGPURenderer is also an issue.
- What is the best practice for passing a
mat4attribute usingWebGPURenderer? Should it be emulated with fourvec4attributes, or is there another method? - I referred to the handling of
instanceMatrixininstanceNodeto pass amat4like this.
const buffer = new InstancedInterleavedBuffer( instanceAttribute.array, 16, 1 );
this.buffer = buffer;
const bufferFn = instancedBufferAttribute;
const buffers = [
// F.Signature -> bufferAttribute( array, type, stride, offset )
bufferFn( buffer, 'vec4', 16, 0 ),
bufferFn( buffer, 'vec4', 16, 4 ),
bufferFn( buffer, 'vec4', 16, 8 ),
bufferFn( buffer, 'vec4', 16, 12 )
];
matrix = mat4( ...buffers ).toVar();
currentMatrix.assign(matrix);
However, when my geometry changes (disposing of the old geometry and creating a new one), the above code causes an error. The above code seems unable to handle geometry changesWhy does this happen?
![]()