question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

InstancedBufferGeometry not updated properly between render calls

See original GitHub issue

When you use InstancedBufferGeometry without using InstancedMesh, your geometry attributes are not updated properly. Here’s the culprit:

https://github.com/mrdoob/three.js/blob/0d7fb8d74f3c4d4e465b5a92ada65e1c789708e1/src/renderers/webgl/WebGLBindingStates.js#L50

Part of the fix would be to check the geometry and not the object. That is if the geometry.isInstancedBufferGeometry instead of checking for InstancedMesh specifically.

Frankly, looking in the binding states implementation - I’m puzzled by the fact that version of the attribute is never checked against the cache, it basically says “oh, look, it’s the same object reference, no update needed”. Or I’m missing something.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Mugen87commented, Nov 16, 2021

Since InstancedGeometryBuffer is updated as expected I think it’s okay to close the issue.

1reaction
Usnulcommented, Nov 16, 2021

I’m afraid that’s not true. WebGLShadowMap does use WebGLObjects. WebGLObjects also does not increase the frame counter. This is done in WebGLRenderer.render():

You’re absolutely right, I guess I’m the first person to have a use-case to modify geometry while assembling a single frame.

For the case of shadow map in three.js - geometry is assumed to remain the same, which is a perfectly valid assumption.

In case anyone’s interested, the reason why it matters for me - is because of the virtual geometry, that is, depending on the view geometry might be drastically simplified, so shadowmaps and the main view may render drastically different number of triangles for the same mesh, depending on the shadowmap resolution, size of the object in the view and a few other factors.

Read more comments on GitHub >

github_iconTop Results From Across the Web

can't get a Three.js InstancedBufferGeometry to appear in a ...
When using InstancedBufferGeometry , you can't create a mesh with ... innerHeight, 0.1, 1000); camera.position.z = 100; scene = new THREE.
Read more >
InstancedMesh from GLTF doesn't work?! - Questions
Hi, InstancedMesh ([1] in code) doesn't work when geometry loaded from GLTF - is this ... InstancedBufferGeometry was the first API for instanced...
Read more >
Instancing with three.js — Part 2 | by Dusan Bosnjak
Notice two things — the number is much smaller than the number of entities created in the demo (2000) and it changes between...
Read more >
Fluffy predator with THREE.js & instanced geometry
Working with instances is slightly different from using regular meshes. ... //creates an instancedBufferGeometry var geometry = new THREE.
Read more >
how to use InstancedBufferGeometry with threejs-three.js
js shape from a series of contours? Broken lights with the normal map shader · Why are new lines added to THREE.Line not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found