Transparency problems

Hello guys,

I want to add a hedge to my scene. The hedge just consists of multiple leafs. Unfortunately I can’t get it done that the hedge looks as it is supposed to be (image).

I tried several things but I think there are some issues with the transparency. Sometimes you can see leafs which are on the backside of the object. If you move the camera some leafs appear and disappear. I thought is has something to do with the backface culling. I turned it on obviously.

The initial model wasn’t perfectly adjusted so I made some changes in blender. I set the blend mode to alpha blend, added the opacity texture and turned “show backface” as well as “backface culling” on.

In blender so leafs are visible through the object as well but the leafs doesn’t appear or disappear as with babylon. just put my model in sandbox so you can see what I mean.


I apprciate your help.

Transparent objects don’t write to the depth buffer and they are only sorted from back to front before being rendered. As you have only 4 big objects for your foliages and they are one over the other, sometimes the ordering of those objects change when the camera moves/rotates because the depth used for the sorting is the center of the bounding sphere.

To correct the problem in your case, for all 4 materials you should:

  • enable the “Need depth pre-pass” option
  • change the transparency mode from “Alpha Blend” to “Alpha blend and test”

With those changes, it does work for me.


Some doc:Transparency and How Meshes Are Rendered - Babylon.js Documentation

It works like a charm. Thank you!

Is it also possible to make a mesh invisible if the camera has a specific alpha, beta, radius condition? My initial thought was to check the camera values on zoom or move. Is there a way an event to track this or do I have to use scene.registerBeforeRender()?

I think you will have to track those conditions yourself, I don’t think there’s an event that can be raised for that.

I implemented a small function to my runRenderLoop(). It works great :slight_smile: