Skip to content

Conversation

@vanruesc
Copy link
Contributor

@vanruesc vanruesc commented Jan 11, 2026

Description

Related: #28151

This PR adds support for per-instance opacity to BatchedMesh. The current implementation of BatchedMesh already uses colors with 4 components and it supports sorting. The only thing missing is to use the alpha information in the shader.

I've removed the opacity option from the example because it no longer made sense with per-instance transparency.

This contribution is funded by Cozy Giant

@github-actions
Copy link

github-actions bot commented Jan 11, 2026

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 355.41
84.51
355.5
84.5
+96 B
-3 B
WebGPU 621.22
172.51
621.22
172.51
+0 B
+0 B
WebGPU Nodes 619.83
172.28
619.83
172.28
+0 B
+0 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 487.36
119.29
487.46
119.29
+96 B
-3 B
WebGPU 691.88
187.8
691.88
187.8
+0 B
+0 B
WebGPU Nodes 641.68
174.96
641.68
174.96
+0 B
+0 B

@mrdoob mrdoob requested a review from gkjohnson January 12, 2026 04:32
@vanruesc
Copy link
Contributor Author

Puppeteer doesn't like my screenshot - probably because of too many random values 🤔

I'll try changing the materials used in the demo back to MeshNormalMaterial when I find some time.

Copy link
Collaborator

@gkjohnson gkjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added some comments - at a high level I don't have an issue with the idea but I think there are some architectural complexities with vertex colors that make this more difficult.

Puppeteer doesn't like my screenshot - probably because of too many random values 🤔

It looks like the uploaded screenshot doesn't include any transparency. Here's the comparison downloaded from the CI artifacts:

Commited CI
Image Image

@@ -1,5 +1,5 @@
export default /* glsl */`
#if defined( USE_COLOR_ALPHA )
#if defined( USE_COLOR_ALPHA ) || defined( USE_BATCHING_COLOR )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we're still unnecessarily checking for "USE_BATCHING_COLOR" below

#ifdef USE_COLOR
vColor *= color;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when vertex colors without alpha are used with batching color, now? The attribute will be vec3 while vColor will be set to vec4 so I'd expect this to throw an error. And if we use vec4 for a 3-element attribute then I'd expect the alpha component to default to 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! I'll test this on Thursday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants