Skip to content

BatchedMesh: Enable per-instance opacity#32725

Merged
Mugen87 merged 16 commits intomrdoob:devfrom
vanruesc:batched-mesh-opacity
Jan 19, 2026
Merged

BatchedMesh: Enable per-instance opacity#32725
Mugen87 merged 16 commits intomrdoob:devfrom
vanruesc:batched-mesh-opacity

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.82
84.56
355.71
84.53
-113 B
-25 B
WebGPU 621.5
172.57
621.5
172.57
+0 B
+0 B
WebGPU Nodes 620.1
172.33
620.1
172.33
+0 B
+0 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 488.06
119.45
487.94
119.42
-113 B
-27 B
WebGPU 691.97
187.85
691.97
187.85
+0 B
+0 B
WebGPU Nodes 641.77
175.02
641.77
175.02
+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

@vanruesc
Copy link
Contributor Author

It looks like the uploaded screenshot doesn't include any transparency.

My bad, I forgot to build the lib before generating the screenshot 🤦‍♂️

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.

A few more comments but generally this is looking like the right direction to merge. To summarize the changes from what I can tell:

  • the vertex color varying is now always set to a vec4
  • vertex colors multiply in just the rgb channel if a vec3 (USE_COLOR). Otherwise all four channels are multiplied if using RGBA (USE_COLOR_ALPHA).
  • BatchedMesh colors always multiply in vec4 rgba
  • InstancedMesh colors always multiply in vec3 rgb

@vanruesc
Copy link
Contributor Author

vanruesc commented Jan 18, 2026

Open question

Should batchedMesh.setColorAt(color, index) set alpha to 1 if a Color object is supplied?

👍 for yes | 👎 for no

Will be reevaluated after #32742 is done.

@gkjohnson gkjohnson added this to the r183 milestone Jan 19, 2026
@Mugen87 Mugen87 merged commit 9d91428 into mrdoob:dev Jan 19, 2026
10 checks passed
@vanruesc vanruesc deleted the batched-mesh-opacity branch January 19, 2026 18:47
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.

3 participants