-
-
Notifications
You must be signed in to change notification settings - Fork 35.9k
TSL: Fix instance buffer size in instance()
.
#31608
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
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
The same rules apply like with InstancedMesh.count. The expected behavior is that Your are not expected to modify the |
I am not modifying
That sounds reasonable, don't you think? Let me give a scenario that should work according to documentation.
The last assignment has no effect, because the shader thinks there are only 10 instance matrices, when in fact the buffer always has size 20. |
That's the faulty shader code that my PR fixes. It should have length of 20.
|
Do you mind demonstrating with a fiddle how the current code breaks? Use https://jsfiddle.net/mnqr9oj0/ as a starter template. |
I think the better fix is to overwrite setup( builder ) {
this.count = this.instancedMesh.count;
super.setup( builder );
} In this way, |
https://jsfiddle.net/fjqLr8nd/2/ A fiddle featuring the bug and comments.
Sounds good, I'll make the changes. |
My suggested change does not fix the issue. The problem is that you set the In other words: The size of the buffers is determined by |
Well, this can also be provoked after the first render. https://jsfiddle.net/xfmynado/1/
I have pushed a solution that works: Instead of
we can use
|
After reconsidering the issue, your first commit was actually the best solution. Do you mind reverting to it? You are right, the buffer size should be evaluated from the buffer attribute count since otherwise you can't properly "reserve" size that you want to use at a later point. Rendering once with the larger size shouldn't be required. Sorry for the back and forth. |
8781e7b
to
da544b5
Compare
Thank you.
I had to change |
instance()
.
I think we should consider this issue in the larger scope, this still does not fix similar problems that we may have related to We can check in |
Um, I'm unsure with adding dynamic resizing since that could cause developers to don't care about resizing anymore which has negative impacts on performance. At least, I think it's a good standard if developers think about maximum sizes for their app and allocate the respective size in advance to avoid reallocations whenever possible. The PR is any event an improvement and should be merged no matter how we move on. |
I agree, misuse could happen if resizing were automatic. I think that as TSL improves, The PR raises a broader issue, but we can certainly address it in later PRs. |
Definitely. For the interested reader: In |
That example looks simple enough. Here's some ideas on how
|
Bug Description
Setting
mesh.count
is currently broken in the webgl fallback. Instance matrices are not added properly.Explanation
I started with one instance, built the material and wanted to add more. They won't show up.
InstancedMesh
defines two counts.this.instanceMatrix.count
: max instance count.this.count
current instance count, may be lower than max.The attached PR defines a buffer big enough for all instances.