Alpha Blending fails when SeaMonkey-Water is in background

Well I think this Screenshot already describes the problem that occurs, the trees are 2D textures drawn on a Quad. The texture is loaded from a .png file and I initialize the material with:

[java]TreeMat = new Material(
Main.assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
TreeMat.setTexture(“ColorMap”,
Main.assetManager.loadTexture(“Models/Trees/tree1.png”));
TreeMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);[/java]

and on the Quad-Geometry itself I call:
[java]tree.setQueueBucket(Bucket.Transparent);[/java]

Is there anything else I’ve forgotten to set when using textures containing alpha values?

Classic alpha sorting problem. You can find about five hundred posts on a similar problem though finding specific keywords may be difficult.

Short answer is to turn on alpha discard or alphatest falloff, etc.

1 Like
@Tjong said: Well I think this Screenshot already describes the problem that occurs, the trees are 2D textures drawn on a Quad. The texture is loaded from a .png file and I initialize the material with:

[java]TreeMat = new Material(
Main.assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
TreeMat.setTexture(“ColorMap”,
Main.assetManager.loadTexture(“Models/Trees/tree1.png”));
TreeMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);[/java]

and on the Quad-Geometry itself I call:
[java]tree.setQueueBucket(Bucket.Transparent);[/java]

wow that’s so pretty!
Is there anything else I’ve forgotten to set when using textures containing alpha values?

You need to set alpha discard on the trees.

@pspeed said: Classic alpha sorting problem. You can find about five hundred posts on a similar problem though finding specific keywords may be difficult.

Short answer is to turn on alpha discard or alphatest falloff, etc.

Wow that a fast answer :slight_smile:
And thanks for the tip, a simple:
[java]TreeMat.getAdditionalRenderState().setAlphaTest(true);[/java]
fixed the Problem.

Uh no, you’ll have plenty of issues doing this.

The real fix is material.setBoolean(“AlphaDiscardThershold”,0.1f); (0.1f being an exemple).

Umm, really don’t want to question a jMe God but…

@nehon: why would you pass a float using a setBoolean?

Just wondering…

haha, use setfloat, probably nehon was thinking about enabling wich usually would be a boolean ^^

@radanz said: why would you pass a float using a setBoolean? .
Because I just woke up, and I'm a mere human :p You're right that's setFloat("AlphaDiscardThreshold", 0.1f);

uhm…
if I replace my working lines
[java]TreeMaterial.getAdditionalRenderState().setAlphaTest(true);
TreeMaterial.getAdditionalRenderState().setAlphaFallOff(0.5f);[/java]
with your line, it throws an exception:

java.lang.IllegalArgumentException: Material parameter is not defined: AlphaDiscardThreshold

Which occurs as I simply use the Unshaded Material which got no such parameter, but then next why am I running into problems with my solution?
Until now everything works quite good so far:

Alpha test is deprecated in way newer OpenGL versions or something and won’t work on Android at all. Other than that, I’m not sure what the issues are.

oh ok unshaded again…
It looks pretty good for unshaded.
Adding the discard on the unshaded material is in my todo.

Hm ok, I will just change the material to lightning anyway now or later as I plan to add a day-night cycle in the future…
Well then thanks for the answers and also great job on that engine, it really makes me not care about all that nasty graphics black magic down there and focus more on stuff which is fun to create :slight_smile: