Instanced Geometry with Multi-Material BufferGeometry?

I’m creating an Instanced Buffer Geometry as per the example

The only difference between my BoxBufferGeometry and the example, is that my mesh (for the boxbuffer geometry) uses multiple materials, and so I’m a little confused how to set up my mesh and/or raw shader rendering the different materials on each instance.

A picture is worth a thousand words - here’s my problem:


The box in the center is my original - the clones don’t look the same - my box is using different materials - and I’m using the shaders from the dynamic example

fragment shader:

precision highp float;
uniform sampler2D map;
varying vec2 vUv;
void main() {
gl_FragColor = texture2D( map, vUv );

vertex shader

precision highp float;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
attribute vec3 position;
attribute vec3 offset;
attribute vec2 uv;
attribute vec4 orientation;
varying vec2 vUv;
void main() {
vec3 vPosition = position;
vec3 vcV = cross(, vPosition );
vPosition = vcV * ( 2.0 * orientation.w ) + ( cross(, vcV ) * 2.0 + vPosition );
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4( offset + vPosition, 1.0 );

I dont think this can be done. You will probably end up having 6 different instanced geometries for each face of the box.

I did manage in the end - I use a mesh with six materials - all the materials share the same vertex shader, but each a different fragment shader, then I do the light color / light calculations in the fragment shader…