How to apply 2 lightmap for two different objects that share same material

I’m using Collada with three.js to apply lightmap to objects that share the same material,
it keep giving the objects the last lightmap.

for (var k = 0; k < AllChildren.length; k++) {
    var ChildID = AllChildren[k].id
    if (AllChildren[k].geometries.length > 0) {
        materialTarget = AllChildren[k].geometries[0].instance_material[0].target;
        matEffectsTarget = collada.dae.materials[materialTarget].instance_effect.url
        var MatCopy = colladar.dae.effects[matEffectsTarget];
        MatCopy.lightMap = THREE.ImageUtils.loadTexture(ObjectsIDAndLightMaps[ChildID]);
	    MatCopy.shader.material.lightMap = THREE.ImageUtils.loadTexture(ObjectsIDAndLightMaps[ChildID]);

    }
}

is it even allowed to have multiobjects shared material each with its lightmap ?
ANYHELP ?

1 Like

No. You need separate materials for each lightmap. Even if you would use .onBeforeRender() to change the material, the uniforms of the underlying shader program are not updated. Also have a look at [r54] I'd like a way to override material diffuse (color) from the mesh level. · Issue #2916 · mrdoob/three.js · GitHub

Thank it worked,
But if i have scene state to change the material it would change to original material, how to deal with this?

I’m afraid i don’t understand. Can you explain your problem a little bit more please?

Sure,
I have 2 objects share one material and i have material animation,
the problem is when i run the animation only one objects material change .

how to deal with this?

Maybe this example helps you: https://threejs.org/examples/misc_animation_groups.html

All cubes share the same material. The internal animation system of three.js animates now the material properties color and opacity. As you can see, all cubes are affected by this animation.

In your case i assume that the objects actually don’t share the same material.

1 Like

Hm. Maybe you can share the dynamic uniforms between the materials?

1 Like