Glow effect material problem

I am trying to use shadders to make diferent effects for each spatial I have in scene (all loaded from the same j3o), they suppose to have different behavior for each spatial material, like, for one space ship turns red the other turns blue.
I tried to get the material from the spatial, and change it, but when I do it, all other objects get changed as well, so I did :

    Geometry geomGreenparts = Utils.findGeom(spatial, "Greenparts");
    Geometry geomDome       = Utils.findGeom(spatial, "Dome");
    Geometry geomBorders    = Utils.findGeom(spatial, "Borders");
    m_greenparts = geomGreenparts.getMaterial().clone();
    m_dome       = geomDome.getMaterial().clone();
    m_borders    = geomBorders.getMaterial().clone();
    geomGreenparts.setMaterial(m_greenparts);
    geomDome.setMaterial(m_dome);
    geomBorders.setMaterial(m_borders); 

For some reason, it didnt work, I got the same result as the clone is not actually cloning anything…
Any tips ?

I am not sure why, but it seens the problem is releted with glowcolor, follow the test case :
Obs: only the first object should show glow effect, but both are showing glow.

  package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.asset.AssetManager;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.post.filters.BloomFilter;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;

public class Main extends SimpleApplication {

    DirectionalLight sun = new DirectionalLight();
    Spatial spatial1,spatial2;
    Material mat1,mat2;

    public static void main(String[] args) { new Main().start(); }

    @Override public void simpleInitApp() {
        FilterPostProcessor fpp=new FilterPostProcessor(assetManager);
        BloomFilter bloom = new BloomFilter(BloomFilter.GlowMode.Objects);
        fpp.addFilter(bloom);
        viewPort.addProcessor(fpp);

        // Sun Light
        sun.setDirection(new Vector3f(1,0,-2).normalize());
        sun.setColor(ColorRGBA.White.mult(0.6f));
        rootNode.addLight(sun);

        Node onwerNode = new Node();
        rootNode.attachChild(onwerNode);

        new NewControl(ColorRGBA.Blue, assetManager, onwerNode, new Vector3f(1, 0, 0));
        new NewControl(null, assetManager, onwerNode, new Vector3f(-1, 0, 0));

    }

    @Override public void simpleUpdate(float tpf) {

    }
}

control code :

package mygame;

import com.jme3.asset.AssetManager;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.AbstractControl;
import com.jme3.scene.control.Control;
import java.io.IOException;

public class NewControl extends AbstractControl {

    private static int indexnum = 0;

    ColorRGBA color;
    AssetManager assetManager;

    Material thismaterial;

    public NewControl(ColorRGBA color, AssetManager assetManager, Node ownerNode, Vector3f position) {
        this.color=color;
        this.assetManager=assetManager;
        indexnum=indexnum+1;

        spatial = assetManager.loadModel("Models/triangle/triangle.j3o");
        spatial.setLocalTranslation(position);

        ownerNode.attachChild(spatial);

        Geometry geom1 = findGeom(spatial, "Dome");
        thismaterial = geom1.getMaterial();
        spatial.addControl(this);

        if(indexnum==1) {
            ColorRGBA newcolor = (ColorRGBA)(thismaterial.getParam("GlowColor").getValue());
            newcolor.a=1; thismaterial.setColor("GlowColor",newcolor);
        }
    }

    @Override protected void controlUpdate(float tpf) {
        //if(color!=null) thismaterial.setColor("GlowColor",color);
    }

    public static  Geometry findGeom(Spatial spatial, String name) {
        if (spatial instanceof Node) {
            Node node = (Node) spatial;
            for (int i = 0; i < node.getQuantity(); i++) {
                Spatial child = node.getChild(i);
                Geometry result = findGeom(child, name);
                if (result != null) return result;
            }
        } else if (spatial instanceof Geometry)
            if (spatial.getName().startsWith(name)) return (Geometry) spatial;
        return null;
    }

