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 :
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) {
}
}
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.
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).
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.
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.
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.