|
|
@@ -6,6 +6,7 @@ import { textureLoad } from './TextureNode.js';
|
|
|
import { textureSize } from './TextureSizeNode.js';
|
|
|
import { tangentLocal } from './TangentNode.js';
|
|
|
import { instanceIndex, drawIndex } from '../core/IndexNode.js';
|
|
|
+import { varyingProperty } from '../core/PropertyNode.js';
|
|
|
|
|
|
class BatchNode extends Node {
|
|
|
|
|
|
@@ -16,8 +17,6 @@ class BatchNode extends Node {
|
|
|
this.batchMesh = batchMesh;
|
|
|
|
|
|
|
|
|
- this.instanceColorNode = null;
|
|
|
-
|
|
|
this.batchingIdNode = null;
|
|
|
|
|
|
}
|
|
|
@@ -55,20 +54,49 @@ class BatchNode extends Node {
|
|
|
]
|
|
|
} );
|
|
|
|
|
|
- const matriceTexture = this.batchMesh._matricesTexture;
|
|
|
+ const indirectId = getIndirectIndex( int( this.batchingIdNode ) );
|
|
|
+
|
|
|
+ const matricesTexture = this.batchMesh._matricesTexture;
|
|
|
|
|
|
- const size = textureSize( textureLoad( matriceTexture ), 0 );
|
|
|
- const j = float( getIndirectIndex( int( this.batchingIdNode ) ) ).mul( 4 ).toVar();
|
|
|
+ const size = textureSize( textureLoad( matricesTexture ), 0 );
|
|
|
+ const j = float( indirectId ).mul( 4 ).toInt().toVar();
|
|
|
|
|
|
- const x = int( j.mod( size ) );
|
|
|
- const y = int( j ).div( int( size ) );
|
|
|
+ const x = j.modInt( size );
|
|
|
+ const y = j.div( int( size ) );
|
|
|
const batchingMatrix = mat4(
|
|
|
- textureLoad( matriceTexture, ivec2( x, y ) ),
|
|
|
- textureLoad( matriceTexture, ivec2( x.add( 1 ), y ) ),
|
|
|
- textureLoad( matriceTexture, ivec2( x.add( 2 ), y ) ),
|
|
|
- textureLoad( matriceTexture, ivec2( x.add( 3 ), y ) )
|
|
|
+ textureLoad( matricesTexture, ivec2( x, y ) ),
|
|
|
+ textureLoad( matricesTexture, ivec2( x.add( 1 ), y ) ),
|
|
|
+ textureLoad( matricesTexture, ivec2( x.add( 2 ), y ) ),
|
|
|
+ textureLoad( matricesTexture, ivec2( x.add( 3 ), y ) )
|
|
|
);
|
|
|
|
|
|
+
|
|
|
+ const colorsTexture = this.batchMesh._colorsTexture;
|
|
|
+
|
|
|
+ if ( colorsTexture !== null ) {
|
|
|
+
|
|
|
+ const getBatchingColor = Fn( ( [ id ] ) => {
|
|
|
+
|
|
|
+ const size = textureSize( textureLoad( colorsTexture ), 0 ).x;
|
|
|
+ const j = id;
|
|
|
+ const x = j.modInt( size );
|
|
|
+ const y = j.div( size );
|
|
|
+ return textureLoad( colorsTexture, ivec2( x, y ) ).rgb;
|
|
|
+
|
|
|
+ } ).setLayout( {
|
|
|
+ name: 'getBatchingColor',
|
|
|
+ type: 'vec3',
|
|
|
+ inputs: [
|
|
|
+ { name: 'id', type: 'int' }
|
|
|
+ ]
|
|
|
+ } );
|
|
|
+
|
|
|
+ const color = getBatchingColor( indirectId );
|
|
|
+
|
|
|
+ varyingProperty( 'vec3', 'vBatchColor' ).assign( color );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
const bm = mat3( batchingMatrix );
|
|
|
|
|
|
positionLocal.assign( batchingMatrix.mul( positionLocal ) );
|