Glow effect material problem

Ok, if you uncomment the commented line :

//if(color!=null) thismaterial.setColor(“GlowColor”,color);

Then just the first cube get the glowcolor correcty, that is what I was trying to say.

Only the first one gets its glow color set.

See… even if this turns out to be a bug in the engine, your test case is 1000% useless for testing it because it really tests 50 unrelated things.

Well, for me this test case is simple enouth, I dont think its possible to make it more simplier.
If you guys dont want to look on this bug ok, bad for the engine, what can I say.
If others come here with this same problem, sorry for they, just look for another engine, this one dont have peaple willing to help.

I described a simpler useful test case already. We cannot run the code you’ve provided so we can’t test it anyway.

One self contained class that creates three boxes, it’s own materials (not loaded from j3ms, not cloned) and sets the glow color on two of them.

Dont need to test it, it will work.
The problem relies on cloned materials, same from same j3o file, using same j3m files.
The thing is, if you dont use getparam, or, dont use glowcolor, it works.
If you use getparam + glowcolor it bugs.
The test case is just loading 2 boxes and setting the glowparam for 1 of they, absoluting nothing else.
Also, I dont know why you could not be able to run it, can you elaborate ?

So, is the issue that it’s only setting the glow on one object? Because all of your code seems to only change the glow color for one object.

Or is the issue that it’s setting it for the wrong object. This has never been clear.

The whole indexnum == 1 bit is a lot of indirection for a test case. The use of controls is also unnecessary for a test case. If cloning the materials is the issue then the use of loaded models is also unnecessary for a test case.

And I checked here and at least in 3.1 the material parameter values are actually cloned so there is nothing special going on here in JME. This makes it easy to blame all of the extra unnecessary things in your code… whether right or wrong.

Basically, the setColor() is an unnecessary no-op… as it’s just resetting the color it already had.

Because all of your code seems to only change the glow color for one object.

The code should set the glow color for one object yes. But its setting for two objects.

Well, you can eliminate all doubt about asset manager cloning by cloning the color you get from getValue()… though it should already have been cloned.

If you want to be super paranoid, then you can also log the System.identityHashCode() for the materials, values, whatever else you want to see which instances are the same or different.

Ok, to make it simplier :

package mygame;

import com.jme3.app.SimpleApplication;
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.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import static mygame.NewControl.findGeom;

public class NewClass extends SimpleApplication {

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

    public static void main(String[] args) { new NewClass().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);

        Spatial spatial1 = assetManager.loadModel("Models/someasset.j3o");
        spatial1.setLocalTranslation(1, 0, 0);
        rootNode.attachChild(spatial1);

        Spatial spatial2 = assetManager.loadModel("Models/someasset.j3o");
        spatial2.setLocalTranslation(-1, 0, 0);
        rootNode.attachChild(spatial2);

        Geometry geom1 = findGeom(spatial1, "Cube");
        Material thismaterial = geom1.getMaterial();

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


    }

    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;
    }

}

Please note that changing the line 39 to

Material thismaterial = geom1.getMaterial().clone();

Dosent work.

Also changing the line 41 to clone it dosent work :

ColorRGBA newcolor = (ColorRGBA)(thismaterial.getParam(“GlowColor”).clone().getValue());

Obs: I just fixed the position on the last test case.

ColorRGBA newcolor = (ColorRGBA)(thismaterial.getParam(“GlowColor”).getValue()).clone();

…also shouldn’t work (based on what I see in the material code) but is what I meant.

Else there is no magic here, you are just messing with values in a hashmap.

Humm…
I cant use it, clone has protected access …

error: clone() has protected access in Object

Uh… no:
@Override
public ColorRGBA clone() {

You may need more parenthesis.

ColorRGBA newcolor = ((ColorRGBA)thismaterial.getParam(“GlowColor”).getValue()).clone();

Well, now it compiles and runs, but both boxes have no glowcolor…
Funy that both the new and the old setting for the newcolor has exactly the same value for the color…

What makes me wander how the filter works… Maybe new materials/colors are not included in the filter ?

Have you tried looking at what newColor is? Like System.out.println()?

Yes, same value from the old declaration.

Read the whole topic and I have several remarks.

When you go

mat.setColor("Whatever", myColor);

on a material you assign the color reference to this material parameter.
meaning that afterward you can go

myColor.r! 0.5f;

and it will change the value in the material without an additional call to mat.setColor.

this implies several things.
for example :

ColorRGBA myColor = new ColorRGBA(whatever);

mat1.setColor("whatever", myColor);
mat2.setColor("whatever", myColor);

myColor.r = 0.5f;

In this case both material color will change.

Another thing :

ColorRGBA myColor = new ColorRGBA(whatever);

mat1.setColor("whatever", myColor);
mat2.setColor("whatever", myColor);

.....

ColorRGBA  myColor2 = (ColorRGBA) (mat2.getParam("whatever").getValue());

in that example myColor == myColor2.

Also newcolor.a = 1 has no effect on the glow color. Alpha is not taken into account anyway and I’m not sure what you think this does.

I can’t test your test case because it needs j3o resource that you didn’t provide. A simple test case also means simple enough for anybody else to run.