HighlightLayer with alpha material has problem

I add sphere as highlighLayerMesh and exclude ground.
why is this effect?
PG:

When the sphere has no alpha,it is different.
PG:

The behavior depends on the order the sphere and the ground are rendered.

In your second PG, the sphere is rendered first, so you get this rendering:
image

If the sphere is rendered after the ground as in this PG (I have simply moved the creation of the ground material before the creation of the sphere material, as the meshes are sorted according to their material id):

Then you get:

image

That’s also the rendering you get when enabling alpha for the sphere, because in that case the sphere is drawn in a later stage (with the transparent meshes) and the ground is rendered first.

This is inherent to the technique and there is not much to do, except to make sure that the meshes are rendered in the right order. In the case of the alpha sphere, you can force the ground to be rendered at a later stage by setting ground.renderingGroupId=1:

2 Likes

Yes, you won’t get any better explanation than those from my ‘hero’ evgeni :man_superhero: :smile:

However, I think I can add a little something to it. :grinning:
Say you don’t want to use the fancy ‘renderingGroupID’ because it will mess-up your scene.

Since alpha meshes are rendered together at a later stage, you can make your occlusion/opaque mesh an alpha blended mesh.

Multiple ways to make the mesh render as alpha blended, I.E.
With a texture, simply add '*Texture.hasAlpha = true;".
Without a texture, simply set the material’s .alpha to something like ‘mat.alpha = 0.9999’;

1 Like

Indeed, but it’s a bit of a performance loss to define a material as transparent if it isn’t, because the blend pass is more resource intensive than the opaque pass. Also, you won’t get the benefit of the depth buffer in this case and you may get rendering artifacts.

I stand corrected, however, the sphere in @Aze’s first PG doesn’t go into the transparent queue but into the alpha test queue instead. This still means that the sphere is rendered after the opaque meshes, but the depth buffer is updated for the alpha tested meshes, which is why you don’t get artifacts in your PG @mawa. If you set alpha=0.999 on the grass material, you will see that you get artifacts that cannot be corrected, because the depth buffer is no longer updated.

Good to know thank you.
As for the performance impact, it’s undeniable but then, in some cases, having to deal with renderingGroupID against a small loss of performance is… well, a choice :grin:

Indeed :slight_smile: