Fading out models independently

I have multiple models with the same material. I want them to fade in/out at different times. I’ve been using

this.meshInstances[i].setParameter("material_opacity", ... );

There is also the method of setting the material opacity and calling the material.update() function, but that results in all models with that material to change their opacity.

as seen in this tutorial:
https://playcanvas.com/project/436566/overview/fading-objects-in-and-out

It has been working fine up until recently. If you try to launch the tutorial from the editor you can also see that noting happens.

  1. Does anyone have a solution that involve independently fading out models with the same material?
  2. If I do create multiple identical materials and simply go with setting the opacity and calling the material.update(); function, will that affect performance in any way?

Hi @Grayson_Ewing,

Your code is correct. The only thing missing is letting the Playcanvas engine somehow know you require the opacity shader chunk included.

The shaders that get generated automatically to render the materials try to include only the relevant pieces depending on your maps/properties. That’s a significant performance improvement.

A common trick used is to change slightly the initial opacity of your material to be !== 1.0:

1 Like

@Leonidas this did the trick, thank you very much!

1 Like