Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BatchedMesh: use texelFetch, textureSize #27077

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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