Already posted this into THREEJS discord server, so just gonna copy it here:
You can open this sandbox code: sandbox code
In the sandboxe code, IdMaterial is a material that should act as an identifier for objects from canvas. When you assign it to an object, nothing happens by default, but you can add an object to material through the use of addObjectGroup.
When object is added it is automatically assigned a drawing id which should get converted to color in shader such as:
Problem arises with instanced Meshes, because I would like to also be able to add a single instance from instancedMesh to this IdMaterial. Everything runs well, but InstancedBufferAttribute seems to not send data to shader. You can see this in my vertex shader where I assign color manually to objects as RED if their id is 0, otherwise BLUE. As you can see Blue objects are Object3D’s and Red ones are single instances I added.
Any insight would be helpful.
Keep mind that this is a really minified version of a much bigger project, but this bug appears in both of them eventually resulting in shader not receiving data from instancedBufferAttribute that was set on CPU.