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

Oh, really. That’s so funny. It’s been 12 years I’m also running my own business and I’m thinking of getting rid of the trouble and return as an employee :slightly_smiling_face: Looks like 12 years might be kind of a limit. :thinking: Well, if so, definetely put this down for a minute, enjoy your Sunday and make ready for your fist-day on this new adventure. That would be my advise.

1 Like

Whoa, this was fun. My wife and I have done what you are thinking, and it has made our daily life easier by only online and not in physical stores anymore :slight_smile: I would recommend trying it out!

One way to do this is to render the object in a separate rtt as an opaque object but force the writing of an alpha value.

Forcing the writing of an alpha value is easy, just set material.alpha = X. Doing this will make the mesh transparent and we don’t want that (because transparent meshes are sorted and don’t write to the depth buffer). Overriding needAlphaBlending and needAlphaBlendingForMesh to return false will trick the system into making the meshes as opaque objects instead.

Then we need to blend this rtt with the scene, which is done with a custom post process.

Here is the PG:

I created an rtt the size of the screen. It would be more efficient to create a smaller RTT that only encompasses the mesh, but it’s a bit more complicated (you have to calculate bounding boxes / define the viewport with the right dimensions).

3 Likes

I didn’t expect a solution this quick, but thank you! This solution works fine for me.

I was wondering if we could achieve a similar effect using a shader? This would open up more possibilities for effects on the “bag of meshes”."

Again thank you :slight_smile:

I couldn’t find a way to make it a shader only solution, the problem being that the faces of the mesh itself should write and be tested against the depth buffer for proper rendering, but at the same time the other objects of the scene should not be affected by the z entries written by this mesh (else we would not be able to see what’s behind the mesh)…

I don’t understand the difference to my first solution - without the normals. Simple set alpha of the materials of the multi-material to 0.2 - that’s it. Why go big with shaders?

If I use an ArcRotateCamera each face has an alpha of 0.2 on both solutions.

MergeMeshes with multimaterial | Babylon.js Playground (babylonjs.com)

We should not see the other cubes by transparency, only the other objects (the plane in this case):

and not:

2 Likes

Unbeatable :mechanical_arm: I just knew you are the one man to handle this :man_superhero: :laughing:

Here is it successfully implemented into my game. Thank you :smiley:

1 Like

That ghost fx sure looks very ghosty :ghost: :grin: GJ there :+1: BtW, How is your ‘new life’ as an employee going,… 'hope it’s all good? :hand_with_index_finger_and_thumb_crossed:

I received a comment that the ghostly figure has shadows :smiley:

It’s only been two days since I started, and I have one week off for Easter. I could get used to this!

So far, my experience has been very positive both in terms of the type of work and colleagues and I hope that continues :slight_smile:

1 Like