Visibility with node materials

Hi there!

I have a simple question:
How i can use “visibility” mesh property with node materials?

In my case I want o hide smoothly some meshes but i want to have only one material for them. I also can use scaling but for me visibility is preferable

You should pass this value to your node material as an input float, and use it to modulate the final alpha value, for eg.

1 Like

Thanks for you answer!

Yes i thought about that but it will works if i had one mesh but what if i had 2 or more meshes and they all have the same material but 1 of visibility of one them is 0.2, second 0.3, and third 1. How I can provide this data to NodeMaterial?

You will have either to clone the material so that each mesh has its own instance, or set the right value on a material.onBindObservable (the mesh is passed to the observer).

1 Like

On bind is works for me, thank you! :metal:

I was too fast…
If we use this way changing of visibility of one sphere actually changes visibility of another sphere how I can avoid this intersections?

I had try to define it but obviously I did something wrong. I think I wrong understand binding

My bad, onBindObservable is called too late in the process, the current value has already been bound to the effect…

You will have to do the binding yourself:

2 Likes

Yees, thank you again, now everything works!) :smiley:

Hi again, @Evgeni_Popov

Few more questions RE this topic. When I apply some texture in this PG it is works for sphere1,2,3 but not for fourth. Because fourth is not a mesh it is instance and material are binding to mesh not to instance. Is there is the way to do the same stuff but with instances/thinInstances?

And question about performance:
For example i have 50 meshes each with simple nodeMaterial (just texture rgb to output). And one material which added specific texture to mesh on bind using mat.getEffect().setTexture(…).

Second way looks more attractive in performance aspect but maybe some underwater rocks? What do you think about that?

Regarding your first question, no, an instance or a thin instance will use the material of its master mesh. You can’t have a different material per instance / thin instance. Actually, that’s what make instances / thin instances faster than using multiple meshes, because we can issue a single draw call to draw all the instances at once.

I’m not sure I understand your second question. If you mean that you have 50 meshes, each one using a different texture, then using 50 different materials is better than using a single material for which you change the texture on a material.onBindObservable observer. But you will consume more memory in the 50 materials case. It’s always a tradeoff!

1 Like