Use array of material(Same material) on InstancedMesh and change some material later to change the behaviour with light (Not to get and cast shadow)

Hi Community,

So, I’m trying to create an InstancedMesh by giving array of materials. Size of array is same as size of InstancedMesh. There is no texture visible on canvas it is just transparent with no errors.

The agenda behind this to keep these instanced solar panels in a way that I can turn off shadow properties for some when sun is below them to stop casting shadow (They cast on themselves).

        let maxPossiblePanels = 100; // Count of panels
        let materialArray = [];

        for (let i = 0; i < maxPossiblePanels; i++) {
            let m = new MeshStandardMaterial({
                map: this.panelTexture.clone(),
                side: DoubleSide,
                transparent: false,
            });
            m.color = new Color(0xffff00);
            materialArray.push(m);
        }


        let panelInstanceMesh = new InstancedMesh(panelGeom, materialArray, maxPossiblePanels); //Making count sufficiently large to accommodate single panels
        InstancedMeshUtil.init(panelInstanceMesh);
        InstancedMeshUtil.setPanelShader(panelInstanceMesh);
        panelInstanceMesh.name = meshTypeEnum.panelArray;
        (panelInstanceMesh.userData as MeshUserData).meshtype = meshTypeEnum.instancedMesh;
        (panelInstanceMesh.userData as MeshUserData).maxInstanceCount = panelInstanceMesh.count;

        panelsUserdataArray.forEach((p,i)=>{
          panelInstanceMesh.setMatrixAt( i, p.matrix as Matrix4);
        //   panelInstanceMesh.setColorAt( i, new Color(0xffffff));
          p.instanceId = i;
        });


What am I doing wrong. Is even my approach correct or it’s not doable. We tried writing dynamic shader but that didn’t work and more complicated.

InstancedMesh cannot draw a different material for each instance, and a single draw call cannot have more than 8–32 textures (depends on device). If you have more unique textures than you can afford in unique draw calls, then I think you might need to combine them (texture atlas or texture array) and then use a custom, shared ShaderMaterial to offset into the right texture for each instance based on instance ID or instance attributes.