Shader material with instances (gl_InstanceID & Viewport)

Hello!

I have some issue during rendering mesh instances, gl_InstanceID in shader is dynamically changed depending on the camera viewport, if mesh instance is not in the viewport it does not have InstanceID.
Expected behavior is that each instance has same color regardless of camera viewport.

Hello!

Can you describe your issue a little bit more? There doesn’t seem to be anything wrong with your Playground.

Click right mouse button and pan camera so that the green cube is not in camera viewport.


Oh, thanks, now I see! gl_InstanceID refers to the index of the instance you’re rendering, not the instance total. So this is expected behavior. If you want to have different colors per instance it would be better to use an instance buffer Instances | Babylon.js Documentation