Skip to content

Conversation

@OndrejSpanel
Copy link
Contributor

@OndrejSpanel OndrejSpanel commented Apr 12, 2024

Description

Since #20135 a single material may be represented by multiple programs. In my scene I use the same material with instanced and non-instanced geometry. As a result I see frequent needsProgramChange = true in WebGLRenderer.setProgram.

This PR adds skinning and instancing as a secondary criterion for sorting into the default painterSortStable just after the material id.

@github-actions
Copy link

github-actions bot commented Apr 12, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
673.2 kB (166.9 kB) 673.4 kB (166.9 kB) +199 B

🌳 Bundle size after tree-shaking

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

Filesize dev Filesize PR Diff
452.9 kB (109.4 kB) 453.1 kB (109.5 kB) +199 B

@OndrejSpanel
Copy link
Contributor Author

@mrdoob @Mugen87 I think this is fairly trivial and obvious. Do you agree with the intention? Is there anything missing or in need of change / improvement?

@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 16, 2024

I did not have the opportunity so far to review this change, sorry. At first sight I do not understand why it's necessary to alter the render lists for your use case so this needs some time for testing and debugging.

@OndrejSpanel
Copy link
Contributor Author

OndrejSpanel commented Apr 16, 2024

When you have a scene where the same material is used for instanced and non-instanced geometry, the sorting currently sorts by material only. As a result, you can get your instanced and non-instanced geometry with the same material rendered in any order, like:

- plain material B
- plain material B
- instanced material B    *** program change
- plain material B        *** program change
- instanced material B    *** program change
- instanced material A    *** program change
- plain material A        *** program change
- instanced material A    *** program change
- plain material A        *** program change

After the change the order is:

- plain material B
- plain material B
- plain material B
- instanced material B      *** program change
- instanced material B
- plain material A          *** program change
- plain material A
- instanced material A      *** program change
- instanced material A

The number of program changes is reduced from 7 to 3. With skinned it works the same way.

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