|
|
@@ -23,26 +23,26 @@ const _previousInstanceMatrices = /*@__PURE__*/ new WeakMap();
|
|
|
*
|
|
|
* @param {NodeBuilder} builder - The current node builder.
|
|
|
* @param {InstancedBufferAttribute|StorageInstancedBufferAttribute} instanceMatrix - The matrix buffer attribute.
|
|
|
- * @param {number} count - The instance count.
|
|
|
* @returns {Node} The matrix node.
|
|
|
*/
|
|
|
-function createInstanceMatrixNode( builder, instanceMatrix, count ) {
|
|
|
+function createInstanceMatrixNode( builder, instanceMatrix ) {
|
|
|
|
|
|
let instanceMatrixNode;
|
|
|
+ const matrixCount = Math.max( instanceMatrix.count, 1 );
|
|
|
|
|
|
const isStorageMatrix = instanceMatrix.isStorageInstancedBufferAttribute === true;
|
|
|
|
|
|
if ( isStorageMatrix ) {
|
|
|
|
|
|
- instanceMatrixNode = storage( instanceMatrix, 'mat4', Math.max( count, 1 ) ).element( instanceIndex );
|
|
|
+ instanceMatrixNode = storage( instanceMatrix, 'mat4', matrixCount ).element( instanceIndex );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- const uniformBufferSize = count * 16 * 4;
|
|
|
+ const uniformBufferSize = matrixCount * 16 * 4;
|
|
|
|
|
|
if ( uniformBufferSize <= builder.getUniformBufferLimit() ) {
|
|
|
|
|
|
- instanceMatrixNode = buffer( instanceMatrix.array, 'mat4', Math.max( count, 1 ) ).element( instanceIndex );
|
|
|
+ instanceMatrixNode = buffer( instanceMatrix.array, 'mat4', matrixCount ).element( instanceIndex );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
@@ -81,10 +81,9 @@ function createInstanceMatrixNode( builder, instanceMatrix, count ) {
|
|
|
* @param {InstancedMesh} instancedMesh - The instanced mesh object.
|
|
|
* @param {InstancedBufferAttribute|StorageInstancedBufferAttribute} instanceMatrix - The current matrix buffer attribute.
|
|
|
* @param {NodeBuilder} builder - The current node builder.
|
|
|
- * @param {number} count - The instance count.
|
|
|
* @returns {Node} The previous frame instance matrix node.
|
|
|
*/
|
|
|
-function getPreviousInstance( instancedMesh, instanceMatrix, builder, count ) {
|
|
|
+function getPreviousInstance( instancedMesh, instanceMatrix, builder ) {
|
|
|
|
|
|
let data = _previousInstanceMatrices.get( instancedMesh );
|
|
|
|
|
|
@@ -94,7 +93,7 @@ function getPreviousInstance( instancedMesh, instanceMatrix, builder, count ) {
|
|
|
|
|
|
data = {
|
|
|
previousInstanceMatrix,
|
|
|
- node: createInstanceMatrixNode( builder, previousInstanceMatrix, count )
|
|
|
+ node: createInstanceMatrixNode( builder, previousInstanceMatrix )
|
|
|
};
|
|
|
|
|
|
_previousInstanceMatrices.set( instancedMesh, data );
|
|
|
@@ -118,26 +117,22 @@ export const instanceColor = /*@__PURE__*/ varyingProperty( 'vec3', 'vInstanceCo
|
|
|
*
|
|
|
* @tsl
|
|
|
* @function
|
|
|
- * @param {number} count - The instance count.
|
|
|
* @param {InstancedBufferAttribute|StorageInstancedBufferAttribute} matrices - The instanced transformation matrices.
|
|
|
* @param {?InstancedBufferAttribute|StorageInstancedBufferAttribute} [colors=null] - The optional instanced colors.
|
|
|
*/
|
|
|
-export const instance = /*@__PURE__*/ Fn( ( [ count, matrices, colors = null ], builder ) => {
|
|
|
-
|
|
|
- // get numeric value (non-node)
|
|
|
- count = count.value;
|
|
|
+export const instance = /*@__PURE__*/ Fn( ( [ matrices, colors = null ], builder ) => {
|
|
|
|
|
|
const isStorageMatrix = matrices.isStorageInstancedBufferAttribute === true;
|
|
|
const isStorageColor = colors && colors.isStorageInstancedBufferAttribute === true;
|
|
|
|
|
|
- const instanceMatrixNode = createInstanceMatrixNode( builder, matrices, count );
|
|
|
+ const instanceMatrixNode = createInstanceMatrixNode( builder, matrices );
|
|
|
|
|
|
// interleaved buffer tracking for matrix
|
|
|
let interleavedMatrix = null;
|
|
|
|
|
|
if ( ! isStorageMatrix ) {
|
|
|
|
|
|
- const uniformBufferSize = count * 16 * 4;
|
|
|
+ const uniformBufferSize = Math.max( matrices.count, 1 ) * 16 * 4;
|
|
|
|
|
|
if ( uniformBufferSize > builder.getUniformBufferLimit() ) {
|
|
|
|
|
|
@@ -229,7 +224,7 @@ export const instance = /*@__PURE__*/ Fn( ( [ count, matrices, colors = null ],
|
|
|
|
|
|
} );
|
|
|
|
|
|
- const previousInstanceMatrixNode = getPreviousInstance( instancedMesh, matrices, builder, count );
|
|
|
+ const previousInstanceMatrixNode = getPreviousInstance( instancedMesh, matrices, builder );
|
|
|
positionPrevious.assign( previousInstanceMatrixNode.mul( positionPrevious ).xyz );
|
|
|
|
|
|
}
|
|
|
@@ -262,10 +257,8 @@ export const instance = /*@__PURE__*/ Fn( ( [ count, matrices, colors = null ],
|
|
|
*/
|
|
|
export const instancedMesh = /*@__PURE__*/ Fn( ( [ instancedMesh ] ) => {
|
|
|
|
|
|
- const { count, instanceMatrix, instanceColor } = instancedMesh;
|
|
|
+ const { instanceMatrix, instanceColor } = instancedMesh;
|
|
|
|
|
|
- instance( count, instanceMatrix, instanceColor );
|
|
|
+ instance( instanceMatrix, instanceColor );
|
|
|
|
|
|
}, 'void' );
|
|
|
-
|
|
|
-
|