    @Override protected void controlRender(RenderManager rm, ViewPort vp) { }

}

For me, it seens thismaterial.getParam is getting the wrong value ( from cache maybe ? ).

How do you know it’s getting the wrong value? We can’t see that part.

If I do :
ColorRGBA newcolor = (ColorRGBA)(thismaterial.getParam(“GlowColor”).getValue());
It gets value from diferent material then this :
ColorRGBA newcolor = (ColorRGBA)(thismaterial.getParam(“Color”).getValue());
I dont know why this is happening, also its an guess.
It seens to be an bug envolving GlowColor filter and getParam, I posted an test case, please ignore the color param in the constructor, its not beeing used.

Well, the posted code never sets the glow color… so I don’t know where any color value is coming from anyway.

The code is setting the glowcolor :

ColorRGBA newcolor = (ColorRGBA)(thismaterial.getParam(“GlowColor”).getValue());
newcolor.a=1; thismaterial.setColor(“GlowColor”,newcolor);

The problem here is that it setts for all spatials in the scene not only for this one.

Please note the if :

if(indexnum==1) { …

Except the glow color that you are getting was set where?

Was it loaded from the material? Like the color value specified in the .j3m and therefore not cloned when you clone the material (since the parameter values are not cloned).

The values from the last j3m I have tested was this :

Unshaded.j3md
GlowColor : red : 1.0 , green : 1.0 , blue 0,0 , alpha : 0.0
Color 1,1,1,1

I have also tested with lighting.j3md, same result.

Retrieves the Color value shared by all other cloned materials.

Changes a field of that color shared by all of the other cloned materials.

…will therefore change all of the other cloned materials.

Since I don’t know what you are testing for. What you saw different, etc… then I can only go by your three or four levels of conclusions that got you here… but by definition if this problem has you stumped then you’ve made some incorrect assumptions somewhere.

I also tried to clone the material, same result.
Please note that if you try to do the same using the “COLOR” parameter it works, the problem is in the “GLOWCOLOR”.
In the test case, there is an comment line testing the color parameter, its working and setting the color for only the first spatial.
Anyway, if you know any workarround to make this first object to have glowcolor but the second continue to have alpha 0, I would like to know.

What you saw different, etc…

Obs: only the first object should show glow effect, but both are showing glow.

You should simplify your test case to have two or three cubes that you create materials for and set their glow colors to different values (or the same value) to eliminate all of the other variables. In the 99% chance case that it works just fine you can backtrack from there.

Just to add, my suspect from a bug on the getParam is because if I dont use it, it works :
Please note the commented line :

thismaterial.setColor(“GlowColor”,color);

What do you mean ?
I tried to make it very simple…
Please note that there is only 2 cubes in the scene…
And I am setting the glowcollor alpha in only 1 of they …

Simple… but you are cloning materials (THAT WILL SHARE THE SAME COLOR VALUES) and stuff.

By changing the value on the material, you are changing the value for all of the cloned materials because the color is not cloned.

Repeating myself for like the fifth time, the colors are not cloned so you are setting the fields on the same instance. Is that the culprit? Hard to say… because the test case is doing half a dozen things that are not directly related to “do glow colors work for multiple objects?” Yes, they should… your problem is likely elsewhere.

Write a SIMPLE test as described that works.

…you know what… good luck with this issue, I’ve exceeded my repeat threshold. Someone else can probably be more helpful now.

Can you explain why if I uncomment the commented line it dosent happens and only the first material is setted ???

What doesn’t happen?

The problem is not does not isn’t almost not didn’t work working?

Be specific please.

Look, I already give up of this effect in my game and moved on, I am just trying to help as well.
For me its an serius bug, I pray to be wrong.

Bottom line: I’m not helping anymore until you write the simple test I suggested.

Hopefully others have more patience than I do… mine is at a premium right now.

The bug is in your code, I think. A simpler test case without all of the cloning and shared values would probably sort it out.