Skip to content

Commit

Permalink
BatchedMesh: use texelFetch, textureSize (#27077)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson committed Oct 28, 2023
1 parent e49ca4e commit 43093ba
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions examples/jsm/objects/BatchedMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,18 @@ const batchingParsVertex = /* glsl */`
#ifdef BATCHING
attribute float ${ ID_ATTR_NAME };
uniform highp sampler2D batchingTexture;
uniform int batchingTextureSize;
mat4 getBatchingMatrix( const in float i ) {
float j = i * 4.0;
float x = mod( j, float( batchingTextureSize ) );
float y = floor( j / float( batchingTextureSize ) );
float dx = 1.0 / float( batchingTextureSize );
float dy = 1.0 / float( batchingTextureSize );
y = dy * ( y + 0.5 );
vec4 v1 = texture2D( batchingTexture, vec2( dx * ( x + 0.5 ), y ) );
vec4 v2 = texture2D( batchingTexture, vec2( dx * ( x + 1.5 ), y ) );
vec4 v3 = texture2D( batchingTexture, vec2( dx * ( x + 2.5 ), y ) );
vec4 v4 = texture2D( batchingTexture, vec2( dx * ( x + 3.5 ), y ) );
int size = textureSize( batchingTexture, 0 ).x;
int j = int( i ) * 4;
int x = j % size;
int y = j / size;
vec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );
vec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );
vec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );
vec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );
return mat4( v1, v2, v3, v4 );
}
#endif
`;
Expand Down Expand Up @@ -127,8 +126,7 @@ class BatchedMesh extends Mesh {
this.frustumCulled = false;

this._customUniforms = {
batchingTexture: { value: null },
batchingTextureSize: { value: 0 }
batchingTexture: { value: null }
};

this._initMatricesTexture();
Expand All @@ -154,7 +152,6 @@ class BatchedMesh extends Mesh {

this._matricesTexture = matricesTexture;
this._customUniforms.batchingTexture.value = this._matricesTexture;
this._customUniforms.batchingTextureSize.value = size;

}

Expand Down

0 comments on commit 43093ba

Please sign in to comment.