WebGPURenderer: Apply batching matrice before instancing and Expand multiDraw Support #27950
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related issue: #27937
Description
This fix addresses an issue where the batching matrices should be applied before the instancing matrices. It also introduces support for
multiDrawElementsInstancedWEBGL
andmultiDrawArraysInstancedWEBGL
, which offer comparable functionality to the basic multiDraw methods and have the same browser support (95%+).The
![image](https://cdn.statically.io/img/private-user-images.githubusercontent.com/15867665/314428209-71da43a5-fc43-4989-96d9-6a0671a2a878.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjI3Mjk0ODEsIm5iZiI6MTcyMjcyOTE4MSwicGF0aCI6Ii8xNTg2NzY2NS8zMTQ0MjgyMDktNzFkYTQzYTUtZmM0My00OTg5LTk2ZDktNmEwNjcxYTJhODc4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODAzVDIzNTMwMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWY5NzI5YTZiMjNiNmRmMWI3NDIyNWRlNTcxOTgyMWE2YTQ1NTQ3NjEyNTdlODFkZTZiNjNlNmI2NDBhM2UwMmImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.fPNXurptKisU3A6RkAkLTetuhX8-zWhYQ045Jf_g4RQ)
WebGPURenderer
andNodes
makes this combination pretty straightforward to achieve and works on both backends, for example this scene is rendered in a single draw call:This enhancement also aims to provide guidance for the
WebGLRenderer
, for example withrenderMultiDrawInstances
.In the future, we might witness the introduction of an
InstancedBatchMesh
or some improvements to theBatchMesh
. The current implementation ofBatchMesh
inefficiently allocates excessive memory by redundantly replicating geometries instead of utilizing a Map for referencing and instancing them.That said, these changes extend to a much wider scope which I do not plan to explore any time soon, unless a bounty or a similar incentive is provided, allowing me the time to do so.
This contribution is funded by Utsubo