Transparency in Android

I have noticed that transparency seems to be off on android. The object is indeed transparent but it covers up object behind it as you see in the image I attached. On my mac it works perfectly and dont have these issues.

Here is the current code i am using:

[java] public void setupLavendar() {
tmp = app.getAssetManager().loadModel(“Models/Levels/Forest/lv1/lv1_lavendar.j3o”);
tmp.setName(“lavendar”);

    Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", app.getAssetManager().loadTexture("Textures/lavendar.png"));
    mat.getAdditionalRenderState().setAlphaFallOff(0.4f);
    mat.getAdditionalRenderState().setAlphaTest(true);
    mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
    mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
    tmp.setQueueBucket(Bucket.Translucent);
    tmp.setMaterial(mat);

    brushNode.attachChild(tmp);
} [/java]

I think the foliage in front of the boat is writing to the z buffer even where it is transparent…then the boat isn’t being drawn in those sections since the z is in front of the boat’s position.

You need to get alpha discard working on that foliage.

(Look at where the “holes” in the boat are, they all match up to where you have something sticking up in front of it).

You need to get alpha discard working on that foliage

Is this something that can be done in blender or through jmonkey? I model the plants with plans and alpha .png textures. I converted the blender file directyl to a .jmo file.

Just to let you know it is a mini golf coarse not a boat XD I haven’t got the texture for the coarse yet.

oh just realized it is a material parameter is for the Lighting.j3md.
I am using Unshaded.j3md which doesn’t have this variable.

Try getAdditionalRenderState - there are a couple of alpha discard settings in there.

erf yeah you would need the alphaDiscardThreshold of lighting material but on unshaded.
I don’t know how comfortable you are with shaders, but i would recommend making your own unshaded. It’s pretty simple you just have to fetch the color from the texture and if the alpha value is below the threshod, discard the pixel (look how it’s done in the lighting material).

The reason it works on mac is because mat.getAdditionalRenderState().setAlphaFallOff(0.4f); use a native opengl setting that is deprecated in opengl3 and does not exists at all on opengles (on mobile).

Presumably shader nodes will fix this by just allowing you to add an “alpha discard” node to the end?

Im not to confortable with shaders but it will give me an excuse to learn them better. It would definitely be a good way to learn how to shader nodes system.

Thanks for the help

@zarch said: Presumably shader nodes will fix this by just allowing you to add an "alpha discard" node to the end?
exactly

coming back on this issue, we talked about it, and you shouldn’t have the issue.even if the discard is not there…

In what bucket is the pink thing in the background?

All the transparency alpha stuff (plants, leaves on the trees, etc) is in the Translucent bucket that is optimized by the GeometryBatchFactory and added to the rootNode . The ground, pink thing, tree trunks rocks, mushrooms are attached to the rootNode. I am not sure what bucket the root is but I never changed it. It has the default setting.

Try changing
[java] tmp.setQueueBucket(Bucket.Translucent);[/java]
to
[java] tmp.setQueueBucket(Bucket.Transparent);[/java]
in your code snippet in the original post

Ok so i switched to Bucket.Transparent

It solved the original issue but now my transparent objects are block themselves. The purple flowers and grass are made from planes with a grass image on it.

Blender File of the grass

Android Using Bucket.Transparent (Outline in red when the plane is block what is behind it)

Desktop what should it look like

Thanks in advance

mhh… so it works on desktop and not on android…
I would need a test case to look deeper into it.

This looks like classic Z sorting transparency problem to me. Try turning off depth write for the material. Since unshaded doesn’t have an alpha discard, this may be your only option without modifying the shader.

Edit: Note: this is just to prove it’s the issue… as it will cause other problems since transparent things will look like they are in front of each other when they aren’t, etc…

So turning off the depth write for the material works but solid objects are written ontop of the plants like you stated. I guess this proves the issue.

uh…actually this seems wrong… this means your golf court (aka the “pink thingy”) is rendered after the transparent objects…which shouldn’t happen

In what bucket is the golf court? do you use several viewports?

I think maybe we need to finally add an alphaDiscard setting to unshaded. I won’t have time until next weekend at the earliest.

To answer your question nehon the golf court is in the default buck when creating the spatial. It uses the TangentBinormalGenerator for normal mapping if that means anything. I noticed that it is added to the rootNode after the plants/flowers and is maybe why it is drawn ontop the the plants. I am also only using one viewport.

@funbox said: I noticed that it is added to the rootNode after the plants/flowers and is maybe why it is drawn ontop the the plants. I am also only using one viewport.
Nope the rendering order is independent to the order the objects are added to the scene graph. if the golf court is in the opaque bucket and the plants are in the transparent bucket it should work.

Anyway the discard threshold on the unshaded material should do the trick. You can override it yourself for now.