Is it possible to fadeIn or fadeOut the opacity with a group of entity?

Thanks @steven, very helpful! I’m now fading on the mesh-instaces instead of the materials.

Ok, I ran into a problem related to this.

I’m trying to fade out an object that has a material with an opacity texture mappen onto it. It’s a plane, with a graphic like an arrow to clip the shape of the plane to an arrow, like so:

I can’t seem to fade it with the technique describe above, but as soon as I remove the opacity mask on the material I can once again fade it. Feature? Bug?


We are looking into this and we think the behaviour is deliberate as an optimisation for the shader when the intensity is set to 1. To get round this, set the intensity to 0.99 (which is what I had to do in the hotspots sample).

Set initial opacity intensity to 0.999, shader is optimised if opacity is 1.0 and does not includes chunk to multiply by intensity.

Thanks both for clarifying again, that did the trick

1 Like

Hi again

I’ve come back to this since now I’m trying to fade out an object that has an opacity mask from the start. The mask is purely black and white to define cut-outs in the surface. Now, my code to fade it out does not work anymore. If I programmatically remove the opacity mask or set it to null, the fade out works again. Is there a way around it or is that a limitation?

Regards

  • Björn

Please provide isolated example.

What blending type you have on it?

Sure, I’ll fork something and isolate it. I have an opacity map and blending mode is set to alpha in the editor. But then programmatically i go through all meshes and set the mode to normal:

    for (i = 0; i < this.meshes.length; i++) {
        this.meshes[i].material.blendType = pc.BLEND_NORMAL;
    }

BLEND_NORMAL - is “Alpha” blend. But you perhaps want try Premultiplied Alpha.

Ah ok. I tried that quickly but it made no difference. For some reason I cannot fork this project either (nothing happens when I press the fork button in that dialouge where I put down the new name and owner). I invited you to the original instead if you dare.

So I’ve checked quickly, and forgot that actually, most parameters you change on material, including opacity have no immediate effect. Material needs to be “updated”.

I’ve played with Base entity, and did this to it’s material that has to fade:
material.setParameter('material_opacity', 0.5);
And it did changed opacity. Additionally, ensure that initial opacity is not 1.0, because if it is, then it will not include opacity uniform into shader, set it to something like 0.999, or ensure you call update() on material if you change from 1.0 to non 1.0.

Thanks for having a look. However, I’m not sure I’m following. The script which I’ve used up until now does not call update on the material after each change. But it does work without doing so.

However, when it comes to the case where the material has an opacity map, the fade script does not fade it anymore.

Even if you do this:

material.opacity = 0.5;
material.update();

And have Alpha (Normal) blend on it?