How to Adjust Visibility/Opacity of Visible Faces in a Mesh

I want to adjust the visibility/alpha settings of a mesh so that only the visible faces are shown with an opacity of 0.2 when using MergeMeshes and MultiMaterial.

Currently, the mesh looks the way I want it to when it’s opaque, but simply setting mesh.visibility to 0.2 doesn’t achieve the same result.

How can I accomplish this? Look at my pre-made example :slight_smile:

With the help of GPT I tried to tackle your problem. It is not a complete solution, but it points in the right direction, I think. You first need the normals to determine which of the vectors point in the direction of the camera. You would still need to determine to which object these vectors are assigned, to determine the color of the material and create a new transparent material of the same color and assign it to the facet. I don’t know if you can assign a material to a facet alone, otherwise you would have to break the objects into sub-objects. A very interesting task. Good luck with the implementation! :slight_smile:

MergeMeshes with multimaterial | Babylon.js Playground (

Hi there!

Thank you for showing interest in this issue. I have been playing around with stencils, which I have worked with before using simpler models.

However, I haven’t been able to find the correct settings for the stencil. If anyone knows the stencil settings, please take a look here:

Here is an example from playground which colors the bottom in white with the stencil function

As you can see they are using another mesh for this purpose…

Interesting approach but it doesn’t seem to work with the alpha as per the request (although I must admit I’m not sure to fully understand the request) like why do the meshes need to be merged (which obviously might create an additional level of complexity since opaque and alpha-test or blended meshes do not render simultaneously.

I think It’s useful for complex models that consist of multiple meshes. A better solution would be to wrap a shader over the ‘bag of meshes’ to achieve the desired effect, allowing us to go beyond alpha on the meshes.

An example from my game where I use alpha 0.4 (alphamode 5) with stencil function not equal (its ~15 meshes)

A better solution would be shader(material) wrapped around, so I could also use other effects.

I guess you should try call-in one of the experts or we’ll just continue ‘fiddling’ with it :grin:
May be @Evgeni_Popov for the alpha and stencil or else @PatrickRyan for his magic :magic_wand: in creating shaders and mastering complex assemblies.

It’s only a matter of time before we dilettantes figure out the right answer. :smiley:

The infinite monkey theorem states that a monkey hitting keys at random on a typewriter keyboard for an infinite amount of time will almost surely type any given text, such as the complete works of William Shakespeare.
Infinite monkey theorem - Wikipedia

I’m sure it is :student:… But as one said, “time is of the essence:hourglass_flowing_sand: :rofl:

My optimistic dilettante approach: if at first you don’t succeed, keep trying until you accidentally stumble upon the right answer :laughing:

I can see we have similar approaches :sweat_smile: How many combinations did you say?… :dizzy_face: Fair enough, just give’me a couple of years and I’ll likely get there (eventually) :joy:

Time is not the problem. Money is the problem!

If you had enough money like Google,
then you could activate enough resources
to solve all the problems of the world
in record time…

Looks like you spotted me :grin: Obviously, I’m no Google; neither in terms of resources :money_mouth_face: nor anything :face_with_hand_over_mouth: But you know what, I’m still happy with my condition. I just need to better scope what I can achieve and where I would likely need a hand :pleading_face: :wink: Probably one of the reasons why I luv this forum and you Guys; Money isn’t just everything :hugs:

I gave chatGPT a run on the issue and it cheated by overriding children materials, Google Bard didn’t like to code :expressionless:

Yeah, looks like our small brains :brain: still have a bit of time before this thing outsmarts us :relieved: :grin: Lucky We, we won’t loose our job just right now :crossed_fingers: But better keep an eye on it :face_with_monocle:

I still have half a cup of coffee and have been thinking a bit more about the problem. What do you think of the idea of blending? Just put a plane over the object and use the blending to mix the pixels to achieve a ghost effect?

blending | Babylon.js Playground (

BabylonJS Documentation (

I can’t imagine handling this in a game. And the plane won’t work with character meshes (or any other shapes). I think a shader might be the only way to go (but then again, I’m sure no specialist of that)

I do not see that as a working solution for me. As Mawa writes, I think a better solution would be a shader that wraps around the meshes without overriding their materials, so we can effectively add alpha and other effects to meshes. However, I do not know how to accomplish this.

I asked ChatGPT to create a shader, but although it made the shader correctly, it did not work on the child meshes.

I’d say wait until tomorrow. Let the experts kick-in and meanwhile move on with something else, or even better, take your sunday off and enjoy some free-time. I’m (quite) sure the solution will come to you beginning of the week. Meanwhile, take care and have a great day :sunglasses:

Yeah, that’s my strategy :slight_smile:

When I get stuck on an issue let it rest for sometime before I try again and ask for guidance.

It’s funny that you say that about free-time, because I have been self-employed-consultant for the last 12 years and I am starting my first permanent job tomorrow! So, I probably won’t be able to go mountain biking in the middle of the day anymore :slight_smile:

1 Like