Instanced Mesh Alternating Textures

I have an instanced mesh of box buffer geometries and I have a texture that I want to apply to some of the instances but not the other. I am following this example as a template:

I am using a MeshPhongMaterial and passing the texture in the map attribute. On the geometry, I have defined an InstancedBufferAttribute called type (0 - no texture, 1 - texture). Do I have to patch MeshPhongMaterial or write my own shader to be able to do this? Can someone give me some pointers or how I can simplify the problem, I don’t want to replace the MeshPhongMaterial functionality.

gl_FragColor = vec4( outgoingLight, diffuseColor.a );

1 Like