[Solved] Bug: GlowLayer going through the mesh with transparency?

Hello!
I had a job for this issue, but after hours of debugging I think there might be a bug?

I have a scene with emissive, opacity and a glowLayer.
For this post though, I have one body piece which contains transparency and a head piece which contains no transparency.
The issue is the glow layer appearing through the opaque part of the mesh as soon as I add transparency.
Maybe related, if I apply the same texture/material on a mesh with no transparency, the glowLayer appears stronger (still appears through the mesh though).

The glow layer appearing through the head:
image

In red, the transparent area, and in blue, arrows showing the difference in glowLayer intensity.
image

Repro:

In the repro above, you can see two issues:

  • You can see the glowLayer appearing through the mesh of the head; (The head has no transparency)
  • You can see the glowLayer is not as bright and not as strong on the body as soon as a part of the mesh is transparent.

While investigating the second issue, I noted the glowLayer in the body piece almost looked “behind” the mesh
image

Things I’ve tried:

  • needDepthPrepass
  • renderingGroupId = 0 on Glowlayer and 1 on the meshes

@labris suggested I use a different texture for the transparent meshes but that’s not an option given we’ll be having hundreds on these meshes and we’re assuming their names are unknown.

I have a feeling this is a bug, but I could also just be dumb. Any thoughts?

Textures would be the same, materials would be different, one with transparency from albedoTexture and one without - https://www.babylonjs-playground.com/#0IV1SL#59
But yes, if you have hundreds of non-tagged assets it could be a problem.

Dealing with transparency is always a problem because meshes don’t write to the depth buffer…

In your case, you could try to create a specific material that is used to render the mesh in the glow layer and have this material write to the depth buffer (by simply using a material without alpha blending). The idea is to use the same material as the source material but only with the emissive texture / color part. So, all other textures should be removed and the material should use the unlit mode:

1 Like

Thanks, that’s a pretty good hack for our use case