UI Mask Pixelated

Hi there,

I’m trying to make a progress bar. I’m using a mask because we want it to have round corners.

Structure looks like this:
image

And the settings on my mask are the following:
image

In game it looks like this:
image

As you can see it is very pixelated, how can I solve this?

Sadly I think you can’t do anything about that with the current masking implementation. Masking elements will use the alpha of the texture provided but only using 1-bit values (masked or not), fading isn’t supported.

Masks and Masking
Image Elements can be used to mask or hide elements that are descendents. To enable this feature set the mask property of an image Element to true.

If there is no texture asset assigned to an image Element used for masking the mask will be a rectangle defined by the width and height. If the image Element has a texture assigned the alpha-channel of the texture is used as the mask. Note, an image mask is 1-bit, i.e. there is no fading out of the mask using the alpha-channel of the texture.

https://developer.playcanvas.com/en/user-manual/user-interface/image-elements/

You could disable masking and try using multiple overlapping elements in place with both textures having alpha. Much like the UI progress bar example does:

https://developer.playcanvas.com/en/tutorials/ui-elements-progress/

Hmm ok, thanks for your answer Leonidas. I’ll try to find another way without masks then.

1 Like

Adding @will and @vaios for reference, in case this is a feature that can be added at some point.

Okay instead of using an image as a mask, I now use a rectangle and I tween its width instead of the Progress entity’s position.

The result is not exactly what I wanted but pretty close:
image

1 Like

I found an easier workaround to this.

UI Images can have a custom material assigned to them (they support a Texture, Sprite, or Material). So you can just create a new material for the UI & set the Opacity Texture of that material to be the shape you want the image to be masked as, and it works very smooth.

See the results here: https://github.com/playcanvas/engine/issues/2083

2 Likes