[SOLVED] Transparent textures, alpha covers alpha problems

I recently built a landscape myself. Now I wanted to represent a cursor. The cursor is a 1x2x1 self-made box with transparent textures. I’m using
mat2.getAdditionalRenderState (). setBlendMode (BlendMode.Alpha);
and
triGeometry.setQueueBucket (Bucket.Transparent);
.

Actually works great:
image

But if I turn around 180 grains, something unexpected happens to me, the transparent side covers the rear transparent side.
image

Has something wrong with the order?

How do I do it right?

Mesh:

public class JaReCursor1P {

	/**
	 * Indexe doppelseitig.
	 */
	short[] indexbuffer = new short[] { //
			0, 1, 2, 0, 2, 1, // AB
			3, 1, 2, 3, 2, 1, // AB
			2, 3, 4, 2, 4, 3, // BC
			5, 3, 4, 5, 4, 3, // BC
			4, 5, 6, 4, 6, 5, // CD
			7, 5, 6, 7, 6, 5, // CD
			6, 7, 0, 6, 0, 7, // DA
			1, 7, 0, 1, 0, 7, // DA
	};

	/**
	 * Punkte A,B,C,D.
	 */
	float[] vertexbuffer = new float[] { //
			-0.48f, 0, -0.48f, // 0 // A low
			-0.48f, 2, -0.48f, // 1 // A hight
			0.48f, 0, -0.48f, // 2 // B low
			0.48f, 2, -0.48f, // 3 // B hight
			0.48f, 0, 0.48f, // 4 // C low
			0.48f, 2, 0.48f, // 5 // C hight
			-0.48f, 0, 0.48f, // 6 // D low
			-0.48f, 2, 0.48f, // 7 // D hight
	};
	/**
	 * Texturkoordinaten.
	 */
	float[] texCoord = new float[] { //
			0.0f, 0.0f, // A
			0.0f, 1.0f, // A
			1.0f, 0.0f, // B
			1.0f, 1.0f, // B
			0.0f, 0.0f, // C
			0.0f, 1.0f, // C
			1.0f, 0.0f, // D
			1.0f, 1.0f, // D
	};

	public Mesh createMesh( ) {
		final Mesh triMesh = new Mesh();
		triMesh.setMode(Mesh.Mode.Triangles);
		triMesh.setDynamic();
		triMesh.setBuffer(VertexBuffer.Type.Position, 3, vertexbuffer);
		triMesh.setBuffer(VertexBuffer.Type.TexCoord, 2, texCoord);
		triMesh.setBuffer(VertexBuffer.Type.Index, 1, indexbuffer);
		triMesh.updateBound();
		return triMesh;
	}
}

This is a common limitation in rendering transparent meshes.
The quickest solution for your use case is to set the AlphaDiscardThreshold in your material

Some background: Alpha/Transparency Sorting, Your Z-buffer, and You

1 Like

tried it out quickly:
mat2.setFloat ("AlphaDiscardThreshold", 0.5f);
Now my Corsor is transparent from all sides. Why did I use 0.5f? Programming by copying, I know.

But if I understand Paul correctly, the problem is simply in the order of the indexbuffer. Tidying up here is probably the neater solution.

Thank you very much Paul, I actually saw this link but didn’t really understand it. Sometimes I unfortunately have to make mistakes first in order to understand the contents of the documentation at all.

If you have inner faces and outer faces in a convex shape then you can sort the inner faces ahead of the outer faces and avoid this problem. If it’s not convex or there are no separate inner faces then reordering the vertexes will only work from a particular angle.

Alpha discard threshold will set the alpha level below which the fragment will be discarded and not even written to the zbuffer. Usually 0.1 is a good value as most of the time we want 0 or close to 0 alpha to not even write anything to the buffers at all. 0.5 would be too high if all of your good alpha is already below 0.5.

Yeah, that’s very often true. It can be useful to have some kind of system to keep track or remember the “info that was nonsense” for when we need it later.

…of course, trying to figure out what that system is for me is why I have 5000 book marks in my browser. :slight_smile: The forum search can be good if you hit the right keywords.

yes, if I always knew the CORRECT KEYWORDS :slight_smile:

Hardly is it done right and suddenly it works.
Thank you so much

short[] indexbuffer = new short[] { //
			0, 2, 1, 3, 1, 2, // AB inner
			2, 4, 3, 5, 3, 4, // BC inner
			4, 6, 5, 7, 5, 6, // CD inner
			6, 0, 7, 1, 7, 0, // DA inner
			0, 1, 2, 3, 2, 1, // AB outer
			2, 3, 4, 5, 4, 3, // BC outer
			4, 5, 6, 7, 6, 5, // CD outer
			6, 7, 0, 1, 0, 7, // DA outer
	};
1 Like

It is the really nice thing about convex hulls that this works.

One of my very very earliest experiences with real OpenGL on actual hardware was sorting out this problem to make something like the scene of the “gibson” in the movie Hackers. Back in 2002 or so.

https://youtu.be/vYNnPx8fZBs?t=20 (note: t=20 for what I’m talking about)

All of my experience prior to that had been home-grown software renderers to it was a crash course in alpha transparency. Ah the days of the fixed function pipeline…

1 Like