@@ -23,19 +23,18 @@ const batchingParsVertex = /* glsl */`
2323#ifdef BATCHING
2424 attribute float ${ ID_ATTR_NAME } ;
2525 uniform highp sampler2D batchingTexture;
26- uniform int batchingTextureSize;
2726 mat4 getBatchingMatrix( const in float i ) {
28- float j = i * 4.0;
29- float x = mod( j, float( batchingTextureSize ) );
30- float y = floor( j / float( batchingTextureSize ) );
31- float dx = 1.0 / float( batchingTextureSize );
32- float dy = 1.0 / float( batchingTextureSize );
33- y = dy * ( y + 0.5 );
34- vec4 v1 = texture2D( batchingTexture, vec2( dx * ( x + 0.5 ), y ) );
35- vec4 v2 = texture2D( batchingTexture, vec2( dx * ( x + 1.5 ), y ) );
36- vec4 v3 = texture2D( batchingTexture, vec2( dx * ( x + 2.5 ), y ) );
37- vec4 v4 = texture2D( batchingTexture, vec2( dx * ( x + 3.5 ), y ) );
27+
28+ int size = textureSize( batchingTexture, 0 ).x;
29+ int j = int( i ) * 4;
30+ int x = j % size;
31+ int y = j / size;
32+ vec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );
33+ vec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );
34+ vec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );
35+ vec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );
3836 return mat4( v1, v2, v3, v4 );
37+
3938 }
4039#endif
4140` ;
@@ -127,8 +126,7 @@ class BatchedMesh extends Mesh {
127126 this . frustumCulled = false ;
128127
129128 this . _customUniforms = {
130- batchingTexture : { value : null } ,
131- batchingTextureSize : { value : 0 }
129+ batchingTexture : { value : null }
132130 } ;
133131
134132 this . _initMatricesTexture ( ) ;
@@ -154,7 +152,6 @@ class BatchedMesh extends Mesh {
154152
155153 this . _matricesTexture = matricesTexture ;
156154 this . _customUniforms . batchingTexture . value = this . _matricesTexture ;
157- this . _customUniforms . batchingTextureSize . value = size ;
158155
159156 }
160157
0 commit comments