Hello,
I’m using textured quads on top of a TerrainQuad and I’d like these textured quads to have translucency (through PNG alpha channel). Everything works fine, my textured quads use the following material:
[java]
Material mat = new Material(game.getAssetManager(), “Common/MatDefs/Light/Lighting.j3md”);
// set DiffuseMap, NormalMap, Shininess
mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
// both of these are necessary to let shadows cast through transparency
mat.getAdditionalRenderState().setAlphaTest(true);
mat.getAdditionalRenderState().setAlphaFallOff(0.8f);
[/java]
Geometry that use this material are later added to the correct bucket:
[java]road.setQueueBucket(Bucket.Transparent);[/java]
And my TerrainQuad uses the following material (two layers of alpha for the two layers of splat textures):
[java]
Material material = new Material(assetManager, “Common/MatDefs/Terrain/TerrainLighting.j3md”);
// red alpha: grass
{
Texture texture = assetManager.loadTexture(“Textures/Terrain/NovaSplat/grass.jpg”);
texture.setWrap(WrapMode.Repeat); // necessary to improve terrain quality
material.setTexture(“DiffuseMap”, // surface color
texture);
material.setFloat(“DiffuseMap_0_scale”, 8f); // doesn’t seem to do anything at the moment
}
// green alpha: dirt
{
Texture texture = assetManager.loadTexture("Textures/Terrain/NovaSplat/dirt.jpg");
texture.setWrap(WrapMode.Repeat); // necessary to improve terrain quality
material.setTexture("DiffuseMap_1", // surface color
texture);
material.setFloat("DiffuseMap_1_scale", 8f); // doesn't seem to do anything at the moment
}
// do not load normal map for terrain to prevent the error
// "ERROR: 0:606: error(#202) No matching overloaded function found calculateNormal" in Common/MatDefs/Terrain/TerrainLighting.frag
material.setFloat("Shininess", 1f); // surface smoothness [1,128]
[/java]
However, I’ve noticed that when I remove and insert the TerrainQuad (to modify it, for example), the alpha textures flicker for a frame before displaying correctly. That is, they flicker like so:
As far as I can tell it’s got something to do with:
[java]mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);[/java]
If I disable the blend mode, then there isn’t any flickering at all - but of course, there is then no translucency.
I don’t think it’s got anything to do with the order of (removing, adding) the terrain - if I add the new terrain node before removing the old one, it still flickers. If you look carefully, it almost looks like the background colour (black) is seeping in through the translucency - so this might be a hack fix.
I’m not sure how the rendering engine works. Are there two passes for calculating translucency values? Is there any way to tell the engine to “skip” rendering a frame to screen so that it can render it correctly on the second pass? Will the recent change (r9768) in reintroducing alphaDiscardThreshold help?
(Sorry about the images, I can’t work out the formatting on this forum.)