Alpha multiplication threshold coming from nowhere


I added a global alpha factor to the unshaded material by just adding this line
(the rest of the code and material definition is just the same as the original)



but when I send values interpolated from 1.0 to 0.0 to the material, the object completely disapears below 0.5f instead of continuing the gradiant…
1.0 → 0.5 object disapears slowly
0.49 → 0.0 object invisible

the material is setup like that

material.getAdditionalRenderState().setAlphaFallOff(0.0f); // also tried different values
 |____Geometry [] loc:(0.65551037, 0.3986414, -0.45436582) rot:(0.0, 0.0, 0.0, 1.0) 
               cull:Dynamic queue:Opaque
          |____Mesh [75]
          |____Material [null] Atest:true Afoff:0.0
               |____VertexColor true
               |____GlobalAlpha (0.77, 0.0)
               |____GlowColor Color[0.0, 0.0, 1.0, 1.0]
               CTRL : mygame.effects.LighteningControl@5d795d

anything I could do wrong ?
been diggging this for a week, still cant figure it out


sounds like an alphaDiscardThreshold set to 0.5
could you try to force it to 0?

I tried to set it to different values, even commented out the threshold code
this dont make any sense to me
I though there was something wrong with the single Float parameter
so I even tried with Vector2F, still the same

I could post a project file, but it’s basicaly about adding that 1 line of code to the Unshaded material
and sending the value to the material

   /* #if defined(DISCARD_ALPHA)
        if(color.a < m_AlphaDiscardThreshold){

        gl_FragColor = color;

this is some crazy s…

I just made a test project and it works, I dont get it

[edit : I noticed the problem occurs when there is another transparent object in the scene, when the other alpha object appears in the frustum, the first alpha object disapear but the two objects are quiet far appart…]

If one is in front of the other then it might be obscuring… but especially if they are in the wrong bucket.

Did you remember to put them in the transparent bucket?

ok I finaly pinpointed the issue

setAlphaFallOff(0.1f);             changed to              setAlphaFallOff(0.5f); 

but why does one object fallof must be at least the other one fallof ??? it should be independent
they are both in transparent bucket… also if the alpha of the fading object goes wide range 0->1, its fallof should be 0

Box b = new Box(1, 1, 1);
        Geometry geom = new Geometry("Box", b);

        mat = new Material(assetManager, "MatDefs/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Blue);


        geom.setLocalTranslation(-133.64247f, 3.129125f, 63.389854f);
        Spatial model = assetManager.loadModel("Models/test.j3o");
        Spatial test = FindNode((Node)model,"Test",false);
        Spatial clonedInstance = test.clone();
        Geometry geo=getGeometry(clonedInstance);
        Material mat2=geo.getMaterial();
        Material unshadedMat = new Material(assetManager, "MatDefs/Unshaded.j3md");
        unshadedMat.setFloat("GlobalAlpha", 1.0f);
        clonedInstance.setLocalTranslation(-90.64992f, 2.9433272f, 75.212364f);
        cam.setLocation(new Vector3f(-133.64247f, 3.129125f, 63.389854f+35));

are setAlphaFallOff and setAlphaTest global settings ?

I created a test project that demonstrates the issue, maybe a bug, or something I dont understand
please enlight me, for the sake of understanding :smile:

(notice the blue fading object is sudently disapearing, but not when the test object is out of the camera fov)

they are deprecated stuff in opengl.
you should not use them and use the alpha discard threshold instead

but I am sure I read in jmonkey doc/forum suggestions to use these …
besides I thought these were related to the alpha discard threshold

That’s how it worked before there was an alpha discard threshold. But both are basically doing the same thing.
Since opengl 3 it’s deprecated so you’d better use the latter.


No. I don’t have time to run your code… maybe you could post a video showing the issue.

But if the problem happens when one object is in front of the other then they might be sorting incorrectly… especially if alpha test or alpha discard threshold is changing what you see. If a transparent object is drawn then any non-discared pixels will fill the z-buffer hiding anything drawn later behind them… even if the pixel was transparent.

will take more time for me to figure how to make and upload a video and you to watch it
feel free to do it when you got time, it’s all ready made, with correct camera position
meanwhile I removed the lines of code, and it is working fine so I am not in a hurry

both objects are aside of each other , if you turn the camera to see only the blue box, the problem disapears and comes back as soon as the other object gets back in the fov

Hmmm… step 1) add VideoRecorderAppState on a key press. 2) upload video to youtube.

Anyway, good luck with your issue.


  1. launch ide
  2. open and launch project

but if you dont feel like it, no worries
dont complain anymore people dont give source code to check out :wink:
as I said, I found a workaround

I tried to open and launch the project… but it wasn’t downloaded. So you missed a step. :wink: Besides, I already have 25 projects open in the IDE… I can’t really add another one for someone who can’t bother to show us a video. :smile:

The point of having people post code is so that we can eyeball it because 99% of the time we can spot the problem there. The only thing I can see glancing at your code that you do differently than I do is cloning the material… perhaps there is some state leakage between the clones. Otherwise, I have lots of transparent objects in my scene and never see this issue.

My time is more precious than your issue to me… so if I can’t solve it from the forum then I’ll defer to someone else. Between two kids, a wife with brain cancer, a full time+ job, and my own projects, several open source projects, and JME… I don’t really have time to download everyone’s projects to try them out. After all, I have my own bugs to solve, too.

I agree and understand 100%

so you can understand I dont have time to waste hours to figure out the right encoding to avoid a 500mb file for a 2 sec video, I really have to go forward with my game, cos it 's the only source of revenue I could have so far
and It gives me a MOUNTAIN of work :stuck_out_tongue:

If i fail this, I’ll be homeless if I cant find money cos nobody wants to hire me after 25 years of experience
like you I got issues, no job, no girl, no kids, no future, no f… perspectives on sight, but that stupid game I try to make

I’ll try to make a vid but I checked the link and it’s working fine :slight_smile:

[edit :made the video, I’ll try to convert it to swf lower size… hang on]

here it is, sorry for the low quality, but I am really a noob about making and uploading vids

Good job, you actually found a bug in the engine. Too bad alpha test was removed from 3.1 and hence its no longer relevant :chimpanzee_cool:

Let’s see if you can spot it:

if (state.getAlphaFallOff() != context.alphaTestFallOff) {
    glAlphaFunc(GL_GREATER, context.alphaTestFallOff);  
    context.alphaTestFallOff = state.getAlphaFallOff();

Yeah, this code was all kinds of broken before… but it was fixed after 3.0… before you removed it. :slight_smile: