I think the description is quite understandable: The OP wants to change the alpha value of the whole material (to achieve a fading effect). Maybe using material colors and changing the alpha value of the material colors over time could do the trick?
Thanks a lot Ogli!
I followed your suggestion and got the effect I wanted.
Here are the codes
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", assetManager.loadTexture("Textures/circle.png"));
opacity -= 0.1f;
ColorRGBA color = new ColorRGBA(1f, 1f, 1f, opacity);
mat.setColor("Color", color);
mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
tag.setMaterial(mat);
With the above method, one should not put the object into the transparent bucket. Otherwise the object will disappear completely.
Then something else is wrong… because if you leave it in the opaque bucket it won’t sort properly with the scene. The only difference between the opaque and transparent bucket is the order things are drawn.
Or do you mean disappear completely when opacity reaches 0? Then, yes, but in the opaque bucket that is also happening but you are just randomly having it sort properly to draw the background instead of the scene that’s behind it. And changing the opacity isn’t really what you want to be doing.
You don’t need to create a new material each time. Just change the alpha in the ‘color’ variable - it will change all the other stuff when rendering the next frame.
Like @pspeed said, you need to put that into the transparent (or translucent) bucket. Otherwise it will lead to visual errors in almost all scenes.
Maybe there is another stupid error in the Unshaded material (some shader error or something like that). There have been several stupid and simple bugs been detected in jME 3 lately:
Show us a screen shot of the effect so we can see how you intend for it to work.
Unshaded works fine for transparency. If you set the opacity to 0 then it will be invisible. If this is not the effect you want then you do not want opacity.
I will code a little example to test this case and report back the results.
If there is another bug then it will be detected via this.
Otherwise it will be a good example for you and you can simply copy the code.
Now is lunch time, so expect some delay until the code arrives.
Oh yes, that’s right.
The thing I want to code will contain several cubes with monkey textures which will fade from fully visible to fully invisible and back again in a 3D scene.
If that’s not what you want, then that code will not help.
You are right. I added it to guiNode. Seems it’s super easy in this case.
It’s good to know there is a difference about transparency handling between Gui Bucket and others.